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 | |
Roshan Pius | e73a506 | 2016-12-12 08:53:34 -0800 | [diff] [blame] | 17 | #ifndef WIFI_LEGACY_HAL_H_ |
| 18 | #define WIFI_LEGACY_HAL_H_ |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 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 | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 24 | #include <wifi_system/interface_tool.h> |
| 25 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace wifi { |
| 29 | namespace V1_0 { |
| 30 | namespace implementation { |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 31 | // This is in a separate namespace to prevent typename conflicts between |
| 32 | // the legacy HAL types and the HIDL interface types. |
| 33 | namespace legacy_hal { |
| 34 | // Wrap all the types defined inside the legacy HAL header files inside this |
| 35 | // namespace. |
| 36 | #include <hardware_legacy/wifi_hal.h> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 37 | |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 38 | // APF capabilities supported by the iface. |
| 39 | struct PacketFilterCapabilities { |
| 40 | uint32_t version; |
| 41 | uint32_t max_len; |
| 42 | }; |
| 43 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 44 | // WARNING: We don't care about the variable sized members of either |
| 45 | // |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma |
| 46 | // to escape the compiler warnings regarding this. |
| 47 | #pragma GCC diagnostic push |
| 48 | #pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end" |
| 49 | // The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in |
| 50 | // |wifi_radio_stat| structure in the legacy HAL API. Separate that out |
| 51 | // into a separate return element to avoid passing pointers around. |
| 52 | struct LinkLayerStats { |
| 53 | wifi_iface_stat iface; |
| 54 | wifi_radio_stat radio; |
| 55 | std::vector<uint32_t> radio_tx_time_per_levels; |
| 56 | }; |
| 57 | #pragma GCC diagnostic pop |
| 58 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 59 | // The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and |
| 60 | // |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided |
| 61 | // as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL |
| 62 | // API. Separate that out into a separate return elements to avoid passing |
| 63 | // pointers around. |
| 64 | struct WakeReasonStats { |
| 65 | WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt; |
| 66 | std::vector<uint32_t> cmd_event_wake_cnt; |
| 67 | std::vector<uint32_t> driver_fw_local_wake_cnt; |
| 68 | }; |
| 69 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 70 | // NAN response and event callbacks struct. |
| 71 | struct NanCallbackHandlers { |
| 72 | // NotifyResponse invoked to notify the status of the Request. |
| 73 | std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response; |
| 74 | // Various event callbacks. |
| 75 | std::function<void(const NanPublishTerminatedInd&)> |
| 76 | on_event_publish_terminated; |
| 77 | std::function<void(const NanMatchInd&)> on_event_match; |
| 78 | std::function<void(const NanMatchExpiredInd&)> on_event_match_expired; |
| 79 | std::function<void(const NanSubscribeTerminatedInd&)> |
| 80 | on_event_subscribe_terminated; |
| 81 | std::function<void(const NanFollowupInd&)> on_event_followup; |
| 82 | std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event; |
| 83 | std::function<void(const NanDisabledInd&)> on_event_disabled; |
| 84 | std::function<void(const NanTCAInd&)> on_event_tca; |
| 85 | std::function<void(const NanBeaconSdfPayloadInd&)> |
| 86 | on_event_beacon_sdf_payload; |
| 87 | std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request; |
| 88 | std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm; |
| 89 | std::function<void(const NanDataPathEndInd&)> on_event_data_path_end; |
| 90 | std::function<void(const NanTransmitFollowupInd&)> |
| 91 | on_event_transmit_follow_up; |
| 92 | }; |
| 93 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 94 | // Full scan results contain IE info and are hence passed by reference, to |
| 95 | // preserve the variable length array member |ie_data|. Callee must not retain |
| 96 | // the pointer. |
| 97 | using on_gscan_full_result_callback = |
| 98 | std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>; |
| 99 | // These scan results don't contain any IE info, so no need to pass by |
| 100 | // reference. |
| 101 | using on_gscan_results_callback = std::function<void( |
| 102 | wifi_request_id, const std::vector<wifi_cached_scan_results>&)>; |
| 103 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 104 | // Invoked when the rssi value breaches the thresholds set. |
| 105 | using on_rssi_threshold_breached_callback = |
| 106 | std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>; |
| 107 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 108 | // Callback for RTT range request results. |
| 109 | // Rtt results contain IE info and are hence passed by reference, to |
| 110 | // preserve the |LCI| and |LCR| pointers. Callee must not retain |
| 111 | // the pointer. |
| 112 | using on_rtt_results_callback = std::function<void( |
| 113 | wifi_request_id, const std::vector<const wifi_rtt_result*>&)>; |
| 114 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 115 | // Callback for ring buffer data. |
| 116 | using on_ring_buffer_data_callback = |
| 117 | std::function<void(const std::string&, |
| 118 | const std::vector<uint8_t>&, |
| 119 | const wifi_ring_buffer_status&)>; |
| 120 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 121 | // Callback for alerts. |
| 122 | using on_error_alert_callback = |
| 123 | std::function<void(int32_t, const std::vector<uint8_t>&)>; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Class that encapsulates all legacy HAL interactions. |
| 126 | * This class manages the lifetime of the event loop thread used by legacy HAL. |
| 127 | */ |
| 128 | class WifiLegacyHal { |
| 129 | public: |
| 130 | WifiLegacyHal(); |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 131 | // Names to use for the different types of iface. |
| 132 | std::string getApIfaceName(); |
| 133 | std::string getNanIfaceName(); |
| 134 | std::string getP2pIfaceName(); |
| 135 | std::string getStaIfaceName(); |
| 136 | |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 137 | // Initialize the legacy HAL function table. |
| 138 | wifi_error initialize(); |
| 139 | // Start the legacy HAL and the event looper thread. |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 140 | wifi_error start(); |
| 141 | // Deinitialize the legacy HAL and stop the event looper thread. |
| 142 | wifi_error stop(const std::function<void()>& on_complete_callback); |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 143 | // Wrappers for all the functions in the legacy HAL function table. |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 144 | std::pair<wifi_error, std::string> getDriverVersion(); |
| 145 | std::pair<wifi_error, std::string> getFirmwareVersion(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 146 | std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(); |
| 147 | std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 148 | std::pair<wifi_error, uint32_t> getSupportedFeatureSet(); |
| 149 | // APF functions. |
| 150 | std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(); |
| 151 | wifi_error setPacketFilter(const std::vector<uint8_t>& program); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 152 | // Gscan functions. |
| 153 | std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(); |
| 154 | // These API's provides a simplified interface over the legacy Gscan API's: |
| 155 | // a) All scan events from the legacy HAL API other than the |
| 156 | // |WIFI_SCAN_FAILED| are treated as notification of results. |
| 157 | // This method then retrieves the cached scan results from the legacy |
| 158 | // HAL API and triggers the externally provided |on_results_user_callback| |
| 159 | // on success. |
| 160 | // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results |
| 161 | // triggers the externally provided |on_failure_user_callback|. |
| 162 | // c) Full scan result event triggers the externally provided |
| 163 | // |on_full_result_user_callback|. |
| 164 | wifi_error startGscan( |
| 165 | wifi_request_id id, |
| 166 | const wifi_scan_cmd_params& params, |
| 167 | const std::function<void(wifi_request_id)>& on_failure_callback, |
| 168 | const on_gscan_results_callback& on_results_callback, |
| 169 | const on_gscan_full_result_callback& on_full_result_callback); |
| 170 | wifi_error stopGscan(wifi_request_id id); |
| 171 | std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForGscan( |
| 172 | wifi_band band); |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 173 | // Link layer stats functions. |
| 174 | wifi_error enableLinkLayerStats(bool debug); |
| 175 | wifi_error disableLinkLayerStats(); |
| 176 | std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(); |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 177 | // RSSI monitor functions. |
| 178 | wifi_error startRssiMonitoring(wifi_request_id id, |
| 179 | int8_t max_rssi, |
| 180 | int8_t min_rssi, |
| 181 | const on_rssi_threshold_breached_callback& |
| 182 | on_threshold_breached_callback); |
| 183 | wifi_error stopRssiMonitoring(wifi_request_id id); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 184 | std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 185 | wifi_error configureRoaming(const wifi_roaming_config& config); |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 186 | wifi_error enableFirmwareRoaming(fw_roaming_state_t state); |
| 187 | wifi_error configureNdOffload(bool enable); |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame^] | 188 | wifi_error startSendingOffloadedPacket( |
| 189 | uint32_t cmd_id, |
| 190 | const std::vector<uint8_t>& ip_packet_data, |
| 191 | const std::array<uint8_t, 6>& src_address, |
| 192 | const std::array<uint8_t, 6>& dst_address, |
| 193 | uint32_t period_in_ms); |
| 194 | wifi_error stopSendingOffloadedPacket(uint32_t cmd_id); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 195 | // Logger/debug functions. |
| 196 | std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(); |
| 197 | wifi_error startPktFateMonitoring(); |
| 198 | std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(); |
| 199 | std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(); |
| 200 | std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(); |
| 201 | wifi_error registerRingBufferCallbackHandler( |
| 202 | const on_ring_buffer_data_callback& on_data_callback); |
Roshan Pius | adc87cb | 2016-12-14 18:02:56 -0800 | [diff] [blame] | 203 | wifi_error deregisterRingBufferCallbackHandler(); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 204 | std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> |
| 205 | getRingBuffersStatus(); |
| 206 | wifi_error startRingBufferLogging(const std::string& ring_name, |
| 207 | uint32_t verbose_level, |
| 208 | uint32_t max_interval_sec, |
| 209 | uint32_t min_data_size); |
| 210 | wifi_error getRingBufferData(const std::string& ring_name); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 211 | wifi_error registerErrorAlertCallbackHandler( |
| 212 | const on_error_alert_callback& on_alert_callback); |
| 213 | wifi_error deregisterErrorAlertCallbackHandler(); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 214 | // RTT functions. |
| 215 | wifi_error startRttRangeRequest( |
| 216 | wifi_request_id id, |
| 217 | const std::vector<wifi_rtt_config>& rtt_configs, |
| 218 | const on_rtt_results_callback& on_results_callback); |
| 219 | wifi_error cancelRttRangeRequest( |
| 220 | wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs); |
| 221 | std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(); |
| 222 | std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(); |
| 223 | wifi_error enableRttResponder(wifi_request_id id, |
| 224 | const wifi_channel_info& channel_hint, |
| 225 | uint32_t max_duration_secs, |
| 226 | const wifi_rtt_responder& info); |
| 227 | wifi_error disableRttResponder(wifi_request_id id); |
| 228 | wifi_error setRttLci(wifi_request_id id, const wifi_lci_information& info); |
| 229 | wifi_error setRttLcr(wifi_request_id id, const wifi_lcr_information& info); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 230 | // NAN functions. |
| 231 | wifi_error nanRegisterCallbackHandlers(const NanCallbackHandlers& callbacks); |
| 232 | wifi_error nanEnableRequest(transaction_id id, const NanEnableRequest& msg); |
| 233 | wifi_error nanDisableRequest(transaction_id id); |
| 234 | wifi_error nanPublishRequest(transaction_id id, const NanPublishRequest& msg); |
| 235 | wifi_error nanPublishCancelRequest(transaction_id id, |
| 236 | const NanPublishCancelRequest& msg); |
| 237 | wifi_error nanSubscribeRequest(transaction_id id, |
| 238 | const NanSubscribeRequest& msg); |
| 239 | wifi_error nanSubscribeCancelRequest(transaction_id id, |
| 240 | const NanSubscribeCancelRequest& msg); |
| 241 | wifi_error nanTransmitFollowupRequest(transaction_id id, |
| 242 | const NanTransmitFollowupRequest& msg); |
| 243 | wifi_error nanStatsRequest(transaction_id id, const NanStatsRequest& msg); |
| 244 | wifi_error nanConfigRequest(transaction_id id, const NanConfigRequest& msg); |
| 245 | wifi_error nanTcaRequest(transaction_id id, const NanTCARequest& msg); |
| 246 | wifi_error nanBeaconSdfPayloadRequest(transaction_id id, |
| 247 | const NanBeaconSdfPayloadRequest& msg); |
| 248 | std::pair<wifi_error, NanVersion> nanGetVersion(); |
| 249 | wifi_error nanGetCapabilities(transaction_id id); |
| 250 | wifi_error nanDataInterfaceCreate(transaction_id id, |
| 251 | const std::string& iface_name); |
| 252 | wifi_error nanDataInterfaceDelete(transaction_id id, |
| 253 | const std::string& iface_name); |
| 254 | wifi_error nanDataRequestInitiator(transaction_id id, |
| 255 | const NanDataPathInitiatorRequest& msg); |
| 256 | wifi_error nanDataIndicationResponse( |
| 257 | transaction_id id, const NanDataPathIndicationResponse& msg); |
| 258 | wifi_error nanDataEnd(transaction_id id, const NanDataPathEndRequest& msg); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 259 | |
| 260 | private: |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 261 | // Retrieve the interface handle to be used for the "wlan" interface. |
| 262 | wifi_error retrieveWlanInterfaceHandle(); |
| 263 | // Run the legacy HAL event loop thread. |
| 264 | void runEventLoop(); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 265 | // Retrieve the cached gscan results to pass the results back to the external |
| 266 | // callbacks. |
| 267 | std::pair<wifi_error, std::vector<wifi_cached_scan_results>> |
| 268 | getGscanCachedResults(); |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 269 | void invalidate(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 270 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 271 | // Global function table of legacy HAL. |
| 272 | wifi_hal_fn global_func_table_; |
| 273 | // Opaque handle to be used for all global operations. |
| 274 | wifi_handle global_handle_; |
| 275 | // Opaque handle to be used for all wlan0 interface specific operations. |
| 276 | wifi_interface_handle wlan_interface_handle_; |
| 277 | // Flag to indicate if we have initiated the cleanup of legacy HAL. |
| 278 | bool awaiting_event_loop_termination_; |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 279 | // Flag to indicate if the legacy HAL has been started. |
| 280 | bool is_started_; |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 281 | wifi_system::InterfaceTool iface_tool_; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 284 | } // namespace legacy_hal |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 285 | } // namespace implementation |
| 286 | } // namespace V1_0 |
| 287 | } // namespace wifi |
| 288 | } // namespace hardware |
| 289 | } // namespace android |
| 290 | |
Roshan Pius | e73a506 | 2016-12-12 08:53:34 -0800 | [diff] [blame] | 291 | #endif // WIFI_LEGACY_HAL_H_ |