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