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