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