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 | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 22 | #include "hidl_sync_util.h" |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 23 | #include "wifi_legacy_hal.h" |
Roshan Pius | e73a506 | 2016-12-12 08:53:34 -0800 | [diff] [blame] | 24 | #include "wifi_legacy_hal_stubs.h" |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 25 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 26 | namespace { |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 27 | // Constants ported over from the legacy HAL calling code |
| 28 | // (com_android_server_wifi_WifiNative.cpp). This will all be thrown |
| 29 | // away when this shim layer is replaced by the real vendor |
| 30 | // implementation. |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 31 | static constexpr uint32_t kMaxVersionStringLength = 256; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 32 | static constexpr uint32_t kMaxCachedGscanResults = 64; |
| 33 | static constexpr uint32_t kMaxGscanFrequenciesForBand = 64; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 34 | static constexpr uint32_t kLinkLayerStatsDataMpduSizeThreshold = 128; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 35 | static constexpr uint32_t kMaxWakeReasonStatsArraySize = 32; |
| 36 | static constexpr uint32_t kMaxRingBuffers = 10; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 37 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 38 | // Helper function to create a non-const char* for legacy Hal API's. |
| 39 | std::vector<char> makeCharVec(const std::string& str) { |
| 40 | std::vector<char> vec(str.size() + 1); |
| 41 | vec.assign(str.begin(), str.end()); |
| 42 | vec.push_back('\0'); |
| 43 | return vec; |
| 44 | } |
| 45 | } // namespace |
| 46 | |
| 47 | namespace android { |
| 48 | namespace hardware { |
| 49 | namespace wifi { |
| 50 | namespace V1_0 { |
| 51 | namespace implementation { |
| 52 | namespace legacy_hal { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 53 | // Legacy HAL functions accept "C" style function pointers, so use global |
| 54 | // functions to pass to the legacy HAL function and store the corresponding |
| 55 | // std::function methods to be invoked. |
| 56 | // Callback to be invoked once |stop| is complete. |
| 57 | std::function<void(wifi_handle handle)> on_stop_complete_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 58 | void onAsyncStopComplete(wifi_handle handle) { |
| 59 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 60 | if (on_stop_complete_internal_callback) { |
| 61 | on_stop_complete_internal_callback(handle); |
Roshan Pius | 46b6454 | 2017-03-09 13:09:49 -0800 | [diff] [blame] | 62 | // Invalidate this callback since we don't want this firing again. |
| 63 | on_stop_complete_internal_callback = nullptr; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 66 | |
| 67 | // Callback to be invoked for driver dump. |
| 68 | std::function<void(char*, int)> on_driver_memory_dump_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 69 | void onSyncDriverMemoryDump(char* buffer, int buffer_size) { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 70 | if (on_driver_memory_dump_internal_callback) { |
| 71 | on_driver_memory_dump_internal_callback(buffer, buffer_size); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Callback to be invoked for firmware dump. |
| 76 | std::function<void(char*, int)> on_firmware_memory_dump_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 77 | void onSyncFirmwareMemoryDump(char* buffer, int buffer_size) { |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 78 | if (on_firmware_memory_dump_internal_callback) { |
| 79 | on_firmware_memory_dump_internal_callback(buffer, buffer_size); |
| 80 | } |
| 81 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 82 | |
| 83 | // Callback to be invoked for Gscan events. |
| 84 | std::function<void(wifi_request_id, wifi_scan_event)> |
| 85 | on_gscan_event_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 86 | void onAsyncGscanEvent(wifi_request_id id, wifi_scan_event event) { |
| 87 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 88 | if (on_gscan_event_internal_callback) { |
| 89 | on_gscan_event_internal_callback(id, event); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Callback to be invoked for Gscan full results. |
| 94 | std::function<void(wifi_request_id, wifi_scan_result*, uint32_t)> |
| 95 | on_gscan_full_result_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 96 | void onAsyncGscanFullResult(wifi_request_id id, |
| 97 | wifi_scan_result* result, |
| 98 | uint32_t buckets_scanned) { |
| 99 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 100 | if (on_gscan_full_result_internal_callback) { |
| 101 | on_gscan_full_result_internal_callback(id, result, buckets_scanned); |
| 102 | } |
| 103 | } |
| 104 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 105 | // Callback to be invoked for link layer stats results. |
| 106 | std::function<void((wifi_request_id, wifi_iface_stat*, int, wifi_radio_stat*))> |
| 107 | on_link_layer_stats_result_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 108 | void onSyncLinkLayerStatsResult(wifi_request_id id, |
| 109 | wifi_iface_stat* iface_stat, |
| 110 | int num_radios, |
| 111 | wifi_radio_stat* radio_stat) { |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 112 | if (on_link_layer_stats_result_internal_callback) { |
| 113 | on_link_layer_stats_result_internal_callback( |
| 114 | id, iface_stat, num_radios, radio_stat); |
| 115 | } |
| 116 | } |
| 117 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 118 | // Callback to be invoked for rssi threshold breach. |
| 119 | std::function<void((wifi_request_id, uint8_t*, int8_t))> |
| 120 | on_rssi_threshold_breached_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 121 | void onAsyncRssiThresholdBreached(wifi_request_id id, |
| 122 | uint8_t* bssid, |
| 123 | int8_t rssi) { |
| 124 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 125 | if (on_rssi_threshold_breached_internal_callback) { |
| 126 | on_rssi_threshold_breached_internal_callback(id, bssid, rssi); |
| 127 | } |
| 128 | } |
| 129 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 130 | // Callback to be invoked for ring buffer data indication. |
| 131 | std::function<void(char*, char*, int, wifi_ring_buffer_status*)> |
| 132 | on_ring_buffer_data_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 133 | void onAsyncRingBufferData(char* ring_name, |
| 134 | char* buffer, |
| 135 | int buffer_size, |
| 136 | wifi_ring_buffer_status* status) { |
| 137 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 138 | if (on_ring_buffer_data_internal_callback) { |
| 139 | on_ring_buffer_data_internal_callback( |
| 140 | ring_name, buffer, buffer_size, status); |
| 141 | } |
| 142 | } |
| 143 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 144 | // Callback to be invoked for error alert indication. |
| 145 | std::function<void(wifi_request_id, char*, int, int)> |
| 146 | on_error_alert_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 147 | void onAsyncErrorAlert(wifi_request_id id, |
| 148 | char* buffer, |
| 149 | int buffer_size, |
| 150 | int err_code) { |
| 151 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 152 | if (on_error_alert_internal_callback) { |
| 153 | on_error_alert_internal_callback(id, buffer, buffer_size, err_code); |
| 154 | } |
| 155 | } |
| 156 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 157 | // Callback to be invoked for rtt results results. |
| 158 | std::function<void( |
| 159 | wifi_request_id, unsigned num_results, wifi_rtt_result* rtt_results[])> |
| 160 | on_rtt_results_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 161 | void onAsyncRttResults(wifi_request_id id, |
| 162 | unsigned num_results, |
| 163 | wifi_rtt_result* rtt_results[]) { |
| 164 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 165 | if (on_rtt_results_internal_callback) { |
| 166 | on_rtt_results_internal_callback(id, num_results, rtt_results); |
| 167 | } |
| 168 | } |
| 169 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 170 | // Callbacks for the various NAN operations. |
| 171 | // NOTE: These have very little conversions to perform before invoking the user |
| 172 | // callbacks. |
| 173 | // So, handle all of them here directly to avoid adding an unnecessary layer. |
| 174 | std::function<void(transaction_id, const NanResponseMsg&)> |
| 175 | on_nan_notify_response_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 176 | void onAysncNanNotifyResponse(transaction_id id, NanResponseMsg* msg) { |
| 177 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 178 | if (on_nan_notify_response_user_callback && msg) { |
| 179 | on_nan_notify_response_user_callback(id, *msg); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | std::function<void(const NanPublishTerminatedInd&)> |
| 184 | on_nan_event_publish_terminated_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 185 | void onAysncNanEventPublishTerminated(NanPublishTerminatedInd* event) { |
| 186 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 187 | if (on_nan_event_publish_terminated_user_callback && event) { |
| 188 | on_nan_event_publish_terminated_user_callback(*event); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | std::function<void(const NanMatchInd&)> on_nan_event_match_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 193 | void onAysncNanEventMatch(NanMatchInd* event) { |
| 194 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 195 | if (on_nan_event_match_user_callback && event) { |
| 196 | on_nan_event_match_user_callback(*event); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | std::function<void(const NanMatchExpiredInd&)> |
| 201 | on_nan_event_match_expired_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 202 | void onAysncNanEventMatchExpired(NanMatchExpiredInd* event) { |
| 203 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 204 | if (on_nan_event_match_expired_user_callback && event) { |
| 205 | on_nan_event_match_expired_user_callback(*event); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | std::function<void(const NanSubscribeTerminatedInd&)> |
| 210 | on_nan_event_subscribe_terminated_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 211 | void onAysncNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) { |
| 212 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 213 | if (on_nan_event_subscribe_terminated_user_callback && event) { |
| 214 | on_nan_event_subscribe_terminated_user_callback(*event); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | std::function<void(const NanFollowupInd&)> on_nan_event_followup_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 219 | void onAysncNanEventFollowup(NanFollowupInd* event) { |
| 220 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 221 | if (on_nan_event_followup_user_callback && event) { |
| 222 | on_nan_event_followup_user_callback(*event); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | std::function<void(const NanDiscEngEventInd&)> |
| 227 | on_nan_event_disc_eng_event_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 228 | void onAysncNanEventDiscEngEvent(NanDiscEngEventInd* event) { |
| 229 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 230 | if (on_nan_event_disc_eng_event_user_callback && event) { |
| 231 | on_nan_event_disc_eng_event_user_callback(*event); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | std::function<void(const NanDisabledInd&)> on_nan_event_disabled_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 236 | void onAysncNanEventDisabled(NanDisabledInd* event) { |
| 237 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 238 | if (on_nan_event_disabled_user_callback && event) { |
| 239 | on_nan_event_disabled_user_callback(*event); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | std::function<void(const NanTCAInd&)> on_nan_event_tca_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 244 | void onAysncNanEventTca(NanTCAInd* event) { |
| 245 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 246 | if (on_nan_event_tca_user_callback && event) { |
| 247 | on_nan_event_tca_user_callback(*event); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | std::function<void(const NanBeaconSdfPayloadInd&)> |
| 252 | on_nan_event_beacon_sdf_payload_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 253 | void onAysncNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) { |
| 254 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 255 | if (on_nan_event_beacon_sdf_payload_user_callback && event) { |
| 256 | on_nan_event_beacon_sdf_payload_user_callback(*event); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | std::function<void(const NanDataPathRequestInd&)> |
| 261 | on_nan_event_data_path_request_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 262 | void onAysncNanEventDataPathRequest(NanDataPathRequestInd* event) { |
| 263 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 264 | if (on_nan_event_data_path_request_user_callback && event) { |
| 265 | on_nan_event_data_path_request_user_callback(*event); |
| 266 | } |
| 267 | } |
| 268 | std::function<void(const NanDataPathConfirmInd&)> |
| 269 | on_nan_event_data_path_confirm_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 270 | void onAysncNanEventDataPathConfirm(NanDataPathConfirmInd* event) { |
| 271 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 272 | if (on_nan_event_data_path_confirm_user_callback && event) { |
| 273 | on_nan_event_data_path_confirm_user_callback(*event); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | std::function<void(const NanDataPathEndInd&)> |
| 278 | on_nan_event_data_path_end_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 279 | void onAysncNanEventDataPathEnd(NanDataPathEndInd* event) { |
| 280 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 281 | if (on_nan_event_data_path_end_user_callback && event) { |
| 282 | on_nan_event_data_path_end_user_callback(*event); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | std::function<void(const NanTransmitFollowupInd&)> |
| 287 | on_nan_event_transmit_follow_up_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 288 | void onAysncNanEventTransmitFollowUp(NanTransmitFollowupInd* event) { |
| 289 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 290 | if (on_nan_event_transmit_follow_up_user_callback && event) { |
| 291 | on_nan_event_transmit_follow_up_user_callback(*event); |
| 292 | } |
| 293 | } |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 294 | |
| 295 | std::function<void(const NanRangeRequestInd&)> |
| 296 | on_nan_event_range_request_user_callback; |
| 297 | void onAysncNanEventRangeRequest(NanRangeRequestInd* event) { |
| 298 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 299 | if (on_nan_event_range_request_user_callback && event) { |
| 300 | on_nan_event_range_request_user_callback(*event); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | std::function<void(const NanRangeReportInd&)> |
| 305 | on_nan_event_range_report_user_callback; |
| 306 | void onAysncNanEventRangeReport(NanRangeReportInd* event) { |
| 307 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 308 | if (on_nan_event_range_report_user_callback && event) { |
| 309 | on_nan_event_range_report_user_callback(*event); |
| 310 | } |
| 311 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 312 | // End of the free-standing "C" style callbacks. |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 313 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 314 | WifiLegacyHal::WifiLegacyHal() |
| 315 | : global_handle_(nullptr), |
| 316 | wlan_interface_handle_(nullptr), |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 317 | awaiting_event_loop_termination_(false), |
| 318 | is_started_(false) {} |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 319 | |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 320 | wifi_error WifiLegacyHal::initialize() { |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 321 | LOG(DEBUG) << "Initialize legacy HAL"; |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 322 | // TODO: Add back the HAL Tool if we need to. All we need from the HAL tool |
| 323 | // for now is this function call which we can directly call. |
Roshan Pius | e73a506 | 2016-12-12 08:53:34 -0800 | [diff] [blame] | 324 | if (!initHalFuncTableWithStubs(&global_func_table_)) { |
| 325 | LOG(ERROR) << "Failed to initialize legacy hal function table with stubs"; |
| 326 | return WIFI_ERROR_UNKNOWN; |
| 327 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 328 | wifi_error status = init_wifi_vendor_hal_func_table(&global_func_table_); |
| 329 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 330 | LOG(ERROR) << "Failed to initialize legacy hal function table"; |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 331 | } |
Roshan Pius | a1c76e4 | 2017-03-20 10:15:18 -0700 | [diff] [blame] | 332 | return status; |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | wifi_error WifiLegacyHal::start() { |
| 336 | // Ensure that we're starting in a good state. |
| 337 | CHECK(global_func_table_.wifi_initialize && !global_handle_ && |
| 338 | !wlan_interface_handle_ && !awaiting_event_loop_termination_); |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 339 | if (is_started_) { |
| 340 | LOG(DEBUG) << "Legacy HAL already started"; |
| 341 | return WIFI_SUCCESS; |
| 342 | } |
| 343 | LOG(DEBUG) << "Starting legacy HAL"; |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 344 | if (!iface_tool_.SetWifiUpState(true)) { |
Roshan Pius | 908a69a | 2016-10-03 13:33:23 -0700 | [diff] [blame] | 345 | LOG(ERROR) << "Failed to set WiFi interface up"; |
| 346 | return WIFI_ERROR_UNKNOWN; |
| 347 | } |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 348 | wifi_error status = global_func_table_.wifi_initialize(&global_handle_); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 349 | if (status != WIFI_SUCCESS || !global_handle_) { |
| 350 | LOG(ERROR) << "Failed to retrieve global handle"; |
| 351 | return status; |
| 352 | } |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 353 | std::thread(&WifiLegacyHal::runEventLoop, this).detach(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 354 | status = retrieveWlanInterfaceHandle(); |
| 355 | if (status != WIFI_SUCCESS || !wlan_interface_handle_) { |
| 356 | LOG(ERROR) << "Failed to retrieve wlan interface handle"; |
| 357 | return status; |
| 358 | } |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 359 | LOG(DEBUG) << "Legacy HAL start complete"; |
| 360 | is_started_ = true; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 361 | return WIFI_SUCCESS; |
| 362 | } |
| 363 | |
| 364 | wifi_error WifiLegacyHal::stop( |
| 365 | const std::function<void()>& on_stop_complete_user_callback) { |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 366 | if (!is_started_) { |
| 367 | LOG(DEBUG) << "Legacy HAL already stopped"; |
| 368 | on_stop_complete_user_callback(); |
| 369 | return WIFI_SUCCESS; |
| 370 | } |
| 371 | LOG(DEBUG) << "Stopping legacy HAL"; |
Roshan Pius | 742bb97 | 2017-02-02 09:54:27 -0800 | [diff] [blame] | 372 | on_stop_complete_internal_callback = [on_stop_complete_user_callback, |
| 373 | this](wifi_handle handle) { |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 374 | CHECK_EQ(global_handle_, handle) << "Handle mismatch"; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 375 | // Invalidate all the internal pointers now that the HAL is |
| 376 | // stopped. |
| 377 | invalidate(); |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 378 | iface_tool_.SetWifiUpState(false); |
| 379 | on_stop_complete_user_callback(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 380 | }; |
| 381 | awaiting_event_loop_termination_ = true; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 382 | global_func_table_.wifi_cleanup(global_handle_, onAsyncStopComplete); |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 383 | LOG(DEBUG) << "Legacy HAL stop complete"; |
| 384 | is_started_ = false; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 385 | return WIFI_SUCCESS; |
| 386 | } |
| 387 | |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 388 | std::string WifiLegacyHal::getApIfaceName() { |
| 389 | // Fake name. This interface does not exist in legacy HAL |
| 390 | // API's. |
| 391 | return "ap0"; |
| 392 | } |
| 393 | |
| 394 | std::string WifiLegacyHal::getNanIfaceName() { |
| 395 | // Fake name. This interface does not exist in legacy HAL |
| 396 | // API's. |
| 397 | return "nan0"; |
| 398 | } |
| 399 | |
| 400 | std::string WifiLegacyHal::getP2pIfaceName() { |
| 401 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 402 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 403 | return buffer.data(); |
| 404 | } |
| 405 | |
| 406 | std::string WifiLegacyHal::getStaIfaceName() { |
| 407 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 408 | property_get("wifi.interface", buffer.data(), "wlan0"); |
| 409 | return buffer.data(); |
| 410 | } |
| 411 | |
| 412 | std::pair<wifi_error, std::string> WifiLegacyHal::getDriverVersion() { |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 413 | std::array<char, kMaxVersionStringLength> buffer; |
| 414 | buffer.fill(0); |
| 415 | wifi_error status = global_func_table_.wifi_get_driver_version( |
| 416 | wlan_interface_handle_, buffer.data(), buffer.size()); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 417 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 420 | std::pair<wifi_error, std::string> WifiLegacyHal::getFirmwareVersion() { |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 421 | std::array<char, kMaxVersionStringLength> buffer; |
| 422 | buffer.fill(0); |
| 423 | wifi_error status = global_func_table_.wifi_get_firmware_version( |
| 424 | wlan_interface_handle_, buffer.data(), buffer.size()); |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 425 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 428 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 429 | WifiLegacyHal::requestDriverMemoryDump() { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 430 | std::vector<uint8_t> driver_dump; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 431 | on_driver_memory_dump_internal_callback = [&driver_dump](char* buffer, |
| 432 | int buffer_size) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 433 | driver_dump.insert(driver_dump.end(), |
| 434 | reinterpret_cast<uint8_t*>(buffer), |
| 435 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 436 | }; |
| 437 | wifi_error status = global_func_table_.wifi_get_driver_memory_dump( |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 438 | wlan_interface_handle_, {onSyncDriverMemoryDump}); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 439 | on_driver_memory_dump_internal_callback = nullptr; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 440 | return {status, std::move(driver_dump)}; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 443 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 444 | WifiLegacyHal::requestFirmwareMemoryDump() { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 445 | std::vector<uint8_t> firmware_dump; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 446 | on_firmware_memory_dump_internal_callback = [&firmware_dump]( |
| 447 | char* buffer, int buffer_size) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 448 | firmware_dump.insert(firmware_dump.end(), |
| 449 | reinterpret_cast<uint8_t*>(buffer), |
| 450 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 451 | }; |
| 452 | wifi_error status = global_func_table_.wifi_get_firmware_memory_dump( |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 453 | wlan_interface_handle_, {onSyncFirmwareMemoryDump}); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 454 | on_firmware_memory_dump_internal_callback = nullptr; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 455 | return {status, std::move(firmware_dump)}; |
| 456 | } |
| 457 | |
| 458 | std::pair<wifi_error, uint32_t> WifiLegacyHal::getSupportedFeatureSet() { |
| 459 | feature_set set; |
| 460 | static_assert(sizeof(set) == sizeof(uint32_t), |
| 461 | "Some features can not be represented in output"); |
| 462 | wifi_error status = global_func_table_.wifi_get_supported_feature_set( |
| 463 | wlan_interface_handle_, &set); |
| 464 | return {status, static_cast<uint32_t>(set)}; |
| 465 | } |
| 466 | |
| 467 | std::pair<wifi_error, PacketFilterCapabilities> |
| 468 | WifiLegacyHal::getPacketFilterCapabilities() { |
| 469 | PacketFilterCapabilities caps; |
| 470 | wifi_error status = global_func_table_.wifi_get_packet_filter_capabilities( |
| 471 | wlan_interface_handle_, &caps.version, &caps.max_len); |
| 472 | return {status, caps}; |
| 473 | } |
| 474 | |
| 475 | wifi_error WifiLegacyHal::setPacketFilter(const std::vector<uint8_t>& program) { |
| 476 | return global_func_table_.wifi_set_packet_filter( |
| 477 | wlan_interface_handle_, program.data(), program.size()); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 480 | std::pair<wifi_error, wifi_gscan_capabilities> |
| 481 | WifiLegacyHal::getGscanCapabilities() { |
| 482 | wifi_gscan_capabilities caps; |
| 483 | wifi_error status = global_func_table_.wifi_get_gscan_capabilities( |
| 484 | wlan_interface_handle_, &caps); |
| 485 | return {status, caps}; |
| 486 | } |
| 487 | |
| 488 | wifi_error WifiLegacyHal::startGscan( |
| 489 | wifi_request_id id, |
| 490 | const wifi_scan_cmd_params& params, |
| 491 | const std::function<void(wifi_request_id)>& on_failure_user_callback, |
| 492 | const on_gscan_results_callback& on_results_user_callback, |
| 493 | const on_gscan_full_result_callback& on_full_result_user_callback) { |
| 494 | // If there is already an ongoing background scan, reject new scan requests. |
| 495 | if (on_gscan_event_internal_callback || |
| 496 | on_gscan_full_result_internal_callback) { |
| 497 | return WIFI_ERROR_NOT_AVAILABLE; |
| 498 | } |
| 499 | |
| 500 | // This callback will be used to either trigger |on_results_user_callback| or |
| 501 | // |on_failure_user_callback|. |
| 502 | on_gscan_event_internal_callback = |
| 503 | [on_failure_user_callback, on_results_user_callback, this]( |
| 504 | wifi_request_id id, wifi_scan_event event) { |
| 505 | switch (event) { |
| 506 | case WIFI_SCAN_RESULTS_AVAILABLE: |
| 507 | case WIFI_SCAN_THRESHOLD_NUM_SCANS: |
| 508 | case WIFI_SCAN_THRESHOLD_PERCENT: { |
| 509 | wifi_error status; |
| 510 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 511 | std::tie(status, cached_scan_results) = getGscanCachedResults(); |
| 512 | if (status == WIFI_SUCCESS) { |
| 513 | on_results_user_callback(id, cached_scan_results); |
| 514 | return; |
| 515 | } |
| 516 | } |
| 517 | // Fall through if failed. Failure to retrieve cached scan results |
| 518 | // should trigger a background scan failure. |
| 519 | case WIFI_SCAN_FAILED: |
| 520 | on_failure_user_callback(id); |
| 521 | on_gscan_event_internal_callback = nullptr; |
| 522 | on_gscan_full_result_internal_callback = nullptr; |
| 523 | return; |
| 524 | } |
| 525 | LOG(FATAL) << "Unexpected gscan event received: " << event; |
| 526 | }; |
| 527 | |
| 528 | on_gscan_full_result_internal_callback = [on_full_result_user_callback]( |
| 529 | wifi_request_id id, wifi_scan_result* result, uint32_t buckets_scanned) { |
| 530 | if (result) { |
| 531 | on_full_result_user_callback(id, result, buckets_scanned); |
| 532 | } |
| 533 | }; |
| 534 | |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 535 | wifi_scan_result_handler handler = {onAsyncGscanFullResult, |
| 536 | onAsyncGscanEvent}; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 537 | wifi_error status = global_func_table_.wifi_start_gscan( |
| 538 | id, wlan_interface_handle_, params, handler); |
| 539 | if (status != WIFI_SUCCESS) { |
| 540 | on_gscan_event_internal_callback = nullptr; |
| 541 | on_gscan_full_result_internal_callback = nullptr; |
| 542 | } |
| 543 | return status; |
| 544 | } |
| 545 | |
| 546 | wifi_error WifiLegacyHal::stopGscan(wifi_request_id id) { |
| 547 | // If there is no an ongoing background scan, reject stop requests. |
| 548 | // TODO(b/32337212): This needs to be handled by the HIDL object because we |
| 549 | // need to return the NOT_STARTED error code. |
| 550 | if (!on_gscan_event_internal_callback && |
| 551 | !on_gscan_full_result_internal_callback) { |
| 552 | return WIFI_ERROR_NOT_AVAILABLE; |
| 553 | } |
| 554 | wifi_error status = |
| 555 | global_func_table_.wifi_stop_gscan(id, wlan_interface_handle_); |
| 556 | // If the request Id is wrong, don't stop the ongoing background scan. Any |
| 557 | // other error should be treated as the end of background scan. |
| 558 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 559 | on_gscan_event_internal_callback = nullptr; |
| 560 | on_gscan_full_result_internal_callback = nullptr; |
| 561 | } |
| 562 | return status; |
| 563 | } |
| 564 | |
| 565 | std::pair<wifi_error, std::vector<uint32_t>> |
Roshan Pius | 7f4574d | 2017-02-22 09:48:03 -0800 | [diff] [blame] | 566 | WifiLegacyHal::getValidFrequenciesForBand(wifi_band band) { |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 567 | static_assert(sizeof(uint32_t) >= sizeof(wifi_channel), |
| 568 | "Wifi Channel cannot be represented in output"); |
| 569 | std::vector<uint32_t> freqs; |
| 570 | freqs.resize(kMaxGscanFrequenciesForBand); |
| 571 | int32_t num_freqs = 0; |
| 572 | wifi_error status = global_func_table_.wifi_get_valid_channels( |
| 573 | wlan_interface_handle_, |
| 574 | band, |
| 575 | freqs.size(), |
| 576 | reinterpret_cast<wifi_channel*>(freqs.data()), |
| 577 | &num_freqs); |
| 578 | CHECK(num_freqs >= 0 && |
| 579 | static_cast<uint32_t>(num_freqs) <= kMaxGscanFrequenciesForBand); |
| 580 | freqs.resize(num_freqs); |
| 581 | return {status, std::move(freqs)}; |
| 582 | } |
| 583 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 584 | wifi_error WifiLegacyHal::enableLinkLayerStats(bool debug) { |
| 585 | wifi_link_layer_params params; |
| 586 | params.mpdu_size_threshold = kLinkLayerStatsDataMpduSizeThreshold; |
| 587 | params.aggressive_statistics_gathering = debug; |
| 588 | return global_func_table_.wifi_set_link_stats(wlan_interface_handle_, params); |
| 589 | } |
| 590 | |
| 591 | wifi_error WifiLegacyHal::disableLinkLayerStats() { |
| 592 | // TODO: Do we care about these responses? |
| 593 | uint32_t clear_mask_rsp; |
| 594 | uint8_t stop_rsp; |
| 595 | return global_func_table_.wifi_clear_link_stats( |
| 596 | wlan_interface_handle_, 0xFFFFFFFF, &clear_mask_rsp, 1, &stop_rsp); |
| 597 | } |
| 598 | |
| 599 | std::pair<wifi_error, LinkLayerStats> WifiLegacyHal::getLinkLayerStats() { |
| 600 | LinkLayerStats link_stats{}; |
| 601 | LinkLayerStats* link_stats_ptr = &link_stats; |
| 602 | |
Roshan Pius | e42ace2 | 2017-03-13 10:44:20 -0700 | [diff] [blame] | 603 | on_link_layer_stats_result_internal_callback = |
| 604 | [&link_stats_ptr](wifi_request_id /* id */, |
| 605 | wifi_iface_stat* iface_stats_ptr, |
| 606 | int num_radios, |
| 607 | wifi_radio_stat* radio_stats_ptr) { |
| 608 | if (iface_stats_ptr != nullptr) { |
| 609 | link_stats_ptr->iface = *iface_stats_ptr; |
| 610 | link_stats_ptr->iface.num_peers = 0; |
| 611 | } else { |
| 612 | LOG(ERROR) << "Invalid iface stats in link layer stats"; |
| 613 | } |
| 614 | if (num_radios <= 0 || radio_stats_ptr == nullptr) { |
| 615 | LOG(ERROR) << "Invalid radio stats in link layer stats"; |
| 616 | return; |
| 617 | } |
| 618 | for (int i = 0; i < num_radios; i++) { |
| 619 | LinkLayerRadioStats radio; |
| 620 | radio.stats = radio_stats_ptr[i]; |
| 621 | // Copy over the tx level array to the separate vector. |
| 622 | if (radio_stats_ptr[i].num_tx_levels > 0 && |
| 623 | radio_stats_ptr[i].tx_time_per_levels != nullptr) { |
| 624 | radio.tx_time_per_levels.assign( |
| 625 | radio_stats_ptr[i].tx_time_per_levels, |
| 626 | radio_stats_ptr[i].tx_time_per_levels + |
| 627 | radio_stats_ptr[i].num_tx_levels); |
| 628 | } |
| 629 | radio.stats.num_tx_levels = 0; |
| 630 | radio.stats.tx_time_per_levels = nullptr; |
| 631 | link_stats_ptr->radios.push_back(radio); |
| 632 | } |
| 633 | }; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 634 | |
| 635 | wifi_error status = global_func_table_.wifi_get_link_stats( |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 636 | 0, wlan_interface_handle_, {onSyncLinkLayerStatsResult}); |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 637 | on_link_layer_stats_result_internal_callback = nullptr; |
| 638 | return {status, link_stats}; |
| 639 | } |
| 640 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 641 | wifi_error WifiLegacyHal::startRssiMonitoring( |
| 642 | wifi_request_id id, |
| 643 | int8_t max_rssi, |
| 644 | int8_t min_rssi, |
| 645 | const on_rssi_threshold_breached_callback& |
| 646 | on_threshold_breached_user_callback) { |
| 647 | if (on_rssi_threshold_breached_internal_callback) { |
| 648 | return WIFI_ERROR_NOT_AVAILABLE; |
| 649 | } |
| 650 | on_rssi_threshold_breached_internal_callback = |
| 651 | [on_threshold_breached_user_callback]( |
| 652 | wifi_request_id id, uint8_t* bssid_ptr, int8_t rssi) { |
| 653 | if (!bssid_ptr) { |
| 654 | return; |
| 655 | } |
| 656 | std::array<uint8_t, 6> bssid_arr; |
| 657 | // |bssid_ptr| pointer is assumed to have 6 bytes for the mac address. |
| 658 | std::copy(bssid_ptr, bssid_ptr + 6, std::begin(bssid_arr)); |
| 659 | on_threshold_breached_user_callback(id, bssid_arr, rssi); |
| 660 | }; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 661 | wifi_error status = global_func_table_.wifi_start_rssi_monitoring( |
| 662 | id, |
| 663 | wlan_interface_handle_, |
| 664 | max_rssi, |
| 665 | min_rssi, |
| 666 | {onAsyncRssiThresholdBreached}); |
Roshan Pius | 7a41d9d | 2016-12-06 10:12:59 -0800 | [diff] [blame] | 667 | if (status != WIFI_SUCCESS) { |
| 668 | on_rssi_threshold_breached_internal_callback = nullptr; |
| 669 | } |
| 670 | return status; |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | wifi_error WifiLegacyHal::stopRssiMonitoring(wifi_request_id id) { |
| 674 | if (!on_rssi_threshold_breached_internal_callback) { |
| 675 | return WIFI_ERROR_NOT_AVAILABLE; |
| 676 | } |
| 677 | wifi_error status = |
| 678 | global_func_table_.wifi_stop_rssi_monitoring(id, wlan_interface_handle_); |
| 679 | // If the request Id is wrong, don't stop the ongoing rssi monitoring. Any |
| 680 | // other error should be treated as the end of background scan. |
| 681 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 682 | on_rssi_threshold_breached_internal_callback = nullptr; |
| 683 | } |
| 684 | return status; |
| 685 | } |
| 686 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 687 | std::pair<wifi_error, wifi_roaming_capabilities> |
| 688 | WifiLegacyHal::getRoamingCapabilities() { |
| 689 | wifi_roaming_capabilities caps; |
| 690 | wifi_error status = global_func_table_.wifi_get_roaming_capabilities( |
| 691 | wlan_interface_handle_, &caps); |
| 692 | return {status, caps}; |
| 693 | } |
| 694 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 695 | wifi_error WifiLegacyHal::configureRoaming(const wifi_roaming_config& config) { |
| 696 | wifi_roaming_config config_internal = config; |
| 697 | return global_func_table_.wifi_configure_roaming(wlan_interface_handle_, |
| 698 | &config_internal); |
| 699 | } |
| 700 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 701 | wifi_error WifiLegacyHal::enableFirmwareRoaming(fw_roaming_state_t state) { |
| 702 | return global_func_table_.wifi_enable_firmware_roaming(wlan_interface_handle_, |
| 703 | state); |
| 704 | } |
| 705 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 706 | wifi_error WifiLegacyHal::configureNdOffload(bool enable) { |
| 707 | return global_func_table_.wifi_configure_nd_offload(wlan_interface_handle_, |
| 708 | enable); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 711 | wifi_error WifiLegacyHal::startSendingOffloadedPacket( |
| 712 | uint32_t cmd_id, |
| 713 | const std::vector<uint8_t>& ip_packet_data, |
| 714 | const std::array<uint8_t, 6>& src_address, |
| 715 | const std::array<uint8_t, 6>& dst_address, |
| 716 | uint32_t period_in_ms) { |
| 717 | std::vector<uint8_t> ip_packet_data_internal(ip_packet_data); |
| 718 | std::vector<uint8_t> src_address_internal( |
| 719 | src_address.data(), src_address.data() + src_address.size()); |
| 720 | std::vector<uint8_t> dst_address_internal( |
| 721 | dst_address.data(), dst_address.data() + dst_address.size()); |
| 722 | return global_func_table_.wifi_start_sending_offloaded_packet( |
| 723 | cmd_id, |
| 724 | wlan_interface_handle_, |
| 725 | ip_packet_data_internal.data(), |
| 726 | ip_packet_data_internal.size(), |
| 727 | src_address_internal.data(), |
| 728 | dst_address_internal.data(), |
| 729 | period_in_ms); |
| 730 | } |
| 731 | |
| 732 | wifi_error WifiLegacyHal::stopSendingOffloadedPacket(uint32_t cmd_id) { |
| 733 | return global_func_table_.wifi_stop_sending_offloaded_packet( |
| 734 | cmd_id, wlan_interface_handle_); |
| 735 | } |
| 736 | |
Roshan Pius | 795bb81 | 2017-02-01 13:09:08 -0800 | [diff] [blame] | 737 | wifi_error WifiLegacyHal::setScanningMacOui(const std::array<uint8_t, 3>& oui) { |
| 738 | std::vector<uint8_t> oui_internal(oui.data(), oui.data() + oui.size()); |
| 739 | return global_func_table_.wifi_set_scanning_mac_oui(wlan_interface_handle_, |
| 740 | oui_internal.data()); |
| 741 | } |
| 742 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 743 | std::pair<wifi_error, uint32_t> WifiLegacyHal::getLoggerSupportedFeatureSet() { |
| 744 | uint32_t supported_features; |
| 745 | wifi_error status = global_func_table_.wifi_get_logger_supported_feature_set( |
| 746 | wlan_interface_handle_, &supported_features); |
| 747 | return {status, supported_features}; |
| 748 | } |
| 749 | |
| 750 | wifi_error WifiLegacyHal::startPktFateMonitoring() { |
| 751 | return global_func_table_.wifi_start_pkt_fate_monitoring( |
| 752 | wlan_interface_handle_); |
| 753 | } |
| 754 | |
| 755 | std::pair<wifi_error, std::vector<wifi_tx_report>> |
| 756 | WifiLegacyHal::getTxPktFates() { |
| 757 | std::vector<wifi_tx_report> tx_pkt_fates; |
| 758 | tx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 759 | size_t num_fates = 0; |
| 760 | wifi_error status = |
| 761 | global_func_table_.wifi_get_tx_pkt_fates(wlan_interface_handle_, |
| 762 | tx_pkt_fates.data(), |
| 763 | tx_pkt_fates.size(), |
| 764 | &num_fates); |
| 765 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 766 | tx_pkt_fates.resize(num_fates); |
| 767 | return {status, std::move(tx_pkt_fates)}; |
| 768 | } |
| 769 | |
| 770 | std::pair<wifi_error, std::vector<wifi_rx_report>> |
| 771 | WifiLegacyHal::getRxPktFates() { |
| 772 | std::vector<wifi_rx_report> rx_pkt_fates; |
| 773 | rx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 774 | size_t num_fates = 0; |
| 775 | wifi_error status = |
| 776 | global_func_table_.wifi_get_rx_pkt_fates(wlan_interface_handle_, |
| 777 | rx_pkt_fates.data(), |
| 778 | rx_pkt_fates.size(), |
| 779 | &num_fates); |
| 780 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 781 | rx_pkt_fates.resize(num_fates); |
| 782 | return {status, std::move(rx_pkt_fates)}; |
| 783 | } |
| 784 | |
| 785 | std::pair<wifi_error, WakeReasonStats> WifiLegacyHal::getWakeReasonStats() { |
| 786 | WakeReasonStats stats; |
| 787 | stats.cmd_event_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
| 788 | stats.driver_fw_local_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
| 789 | |
| 790 | // This legacy struct needs separate memory to store the variable sized wake |
| 791 | // reason types. |
| 792 | stats.wake_reason_cnt.cmd_event_wake_cnt = |
| 793 | reinterpret_cast<int32_t*>(stats.cmd_event_wake_cnt.data()); |
| 794 | stats.wake_reason_cnt.cmd_event_wake_cnt_sz = stats.cmd_event_wake_cnt.size(); |
| 795 | stats.wake_reason_cnt.cmd_event_wake_cnt_used = 0; |
| 796 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = |
| 797 | reinterpret_cast<int32_t*>(stats.driver_fw_local_wake_cnt.data()); |
| 798 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_sz = |
| 799 | stats.driver_fw_local_wake_cnt.size(); |
| 800 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used = 0; |
| 801 | |
| 802 | wifi_error status = global_func_table_.wifi_get_wake_reason_stats( |
| 803 | wlan_interface_handle_, &stats.wake_reason_cnt); |
| 804 | |
| 805 | CHECK(stats.wake_reason_cnt.cmd_event_wake_cnt_used >= 0 && |
| 806 | static_cast<uint32_t>(stats.wake_reason_cnt.cmd_event_wake_cnt_used) <= |
| 807 | kMaxWakeReasonStatsArraySize); |
| 808 | stats.cmd_event_wake_cnt.resize( |
| 809 | stats.wake_reason_cnt.cmd_event_wake_cnt_used); |
| 810 | stats.wake_reason_cnt.cmd_event_wake_cnt = nullptr; |
| 811 | |
| 812 | CHECK(stats.wake_reason_cnt.driver_fw_local_wake_cnt_used >= 0 && |
| 813 | static_cast<uint32_t>( |
| 814 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used) <= |
| 815 | kMaxWakeReasonStatsArraySize); |
| 816 | stats.driver_fw_local_wake_cnt.resize( |
| 817 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used); |
| 818 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = nullptr; |
| 819 | |
| 820 | return {status, stats}; |
| 821 | } |
| 822 | |
| 823 | wifi_error WifiLegacyHal::registerRingBufferCallbackHandler( |
| 824 | const on_ring_buffer_data_callback& on_user_data_callback) { |
| 825 | if (on_ring_buffer_data_internal_callback) { |
| 826 | return WIFI_ERROR_NOT_AVAILABLE; |
| 827 | } |
| 828 | on_ring_buffer_data_internal_callback = [on_user_data_callback]( |
| 829 | char* ring_name, |
| 830 | char* buffer, |
| 831 | int buffer_size, |
| 832 | wifi_ring_buffer_status* status) { |
| 833 | if (status && buffer) { |
| 834 | std::vector<uint8_t> buffer_vector( |
| 835 | reinterpret_cast<uint8_t*>(buffer), |
| 836 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
| 837 | on_user_data_callback(ring_name, buffer_vector, *status); |
| 838 | } |
| 839 | }; |
Roshan Pius | adc87cb | 2016-12-14 18:02:56 -0800 | [diff] [blame] | 840 | wifi_error status = global_func_table_.wifi_set_log_handler( |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 841 | 0, wlan_interface_handle_, {onAsyncRingBufferData}); |
Roshan Pius | adc87cb | 2016-12-14 18:02:56 -0800 | [diff] [blame] | 842 | if (status != WIFI_SUCCESS) { |
| 843 | on_ring_buffer_data_internal_callback = nullptr; |
| 844 | } |
| 845 | return status; |
| 846 | } |
| 847 | |
| 848 | wifi_error WifiLegacyHal::deregisterRingBufferCallbackHandler() { |
| 849 | if (!on_ring_buffer_data_internal_callback) { |
| 850 | return WIFI_ERROR_NOT_AVAILABLE; |
| 851 | } |
| 852 | on_ring_buffer_data_internal_callback = nullptr; |
| 853 | return global_func_table_.wifi_reset_log_handler(0, wlan_interface_handle_); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> |
| 857 | WifiLegacyHal::getRingBuffersStatus() { |
| 858 | std::vector<wifi_ring_buffer_status> ring_buffers_status; |
| 859 | ring_buffers_status.resize(kMaxRingBuffers); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 860 | uint32_t num_rings = kMaxRingBuffers; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 861 | wifi_error status = global_func_table_.wifi_get_ring_buffers_status( |
| 862 | wlan_interface_handle_, &num_rings, ring_buffers_status.data()); |
| 863 | CHECK(num_rings <= kMaxRingBuffers); |
| 864 | ring_buffers_status.resize(num_rings); |
| 865 | return {status, std::move(ring_buffers_status)}; |
| 866 | } |
| 867 | |
| 868 | wifi_error WifiLegacyHal::startRingBufferLogging(const std::string& ring_name, |
| 869 | uint32_t verbose_level, |
| 870 | uint32_t max_interval_sec, |
| 871 | uint32_t min_data_size) { |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 872 | return global_func_table_.wifi_start_logging(wlan_interface_handle_, |
| 873 | verbose_level, |
| 874 | 0, |
| 875 | max_interval_sec, |
| 876 | min_data_size, |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 877 | makeCharVec(ring_name).data()); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | wifi_error WifiLegacyHal::getRingBufferData(const std::string& ring_name) { |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 881 | return global_func_table_.wifi_get_ring_data(wlan_interface_handle_, |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 882 | makeCharVec(ring_name).data()); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 885 | wifi_error WifiLegacyHal::registerErrorAlertCallbackHandler( |
| 886 | const on_error_alert_callback& on_user_alert_callback) { |
| 887 | if (on_error_alert_internal_callback) { |
| 888 | return WIFI_ERROR_NOT_AVAILABLE; |
| 889 | } |
| 890 | on_error_alert_internal_callback = [on_user_alert_callback]( |
| 891 | wifi_request_id id, char* buffer, int buffer_size, int err_code) { |
| 892 | if (buffer) { |
| 893 | CHECK(id == 0); |
| 894 | on_user_alert_callback( |
| 895 | err_code, |
| 896 | std::vector<uint8_t>( |
| 897 | reinterpret_cast<uint8_t*>(buffer), |
| 898 | reinterpret_cast<uint8_t*>(buffer) + buffer_size)); |
| 899 | } |
| 900 | }; |
| 901 | wifi_error status = global_func_table_.wifi_set_alert_handler( |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 902 | 0, wlan_interface_handle_, {onAsyncErrorAlert}); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 903 | if (status != WIFI_SUCCESS) { |
| 904 | on_error_alert_internal_callback = nullptr; |
| 905 | } |
| 906 | return status; |
| 907 | } |
| 908 | |
| 909 | wifi_error WifiLegacyHal::deregisterErrorAlertCallbackHandler() { |
| 910 | if (!on_error_alert_internal_callback) { |
| 911 | return WIFI_ERROR_NOT_AVAILABLE; |
| 912 | } |
| 913 | on_error_alert_internal_callback = nullptr; |
| 914 | return global_func_table_.wifi_reset_alert_handler(0, wlan_interface_handle_); |
| 915 | } |
| 916 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 917 | wifi_error WifiLegacyHal::startRttRangeRequest( |
| 918 | wifi_request_id id, |
| 919 | const std::vector<wifi_rtt_config>& rtt_configs, |
| 920 | const on_rtt_results_callback& on_results_user_callback) { |
| 921 | if (on_rtt_results_internal_callback) { |
| 922 | return WIFI_ERROR_NOT_AVAILABLE; |
| 923 | } |
| 924 | |
| 925 | on_rtt_results_internal_callback = [on_results_user_callback]( |
| 926 | wifi_request_id id, |
| 927 | unsigned num_results, |
| 928 | wifi_rtt_result* rtt_results[]) { |
| 929 | if (num_results > 0 && !rtt_results) { |
| 930 | LOG(ERROR) << "Unexpected nullptr in RTT results"; |
| 931 | return; |
| 932 | } |
| 933 | std::vector<const wifi_rtt_result*> rtt_results_vec; |
| 934 | std::copy_if( |
| 935 | rtt_results, |
| 936 | rtt_results + num_results, |
| 937 | back_inserter(rtt_results_vec), |
| 938 | [](wifi_rtt_result* rtt_result) { return rtt_result != nullptr; }); |
| 939 | on_results_user_callback(id, rtt_results_vec); |
| 940 | }; |
| 941 | |
| 942 | std::vector<wifi_rtt_config> rtt_configs_internal(rtt_configs); |
Roshan Pius | 7a41d9d | 2016-12-06 10:12:59 -0800 | [diff] [blame] | 943 | wifi_error status = |
| 944 | global_func_table_.wifi_rtt_range_request(id, |
| 945 | wlan_interface_handle_, |
| 946 | rtt_configs.size(), |
| 947 | rtt_configs_internal.data(), |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 948 | {onAsyncRttResults}); |
Roshan Pius | 7a41d9d | 2016-12-06 10:12:59 -0800 | [diff] [blame] | 949 | if (status != WIFI_SUCCESS) { |
| 950 | on_rtt_results_internal_callback = nullptr; |
| 951 | } |
| 952 | return status; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | wifi_error WifiLegacyHal::cancelRttRangeRequest( |
| 956 | wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs) { |
| 957 | if (!on_rtt_results_internal_callback) { |
| 958 | return WIFI_ERROR_NOT_AVAILABLE; |
| 959 | } |
| 960 | static_assert(sizeof(mac_addr) == sizeof(std::array<uint8_t, 6>), |
| 961 | "MAC address size mismatch"); |
| 962 | // TODO: How do we handle partial cancels (i.e only a subset of enabled mac |
| 963 | // addressed are cancelled). |
| 964 | std::vector<std::array<uint8_t, 6>> mac_addrs_internal(mac_addrs); |
| 965 | wifi_error status = global_func_table_.wifi_rtt_range_cancel( |
| 966 | id, |
| 967 | wlan_interface_handle_, |
| 968 | mac_addrs.size(), |
| 969 | reinterpret_cast<mac_addr*>(mac_addrs_internal.data())); |
| 970 | // If the request Id is wrong, don't stop the ongoing range request. Any |
| 971 | // other error should be treated as the end of rtt ranging. |
| 972 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 973 | on_rtt_results_internal_callback = nullptr; |
| 974 | } |
| 975 | return status; |
| 976 | } |
| 977 | |
| 978 | std::pair<wifi_error, wifi_rtt_capabilities> |
| 979 | WifiLegacyHal::getRttCapabilities() { |
| 980 | wifi_rtt_capabilities rtt_caps; |
| 981 | wifi_error status = global_func_table_.wifi_get_rtt_capabilities( |
| 982 | wlan_interface_handle_, &rtt_caps); |
| 983 | return {status, rtt_caps}; |
| 984 | } |
| 985 | |
| 986 | std::pair<wifi_error, wifi_rtt_responder> WifiLegacyHal::getRttResponderInfo() { |
| 987 | wifi_rtt_responder rtt_responder; |
| 988 | wifi_error status = global_func_table_.wifi_rtt_get_responder_info( |
| 989 | wlan_interface_handle_, &rtt_responder); |
| 990 | return {status, rtt_responder}; |
| 991 | } |
| 992 | |
| 993 | wifi_error WifiLegacyHal::enableRttResponder( |
| 994 | wifi_request_id id, |
| 995 | const wifi_channel_info& channel_hint, |
| 996 | uint32_t max_duration_secs, |
| 997 | const wifi_rtt_responder& info) { |
| 998 | wifi_rtt_responder info_internal(info); |
| 999 | return global_func_table_.wifi_enable_responder(id, |
| 1000 | wlan_interface_handle_, |
| 1001 | channel_hint, |
| 1002 | max_duration_secs, |
| 1003 | &info_internal); |
| 1004 | } |
| 1005 | |
| 1006 | wifi_error WifiLegacyHal::disableRttResponder(wifi_request_id id) { |
| 1007 | return global_func_table_.wifi_disable_responder(id, wlan_interface_handle_); |
| 1008 | } |
| 1009 | |
| 1010 | wifi_error WifiLegacyHal::setRttLci(wifi_request_id id, |
| 1011 | const wifi_lci_information& info) { |
| 1012 | wifi_lci_information info_internal(info); |
| 1013 | return global_func_table_.wifi_set_lci( |
| 1014 | id, wlan_interface_handle_, &info_internal); |
| 1015 | } |
| 1016 | |
| 1017 | wifi_error WifiLegacyHal::setRttLcr(wifi_request_id id, |
| 1018 | const wifi_lcr_information& info) { |
| 1019 | wifi_lcr_information info_internal(info); |
| 1020 | return global_func_table_.wifi_set_lcr( |
| 1021 | id, wlan_interface_handle_, &info_internal); |
| 1022 | } |
| 1023 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1024 | wifi_error WifiLegacyHal::nanRegisterCallbackHandlers( |
| 1025 | const NanCallbackHandlers& user_callbacks) { |
| 1026 | on_nan_notify_response_user_callback = user_callbacks.on_notify_response; |
| 1027 | on_nan_event_publish_terminated_user_callback = |
| 1028 | user_callbacks.on_event_publish_terminated; |
| 1029 | on_nan_event_match_user_callback = user_callbacks.on_event_match; |
| 1030 | on_nan_event_match_expired_user_callback = |
| 1031 | user_callbacks.on_event_match_expired; |
| 1032 | on_nan_event_subscribe_terminated_user_callback = |
| 1033 | user_callbacks.on_event_subscribe_terminated; |
| 1034 | on_nan_event_followup_user_callback = user_callbacks.on_event_followup; |
| 1035 | on_nan_event_disc_eng_event_user_callback = |
| 1036 | user_callbacks.on_event_disc_eng_event; |
| 1037 | on_nan_event_disabled_user_callback = user_callbacks.on_event_disabled; |
| 1038 | on_nan_event_tca_user_callback = user_callbacks.on_event_tca; |
| 1039 | on_nan_event_beacon_sdf_payload_user_callback = |
| 1040 | user_callbacks.on_event_beacon_sdf_payload; |
| 1041 | on_nan_event_data_path_request_user_callback = |
| 1042 | user_callbacks.on_event_data_path_request; |
| 1043 | on_nan_event_data_path_confirm_user_callback = |
| 1044 | user_callbacks.on_event_data_path_confirm; |
| 1045 | on_nan_event_data_path_end_user_callback = |
| 1046 | user_callbacks.on_event_data_path_end; |
| 1047 | on_nan_event_transmit_follow_up_user_callback = |
| 1048 | user_callbacks.on_event_transmit_follow_up; |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 1049 | on_nan_event_range_request_user_callback = |
| 1050 | user_callbacks.on_event_range_request; |
| 1051 | on_nan_event_range_report_user_callback = |
| 1052 | user_callbacks.on_event_range_report; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1053 | |
| 1054 | return global_func_table_.wifi_nan_register_handler( |
| 1055 | wlan_interface_handle_, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 1056 | {onAysncNanNotifyResponse, |
| 1057 | onAysncNanEventPublishTerminated, |
| 1058 | onAysncNanEventMatch, |
| 1059 | onAysncNanEventMatchExpired, |
| 1060 | onAysncNanEventSubscribeTerminated, |
| 1061 | onAysncNanEventFollowup, |
| 1062 | onAysncNanEventDiscEngEvent, |
| 1063 | onAysncNanEventDisabled, |
| 1064 | onAysncNanEventTca, |
| 1065 | onAysncNanEventBeaconSdfPayload, |
| 1066 | onAysncNanEventDataPathRequest, |
| 1067 | onAysncNanEventDataPathConfirm, |
| 1068 | onAysncNanEventDataPathEnd, |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 1069 | onAysncNanEventTransmitFollowUp, |
| 1070 | onAysncNanEventRangeRequest, |
| 1071 | onAysncNanEventRangeReport}); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | wifi_error WifiLegacyHal::nanEnableRequest(transaction_id id, |
| 1075 | const NanEnableRequest& msg) { |
| 1076 | NanEnableRequest msg_internal(msg); |
| 1077 | return global_func_table_.wifi_nan_enable_request( |
| 1078 | id, wlan_interface_handle_, &msg_internal); |
| 1079 | } |
| 1080 | |
| 1081 | wifi_error WifiLegacyHal::nanDisableRequest(transaction_id id) { |
| 1082 | return global_func_table_.wifi_nan_disable_request(id, |
| 1083 | wlan_interface_handle_); |
| 1084 | } |
| 1085 | |
| 1086 | wifi_error WifiLegacyHal::nanPublishRequest(transaction_id id, |
| 1087 | const NanPublishRequest& msg) { |
| 1088 | NanPublishRequest msg_internal(msg); |
| 1089 | return global_func_table_.wifi_nan_publish_request( |
| 1090 | id, wlan_interface_handle_, &msg_internal); |
| 1091 | } |
| 1092 | |
| 1093 | wifi_error WifiLegacyHal::nanPublishCancelRequest( |
| 1094 | transaction_id id, const NanPublishCancelRequest& msg) { |
| 1095 | NanPublishCancelRequest msg_internal(msg); |
| 1096 | return global_func_table_.wifi_nan_publish_cancel_request( |
| 1097 | id, wlan_interface_handle_, &msg_internal); |
| 1098 | } |
| 1099 | |
| 1100 | wifi_error WifiLegacyHal::nanSubscribeRequest(transaction_id id, |
| 1101 | const NanSubscribeRequest& msg) { |
| 1102 | NanSubscribeRequest msg_internal(msg); |
| 1103 | return global_func_table_.wifi_nan_subscribe_request( |
| 1104 | id, wlan_interface_handle_, &msg_internal); |
| 1105 | } |
| 1106 | |
| 1107 | wifi_error WifiLegacyHal::nanSubscribeCancelRequest( |
| 1108 | transaction_id id, const NanSubscribeCancelRequest& msg) { |
| 1109 | NanSubscribeCancelRequest msg_internal(msg); |
| 1110 | return global_func_table_.wifi_nan_subscribe_cancel_request( |
| 1111 | id, wlan_interface_handle_, &msg_internal); |
| 1112 | } |
| 1113 | |
| 1114 | wifi_error WifiLegacyHal::nanTransmitFollowupRequest( |
| 1115 | transaction_id id, const NanTransmitFollowupRequest& msg) { |
| 1116 | NanTransmitFollowupRequest msg_internal(msg); |
| 1117 | return global_func_table_.wifi_nan_transmit_followup_request( |
| 1118 | id, wlan_interface_handle_, &msg_internal); |
| 1119 | } |
| 1120 | |
| 1121 | wifi_error WifiLegacyHal::nanStatsRequest(transaction_id id, |
| 1122 | const NanStatsRequest& msg) { |
| 1123 | NanStatsRequest msg_internal(msg); |
| 1124 | return global_func_table_.wifi_nan_stats_request( |
| 1125 | id, wlan_interface_handle_, &msg_internal); |
| 1126 | } |
| 1127 | |
| 1128 | wifi_error WifiLegacyHal::nanConfigRequest(transaction_id id, |
| 1129 | const NanConfigRequest& msg) { |
| 1130 | NanConfigRequest msg_internal(msg); |
| 1131 | return global_func_table_.wifi_nan_config_request( |
| 1132 | id, wlan_interface_handle_, &msg_internal); |
| 1133 | } |
| 1134 | |
| 1135 | wifi_error WifiLegacyHal::nanTcaRequest(transaction_id id, |
| 1136 | const NanTCARequest& msg) { |
| 1137 | NanTCARequest msg_internal(msg); |
| 1138 | return global_func_table_.wifi_nan_tca_request( |
| 1139 | id, wlan_interface_handle_, &msg_internal); |
| 1140 | } |
| 1141 | |
| 1142 | wifi_error WifiLegacyHal::nanBeaconSdfPayloadRequest( |
| 1143 | transaction_id id, const NanBeaconSdfPayloadRequest& msg) { |
| 1144 | NanBeaconSdfPayloadRequest msg_internal(msg); |
| 1145 | return global_func_table_.wifi_nan_beacon_sdf_payload_request( |
| 1146 | id, wlan_interface_handle_, &msg_internal); |
| 1147 | } |
| 1148 | |
| 1149 | std::pair<wifi_error, NanVersion> WifiLegacyHal::nanGetVersion() { |
| 1150 | NanVersion version; |
| 1151 | wifi_error status = |
| 1152 | global_func_table_.wifi_nan_get_version(global_handle_, &version); |
| 1153 | return {status, version}; |
| 1154 | } |
| 1155 | |
| 1156 | wifi_error WifiLegacyHal::nanGetCapabilities(transaction_id id) { |
| 1157 | return global_func_table_.wifi_nan_get_capabilities(id, |
| 1158 | wlan_interface_handle_); |
| 1159 | } |
| 1160 | |
| 1161 | wifi_error WifiLegacyHal::nanDataInterfaceCreate( |
| 1162 | transaction_id id, const std::string& iface_name) { |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1163 | return global_func_table_.wifi_nan_data_interface_create( |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 1164 | id, wlan_interface_handle_, makeCharVec(iface_name).data()); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | wifi_error WifiLegacyHal::nanDataInterfaceDelete( |
| 1168 | transaction_id id, const std::string& iface_name) { |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1169 | return global_func_table_.wifi_nan_data_interface_delete( |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 1170 | id, wlan_interface_handle_, makeCharVec(iface_name).data()); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | wifi_error WifiLegacyHal::nanDataRequestInitiator( |
| 1174 | transaction_id id, const NanDataPathInitiatorRequest& msg) { |
| 1175 | NanDataPathInitiatorRequest msg_internal(msg); |
| 1176 | return global_func_table_.wifi_nan_data_request_initiator( |
| 1177 | id, wlan_interface_handle_, &msg_internal); |
| 1178 | } |
| 1179 | |
| 1180 | wifi_error WifiLegacyHal::nanDataIndicationResponse( |
| 1181 | transaction_id id, const NanDataPathIndicationResponse& msg) { |
| 1182 | NanDataPathIndicationResponse msg_internal(msg); |
| 1183 | return global_func_table_.wifi_nan_data_indication_response( |
| 1184 | id, wlan_interface_handle_, &msg_internal); |
| 1185 | } |
| 1186 | |
| 1187 | wifi_error WifiLegacyHal::nanDataEnd(transaction_id id, |
| 1188 | const NanDataPathEndRequest& msg) { |
| 1189 | NanDataPathEndRequest msg_internal(msg); |
| 1190 | return global_func_table_.wifi_nan_data_end( |
| 1191 | id, wlan_interface_handle_, &msg_internal); |
| 1192 | } |
| 1193 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 1194 | wifi_error WifiLegacyHal::setCountryCode(std::array<int8_t, 2> code) { |
| 1195 | std::string code_str(code.data(), code.data() + code.size()); |
| 1196 | return global_func_table_.wifi_set_country_code(wlan_interface_handle_, |
| 1197 | code_str.c_str()); |
| 1198 | } |
| 1199 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1200 | wifi_error WifiLegacyHal::retrieveWlanInterfaceHandle() { |
Roshan Pius | ab5c471 | 2016-10-06 14:37:15 -0700 | [diff] [blame] | 1201 | const std::string& ifname_to_find = getStaIfaceName(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1202 | wifi_interface_handle* iface_handles = nullptr; |
| 1203 | int num_iface_handles = 0; |
| 1204 | wifi_error status = global_func_table_.wifi_get_ifaces( |
| 1205 | global_handle_, &num_iface_handles, &iface_handles); |
| 1206 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1207 | LOG(ERROR) << "Failed to enumerate interface handles"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1208 | return status; |
| 1209 | } |
| 1210 | for (int i = 0; i < num_iface_handles; ++i) { |
| 1211 | std::array<char, IFNAMSIZ> current_ifname; |
| 1212 | current_ifname.fill(0); |
| 1213 | status = global_func_table_.wifi_get_iface_name( |
| 1214 | iface_handles[i], current_ifname.data(), current_ifname.size()); |
| 1215 | if (status != WIFI_SUCCESS) { |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1216 | LOG(WARNING) << "Failed to get interface handle name"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1217 | continue; |
| 1218 | } |
| 1219 | if (ifname_to_find == current_ifname.data()) { |
| 1220 | wlan_interface_handle_ = iface_handles[i]; |
| 1221 | return WIFI_SUCCESS; |
| 1222 | } |
| 1223 | } |
| 1224 | return WIFI_ERROR_UNKNOWN; |
| 1225 | } |
| 1226 | |
| 1227 | void WifiLegacyHal::runEventLoop() { |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 1228 | LOG(DEBUG) << "Starting legacy HAL event loop"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1229 | global_func_table_.wifi_event_loop(global_handle_); |
| 1230 | if (!awaiting_event_loop_termination_) { |
| 1231 | LOG(FATAL) << "Legacy HAL event loop terminated, but HAL was not stopping"; |
| 1232 | } |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 1233 | LOG(DEBUG) << "Legacy HAL event loop terminated"; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1234 | awaiting_event_loop_termination_ = false; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1237 | std::pair<wifi_error, std::vector<wifi_cached_scan_results>> |
| 1238 | WifiLegacyHal::getGscanCachedResults() { |
| 1239 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 1240 | cached_scan_results.resize(kMaxCachedGscanResults); |
| 1241 | int32_t num_results = 0; |
| 1242 | wifi_error status = global_func_table_.wifi_get_cached_gscan_results( |
| 1243 | wlan_interface_handle_, |
| 1244 | true /* always flush */, |
| 1245 | cached_scan_results.size(), |
| 1246 | cached_scan_results.data(), |
| 1247 | &num_results); |
| 1248 | CHECK(num_results >= 0 && |
| 1249 | static_cast<uint32_t>(num_results) <= kMaxCachedGscanResults); |
| 1250 | cached_scan_results.resize(num_results); |
| 1251 | // Check for invalid IE lengths in these cached scan results and correct it. |
| 1252 | for (auto& cached_scan_result : cached_scan_results) { |
| 1253 | int num_scan_results = cached_scan_result.num_results; |
| 1254 | for (int i = 0; i < num_scan_results; i++) { |
| 1255 | auto& scan_result = cached_scan_result.results[i]; |
| 1256 | if (scan_result.ie_length > 0) { |
| 1257 | LOG(ERROR) << "Cached scan result has non-zero IE length " |
| 1258 | << scan_result.ie_length; |
| 1259 | scan_result.ie_length = 0; |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | return {status, std::move(cached_scan_results)}; |
| 1264 | } |
| 1265 | |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1266 | void WifiLegacyHal::invalidate() { |
| 1267 | global_handle_ = nullptr; |
| 1268 | wlan_interface_handle_ = nullptr; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1269 | on_driver_memory_dump_internal_callback = nullptr; |
| 1270 | on_firmware_memory_dump_internal_callback = nullptr; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1271 | on_gscan_event_internal_callback = nullptr; |
| 1272 | on_gscan_full_result_internal_callback = nullptr; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 1273 | on_link_layer_stats_result_internal_callback = nullptr; |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 1274 | on_rssi_threshold_breached_internal_callback = nullptr; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 1275 | on_ring_buffer_data_internal_callback = nullptr; |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1276 | on_error_alert_internal_callback = nullptr; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1277 | on_rtt_results_internal_callback = nullptr; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1278 | on_nan_notify_response_user_callback = nullptr; |
| 1279 | on_nan_event_publish_terminated_user_callback = nullptr; |
| 1280 | on_nan_event_match_user_callback = nullptr; |
| 1281 | on_nan_event_match_expired_user_callback = nullptr; |
| 1282 | on_nan_event_subscribe_terminated_user_callback = nullptr; |
| 1283 | on_nan_event_followup_user_callback = nullptr; |
| 1284 | on_nan_event_disc_eng_event_user_callback = nullptr; |
| 1285 | on_nan_event_disabled_user_callback = nullptr; |
| 1286 | on_nan_event_tca_user_callback = nullptr; |
| 1287 | on_nan_event_beacon_sdf_payload_user_callback = nullptr; |
| 1288 | on_nan_event_data_path_request_user_callback = nullptr; |
| 1289 | on_nan_event_data_path_confirm_user_callback = nullptr; |
| 1290 | on_nan_event_data_path_end_user_callback = nullptr; |
| 1291 | on_nan_event_transmit_follow_up_user_callback = nullptr; |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 1292 | on_nan_event_range_request_user_callback = nullptr; |
| 1293 | on_nan_event_range_report_user_callback = nullptr; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1294 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 1295 | |
| 1296 | } // namespace legacy_hal |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1297 | } // namespace implementation |
| 1298 | } // namespace V1_0 |
| 1299 | } // namespace wifi |
| 1300 | } // namespace hardware |
| 1301 | } // namespace android |