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