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 | #include <array> |
| 18 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 19 | #include <android-base/logging.h> |
| 20 | #include <cutils/properties.h> |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 21 | #include <wifi_system/interface_tool.h> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 22 | |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 23 | #include "wifi_legacy_hal.h" |
| 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace wifi { |
| 28 | namespace V1_0 { |
| 29 | namespace implementation { |
| 30 | namespace legacy_hal { |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 31 | // Constants ported over from the legacy HAL calling code |
| 32 | // (com_android_server_wifi_WifiNative.cpp). This will all be thrown |
| 33 | // away when this shim layer is replaced by the real vendor |
| 34 | // implementation. |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 35 | static constexpr uint32_t kMaxVersionStringLength = 256; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 36 | static constexpr uint32_t kMaxCachedGscanResults = 64; |
| 37 | static constexpr uint32_t kMaxGscanFrequenciesForBand = 64; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 38 | static constexpr uint32_t kLinkLayerStatsDataMpduSizeThreshold = 128; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 39 | static constexpr uint32_t kMaxWakeReasonStatsArraySize = 32; |
| 40 | static constexpr uint32_t kMaxRingBuffers = 10; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 41 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 42 | // Legacy HAL functions accept "C" style function pointers, so use global |
| 43 | // functions to pass to the legacy HAL function and store the corresponding |
| 44 | // std::function methods to be invoked. |
| 45 | // Callback to be invoked once |stop| is complete. |
| 46 | std::function<void(wifi_handle handle)> on_stop_complete_internal_callback; |
| 47 | void onStopComplete(wifi_handle handle) { |
| 48 | if (on_stop_complete_internal_callback) { |
| 49 | on_stop_complete_internal_callback(handle); |
| 50 | } |
| 51 | } |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 52 | |
| 53 | // Callback to be invoked for driver dump. |
| 54 | std::function<void(char*, int)> on_driver_memory_dump_internal_callback; |
| 55 | void onDriverMemoryDump(char* buffer, int buffer_size) { |
| 56 | if (on_driver_memory_dump_internal_callback) { |
| 57 | on_driver_memory_dump_internal_callback(buffer, buffer_size); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Callback to be invoked for firmware dump. |
| 62 | std::function<void(char*, int)> on_firmware_memory_dump_internal_callback; |
| 63 | void onFirmwareMemoryDump(char* buffer, int buffer_size) { |
| 64 | if (on_firmware_memory_dump_internal_callback) { |
| 65 | on_firmware_memory_dump_internal_callback(buffer, buffer_size); |
| 66 | } |
| 67 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 68 | |
| 69 | // Callback to be invoked for Gscan events. |
| 70 | std::function<void(wifi_request_id, wifi_scan_event)> |
| 71 | on_gscan_event_internal_callback; |
| 72 | void onGscanEvent(wifi_request_id id, wifi_scan_event event) { |
| 73 | if (on_gscan_event_internal_callback) { |
| 74 | on_gscan_event_internal_callback(id, event); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Callback to be invoked for Gscan full results. |
| 79 | std::function<void(wifi_request_id, wifi_scan_result*, uint32_t)> |
| 80 | on_gscan_full_result_internal_callback; |
| 81 | void onGscanFullResult(wifi_request_id id, |
| 82 | wifi_scan_result* result, |
| 83 | uint32_t buckets_scanned) { |
| 84 | if (on_gscan_full_result_internal_callback) { |
| 85 | on_gscan_full_result_internal_callback(id, result, buckets_scanned); |
| 86 | } |
| 87 | } |
| 88 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 89 | // Callback to be invoked for link layer stats results. |
| 90 | std::function<void((wifi_request_id, wifi_iface_stat*, int, wifi_radio_stat*))> |
| 91 | on_link_layer_stats_result_internal_callback; |
| 92 | void onLinkLayerStatsDataResult(wifi_request_id id, |
| 93 | wifi_iface_stat* iface_stat, |
| 94 | int num_radios, |
| 95 | wifi_radio_stat* radio_stat) { |
| 96 | if (on_link_layer_stats_result_internal_callback) { |
| 97 | on_link_layer_stats_result_internal_callback( |
| 98 | id, iface_stat, num_radios, radio_stat); |
| 99 | } |
| 100 | } |
| 101 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 102 | // Callback to be invoked for ring buffer data indication. |
| 103 | std::function<void(char*, char*, int, wifi_ring_buffer_status*)> |
| 104 | on_ring_buffer_data_internal_callback; |
| 105 | void onRingBufferData(char* ring_name, |
| 106 | char* buffer, |
| 107 | int buffer_size, |
| 108 | wifi_ring_buffer_status* status) { |
| 109 | if (on_ring_buffer_data_internal_callback) { |
| 110 | on_ring_buffer_data_internal_callback( |
| 111 | ring_name, buffer, buffer_size, status); |
| 112 | } |
| 113 | } |
| 114 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 115 | // Callback to be invoked for rtt results results. |
| 116 | std::function<void( |
| 117 | wifi_request_id, unsigned num_results, wifi_rtt_result* rtt_results[])> |
| 118 | on_rtt_results_internal_callback; |
| 119 | void onRttResults(wifi_request_id id, |
| 120 | unsigned num_results, |
| 121 | wifi_rtt_result* rtt_results[]) { |
| 122 | if (on_rtt_results_internal_callback) { |
| 123 | on_rtt_results_internal_callback(id, num_results, rtt_results); |
| 124 | } |
| 125 | } |
| 126 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 127 | // Callbacks for the various NAN operations. |
| 128 | // NOTE: These have very little conversions to perform before invoking the user |
| 129 | // callbacks. |
| 130 | // So, handle all of them here directly to avoid adding an unnecessary layer. |
| 131 | std::function<void(transaction_id, const NanResponseMsg&)> |
| 132 | on_nan_notify_response_user_callback; |
| 133 | void onNanNotifyResponse(transaction_id id, NanResponseMsg* msg) { |
| 134 | if (on_nan_notify_response_user_callback && msg) { |
| 135 | on_nan_notify_response_user_callback(id, *msg); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | std::function<void(const NanPublishTerminatedInd&)> |
| 140 | on_nan_event_publish_terminated_user_callback; |
| 141 | void onNanEventPublishTerminated(NanPublishTerminatedInd* event) { |
| 142 | if (on_nan_event_publish_terminated_user_callback && event) { |
| 143 | on_nan_event_publish_terminated_user_callback(*event); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | std::function<void(const NanMatchInd&)> on_nan_event_match_user_callback; |
| 148 | void onNanEventMatch(NanMatchInd* event) { |
| 149 | if (on_nan_event_match_user_callback && event) { |
| 150 | on_nan_event_match_user_callback(*event); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | std::function<void(const NanMatchExpiredInd&)> |
| 155 | on_nan_event_match_expired_user_callback; |
| 156 | void onNanEventMatchExpired(NanMatchExpiredInd* event) { |
| 157 | if (on_nan_event_match_expired_user_callback && event) { |
| 158 | on_nan_event_match_expired_user_callback(*event); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | std::function<void(const NanSubscribeTerminatedInd&)> |
| 163 | on_nan_event_subscribe_terminated_user_callback; |
| 164 | void onNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) { |
| 165 | if (on_nan_event_subscribe_terminated_user_callback && event) { |
| 166 | on_nan_event_subscribe_terminated_user_callback(*event); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | std::function<void(const NanFollowupInd&)> on_nan_event_followup_user_callback; |
| 171 | void onNanEventFollowup(NanFollowupInd* event) { |
| 172 | if (on_nan_event_followup_user_callback && event) { |
| 173 | on_nan_event_followup_user_callback(*event); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | std::function<void(const NanDiscEngEventInd&)> |
| 178 | on_nan_event_disc_eng_event_user_callback; |
| 179 | void onNanEventDiscEngEvent(NanDiscEngEventInd* event) { |
| 180 | if (on_nan_event_disc_eng_event_user_callback && event) { |
| 181 | on_nan_event_disc_eng_event_user_callback(*event); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | std::function<void(const NanDisabledInd&)> on_nan_event_disabled_user_callback; |
| 186 | void onNanEventDisabled(NanDisabledInd* event) { |
| 187 | if (on_nan_event_disabled_user_callback && event) { |
| 188 | on_nan_event_disabled_user_callback(*event); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | std::function<void(const NanTCAInd&)> on_nan_event_tca_user_callback; |
| 193 | void onNanEventTca(NanTCAInd* event) { |
| 194 | if (on_nan_event_tca_user_callback && event) { |
| 195 | on_nan_event_tca_user_callback(*event); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | std::function<void(const NanBeaconSdfPayloadInd&)> |
| 200 | on_nan_event_beacon_sdf_payload_user_callback; |
| 201 | void onNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) { |
| 202 | if (on_nan_event_beacon_sdf_payload_user_callback && event) { |
| 203 | on_nan_event_beacon_sdf_payload_user_callback(*event); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | std::function<void(const NanDataPathRequestInd&)> |
| 208 | on_nan_event_data_path_request_user_callback; |
| 209 | void onNanEventDataPathRequest(NanDataPathRequestInd* event) { |
| 210 | if (on_nan_event_data_path_request_user_callback && event) { |
| 211 | on_nan_event_data_path_request_user_callback(*event); |
| 212 | } |
| 213 | } |
| 214 | std::function<void(const NanDataPathConfirmInd&)> |
| 215 | on_nan_event_data_path_confirm_user_callback; |
| 216 | void onNanEventDataPathConfirm(NanDataPathConfirmInd* event) { |
| 217 | if (on_nan_event_data_path_confirm_user_callback && event) { |
| 218 | on_nan_event_data_path_confirm_user_callback(*event); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | std::function<void(const NanDataPathEndInd&)> |
| 223 | on_nan_event_data_path_end_user_callback; |
| 224 | void onNanEventDataPathEnd(NanDataPathEndInd* event) { |
| 225 | if (on_nan_event_data_path_end_user_callback && event) { |
| 226 | on_nan_event_data_path_end_user_callback(*event); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | std::function<void(const NanTransmitFollowupInd&)> |
| 231 | on_nan_event_transmit_follow_up_user_callback; |
| 232 | void onNanEventTransmitFollowUp(NanTransmitFollowupInd* event) { |
| 233 | if (on_nan_event_transmit_follow_up_user_callback && event) { |
| 234 | on_nan_event_transmit_follow_up_user_callback(*event); |
| 235 | } |
| 236 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 237 | // End of the free-standing "C" style callbacks. |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 238 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 239 | WifiLegacyHal::WifiLegacyHal() |
| 240 | : global_handle_(nullptr), |
| 241 | wlan_interface_handle_(nullptr), |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 242 | awaiting_event_loop_termination_(false) {} |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 243 | |
| 244 | wifi_error WifiLegacyHal::start() { |
| 245 | // Ensure that we're starting in a good state. |
| 246 | CHECK(!global_handle_ && !wlan_interface_handle_ && |
| 247 | !awaiting_event_loop_termination_); |
| 248 | |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 249 | android::wifi_system::InterfaceTool if_tool; |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 250 | // TODO: Add back the HAL Tool if we need to. All we need from the HAL tool |
| 251 | // for now is this function call which we can directly call. |
| 252 | wifi_error status = init_wifi_vendor_hal_func_table(&global_func_table_); |
| 253 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 254 | LOG(ERROR) << "Failed to initialize legacy hal function table"; |
| 255 | return WIFI_ERROR_UNKNOWN; |
| 256 | } |
| 257 | if (!if_tool.SetWifiUpState(true)) { |
| 258 | LOG(ERROR) << "Failed to set WiFi interface up"; |
| 259 | return WIFI_ERROR_UNKNOWN; |
| 260 | } |
| 261 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 262 | LOG(INFO) << "Starting legacy HAL"; |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 263 | status = global_func_table_.wifi_initialize(&global_handle_); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 264 | if (status != WIFI_SUCCESS || !global_handle_) { |
| 265 | LOG(ERROR) << "Failed to retrieve global handle"; |
| 266 | return status; |
| 267 | } |
| 268 | event_loop_thread_ = std::thread(&WifiLegacyHal::runEventLoop, this); |
| 269 | status = retrieveWlanInterfaceHandle(); |
| 270 | if (status != WIFI_SUCCESS || !wlan_interface_handle_) { |
| 271 | LOG(ERROR) << "Failed to retrieve wlan interface handle"; |
| 272 | return status; |
| 273 | } |
| 274 | LOG(VERBOSE) << "Legacy HAL start complete"; |
| 275 | return WIFI_SUCCESS; |
| 276 | } |
| 277 | |
| 278 | wifi_error WifiLegacyHal::stop( |
| 279 | const std::function<void()>& on_stop_complete_user_callback) { |
| 280 | LOG(INFO) << "Stopping legacy HAL"; |
| 281 | on_stop_complete_internal_callback = [&](wifi_handle handle) { |
| 282 | CHECK_EQ(global_handle_, handle) << "Handle mismatch"; |
| 283 | on_stop_complete_user_callback(); |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 284 | // Invalidate all the internal pointers now that the HAL is |
| 285 | // stopped. |
| 286 | invalidate(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 287 | }; |
| 288 | awaiting_event_loop_termination_ = true; |
| 289 | global_func_table_.wifi_cleanup(global_handle_, onStopComplete); |
| 290 | LOG(VERBOSE) << "Legacy HAL stop initiated"; |
| 291 | return WIFI_SUCCESS; |
| 292 | } |
| 293 | |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 294 | std::string WifiLegacyHal::getApIfaceName() { |
| 295 | // Fake name. This interface does not exist in legacy HAL |
| 296 | // API's. |
| 297 | return "ap0"; |
| 298 | } |
| 299 | |
| 300 | std::string WifiLegacyHal::getNanIfaceName() { |
| 301 | // Fake name. This interface does not exist in legacy HAL |
| 302 | // API's. |
| 303 | return "nan0"; |
| 304 | } |
| 305 | |
| 306 | std::string WifiLegacyHal::getP2pIfaceName() { |
| 307 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 308 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 309 | return buffer.data(); |
| 310 | } |
| 311 | |
| 312 | std::string WifiLegacyHal::getStaIfaceName() { |
| 313 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 314 | property_get("wifi.interface", buffer.data(), "wlan0"); |
| 315 | return buffer.data(); |
| 316 | } |
| 317 | |
| 318 | std::pair<wifi_error, std::string> WifiLegacyHal::getDriverVersion() { |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 319 | std::array<char, kMaxVersionStringLength> buffer; |
| 320 | buffer.fill(0); |
| 321 | wifi_error status = global_func_table_.wifi_get_driver_version( |
| 322 | wlan_interface_handle_, buffer.data(), buffer.size()); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 323 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 326 | std::pair<wifi_error, std::string> WifiLegacyHal::getFirmwareVersion() { |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 327 | std::array<char, kMaxVersionStringLength> buffer; |
| 328 | buffer.fill(0); |
| 329 | wifi_error status = global_func_table_.wifi_get_firmware_version( |
| 330 | wlan_interface_handle_, buffer.data(), buffer.size()); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 331 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 334 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 335 | WifiLegacyHal::requestDriverMemoryDump() { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 336 | std::vector<uint8_t> driver_dump; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 337 | on_driver_memory_dump_internal_callback = [&driver_dump](char* buffer, |
| 338 | int buffer_size) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 339 | driver_dump.insert(driver_dump.end(), |
| 340 | reinterpret_cast<uint8_t*>(buffer), |
| 341 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 342 | }; |
| 343 | wifi_error status = global_func_table_.wifi_get_driver_memory_dump( |
| 344 | wlan_interface_handle_, {onDriverMemoryDump}); |
| 345 | on_driver_memory_dump_internal_callback = nullptr; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 346 | return {status, std::move(driver_dump)}; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 349 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 350 | WifiLegacyHal::requestFirmwareMemoryDump() { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 351 | std::vector<uint8_t> firmware_dump; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 352 | on_firmware_memory_dump_internal_callback = [&firmware_dump]( |
| 353 | char* buffer, int buffer_size) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 354 | firmware_dump.insert(firmware_dump.end(), |
| 355 | reinterpret_cast<uint8_t*>(buffer), |
| 356 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 357 | }; |
| 358 | wifi_error status = global_func_table_.wifi_get_firmware_memory_dump( |
| 359 | wlan_interface_handle_, {onFirmwareMemoryDump}); |
| 360 | on_firmware_memory_dump_internal_callback = nullptr; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 361 | return {status, std::move(firmware_dump)}; |
| 362 | } |
| 363 | |
| 364 | std::pair<wifi_error, uint32_t> WifiLegacyHal::getSupportedFeatureSet() { |
| 365 | feature_set set; |
| 366 | static_assert(sizeof(set) == sizeof(uint32_t), |
| 367 | "Some features can not be represented in output"); |
| 368 | wifi_error status = global_func_table_.wifi_get_supported_feature_set( |
| 369 | wlan_interface_handle_, &set); |
| 370 | return {status, static_cast<uint32_t>(set)}; |
| 371 | } |
| 372 | |
| 373 | std::pair<wifi_error, PacketFilterCapabilities> |
| 374 | WifiLegacyHal::getPacketFilterCapabilities() { |
| 375 | PacketFilterCapabilities caps; |
| 376 | wifi_error status = global_func_table_.wifi_get_packet_filter_capabilities( |
| 377 | wlan_interface_handle_, &caps.version, &caps.max_len); |
| 378 | return {status, caps}; |
| 379 | } |
| 380 | |
| 381 | wifi_error WifiLegacyHal::setPacketFilter(const std::vector<uint8_t>& program) { |
| 382 | return global_func_table_.wifi_set_packet_filter( |
| 383 | wlan_interface_handle_, program.data(), program.size()); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 386 | std::pair<wifi_error, wifi_gscan_capabilities> |
| 387 | WifiLegacyHal::getGscanCapabilities() { |
| 388 | wifi_gscan_capabilities caps; |
| 389 | wifi_error status = global_func_table_.wifi_get_gscan_capabilities( |
| 390 | wlan_interface_handle_, &caps); |
| 391 | return {status, caps}; |
| 392 | } |
| 393 | |
| 394 | wifi_error WifiLegacyHal::startGscan( |
| 395 | wifi_request_id id, |
| 396 | const wifi_scan_cmd_params& params, |
| 397 | const std::function<void(wifi_request_id)>& on_failure_user_callback, |
| 398 | const on_gscan_results_callback& on_results_user_callback, |
| 399 | const on_gscan_full_result_callback& on_full_result_user_callback) { |
| 400 | // If there is already an ongoing background scan, reject new scan requests. |
| 401 | if (on_gscan_event_internal_callback || |
| 402 | on_gscan_full_result_internal_callback) { |
| 403 | return WIFI_ERROR_NOT_AVAILABLE; |
| 404 | } |
| 405 | |
| 406 | // This callback will be used to either trigger |on_results_user_callback| or |
| 407 | // |on_failure_user_callback|. |
| 408 | on_gscan_event_internal_callback = |
| 409 | [on_failure_user_callback, on_results_user_callback, this]( |
| 410 | wifi_request_id id, wifi_scan_event event) { |
| 411 | switch (event) { |
| 412 | case WIFI_SCAN_RESULTS_AVAILABLE: |
| 413 | case WIFI_SCAN_THRESHOLD_NUM_SCANS: |
| 414 | case WIFI_SCAN_THRESHOLD_PERCENT: { |
| 415 | wifi_error status; |
| 416 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 417 | std::tie(status, cached_scan_results) = getGscanCachedResults(); |
| 418 | if (status == WIFI_SUCCESS) { |
| 419 | on_results_user_callback(id, cached_scan_results); |
| 420 | return; |
| 421 | } |
| 422 | } |
| 423 | // Fall through if failed. Failure to retrieve cached scan results |
| 424 | // should trigger a background scan failure. |
| 425 | case WIFI_SCAN_FAILED: |
| 426 | on_failure_user_callback(id); |
| 427 | on_gscan_event_internal_callback = nullptr; |
| 428 | on_gscan_full_result_internal_callback = nullptr; |
| 429 | return; |
| 430 | } |
| 431 | LOG(FATAL) << "Unexpected gscan event received: " << event; |
| 432 | }; |
| 433 | |
| 434 | on_gscan_full_result_internal_callback = [on_full_result_user_callback]( |
| 435 | wifi_request_id id, wifi_scan_result* result, uint32_t buckets_scanned) { |
| 436 | if (result) { |
| 437 | on_full_result_user_callback(id, result, buckets_scanned); |
| 438 | } |
| 439 | }; |
| 440 | |
| 441 | wifi_scan_result_handler handler = {onGscanFullResult, onGscanEvent}; |
| 442 | wifi_error status = global_func_table_.wifi_start_gscan( |
| 443 | id, wlan_interface_handle_, params, handler); |
| 444 | if (status != WIFI_SUCCESS) { |
| 445 | on_gscan_event_internal_callback = nullptr; |
| 446 | on_gscan_full_result_internal_callback = nullptr; |
| 447 | } |
| 448 | return status; |
| 449 | } |
| 450 | |
| 451 | wifi_error WifiLegacyHal::stopGscan(wifi_request_id id) { |
| 452 | // If there is no an ongoing background scan, reject stop requests. |
| 453 | // TODO(b/32337212): This needs to be handled by the HIDL object because we |
| 454 | // need to return the NOT_STARTED error code. |
| 455 | if (!on_gscan_event_internal_callback && |
| 456 | !on_gscan_full_result_internal_callback) { |
| 457 | return WIFI_ERROR_NOT_AVAILABLE; |
| 458 | } |
| 459 | wifi_error status = |
| 460 | global_func_table_.wifi_stop_gscan(id, wlan_interface_handle_); |
| 461 | // If the request Id is wrong, don't stop the ongoing background scan. Any |
| 462 | // other error should be treated as the end of background scan. |
| 463 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 464 | on_gscan_event_internal_callback = nullptr; |
| 465 | on_gscan_full_result_internal_callback = nullptr; |
| 466 | } |
| 467 | return status; |
| 468 | } |
| 469 | |
| 470 | std::pair<wifi_error, std::vector<uint32_t>> |
| 471 | WifiLegacyHal::getValidFrequenciesForGscan(wifi_band band) { |
| 472 | static_assert(sizeof(uint32_t) >= sizeof(wifi_channel), |
| 473 | "Wifi Channel cannot be represented in output"); |
| 474 | std::vector<uint32_t> freqs; |
| 475 | freqs.resize(kMaxGscanFrequenciesForBand); |
| 476 | int32_t num_freqs = 0; |
| 477 | wifi_error status = global_func_table_.wifi_get_valid_channels( |
| 478 | wlan_interface_handle_, |
| 479 | band, |
| 480 | freqs.size(), |
| 481 | reinterpret_cast<wifi_channel*>(freqs.data()), |
| 482 | &num_freqs); |
| 483 | CHECK(num_freqs >= 0 && |
| 484 | static_cast<uint32_t>(num_freqs) <= kMaxGscanFrequenciesForBand); |
| 485 | freqs.resize(num_freqs); |
| 486 | return {status, std::move(freqs)}; |
| 487 | } |
| 488 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 489 | wifi_error WifiLegacyHal::enableLinkLayerStats(bool debug) { |
| 490 | wifi_link_layer_params params; |
| 491 | params.mpdu_size_threshold = kLinkLayerStatsDataMpduSizeThreshold; |
| 492 | params.aggressive_statistics_gathering = debug; |
| 493 | return global_func_table_.wifi_set_link_stats(wlan_interface_handle_, params); |
| 494 | } |
| 495 | |
| 496 | wifi_error WifiLegacyHal::disableLinkLayerStats() { |
| 497 | // TODO: Do we care about these responses? |
| 498 | uint32_t clear_mask_rsp; |
| 499 | uint8_t stop_rsp; |
| 500 | return global_func_table_.wifi_clear_link_stats( |
| 501 | wlan_interface_handle_, 0xFFFFFFFF, &clear_mask_rsp, 1, &stop_rsp); |
| 502 | } |
| 503 | |
| 504 | std::pair<wifi_error, LinkLayerStats> WifiLegacyHal::getLinkLayerStats() { |
| 505 | LinkLayerStats link_stats{}; |
| 506 | LinkLayerStats* link_stats_ptr = &link_stats; |
| 507 | |
| 508 | on_link_layer_stats_result_internal_callback = [&link_stats_ptr]( |
| 509 | wifi_request_id /* id */, |
| 510 | wifi_iface_stat* iface_stats_ptr, |
| 511 | int num_radios, |
| 512 | wifi_radio_stat* radio_stats_ptr) { |
| 513 | if (iface_stats_ptr != nullptr) { |
| 514 | link_stats_ptr->iface = *iface_stats_ptr; |
| 515 | link_stats_ptr->iface.num_peers = 0; |
| 516 | } else { |
| 517 | LOG(ERROR) << "Invalid iface stats in link layer stats"; |
| 518 | } |
| 519 | if (num_radios == 1 && radio_stats_ptr != nullptr) { |
| 520 | link_stats_ptr->radio = *radio_stats_ptr; |
| 521 | // Copy over the tx level array to the separate vector. |
| 522 | if (radio_stats_ptr->num_tx_levels > 0 && |
| 523 | radio_stats_ptr->tx_time_per_levels != nullptr) { |
| 524 | link_stats_ptr->radio_tx_time_per_levels.assign( |
| 525 | radio_stats_ptr->tx_time_per_levels, |
| 526 | radio_stats_ptr->tx_time_per_levels + |
| 527 | radio_stats_ptr->num_tx_levels); |
| 528 | } |
| 529 | link_stats_ptr->radio.num_tx_levels = 0; |
| 530 | link_stats_ptr->radio.tx_time_per_levels = nullptr; |
| 531 | } else { |
| 532 | LOG(ERROR) << "Invalid radio stats in link layer stats"; |
| 533 | } |
| 534 | }; |
| 535 | |
| 536 | wifi_error status = global_func_table_.wifi_get_link_stats( |
| 537 | 0, wlan_interface_handle_, {onLinkLayerStatsDataResult}); |
| 538 | on_link_layer_stats_result_internal_callback = nullptr; |
| 539 | return {status, link_stats}; |
| 540 | } |
| 541 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 542 | std::pair<wifi_error, uint32_t> WifiLegacyHal::getLoggerSupportedFeatureSet() { |
| 543 | uint32_t supported_features; |
| 544 | wifi_error status = global_func_table_.wifi_get_logger_supported_feature_set( |
| 545 | wlan_interface_handle_, &supported_features); |
| 546 | return {status, supported_features}; |
| 547 | } |
| 548 | |
| 549 | wifi_error WifiLegacyHal::startPktFateMonitoring() { |
| 550 | return global_func_table_.wifi_start_pkt_fate_monitoring( |
| 551 | wlan_interface_handle_); |
| 552 | } |
| 553 | |
| 554 | std::pair<wifi_error, std::vector<wifi_tx_report>> |
| 555 | WifiLegacyHal::getTxPktFates() { |
| 556 | std::vector<wifi_tx_report> tx_pkt_fates; |
| 557 | tx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 558 | size_t num_fates = 0; |
| 559 | wifi_error status = |
| 560 | global_func_table_.wifi_get_tx_pkt_fates(wlan_interface_handle_, |
| 561 | tx_pkt_fates.data(), |
| 562 | tx_pkt_fates.size(), |
| 563 | &num_fates); |
| 564 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 565 | tx_pkt_fates.resize(num_fates); |
| 566 | return {status, std::move(tx_pkt_fates)}; |
| 567 | } |
| 568 | |
| 569 | std::pair<wifi_error, std::vector<wifi_rx_report>> |
| 570 | WifiLegacyHal::getRxPktFates() { |
| 571 | std::vector<wifi_rx_report> rx_pkt_fates; |
| 572 | rx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 573 | size_t num_fates = 0; |
| 574 | wifi_error status = |
| 575 | global_func_table_.wifi_get_rx_pkt_fates(wlan_interface_handle_, |
| 576 | rx_pkt_fates.data(), |
| 577 | rx_pkt_fates.size(), |
| 578 | &num_fates); |
| 579 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 580 | rx_pkt_fates.resize(num_fates); |
| 581 | return {status, std::move(rx_pkt_fates)}; |
| 582 | } |
| 583 | |
| 584 | std::pair<wifi_error, WakeReasonStats> WifiLegacyHal::getWakeReasonStats() { |
| 585 | WakeReasonStats stats; |
| 586 | stats.cmd_event_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
| 587 | stats.driver_fw_local_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
| 588 | |
| 589 | // This legacy struct needs separate memory to store the variable sized wake |
| 590 | // reason types. |
| 591 | stats.wake_reason_cnt.cmd_event_wake_cnt = |
| 592 | reinterpret_cast<int32_t*>(stats.cmd_event_wake_cnt.data()); |
| 593 | stats.wake_reason_cnt.cmd_event_wake_cnt_sz = stats.cmd_event_wake_cnt.size(); |
| 594 | stats.wake_reason_cnt.cmd_event_wake_cnt_used = 0; |
| 595 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = |
| 596 | reinterpret_cast<int32_t*>(stats.driver_fw_local_wake_cnt.data()); |
| 597 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_sz = |
| 598 | stats.driver_fw_local_wake_cnt.size(); |
| 599 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used = 0; |
| 600 | |
| 601 | wifi_error status = global_func_table_.wifi_get_wake_reason_stats( |
| 602 | wlan_interface_handle_, &stats.wake_reason_cnt); |
| 603 | |
| 604 | CHECK(stats.wake_reason_cnt.cmd_event_wake_cnt_used >= 0 && |
| 605 | static_cast<uint32_t>(stats.wake_reason_cnt.cmd_event_wake_cnt_used) <= |
| 606 | kMaxWakeReasonStatsArraySize); |
| 607 | stats.cmd_event_wake_cnt.resize( |
| 608 | stats.wake_reason_cnt.cmd_event_wake_cnt_used); |
| 609 | stats.wake_reason_cnt.cmd_event_wake_cnt = nullptr; |
| 610 | |
| 611 | CHECK(stats.wake_reason_cnt.driver_fw_local_wake_cnt_used >= 0 && |
| 612 | static_cast<uint32_t>( |
| 613 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used) <= |
| 614 | kMaxWakeReasonStatsArraySize); |
| 615 | stats.driver_fw_local_wake_cnt.resize( |
| 616 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used); |
| 617 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = nullptr; |
| 618 | |
| 619 | return {status, stats}; |
| 620 | } |
| 621 | |
| 622 | wifi_error WifiLegacyHal::registerRingBufferCallbackHandler( |
| 623 | const on_ring_buffer_data_callback& on_user_data_callback) { |
| 624 | if (on_ring_buffer_data_internal_callback) { |
| 625 | return WIFI_ERROR_NOT_AVAILABLE; |
| 626 | } |
| 627 | on_ring_buffer_data_internal_callback = [on_user_data_callback]( |
| 628 | char* ring_name, |
| 629 | char* buffer, |
| 630 | int buffer_size, |
| 631 | wifi_ring_buffer_status* status) { |
| 632 | if (status && buffer) { |
| 633 | std::vector<uint8_t> buffer_vector( |
| 634 | reinterpret_cast<uint8_t*>(buffer), |
| 635 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
| 636 | on_user_data_callback(ring_name, buffer_vector, *status); |
| 637 | } |
| 638 | }; |
| 639 | return global_func_table_.wifi_set_log_handler( |
| 640 | 0, wlan_interface_handle_, {onRingBufferData}); |
| 641 | } |
| 642 | |
| 643 | std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> |
| 644 | WifiLegacyHal::getRingBuffersStatus() { |
| 645 | std::vector<wifi_ring_buffer_status> ring_buffers_status; |
| 646 | ring_buffers_status.resize(kMaxRingBuffers); |
| 647 | uint32_t num_rings = 0; |
| 648 | wifi_error status = global_func_table_.wifi_get_ring_buffers_status( |
| 649 | wlan_interface_handle_, &num_rings, ring_buffers_status.data()); |
| 650 | CHECK(num_rings <= kMaxRingBuffers); |
| 651 | ring_buffers_status.resize(num_rings); |
| 652 | return {status, std::move(ring_buffers_status)}; |
| 653 | } |
| 654 | |
| 655 | wifi_error WifiLegacyHal::startRingBufferLogging(const std::string& ring_name, |
| 656 | uint32_t verbose_level, |
| 657 | uint32_t max_interval_sec, |
| 658 | uint32_t min_data_size) { |
| 659 | std::vector<char> ring_name_internal(ring_name.begin(), ring_name.end()); |
| 660 | return global_func_table_.wifi_start_logging(wlan_interface_handle_, |
| 661 | verbose_level, |
| 662 | 0, |
| 663 | max_interval_sec, |
| 664 | min_data_size, |
| 665 | ring_name_internal.data()); |
| 666 | } |
| 667 | |
| 668 | wifi_error WifiLegacyHal::getRingBufferData(const std::string& ring_name) { |
| 669 | std::vector<char> ring_name_internal(ring_name.begin(), ring_name.end()); |
| 670 | return global_func_table_.wifi_get_ring_data(wlan_interface_handle_, |
| 671 | ring_name_internal.data()); |
| 672 | } |
| 673 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 674 | wifi_error WifiLegacyHal::startRttRangeRequest( |
| 675 | wifi_request_id id, |
| 676 | const std::vector<wifi_rtt_config>& rtt_configs, |
| 677 | const on_rtt_results_callback& on_results_user_callback) { |
| 678 | if (on_rtt_results_internal_callback) { |
| 679 | return WIFI_ERROR_NOT_AVAILABLE; |
| 680 | } |
| 681 | |
| 682 | on_rtt_results_internal_callback = [on_results_user_callback]( |
| 683 | wifi_request_id id, |
| 684 | unsigned num_results, |
| 685 | wifi_rtt_result* rtt_results[]) { |
| 686 | if (num_results > 0 && !rtt_results) { |
| 687 | LOG(ERROR) << "Unexpected nullptr in RTT results"; |
| 688 | return; |
| 689 | } |
| 690 | std::vector<const wifi_rtt_result*> rtt_results_vec; |
| 691 | std::copy_if( |
| 692 | rtt_results, |
| 693 | rtt_results + num_results, |
| 694 | back_inserter(rtt_results_vec), |
| 695 | [](wifi_rtt_result* rtt_result) { return rtt_result != nullptr; }); |
| 696 | on_results_user_callback(id, rtt_results_vec); |
| 697 | }; |
| 698 | |
| 699 | std::vector<wifi_rtt_config> rtt_configs_internal(rtt_configs); |
| 700 | return global_func_table_.wifi_rtt_range_request(id, |
| 701 | wlan_interface_handle_, |
| 702 | rtt_configs.size(), |
| 703 | rtt_configs_internal.data(), |
| 704 | {onRttResults}); |
| 705 | } |
| 706 | |
| 707 | wifi_error WifiLegacyHal::cancelRttRangeRequest( |
| 708 | wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs) { |
| 709 | if (!on_rtt_results_internal_callback) { |
| 710 | return WIFI_ERROR_NOT_AVAILABLE; |
| 711 | } |
| 712 | static_assert(sizeof(mac_addr) == sizeof(std::array<uint8_t, 6>), |
| 713 | "MAC address size mismatch"); |
| 714 | // TODO: How do we handle partial cancels (i.e only a subset of enabled mac |
| 715 | // addressed are cancelled). |
| 716 | std::vector<std::array<uint8_t, 6>> mac_addrs_internal(mac_addrs); |
| 717 | wifi_error status = global_func_table_.wifi_rtt_range_cancel( |
| 718 | id, |
| 719 | wlan_interface_handle_, |
| 720 | mac_addrs.size(), |
| 721 | reinterpret_cast<mac_addr*>(mac_addrs_internal.data())); |
| 722 | // If the request Id is wrong, don't stop the ongoing range request. Any |
| 723 | // other error should be treated as the end of rtt ranging. |
| 724 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 725 | on_rtt_results_internal_callback = nullptr; |
| 726 | } |
| 727 | return status; |
| 728 | } |
| 729 | |
| 730 | std::pair<wifi_error, wifi_rtt_capabilities> |
| 731 | WifiLegacyHal::getRttCapabilities() { |
| 732 | wifi_rtt_capabilities rtt_caps; |
| 733 | wifi_error status = global_func_table_.wifi_get_rtt_capabilities( |
| 734 | wlan_interface_handle_, &rtt_caps); |
| 735 | return {status, rtt_caps}; |
| 736 | } |
| 737 | |
| 738 | std::pair<wifi_error, wifi_rtt_responder> WifiLegacyHal::getRttResponderInfo() { |
| 739 | wifi_rtt_responder rtt_responder; |
| 740 | wifi_error status = global_func_table_.wifi_rtt_get_responder_info( |
| 741 | wlan_interface_handle_, &rtt_responder); |
| 742 | return {status, rtt_responder}; |
| 743 | } |
| 744 | |
| 745 | wifi_error WifiLegacyHal::enableRttResponder( |
| 746 | wifi_request_id id, |
| 747 | const wifi_channel_info& channel_hint, |
| 748 | uint32_t max_duration_secs, |
| 749 | const wifi_rtt_responder& info) { |
| 750 | wifi_rtt_responder info_internal(info); |
| 751 | return global_func_table_.wifi_enable_responder(id, |
| 752 | wlan_interface_handle_, |
| 753 | channel_hint, |
| 754 | max_duration_secs, |
| 755 | &info_internal); |
| 756 | } |
| 757 | |
| 758 | wifi_error WifiLegacyHal::disableRttResponder(wifi_request_id id) { |
| 759 | return global_func_table_.wifi_disable_responder(id, wlan_interface_handle_); |
| 760 | } |
| 761 | |
| 762 | wifi_error WifiLegacyHal::setRttLci(wifi_request_id id, |
| 763 | const wifi_lci_information& info) { |
| 764 | wifi_lci_information info_internal(info); |
| 765 | return global_func_table_.wifi_set_lci( |
| 766 | id, wlan_interface_handle_, &info_internal); |
| 767 | } |
| 768 | |
| 769 | wifi_error WifiLegacyHal::setRttLcr(wifi_request_id id, |
| 770 | const wifi_lcr_information& info) { |
| 771 | wifi_lcr_information info_internal(info); |
| 772 | return global_func_table_.wifi_set_lcr( |
| 773 | id, wlan_interface_handle_, &info_internal); |
| 774 | } |
| 775 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 776 | wifi_error WifiLegacyHal::nanRegisterCallbackHandlers( |
| 777 | const NanCallbackHandlers& user_callbacks) { |
| 778 | on_nan_notify_response_user_callback = user_callbacks.on_notify_response; |
| 779 | on_nan_event_publish_terminated_user_callback = |
| 780 | user_callbacks.on_event_publish_terminated; |
| 781 | on_nan_event_match_user_callback = user_callbacks.on_event_match; |
| 782 | on_nan_event_match_expired_user_callback = |
| 783 | user_callbacks.on_event_match_expired; |
| 784 | on_nan_event_subscribe_terminated_user_callback = |
| 785 | user_callbacks.on_event_subscribe_terminated; |
| 786 | on_nan_event_followup_user_callback = user_callbacks.on_event_followup; |
| 787 | on_nan_event_disc_eng_event_user_callback = |
| 788 | user_callbacks.on_event_disc_eng_event; |
| 789 | on_nan_event_disabled_user_callback = user_callbacks.on_event_disabled; |
| 790 | on_nan_event_tca_user_callback = user_callbacks.on_event_tca; |
| 791 | on_nan_event_beacon_sdf_payload_user_callback = |
| 792 | user_callbacks.on_event_beacon_sdf_payload; |
| 793 | on_nan_event_data_path_request_user_callback = |
| 794 | user_callbacks.on_event_data_path_request; |
| 795 | on_nan_event_data_path_confirm_user_callback = |
| 796 | user_callbacks.on_event_data_path_confirm; |
| 797 | on_nan_event_data_path_end_user_callback = |
| 798 | user_callbacks.on_event_data_path_end; |
| 799 | on_nan_event_transmit_follow_up_user_callback = |
| 800 | user_callbacks.on_event_transmit_follow_up; |
| 801 | |
| 802 | return global_func_table_.wifi_nan_register_handler( |
| 803 | wlan_interface_handle_, |
| 804 | {onNanNotifyResponse, |
| 805 | onNanEventPublishTerminated, |
| 806 | onNanEventMatch, |
| 807 | onNanEventMatchExpired, |
| 808 | onNanEventSubscribeTerminated, |
| 809 | onNanEventFollowup, |
| 810 | onNanEventDiscEngEvent, |
| 811 | onNanEventDisabled, |
| 812 | onNanEventTca, |
| 813 | onNanEventBeaconSdfPayload, |
| 814 | onNanEventDataPathRequest, |
| 815 | onNanEventDataPathConfirm, |
| 816 | onNanEventDataPathEnd, |
| 817 | onNanEventTransmitFollowUp}); |
| 818 | } |
| 819 | |
| 820 | wifi_error WifiLegacyHal::nanEnableRequest(transaction_id id, |
| 821 | const NanEnableRequest& msg) { |
| 822 | NanEnableRequest msg_internal(msg); |
| 823 | return global_func_table_.wifi_nan_enable_request( |
| 824 | id, wlan_interface_handle_, &msg_internal); |
| 825 | } |
| 826 | |
| 827 | wifi_error WifiLegacyHal::nanDisableRequest(transaction_id id) { |
| 828 | return global_func_table_.wifi_nan_disable_request(id, |
| 829 | wlan_interface_handle_); |
| 830 | } |
| 831 | |
| 832 | wifi_error WifiLegacyHal::nanPublishRequest(transaction_id id, |
| 833 | const NanPublishRequest& msg) { |
| 834 | NanPublishRequest msg_internal(msg); |
| 835 | return global_func_table_.wifi_nan_publish_request( |
| 836 | id, wlan_interface_handle_, &msg_internal); |
| 837 | } |
| 838 | |
| 839 | wifi_error WifiLegacyHal::nanPublishCancelRequest( |
| 840 | transaction_id id, const NanPublishCancelRequest& msg) { |
| 841 | NanPublishCancelRequest msg_internal(msg); |
| 842 | return global_func_table_.wifi_nan_publish_cancel_request( |
| 843 | id, wlan_interface_handle_, &msg_internal); |
| 844 | } |
| 845 | |
| 846 | wifi_error WifiLegacyHal::nanSubscribeRequest(transaction_id id, |
| 847 | const NanSubscribeRequest& msg) { |
| 848 | NanSubscribeRequest msg_internal(msg); |
| 849 | return global_func_table_.wifi_nan_subscribe_request( |
| 850 | id, wlan_interface_handle_, &msg_internal); |
| 851 | } |
| 852 | |
| 853 | wifi_error WifiLegacyHal::nanSubscribeCancelRequest( |
| 854 | transaction_id id, const NanSubscribeCancelRequest& msg) { |
| 855 | NanSubscribeCancelRequest msg_internal(msg); |
| 856 | return global_func_table_.wifi_nan_subscribe_cancel_request( |
| 857 | id, wlan_interface_handle_, &msg_internal); |
| 858 | } |
| 859 | |
| 860 | wifi_error WifiLegacyHal::nanTransmitFollowupRequest( |
| 861 | transaction_id id, const NanTransmitFollowupRequest& msg) { |
| 862 | NanTransmitFollowupRequest msg_internal(msg); |
| 863 | return global_func_table_.wifi_nan_transmit_followup_request( |
| 864 | id, wlan_interface_handle_, &msg_internal); |
| 865 | } |
| 866 | |
| 867 | wifi_error WifiLegacyHal::nanStatsRequest(transaction_id id, |
| 868 | const NanStatsRequest& msg) { |
| 869 | NanStatsRequest msg_internal(msg); |
| 870 | return global_func_table_.wifi_nan_stats_request( |
| 871 | id, wlan_interface_handle_, &msg_internal); |
| 872 | } |
| 873 | |
| 874 | wifi_error WifiLegacyHal::nanConfigRequest(transaction_id id, |
| 875 | const NanConfigRequest& msg) { |
| 876 | NanConfigRequest msg_internal(msg); |
| 877 | return global_func_table_.wifi_nan_config_request( |
| 878 | id, wlan_interface_handle_, &msg_internal); |
| 879 | } |
| 880 | |
| 881 | wifi_error WifiLegacyHal::nanTcaRequest(transaction_id id, |
| 882 | const NanTCARequest& msg) { |
| 883 | NanTCARequest msg_internal(msg); |
| 884 | return global_func_table_.wifi_nan_tca_request( |
| 885 | id, wlan_interface_handle_, &msg_internal); |
| 886 | } |
| 887 | |
| 888 | wifi_error WifiLegacyHal::nanBeaconSdfPayloadRequest( |
| 889 | transaction_id id, const NanBeaconSdfPayloadRequest& msg) { |
| 890 | NanBeaconSdfPayloadRequest msg_internal(msg); |
| 891 | return global_func_table_.wifi_nan_beacon_sdf_payload_request( |
| 892 | id, wlan_interface_handle_, &msg_internal); |
| 893 | } |
| 894 | |
| 895 | std::pair<wifi_error, NanVersion> WifiLegacyHal::nanGetVersion() { |
| 896 | NanVersion version; |
| 897 | wifi_error status = |
| 898 | global_func_table_.wifi_nan_get_version(global_handle_, &version); |
| 899 | return {status, version}; |
| 900 | } |
| 901 | |
| 902 | wifi_error WifiLegacyHal::nanGetCapabilities(transaction_id id) { |
| 903 | return global_func_table_.wifi_nan_get_capabilities(id, |
| 904 | wlan_interface_handle_); |
| 905 | } |
| 906 | |
| 907 | wifi_error WifiLegacyHal::nanDataInterfaceCreate( |
| 908 | transaction_id id, const std::string& iface_name) { |
| 909 | std::vector<char> iface_name_internal(iface_name.begin(), iface_name.end()); |
| 910 | return global_func_table_.wifi_nan_data_interface_create( |
| 911 | id, wlan_interface_handle_, iface_name_internal.data()); |
| 912 | } |
| 913 | |
| 914 | wifi_error WifiLegacyHal::nanDataInterfaceDelete( |
| 915 | transaction_id id, const std::string& iface_name) { |
| 916 | std::vector<char> iface_name_internal(iface_name.begin(), iface_name.end()); |
| 917 | return global_func_table_.wifi_nan_data_interface_delete( |
| 918 | id, wlan_interface_handle_, iface_name_internal.data()); |
| 919 | } |
| 920 | |
| 921 | wifi_error WifiLegacyHal::nanDataRequestInitiator( |
| 922 | transaction_id id, const NanDataPathInitiatorRequest& msg) { |
| 923 | NanDataPathInitiatorRequest msg_internal(msg); |
| 924 | return global_func_table_.wifi_nan_data_request_initiator( |
| 925 | id, wlan_interface_handle_, &msg_internal); |
| 926 | } |
| 927 | |
| 928 | wifi_error WifiLegacyHal::nanDataIndicationResponse( |
| 929 | transaction_id id, const NanDataPathIndicationResponse& msg) { |
| 930 | NanDataPathIndicationResponse msg_internal(msg); |
| 931 | return global_func_table_.wifi_nan_data_indication_response( |
| 932 | id, wlan_interface_handle_, &msg_internal); |
| 933 | } |
| 934 | |
| 935 | wifi_error WifiLegacyHal::nanDataEnd(transaction_id id, |
| 936 | const NanDataPathEndRequest& msg) { |
| 937 | NanDataPathEndRequest msg_internal(msg); |
| 938 | return global_func_table_.wifi_nan_data_end( |
| 939 | id, wlan_interface_handle_, &msg_internal); |
| 940 | } |
| 941 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 942 | wifi_error WifiLegacyHal::retrieveWlanInterfaceHandle() { |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 943 | const std::string& ifname_to_find = getStaIfaceName(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 944 | wifi_interface_handle* iface_handles = nullptr; |
| 945 | int num_iface_handles = 0; |
| 946 | wifi_error status = global_func_table_.wifi_get_ifaces( |
| 947 | global_handle_, &num_iface_handles, &iface_handles); |
| 948 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 949 | LOG(ERROR) << "Failed to enumerate interface handles"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 950 | return status; |
| 951 | } |
| 952 | for (int i = 0; i < num_iface_handles; ++i) { |
| 953 | std::array<char, IFNAMSIZ> current_ifname; |
| 954 | current_ifname.fill(0); |
| 955 | status = global_func_table_.wifi_get_iface_name( |
| 956 | iface_handles[i], current_ifname.data(), current_ifname.size()); |
| 957 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 958 | LOG(WARNING) << "Failed to get interface handle name"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 959 | continue; |
| 960 | } |
| 961 | if (ifname_to_find == current_ifname.data()) { |
| 962 | wlan_interface_handle_ = iface_handles[i]; |
| 963 | return WIFI_SUCCESS; |
| 964 | } |
| 965 | } |
| 966 | return WIFI_ERROR_UNKNOWN; |
| 967 | } |
| 968 | |
| 969 | void WifiLegacyHal::runEventLoop() { |
| 970 | LOG(VERBOSE) << "Starting legacy HAL event loop"; |
| 971 | global_func_table_.wifi_event_loop(global_handle_); |
| 972 | if (!awaiting_event_loop_termination_) { |
| 973 | LOG(FATAL) << "Legacy HAL event loop terminated, but HAL was not stopping"; |
| 974 | } |
| 975 | LOG(VERBOSE) << "Legacy HAL event loop terminated"; |
| 976 | awaiting_event_loop_termination_ = false; |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 977 | android::wifi_system::InterfaceTool if_tool; |
| 978 | if_tool.SetWifiUpState(false); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 981 | std::pair<wifi_error, std::vector<wifi_cached_scan_results>> |
| 982 | WifiLegacyHal::getGscanCachedResults() { |
| 983 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 984 | cached_scan_results.resize(kMaxCachedGscanResults); |
| 985 | int32_t num_results = 0; |
| 986 | wifi_error status = global_func_table_.wifi_get_cached_gscan_results( |
| 987 | wlan_interface_handle_, |
| 988 | true /* always flush */, |
| 989 | cached_scan_results.size(), |
| 990 | cached_scan_results.data(), |
| 991 | &num_results); |
| 992 | CHECK(num_results >= 0 && |
| 993 | static_cast<uint32_t>(num_results) <= kMaxCachedGscanResults); |
| 994 | cached_scan_results.resize(num_results); |
| 995 | // Check for invalid IE lengths in these cached scan results and correct it. |
| 996 | for (auto& cached_scan_result : cached_scan_results) { |
| 997 | int num_scan_results = cached_scan_result.num_results; |
| 998 | for (int i = 0; i < num_scan_results; i++) { |
| 999 | auto& scan_result = cached_scan_result.results[i]; |
| 1000 | if (scan_result.ie_length > 0) { |
| 1001 | LOG(ERROR) << "Cached scan result has non-zero IE length " |
| 1002 | << scan_result.ie_length; |
| 1003 | scan_result.ie_length = 0; |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | return {status, std::move(cached_scan_results)}; |
| 1008 | } |
| 1009 | |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1010 | void WifiLegacyHal::invalidate() { |
| 1011 | global_handle_ = nullptr; |
| 1012 | wlan_interface_handle_ = nullptr; |
| 1013 | on_stop_complete_internal_callback = nullptr; |
| 1014 | on_driver_memory_dump_internal_callback = nullptr; |
| 1015 | on_firmware_memory_dump_internal_callback = nullptr; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1016 | on_gscan_event_internal_callback = nullptr; |
| 1017 | on_gscan_full_result_internal_callback = nullptr; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 1018 | on_link_layer_stats_result_internal_callback = nullptr; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 1019 | on_ring_buffer_data_internal_callback = nullptr; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1020 | on_rtt_results_internal_callback = nullptr; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1021 | on_nan_notify_response_user_callback = nullptr; |
| 1022 | on_nan_event_publish_terminated_user_callback = nullptr; |
| 1023 | on_nan_event_match_user_callback = nullptr; |
| 1024 | on_nan_event_match_expired_user_callback = nullptr; |
| 1025 | on_nan_event_subscribe_terminated_user_callback = nullptr; |
| 1026 | on_nan_event_followup_user_callback = nullptr; |
| 1027 | on_nan_event_disc_eng_event_user_callback = nullptr; |
| 1028 | on_nan_event_disabled_user_callback = nullptr; |
| 1029 | on_nan_event_tca_user_callback = nullptr; |
| 1030 | on_nan_event_beacon_sdf_payload_user_callback = nullptr; |
| 1031 | on_nan_event_data_path_request_user_callback = nullptr; |
| 1032 | on_nan_event_data_path_confirm_user_callback = nullptr; |
| 1033 | on_nan_event_data_path_end_user_callback = nullptr; |
| 1034 | on_nan_event_transmit_follow_up_user_callback = nullptr; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1035 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 1036 | |
| 1037 | } // namespace legacy_hal |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1038 | } // namespace implementation |
| 1039 | } // namespace V1_0 |
| 1040 | } // namespace wifi |
| 1041 | } // namespace hardware |
| 1042 | } // namespace android |