Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef WIFI_LEGACY_WIFI_HAL_H_ |
| 18 | #define WIFI_LEGACY_WIFI_HAL_H_ |
| 19 | |
| 20 | #include <functional> |
| 21 | #include <thread> |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 22 | #include <vector> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 23 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
| 27 | namespace V1_0 { |
| 28 | namespace implementation { |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 29 | // This is in a separate namespace to prevent typename conflicts between |
| 30 | // the legacy HAL types and the HIDL interface types. |
| 31 | namespace legacy_hal { |
| 32 | // Wrap all the types defined inside the legacy HAL header files inside this |
| 33 | // namespace. |
| 34 | #include <hardware_legacy/wifi_hal.h> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 35 | |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 36 | // APF capabilities supported by the iface. |
| 37 | struct PacketFilterCapabilities { |
| 38 | uint32_t version; |
| 39 | uint32_t max_len; |
| 40 | }; |
| 41 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame^] | 42 | // WARNING: We don't care about the variable sized members of either |
| 43 | // |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma |
| 44 | // to escape the compiler warnings regarding this. |
| 45 | #pragma GCC diagnostic push |
| 46 | #pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end" |
| 47 | // The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in |
| 48 | // |wifi_radio_stat| structure in the legacy HAL API. Separate that out |
| 49 | // into a separate return element to avoid passing pointers around. |
| 50 | struct LinkLayerStats { |
| 51 | wifi_iface_stat iface; |
| 52 | wifi_radio_stat radio; |
| 53 | std::vector<uint32_t> radio_tx_time_per_levels; |
| 54 | }; |
| 55 | #pragma GCC diagnostic pop |
| 56 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 57 | // Full scan results contain IE info and are hence passed by reference, to |
| 58 | // preserve the variable length array member |ie_data|. Callee must not retain |
| 59 | // the pointer. |
| 60 | using on_gscan_full_result_callback = |
| 61 | std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>; |
| 62 | // These scan results don't contain any IE info, so no need to pass by |
| 63 | // reference. |
| 64 | using on_gscan_results_callback = std::function<void( |
| 65 | wifi_request_id, const std::vector<wifi_cached_scan_results>&)>; |
| 66 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Class that encapsulates all legacy HAL interactions. |
| 69 | * This class manages the lifetime of the event loop thread used by legacy HAL. |
| 70 | */ |
| 71 | class WifiLegacyHal { |
| 72 | public: |
| 73 | WifiLegacyHal(); |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 74 | // Names to use for the different types of iface. |
| 75 | std::string getApIfaceName(); |
| 76 | std::string getNanIfaceName(); |
| 77 | std::string getP2pIfaceName(); |
| 78 | std::string getStaIfaceName(); |
| 79 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 80 | // Initialize the legacy HAL and start the event looper thread. |
| 81 | wifi_error start(); |
| 82 | // Deinitialize the legacy HAL and stop the event looper thread. |
| 83 | wifi_error stop(const std::function<void()>& on_complete_callback); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 84 | // Wrappers for all the functions in the legacy HAL function table. |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 85 | std::pair<wifi_error, std::string> getDriverVersion(); |
| 86 | std::pair<wifi_error, std::string> getFirmwareVersion(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 87 | std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(); |
| 88 | std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 89 | std::pair<wifi_error, uint32_t> getSupportedFeatureSet(); |
| 90 | // APF functions. |
| 91 | std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(); |
| 92 | wifi_error setPacketFilter(const std::vector<uint8_t>& program); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 93 | // Gscan functions. |
| 94 | std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(); |
| 95 | // These API's provides a simplified interface over the legacy Gscan API's: |
| 96 | // a) All scan events from the legacy HAL API other than the |
| 97 | // |WIFI_SCAN_FAILED| are treated as notification of results. |
| 98 | // This method then retrieves the cached scan results from the legacy |
| 99 | // HAL API and triggers the externally provided |on_results_user_callback| |
| 100 | // on success. |
| 101 | // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results |
| 102 | // triggers the externally provided |on_failure_user_callback|. |
| 103 | // c) Full scan result event triggers the externally provided |
| 104 | // |on_full_result_user_callback|. |
| 105 | wifi_error startGscan( |
| 106 | wifi_request_id id, |
| 107 | const wifi_scan_cmd_params& params, |
| 108 | const std::function<void(wifi_request_id)>& on_failure_callback, |
| 109 | const on_gscan_results_callback& on_results_callback, |
| 110 | const on_gscan_full_result_callback& on_full_result_callback); |
| 111 | wifi_error stopGscan(wifi_request_id id); |
| 112 | std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForGscan( |
| 113 | wifi_band band); |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame^] | 114 | // Link layer stats functions. |
| 115 | wifi_error enableLinkLayerStats(bool debug); |
| 116 | wifi_error disableLinkLayerStats(); |
| 117 | std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 118 | |
| 119 | private: |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 120 | // Retrieve the interface handle to be used for the "wlan" interface. |
| 121 | wifi_error retrieveWlanInterfaceHandle(); |
| 122 | // Run the legacy HAL event loop thread. |
| 123 | void runEventLoop(); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 124 | // Retrieve the cached gscan results to pass the results back to the external |
| 125 | // callbacks. |
| 126 | std::pair<wifi_error, std::vector<wifi_cached_scan_results>> |
| 127 | getGscanCachedResults(); |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 128 | void invalidate(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 129 | |
| 130 | // Event loop thread used by legacy HAL. |
| 131 | std::thread event_loop_thread_; |
| 132 | // Global function table of legacy HAL. |
| 133 | wifi_hal_fn global_func_table_; |
| 134 | // Opaque handle to be used for all global operations. |
| 135 | wifi_handle global_handle_; |
| 136 | // Opaque handle to be used for all wlan0 interface specific operations. |
| 137 | wifi_interface_handle wlan_interface_handle_; |
| 138 | // Flag to indicate if we have initiated the cleanup of legacy HAL. |
| 139 | bool awaiting_event_loop_termination_; |
| 140 | }; |
| 141 | |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 142 | } // namespace legacy_hal |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 143 | } // namespace implementation |
| 144 | } // namespace V1_0 |
| 145 | } // namespace wifi |
| 146 | } // namespace hardware |
| 147 | } // namespace android |
| 148 | |
| 149 | #endif // WIFI_LEGACY_WIFI_HAL_H_ |