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> |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 18 | #include <chrono> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 19 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 20 | #include <android-base/logging.h> |
Ahmed ElArabawy | 7153e81 | 2018-06-05 11:09:39 -0700 | [diff] [blame] | 21 | #include <cutils/properties.h> |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 22 | #include <net/if.h> |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 23 | |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 24 | #include "hidl_sync_util.h" |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 25 | #include "wifi_legacy_hal.h" |
Roshan Pius | e73a506 | 2016-12-12 08:53:34 -0800 | [diff] [blame] | 26 | #include "wifi_legacy_hal_stubs.h" |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 27 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 28 | namespace { |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 29 | // Constants ported over from the legacy HAL calling code |
| 30 | // (com_android_server_wifi_WifiNative.cpp). This will all be thrown |
| 31 | // away when this shim layer is replaced by the real vendor |
| 32 | // implementation. |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 33 | static constexpr uint32_t kMaxVersionStringLength = 256; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 34 | static constexpr uint32_t kMaxCachedGscanResults = 64; |
| 35 | static constexpr uint32_t kMaxGscanFrequenciesForBand = 64; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 36 | static constexpr uint32_t kLinkLayerStatsDataMpduSizeThreshold = 128; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 37 | static constexpr uint32_t kMaxWakeReasonStatsArraySize = 32; |
| 38 | static constexpr uint32_t kMaxRingBuffers = 10; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 39 | // need a long timeout (1000ms) for chips that unload their driver. |
| 40 | static constexpr uint32_t kMaxStopCompleteWaitMs = 1000; |
Ahmed ElArabawy | 7153e81 | 2018-06-05 11:09:39 -0700 | [diff] [blame] | 41 | static constexpr char kDriverPropName[] = "wlan.driver.status"; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 42 | |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 43 | // Helper function to create a non-const char* for legacy Hal API's. |
| 44 | std::vector<char> makeCharVec(const std::string& str) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 45 | std::vector<char> vec(str.size() + 1); |
| 46 | vec.assign(str.begin(), str.end()); |
| 47 | vec.push_back('\0'); |
| 48 | return vec; |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 49 | } |
| 50 | } // namespace |
| 51 | |
| 52 | namespace android { |
| 53 | namespace hardware { |
| 54 | namespace wifi { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 55 | namespace V1_5 { |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 56 | namespace implementation { |
| 57 | namespace legacy_hal { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 58 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 59 | // Legacy HAL functions accept "C" style function pointers, so use global |
| 60 | // functions to pass to the legacy HAL function and store the corresponding |
| 61 | // std::function methods to be invoked. |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 62 | // |
| 63 | // Callback to be invoked once |stop| is complete |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 64 | std::function<void(wifi_handle handle)> on_stop_complete_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 65 | void onAsyncStopComplete(wifi_handle handle) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 66 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 67 | if (on_stop_complete_internal_callback) { |
| 68 | on_stop_complete_internal_callback(handle); |
| 69 | // Invalidate this callback since we don't want this firing again. |
| 70 | on_stop_complete_internal_callback = nullptr; |
| 71 | } |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 72 | } |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 73 | |
| 74 | // Callback to be invoked for driver dump. |
| 75 | std::function<void(char*, int)> on_driver_memory_dump_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 76 | void onSyncDriverMemoryDump(char* buffer, int buffer_size) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 77 | if (on_driver_memory_dump_internal_callback) { |
| 78 | on_driver_memory_dump_internal_callback(buffer, buffer_size); |
| 79 | } |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Callback to be invoked for firmware dump. |
| 83 | std::function<void(char*, int)> on_firmware_memory_dump_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 84 | void onSyncFirmwareMemoryDump(char* buffer, int buffer_size) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 85 | if (on_firmware_memory_dump_internal_callback) { |
| 86 | on_firmware_memory_dump_internal_callback(buffer, buffer_size); |
| 87 | } |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 88 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 89 | |
| 90 | // Callback to be invoked for Gscan events. |
| 91 | std::function<void(wifi_request_id, wifi_scan_event)> |
| 92 | on_gscan_event_internal_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 93 | void onAsyncGscanEvent(wifi_request_id id, wifi_scan_event event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 94 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 95 | if (on_gscan_event_internal_callback) { |
| 96 | on_gscan_event_internal_callback(id, event); |
| 97 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Callback to be invoked for Gscan full results. |
| 101 | std::function<void(wifi_request_id, wifi_scan_result*, uint32_t)> |
| 102 | on_gscan_full_result_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 103 | void onAsyncGscanFullResult(wifi_request_id id, wifi_scan_result* result, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 104 | uint32_t buckets_scanned) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 105 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 106 | if (on_gscan_full_result_internal_callback) { |
| 107 | on_gscan_full_result_internal_callback(id, result, buckets_scanned); |
| 108 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 111 | // Callback to be invoked for link layer stats results. |
| 112 | std::function<void((wifi_request_id, wifi_iface_stat*, int, wifi_radio_stat*))> |
| 113 | on_link_layer_stats_result_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 114 | void onSyncLinkLayerStatsResult(wifi_request_id id, wifi_iface_stat* iface_stat, |
| 115 | int num_radios, wifi_radio_stat* radio_stat) { |
| 116 | if (on_link_layer_stats_result_internal_callback) { |
| 117 | on_link_layer_stats_result_internal_callback(id, iface_stat, num_radios, |
| 118 | radio_stat); |
| 119 | } |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 122 | // Callback to be invoked for rssi threshold breach. |
| 123 | std::function<void((wifi_request_id, uint8_t*, int8_t))> |
| 124 | on_rssi_threshold_breached_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 125 | void onAsyncRssiThresholdBreached(wifi_request_id id, uint8_t* bssid, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 126 | int8_t rssi) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 127 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 128 | if (on_rssi_threshold_breached_internal_callback) { |
| 129 | on_rssi_threshold_breached_internal_callback(id, bssid, rssi); |
| 130 | } |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 133 | // Callback to be invoked for ring buffer data indication. |
| 134 | std::function<void(char*, char*, int, wifi_ring_buffer_status*)> |
| 135 | on_ring_buffer_data_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 136 | void onAsyncRingBufferData(char* ring_name, char* buffer, int buffer_size, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 137 | wifi_ring_buffer_status* status) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 138 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 139 | if (on_ring_buffer_data_internal_callback) { |
| 140 | on_ring_buffer_data_internal_callback(ring_name, buffer, buffer_size, |
| 141 | status); |
| 142 | } |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 145 | // Callback to be invoked for error alert indication. |
| 146 | std::function<void(wifi_request_id, char*, int, int)> |
| 147 | on_error_alert_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 148 | void onAsyncErrorAlert(wifi_request_id id, char* buffer, int buffer_size, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 149 | int err_code) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 150 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 151 | if (on_error_alert_internal_callback) { |
| 152 | on_error_alert_internal_callback(id, buffer, buffer_size, err_code); |
| 153 | } |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Roshan Pius | 01f0877 | 2018-01-22 17:56:06 -0800 | [diff] [blame] | 156 | // Callback to be invoked for radio mode change indication. |
| 157 | std::function<void(wifi_request_id, uint32_t, wifi_mac_info*)> |
| 158 | on_radio_mode_change_internal_callback; |
| 159 | void onAsyncRadioModeChange(wifi_request_id id, uint32_t num_macs, |
| 160 | wifi_mac_info* mac_infos) { |
| 161 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 162 | if (on_radio_mode_change_internal_callback) { |
| 163 | on_radio_mode_change_internal_callback(id, num_macs, mac_infos); |
| 164 | } |
| 165 | } |
| 166 | |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 167 | // Callback to be invoked to report subsystem restart |
| 168 | std::function<void(const char*)> on_subsystem_restart_internal_callback; |
| 169 | void onAsyncSubsystemRestart(const char* error) { |
| 170 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 171 | if (on_subsystem_restart_internal_callback) { |
| 172 | on_subsystem_restart_internal_callback(error); |
| 173 | } |
| 174 | } |
| 175 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 176 | // Callback to be invoked for rtt results results. |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 177 | std::function<void(wifi_request_id, unsigned num_results, |
| 178 | wifi_rtt_result* rtt_results[])> |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 179 | on_rtt_results_internal_callback; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 180 | void onAsyncRttResults(wifi_request_id id, unsigned num_results, |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 181 | wifi_rtt_result* rtt_results[]) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 182 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 183 | if (on_rtt_results_internal_callback) { |
| 184 | on_rtt_results_internal_callback(id, num_results, rtt_results); |
| 185 | on_rtt_results_internal_callback = nullptr; |
| 186 | } |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 189 | // Callbacks for the various NAN operations. |
| 190 | // NOTE: These have very little conversions to perform before invoking the user |
| 191 | // callbacks. |
| 192 | // So, handle all of them here directly to avoid adding an unnecessary layer. |
| 193 | std::function<void(transaction_id, const NanResponseMsg&)> |
| 194 | on_nan_notify_response_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 195 | void onAysncNanNotifyResponse(transaction_id id, NanResponseMsg* msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 196 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 197 | if (on_nan_notify_response_user_callback && msg) { |
| 198 | on_nan_notify_response_user_callback(id, *msg); |
| 199 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Etan Cohen | 20925b0 | 2017-04-04 13:00:14 -0700 | [diff] [blame] | 202 | std::function<void(const NanPublishRepliedInd&)> |
| 203 | on_nan_event_publish_replied_user_callback; |
| 204 | void onAysncNanEventPublishReplied(NanPublishRepliedInd* /* event */) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 205 | LOG(ERROR) << "onAysncNanEventPublishReplied triggered"; |
Etan Cohen | 20925b0 | 2017-04-04 13:00:14 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 208 | std::function<void(const NanPublishTerminatedInd&)> |
| 209 | on_nan_event_publish_terminated_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 210 | void onAysncNanEventPublishTerminated(NanPublishTerminatedInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 211 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 212 | if (on_nan_event_publish_terminated_user_callback && event) { |
| 213 | on_nan_event_publish_terminated_user_callback(*event); |
| 214 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | std::function<void(const NanMatchInd&)> on_nan_event_match_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 218 | void onAysncNanEventMatch(NanMatchInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 219 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 220 | if (on_nan_event_match_user_callback && event) { |
| 221 | on_nan_event_match_user_callback(*event); |
| 222 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | std::function<void(const NanMatchExpiredInd&)> |
| 226 | on_nan_event_match_expired_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 227 | void onAysncNanEventMatchExpired(NanMatchExpiredInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 228 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 229 | if (on_nan_event_match_expired_user_callback && event) { |
| 230 | on_nan_event_match_expired_user_callback(*event); |
| 231 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | std::function<void(const NanSubscribeTerminatedInd&)> |
| 235 | on_nan_event_subscribe_terminated_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 236 | void onAysncNanEventSubscribeTerminated(NanSubscribeTerminatedInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 237 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 238 | if (on_nan_event_subscribe_terminated_user_callback && event) { |
| 239 | on_nan_event_subscribe_terminated_user_callback(*event); |
| 240 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | std::function<void(const NanFollowupInd&)> on_nan_event_followup_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 244 | void onAysncNanEventFollowup(NanFollowupInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 245 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 246 | if (on_nan_event_followup_user_callback && event) { |
| 247 | on_nan_event_followup_user_callback(*event); |
| 248 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | std::function<void(const NanDiscEngEventInd&)> |
| 252 | on_nan_event_disc_eng_event_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 253 | void onAysncNanEventDiscEngEvent(NanDiscEngEventInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 254 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 255 | if (on_nan_event_disc_eng_event_user_callback && event) { |
| 256 | on_nan_event_disc_eng_event_user_callback(*event); |
| 257 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | std::function<void(const NanDisabledInd&)> on_nan_event_disabled_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 261 | void onAysncNanEventDisabled(NanDisabledInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 262 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 263 | if (on_nan_event_disabled_user_callback && event) { |
| 264 | on_nan_event_disabled_user_callback(*event); |
| 265 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | std::function<void(const NanTCAInd&)> on_nan_event_tca_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 269 | void onAysncNanEventTca(NanTCAInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 270 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 271 | if (on_nan_event_tca_user_callback && event) { |
| 272 | on_nan_event_tca_user_callback(*event); |
| 273 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | std::function<void(const NanBeaconSdfPayloadInd&)> |
| 277 | on_nan_event_beacon_sdf_payload_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 278 | void onAysncNanEventBeaconSdfPayload(NanBeaconSdfPayloadInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 279 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 280 | if (on_nan_event_beacon_sdf_payload_user_callback && event) { |
| 281 | on_nan_event_beacon_sdf_payload_user_callback(*event); |
| 282 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | std::function<void(const NanDataPathRequestInd&)> |
| 286 | on_nan_event_data_path_request_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 287 | void onAysncNanEventDataPathRequest(NanDataPathRequestInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 288 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 289 | if (on_nan_event_data_path_request_user_callback && event) { |
| 290 | on_nan_event_data_path_request_user_callback(*event); |
| 291 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 292 | } |
| 293 | std::function<void(const NanDataPathConfirmInd&)> |
| 294 | on_nan_event_data_path_confirm_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 295 | void onAysncNanEventDataPathConfirm(NanDataPathConfirmInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 296 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 297 | if (on_nan_event_data_path_confirm_user_callback && event) { |
| 298 | on_nan_event_data_path_confirm_user_callback(*event); |
| 299 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | std::function<void(const NanDataPathEndInd&)> |
| 303 | on_nan_event_data_path_end_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 304 | void onAysncNanEventDataPathEnd(NanDataPathEndInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 305 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 306 | if (on_nan_event_data_path_end_user_callback && event) { |
| 307 | on_nan_event_data_path_end_user_callback(*event); |
| 308 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | std::function<void(const NanTransmitFollowupInd&)> |
| 312 | on_nan_event_transmit_follow_up_user_callback; |
Roshan Pius | 091e1c1 | 2017-01-30 16:40:50 -0800 | [diff] [blame] | 313 | void onAysncNanEventTransmitFollowUp(NanTransmitFollowupInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 314 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 315 | if (on_nan_event_transmit_follow_up_user_callback && event) { |
| 316 | on_nan_event_transmit_follow_up_user_callback(*event); |
| 317 | } |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 318 | } |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 319 | |
| 320 | std::function<void(const NanRangeRequestInd&)> |
| 321 | on_nan_event_range_request_user_callback; |
| 322 | void onAysncNanEventRangeRequest(NanRangeRequestInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 323 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 324 | if (on_nan_event_range_request_user_callback && event) { |
| 325 | on_nan_event_range_request_user_callback(*event); |
| 326 | } |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | std::function<void(const NanRangeReportInd&)> |
| 330 | on_nan_event_range_report_user_callback; |
| 331 | void onAysncNanEventRangeReport(NanRangeReportInd* event) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 332 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 333 | if (on_nan_event_range_report_user_callback && event) { |
| 334 | on_nan_event_range_report_user_callback(*event); |
| 335 | } |
Etan Cohen | c190f93 | 2017-02-17 13:06:55 -0800 | [diff] [blame] | 336 | } |
Etan Cohen | 1bf15f1 | 2017-12-12 16:15:16 -0800 | [diff] [blame] | 337 | |
| 338 | std::function<void(const NanDataPathScheduleUpdateInd&)> |
| 339 | on_nan_event_schedule_update_user_callback; |
| 340 | void onAsyncNanEventScheduleUpdate(NanDataPathScheduleUpdateInd* event) { |
| 341 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 342 | if (on_nan_event_schedule_update_user_callback && event) { |
| 343 | on_nan_event_schedule_update_user_callback(*event); |
| 344 | } |
| 345 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 346 | // End of the free-standing "C" style callbacks. |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 347 | |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 348 | WifiLegacyHal::WifiLegacyHal( |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 349 | const std::weak_ptr<wifi_system::InterfaceTool> iface_tool, |
| 350 | const wifi_hal_fn& fn, bool is_primary) |
| 351 | : global_func_table_(fn), |
| 352 | global_handle_(nullptr), |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 353 | awaiting_event_loop_termination_(false), |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 354 | is_started_(false), |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 355 | iface_tool_(iface_tool), |
| 356 | is_primary_(is_primary) {} |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 357 | |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 358 | wifi_error WifiLegacyHal::initialize() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 359 | LOG(DEBUG) << "Initialize legacy HAL"; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 360 | // this now does nothing, since HAL function table is provided |
| 361 | // to the constructor |
| 362 | return WIFI_SUCCESS; |
Roshan Pius | 9733411 | 2016-11-18 14:07:54 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | wifi_error WifiLegacyHal::start() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 366 | // Ensure that we're starting in a good state. |
| 367 | CHECK(global_func_table_.wifi_initialize && !global_handle_ && |
| 368 | iface_name_to_handle_.empty() && !awaiting_event_loop_termination_); |
| 369 | if (is_started_) { |
| 370 | LOG(DEBUG) << "Legacy HAL already started"; |
| 371 | return WIFI_SUCCESS; |
| 372 | } |
Ahmed ElArabawy | c101815 | 2018-03-02 14:35:04 -0800 | [diff] [blame] | 373 | LOG(DEBUG) << "Waiting for the driver ready"; |
| 374 | wifi_error status = global_func_table_.wifi_wait_for_driver_ready(); |
Veerendranath Jakkam | b3d4348 | 2020-06-11 20:12:48 +0530 | [diff] [blame] | 375 | if (status == WIFI_ERROR_TIMED_OUT || status == WIFI_ERROR_UNKNOWN) { |
| 376 | LOG(ERROR) << "Failed or timed out awaiting driver ready"; |
Ahmed ElArabawy | c101815 | 2018-03-02 14:35:04 -0800 | [diff] [blame] | 377 | return status; |
| 378 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 379 | |
| 380 | if (is_primary_) { |
| 381 | property_set(kDriverPropName, "ok"); |
| 382 | |
| 383 | if (!iface_tool_.lock()->SetWifiUpState(true)) { |
| 384 | LOG(ERROR) << "Failed to set WiFi interface up"; |
| 385 | return WIFI_ERROR_UNKNOWN; |
| 386 | } |
| 387 | } |
Ahmed ElArabawy | 7153e81 | 2018-06-05 11:09:39 -0700 | [diff] [blame] | 388 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 389 | LOG(DEBUG) << "Starting legacy HAL"; |
Ahmed ElArabawy | c101815 | 2018-03-02 14:35:04 -0800 | [diff] [blame] | 390 | status = global_func_table_.wifi_initialize(&global_handle_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 391 | if (status != WIFI_SUCCESS || !global_handle_) { |
| 392 | LOG(ERROR) << "Failed to retrieve global handle"; |
| 393 | return status; |
| 394 | } |
| 395 | std::thread(&WifiLegacyHal::runEventLoop, this).detach(); |
| 396 | status = retrieveIfaceHandles(); |
| 397 | if (status != WIFI_SUCCESS || iface_name_to_handle_.empty()) { |
| 398 | LOG(ERROR) << "Failed to retrieve wlan interface handle"; |
| 399 | return status; |
| 400 | } |
| 401 | LOG(DEBUG) << "Legacy HAL start complete"; |
| 402 | is_started_ = true; |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 403 | return WIFI_SUCCESS; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | wifi_error WifiLegacyHal::stop( |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 407 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 408 | const std::function<void()>& on_stop_complete_user_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 409 | if (!is_started_) { |
| 410 | LOG(DEBUG) << "Legacy HAL already stopped"; |
| 411 | on_stop_complete_user_callback(); |
| 412 | return WIFI_SUCCESS; |
| 413 | } |
| 414 | LOG(DEBUG) << "Stopping legacy HAL"; |
| 415 | on_stop_complete_internal_callback = [on_stop_complete_user_callback, |
| 416 | this](wifi_handle handle) { |
| 417 | CHECK_EQ(global_handle_, handle) << "Handle mismatch"; |
| 418 | LOG(INFO) << "Legacy HAL stop complete callback received"; |
| 419 | // Invalidate all the internal pointers now that the HAL is |
| 420 | // stopped. |
| 421 | invalidate(); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 422 | if (is_primary_) iface_tool_.lock()->SetWifiUpState(false); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 423 | on_stop_complete_user_callback(); |
| 424 | is_started_ = false; |
| 425 | }; |
| 426 | awaiting_event_loop_termination_ = true; |
| 427 | global_func_table_.wifi_cleanup(global_handle_, onAsyncStopComplete); |
| 428 | const auto status = stop_wait_cv_.wait_for( |
| 429 | *lock, std::chrono::milliseconds(kMaxStopCompleteWaitMs), |
| 430 | [this] { return !awaiting_event_loop_termination_; }); |
| 431 | if (!status) { |
| 432 | LOG(ERROR) << "Legacy HAL stop failed or timed out"; |
| 433 | return WIFI_ERROR_UNKNOWN; |
| 434 | } |
| 435 | LOG(DEBUG) << "Legacy HAL stop complete"; |
Roshan Pius | 11f9303 | 2016-12-09 10:26:17 -0800 | [diff] [blame] | 436 | return WIFI_SUCCESS; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Ahmed ElArabawy | 4822938 | 2019-02-07 22:04:53 -0800 | [diff] [blame] | 439 | bool WifiLegacyHal::isStarted() { return is_started_; } |
| 440 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 441 | std::pair<wifi_error, std::string> WifiLegacyHal::getDriverVersion( |
| 442 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 443 | std::array<char, kMaxVersionStringLength> buffer; |
| 444 | buffer.fill(0); |
| 445 | wifi_error status = global_func_table_.wifi_get_driver_version( |
| 446 | getIfaceHandle(iface_name), buffer.data(), buffer.size()); |
| 447 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 450 | std::pair<wifi_error, std::string> WifiLegacyHal::getFirmwareVersion( |
| 451 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 452 | std::array<char, kMaxVersionStringLength> buffer; |
| 453 | buffer.fill(0); |
| 454 | wifi_error status = global_func_table_.wifi_get_firmware_version( |
| 455 | getIfaceHandle(iface_name), buffer.data(), buffer.size()); |
| 456 | return {status, buffer.data()}; |
Roshan Pius | 4b26c83 | 2016-10-03 12:49:58 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 459 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 460 | WifiLegacyHal::requestDriverMemoryDump(const std::string& iface_name) { |
| 461 | std::vector<uint8_t> driver_dump; |
| 462 | on_driver_memory_dump_internal_callback = [&driver_dump](char* buffer, |
| 463 | int buffer_size) { |
| 464 | driver_dump.insert(driver_dump.end(), |
| 465 | reinterpret_cast<uint8_t*>(buffer), |
| 466 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
| 467 | }; |
| 468 | wifi_error status = global_func_table_.wifi_get_driver_memory_dump( |
| 469 | getIfaceHandle(iface_name), {onSyncDriverMemoryDump}); |
| 470 | on_driver_memory_dump_internal_callback = nullptr; |
| 471 | return {status, std::move(driver_dump)}; |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 474 | std::pair<wifi_error, std::vector<uint8_t>> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 475 | WifiLegacyHal::requestFirmwareMemoryDump(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 476 | std::vector<uint8_t> firmware_dump; |
| 477 | on_firmware_memory_dump_internal_callback = |
| 478 | [&firmware_dump](char* buffer, int buffer_size) { |
| 479 | firmware_dump.insert( |
| 480 | firmware_dump.end(), reinterpret_cast<uint8_t*>(buffer), |
| 481 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
| 482 | }; |
| 483 | wifi_error status = global_func_table_.wifi_get_firmware_memory_dump( |
| 484 | getIfaceHandle(iface_name), {onSyncFirmwareMemoryDump}); |
| 485 | on_firmware_memory_dump_internal_callback = nullptr; |
| 486 | return {status, std::move(firmware_dump)}; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 487 | } |
| 488 | |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 489 | std::pair<wifi_error, uint64_t> WifiLegacyHal::getSupportedFeatureSet( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 490 | const std::string& iface_name) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 491 | feature_set set = 0, chip_set = 0; |
| 492 | wifi_error status = WIFI_SUCCESS; |
| 493 | |
Ahmed ElArabawy | 95e36b7 | 2019-11-15 21:24:53 +0000 | [diff] [blame] | 494 | static_assert(sizeof(set) == sizeof(uint64_t), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 495 | "Some feature_flags can not be represented in output"); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 496 | wifi_interface_handle iface_handle = getIfaceHandle(iface_name); |
| 497 | |
| 498 | global_func_table_.wifi_get_chip_feature_set( |
| 499 | global_handle_, &chip_set); /* ignore error, chip_set will stay 0 */ |
| 500 | |
| 501 | if (iface_handle) { |
| 502 | status = global_func_table_.wifi_get_supported_feature_set(iface_handle, |
| 503 | &set); |
| 504 | } |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 505 | return {status, static_cast<uint64_t>(set | chip_set)}; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | std::pair<wifi_error, PacketFilterCapabilities> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 509 | WifiLegacyHal::getPacketFilterCapabilities(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 510 | PacketFilterCapabilities caps; |
| 511 | wifi_error status = global_func_table_.wifi_get_packet_filter_capabilities( |
| 512 | getIfaceHandle(iface_name), &caps.version, &caps.max_len); |
| 513 | return {status, caps}; |
Roshan Pius | 0a47c18 | 2016-10-28 10:23:00 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 516 | wifi_error WifiLegacyHal::setPacketFilter(const std::string& iface_name, |
| 517 | const std::vector<uint8_t>& program) { |
| 518 | return global_func_table_.wifi_set_packet_filter( |
| 519 | getIfaceHandle(iface_name), program.data(), program.size()); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Bernie Innocenti | 7e6f71a | 2018-03-07 00:17:50 +0900 | [diff] [blame] | 522 | std::pair<wifi_error, std::vector<uint8_t>> |
| 523 | WifiLegacyHal::readApfPacketFilterData(const std::string& iface_name) { |
Bernie Innocenti | 7e6f71a | 2018-03-07 00:17:50 +0900 | [diff] [blame] | 524 | PacketFilterCapabilities caps; |
| 525 | wifi_error status = global_func_table_.wifi_get_packet_filter_capabilities( |
| 526 | getIfaceHandle(iface_name), &caps.version, &caps.max_len); |
| 527 | if (status != WIFI_SUCCESS) { |
| 528 | return {status, {}}; |
| 529 | } |
| 530 | |
| 531 | // Size the buffer to read the entire program & work memory. |
| 532 | std::vector<uint8_t> buffer(caps.max_len); |
| 533 | |
| 534 | status = global_func_table_.wifi_read_packet_filter( |
| 535 | getIfaceHandle(iface_name), /*src_offset=*/0, buffer.data(), |
| 536 | buffer.size()); |
| 537 | return {status, move(buffer)}; |
| 538 | } |
| 539 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 540 | std::pair<wifi_error, wifi_gscan_capabilities> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 541 | WifiLegacyHal::getGscanCapabilities(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 542 | wifi_gscan_capabilities caps; |
| 543 | wifi_error status = global_func_table_.wifi_get_gscan_capabilities( |
| 544 | getIfaceHandle(iface_name), &caps); |
| 545 | return {status, caps}; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | wifi_error WifiLegacyHal::startGscan( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 549 | const std::string& iface_name, wifi_request_id id, |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 550 | const wifi_scan_cmd_params& params, |
| 551 | const std::function<void(wifi_request_id)>& on_failure_user_callback, |
| 552 | const on_gscan_results_callback& on_results_user_callback, |
| 553 | const on_gscan_full_result_callback& on_full_result_user_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 554 | // If there is already an ongoing background scan, reject new scan requests. |
| 555 | if (on_gscan_event_internal_callback || |
| 556 | on_gscan_full_result_internal_callback) { |
| 557 | return WIFI_ERROR_NOT_AVAILABLE; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 558 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 559 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 560 | // This callback will be used to either trigger |on_results_user_callback| |
| 561 | // or |on_failure_user_callback|. |
| 562 | on_gscan_event_internal_callback = |
| 563 | [iface_name, on_failure_user_callback, on_results_user_callback, this]( |
| 564 | wifi_request_id id, wifi_scan_event event) { |
| 565 | switch (event) { |
| 566 | case WIFI_SCAN_RESULTS_AVAILABLE: |
| 567 | case WIFI_SCAN_THRESHOLD_NUM_SCANS: |
| 568 | case WIFI_SCAN_THRESHOLD_PERCENT: { |
| 569 | wifi_error status; |
| 570 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 571 | std::tie(status, cached_scan_results) = |
| 572 | getGscanCachedResults(iface_name); |
| 573 | if (status == WIFI_SUCCESS) { |
| 574 | on_results_user_callback(id, cached_scan_results); |
| 575 | return; |
| 576 | } |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 577 | FALLTHROUGH_INTENDED; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 578 | } |
| 579 | // Fall through if failed. Failure to retrieve cached scan |
| 580 | // results should trigger a background scan failure. |
| 581 | case WIFI_SCAN_FAILED: |
| 582 | on_failure_user_callback(id); |
| 583 | on_gscan_event_internal_callback = nullptr; |
| 584 | on_gscan_full_result_internal_callback = nullptr; |
| 585 | return; |
| 586 | } |
| 587 | LOG(FATAL) << "Unexpected gscan event received: " << event; |
| 588 | }; |
| 589 | |
| 590 | on_gscan_full_result_internal_callback = [on_full_result_user_callback]( |
| 591 | wifi_request_id id, |
| 592 | wifi_scan_result* result, |
| 593 | uint32_t buckets_scanned) { |
| 594 | if (result) { |
| 595 | on_full_result_user_callback(id, result, buckets_scanned); |
| 596 | } |
| 597 | }; |
| 598 | |
| 599 | wifi_scan_result_handler handler = {onAsyncGscanFullResult, |
| 600 | onAsyncGscanEvent}; |
| 601 | wifi_error status = global_func_table_.wifi_start_gscan( |
| 602 | id, getIfaceHandle(iface_name), params, handler); |
| 603 | if (status != WIFI_SUCCESS) { |
| 604 | on_gscan_event_internal_callback = nullptr; |
| 605 | on_gscan_full_result_internal_callback = nullptr; |
| 606 | } |
| 607 | return status; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 610 | wifi_error WifiLegacyHal::stopGscan(const std::string& iface_name, |
| 611 | wifi_request_id id) { |
| 612 | // If there is no an ongoing background scan, reject stop requests. |
| 613 | // TODO(b/32337212): This needs to be handled by the HIDL object because we |
| 614 | // need to return the NOT_STARTED error code. |
| 615 | if (!on_gscan_event_internal_callback && |
| 616 | !on_gscan_full_result_internal_callback) { |
| 617 | return WIFI_ERROR_NOT_AVAILABLE; |
| 618 | } |
| 619 | wifi_error status = |
| 620 | global_func_table_.wifi_stop_gscan(id, getIfaceHandle(iface_name)); |
| 621 | // If the request Id is wrong, don't stop the ongoing background scan. Any |
| 622 | // other error should be treated as the end of background scan. |
| 623 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 624 | on_gscan_event_internal_callback = nullptr; |
| 625 | on_gscan_full_result_internal_callback = nullptr; |
| 626 | } |
| 627 | return status; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | std::pair<wifi_error, std::vector<uint32_t>> |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 631 | WifiLegacyHal::getValidFrequenciesForBand(const std::string& iface_name, |
| 632 | wifi_band band) { |
| 633 | static_assert(sizeof(uint32_t) >= sizeof(wifi_channel), |
| 634 | "Wifi Channel cannot be represented in output"); |
| 635 | std::vector<uint32_t> freqs; |
| 636 | freqs.resize(kMaxGscanFrequenciesForBand); |
| 637 | int32_t num_freqs = 0; |
| 638 | wifi_error status = global_func_table_.wifi_get_valid_channels( |
| 639 | getIfaceHandle(iface_name), band, freqs.size(), |
| 640 | reinterpret_cast<wifi_channel*>(freqs.data()), &num_freqs); |
| 641 | CHECK(num_freqs >= 0 && |
| 642 | static_cast<uint32_t>(num_freqs) <= kMaxGscanFrequenciesForBand); |
| 643 | freqs.resize(num_freqs); |
| 644 | return {status, std::move(freqs)}; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 647 | wifi_error WifiLegacyHal::setDfsFlag(const std::string& iface_name, |
| 648 | bool dfs_on) { |
| 649 | return global_func_table_.wifi_set_nodfs_flag(getIfaceHandle(iface_name), |
| 650 | dfs_on ? 0 : 1); |
Roshan Pius | 08d1df4 | 2017-04-19 23:11:07 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 653 | wifi_error WifiLegacyHal::enableLinkLayerStats(const std::string& iface_name, |
| 654 | bool debug) { |
| 655 | wifi_link_layer_params params; |
| 656 | params.mpdu_size_threshold = kLinkLayerStatsDataMpduSizeThreshold; |
| 657 | params.aggressive_statistics_gathering = debug; |
| 658 | return global_func_table_.wifi_set_link_stats(getIfaceHandle(iface_name), |
| 659 | params); |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 662 | wifi_error WifiLegacyHal::disableLinkLayerStats(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 663 | // TODO: Do we care about these responses? |
| 664 | uint32_t clear_mask_rsp; |
| 665 | uint8_t stop_rsp; |
| 666 | return global_func_table_.wifi_clear_link_stats( |
| 667 | getIfaceHandle(iface_name), 0xFFFFFFFF, &clear_mask_rsp, 1, &stop_rsp); |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 670 | std::pair<wifi_error, LinkLayerStats> WifiLegacyHal::getLinkLayerStats( |
| 671 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 672 | LinkLayerStats link_stats{}; |
| 673 | LinkLayerStats* link_stats_ptr = &link_stats; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 674 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 675 | on_link_layer_stats_result_internal_callback = |
| 676 | [&link_stats_ptr](wifi_request_id /* id */, |
| 677 | wifi_iface_stat* iface_stats_ptr, int num_radios, |
| 678 | wifi_radio_stat* radio_stats_ptr) { |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 679 | wifi_radio_stat* l_radio_stats_ptr; |
| 680 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 681 | if (iface_stats_ptr != nullptr) { |
| 682 | link_stats_ptr->iface = *iface_stats_ptr; |
| 683 | link_stats_ptr->iface.num_peers = 0; |
| 684 | } else { |
| 685 | LOG(ERROR) << "Invalid iface stats in link layer stats"; |
| 686 | } |
| 687 | if (num_radios <= 0 || radio_stats_ptr == nullptr) { |
| 688 | LOG(ERROR) << "Invalid radio stats in link layer stats"; |
| 689 | return; |
| 690 | } |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 691 | l_radio_stats_ptr = radio_stats_ptr; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 692 | for (int i = 0; i < num_radios; i++) { |
| 693 | LinkLayerRadioStats radio; |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 694 | |
| 695 | radio.stats = *l_radio_stats_ptr; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 696 | // Copy over the tx level array to the separate vector. |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 697 | if (l_radio_stats_ptr->num_tx_levels > 0 && |
| 698 | l_radio_stats_ptr->tx_time_per_levels != nullptr) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 699 | radio.tx_time_per_levels.assign( |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 700 | l_radio_stats_ptr->tx_time_per_levels, |
| 701 | l_radio_stats_ptr->tx_time_per_levels + |
| 702 | l_radio_stats_ptr->num_tx_levels); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 703 | } |
| 704 | radio.stats.num_tx_levels = 0; |
| 705 | radio.stats.tx_time_per_levels = nullptr; |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 706 | /* Copy over the channel stat to separate vector */ |
| 707 | if (l_radio_stats_ptr->num_channels > 0) { |
| 708 | /* Copy the channel stats */ |
| 709 | radio.channel_stats.assign( |
| 710 | l_radio_stats_ptr->channels, |
| 711 | l_radio_stats_ptr->channels + |
| 712 | l_radio_stats_ptr->num_channels); |
| 713 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 714 | link_stats_ptr->radios.push_back(radio); |
Sunil Ravi | b0343e7 | 2018-11-13 15:52:00 -0800 | [diff] [blame] | 715 | l_radio_stats_ptr = |
| 716 | (wifi_radio_stat*)((u8*)l_radio_stats_ptr + |
| 717 | sizeof(wifi_radio_stat) + |
| 718 | (sizeof(wifi_channel_stat) * |
| 719 | l_radio_stats_ptr->num_channels)); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 720 | } |
| 721 | }; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 722 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 723 | wifi_error status = global_func_table_.wifi_get_link_stats( |
| 724 | 0, getIfaceHandle(iface_name), {onSyncLinkLayerStatsResult}); |
| 725 | on_link_layer_stats_result_internal_callback = nullptr; |
| 726 | return {status, link_stats}; |
Roshan Pius | 7cece41 | 2016-10-28 10:38:21 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 729 | wifi_error WifiLegacyHal::startRssiMonitoring( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 730 | const std::string& iface_name, wifi_request_id id, int8_t max_rssi, |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 731 | int8_t min_rssi, |
| 732 | const on_rssi_threshold_breached_callback& |
| 733 | on_threshold_breached_user_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 734 | if (on_rssi_threshold_breached_internal_callback) { |
| 735 | return WIFI_ERROR_NOT_AVAILABLE; |
| 736 | } |
| 737 | on_rssi_threshold_breached_internal_callback = |
| 738 | [on_threshold_breached_user_callback](wifi_request_id id, |
| 739 | uint8_t* bssid_ptr, int8_t rssi) { |
| 740 | if (!bssid_ptr) { |
| 741 | return; |
| 742 | } |
| 743 | std::array<uint8_t, 6> bssid_arr; |
| 744 | // |bssid_ptr| pointer is assumed to have 6 bytes for the mac |
| 745 | // address. |
| 746 | std::copy(bssid_ptr, bssid_ptr + 6, std::begin(bssid_arr)); |
| 747 | on_threshold_breached_user_callback(id, bssid_arr, rssi); |
| 748 | }; |
| 749 | wifi_error status = global_func_table_.wifi_start_rssi_monitoring( |
| 750 | id, getIfaceHandle(iface_name), max_rssi, min_rssi, |
| 751 | {onAsyncRssiThresholdBreached}); |
| 752 | if (status != WIFI_SUCCESS) { |
| 753 | on_rssi_threshold_breached_internal_callback = nullptr; |
| 754 | } |
| 755 | return status; |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 758 | wifi_error WifiLegacyHal::stopRssiMonitoring(const std::string& iface_name, |
| 759 | wifi_request_id id) { |
| 760 | if (!on_rssi_threshold_breached_internal_callback) { |
| 761 | return WIFI_ERROR_NOT_AVAILABLE; |
| 762 | } |
| 763 | wifi_error status = global_func_table_.wifi_stop_rssi_monitoring( |
| 764 | id, getIfaceHandle(iface_name)); |
| 765 | // If the request Id is wrong, don't stop the ongoing rssi monitoring. Any |
| 766 | // other error should be treated as the end of background scan. |
| 767 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 768 | on_rssi_threshold_breached_internal_callback = nullptr; |
| 769 | } |
| 770 | return status; |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 771 | } |
| 772 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 773 | std::pair<wifi_error, wifi_roaming_capabilities> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 774 | WifiLegacyHal::getRoamingCapabilities(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 775 | wifi_roaming_capabilities caps; |
| 776 | wifi_error status = global_func_table_.wifi_get_roaming_capabilities( |
| 777 | getIfaceHandle(iface_name), &caps); |
| 778 | return {status, caps}; |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 781 | wifi_error WifiLegacyHal::configureRoaming(const std::string& iface_name, |
| 782 | const wifi_roaming_config& config) { |
| 783 | wifi_roaming_config config_internal = config; |
| 784 | return global_func_table_.wifi_configure_roaming(getIfaceHandle(iface_name), |
| 785 | &config_internal); |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 786 | } |
| 787 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 788 | wifi_error WifiLegacyHal::enableFirmwareRoaming(const std::string& iface_name, |
| 789 | fw_roaming_state_t state) { |
| 790 | return global_func_table_.wifi_enable_firmware_roaming( |
| 791 | getIfaceHandle(iface_name), state); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 792 | } |
| 793 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 794 | wifi_error WifiLegacyHal::configureNdOffload(const std::string& iface_name, |
| 795 | bool enable) { |
| 796 | return global_func_table_.wifi_configure_nd_offload( |
| 797 | getIfaceHandle(iface_name), enable); |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 798 | } |
| 799 | |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 800 | wifi_error WifiLegacyHal::startSendingOffloadedPacket( |
Ahmed ElArabawy | ffbad18 | 2019-03-05 17:38:06 -0800 | [diff] [blame] | 801 | const std::string& iface_name, uint32_t cmd_id, uint16_t ether_type, |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 802 | const std::vector<uint8_t>& ip_packet_data, |
| 803 | const std::array<uint8_t, 6>& src_address, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 804 | const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms) { |
| 805 | std::vector<uint8_t> ip_packet_data_internal(ip_packet_data); |
| 806 | std::vector<uint8_t> src_address_internal( |
| 807 | src_address.data(), src_address.data() + src_address.size()); |
| 808 | std::vector<uint8_t> dst_address_internal( |
| 809 | dst_address.data(), dst_address.data() + dst_address.size()); |
| 810 | return global_func_table_.wifi_start_sending_offloaded_packet( |
Ahmed ElArabawy | ffbad18 | 2019-03-05 17:38:06 -0800 | [diff] [blame] | 811 | cmd_id, getIfaceHandle(iface_name), ether_type, |
| 812 | ip_packet_data_internal.data(), ip_packet_data_internal.size(), |
| 813 | src_address_internal.data(), dst_address_internal.data(), period_in_ms); |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 816 | wifi_error WifiLegacyHal::stopSendingOffloadedPacket( |
| 817 | const std::string& iface_name, uint32_t cmd_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 818 | return global_func_table_.wifi_stop_sending_offloaded_packet( |
| 819 | cmd_id, getIfaceHandle(iface_name)); |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 820 | } |
| 821 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 822 | wifi_error WifiLegacyHal::selectTxPowerScenario(const std::string& iface_name, |
| 823 | wifi_power_scenario scenario) { |
| 824 | return global_func_table_.wifi_select_tx_power_scenario( |
| 825 | getIfaceHandle(iface_name), scenario); |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 828 | wifi_error WifiLegacyHal::resetTxPowerScenario(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 829 | return global_func_table_.wifi_reset_tx_power_scenario( |
| 830 | getIfaceHandle(iface_name)); |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 833 | wifi_error WifiLegacyHal::setLatencyMode(const std::string& iface_name, |
| 834 | wifi_latency_mode mode) { |
| 835 | return global_func_table_.wifi_set_latency_mode(getIfaceHandle(iface_name), |
| 836 | mode); |
| 837 | } |
| 838 | |
Kumar Anand | f2747e0 | 2020-01-10 16:49:13 -0800 | [diff] [blame] | 839 | wifi_error WifiLegacyHal::setThermalMitigationMode(wifi_thermal_mode mode, |
| 840 | uint32_t completion_window) { |
Kumar Anand | 913d560 | 2019-12-18 16:02:37 -0800 | [diff] [blame] | 841 | return global_func_table_.wifi_set_thermal_mitigation_mode( |
Kumar Anand | f2747e0 | 2020-01-10 16:49:13 -0800 | [diff] [blame] | 842 | global_handle_, mode, completion_window); |
Kumar Anand | 913d560 | 2019-12-18 16:02:37 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Ahmed ElArabawy | a1d1365 | 2020-01-29 09:22:28 -0800 | [diff] [blame] | 845 | wifi_error WifiLegacyHal::setDscpToAccessCategoryMapping( |
| 846 | uint32_t start, uint32_t end, uint32_t access_category) { |
| 847 | return global_func_table_.wifi_map_dscp_access_category( |
| 848 | global_handle_, start, end, access_category); |
| 849 | } |
| 850 | |
| 851 | wifi_error WifiLegacyHal::resetDscpToAccessCategoryMapping() { |
| 852 | return global_func_table_.wifi_reset_dscp_mapping(global_handle_); |
| 853 | } |
| 854 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 855 | std::pair<wifi_error, uint32_t> WifiLegacyHal::getLoggerSupportedFeatureSet( |
| 856 | const std::string& iface_name) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 857 | uint32_t supported_feature_flags = 0; |
| 858 | wifi_error status = WIFI_SUCCESS; |
| 859 | |
| 860 | wifi_interface_handle iface_handle = getIfaceHandle(iface_name); |
| 861 | |
| 862 | if (iface_handle) { |
| 863 | status = global_func_table_.wifi_get_logger_supported_feature_set( |
| 864 | iface_handle, &supported_feature_flags); |
| 865 | } |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 866 | return {status, supported_feature_flags}; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 869 | wifi_error WifiLegacyHal::startPktFateMonitoring( |
| 870 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 871 | return global_func_table_.wifi_start_pkt_fate_monitoring( |
| 872 | getIfaceHandle(iface_name)); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 875 | std::pair<wifi_error, std::vector<wifi_tx_report>> WifiLegacyHal::getTxPktFates( |
| 876 | const std::string& iface_name) { |
| 877 | std::vector<wifi_tx_report> tx_pkt_fates; |
| 878 | tx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 879 | size_t num_fates = 0; |
| 880 | wifi_error status = global_func_table_.wifi_get_tx_pkt_fates( |
| 881 | getIfaceHandle(iface_name), tx_pkt_fates.data(), tx_pkt_fates.size(), |
| 882 | &num_fates); |
| 883 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 884 | tx_pkt_fates.resize(num_fates); |
| 885 | return {status, std::move(tx_pkt_fates)}; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 888 | std::pair<wifi_error, std::vector<wifi_rx_report>> WifiLegacyHal::getRxPktFates( |
| 889 | const std::string& iface_name) { |
| 890 | std::vector<wifi_rx_report> rx_pkt_fates; |
| 891 | rx_pkt_fates.resize(MAX_FATE_LOG_LEN); |
| 892 | size_t num_fates = 0; |
| 893 | wifi_error status = global_func_table_.wifi_get_rx_pkt_fates( |
| 894 | getIfaceHandle(iface_name), rx_pkt_fates.data(), rx_pkt_fates.size(), |
| 895 | &num_fates); |
| 896 | CHECK(num_fates <= MAX_FATE_LOG_LEN); |
| 897 | rx_pkt_fates.resize(num_fates); |
| 898 | return {status, std::move(rx_pkt_fates)}; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 901 | std::pair<wifi_error, WakeReasonStats> WifiLegacyHal::getWakeReasonStats( |
| 902 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 903 | WakeReasonStats stats; |
| 904 | stats.cmd_event_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
| 905 | stats.driver_fw_local_wake_cnt.resize(kMaxWakeReasonStatsArraySize); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 906 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 907 | // This legacy struct needs separate memory to store the variable sized wake |
| 908 | // reason types. |
| 909 | stats.wake_reason_cnt.cmd_event_wake_cnt = |
| 910 | reinterpret_cast<int32_t*>(stats.cmd_event_wake_cnt.data()); |
| 911 | stats.wake_reason_cnt.cmd_event_wake_cnt_sz = |
| 912 | stats.cmd_event_wake_cnt.size(); |
| 913 | stats.wake_reason_cnt.cmd_event_wake_cnt_used = 0; |
| 914 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = |
| 915 | reinterpret_cast<int32_t*>(stats.driver_fw_local_wake_cnt.data()); |
| 916 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_sz = |
| 917 | stats.driver_fw_local_wake_cnt.size(); |
| 918 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used = 0; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 919 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 920 | wifi_error status = global_func_table_.wifi_get_wake_reason_stats( |
| 921 | getIfaceHandle(iface_name), &stats.wake_reason_cnt); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 922 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 923 | CHECK( |
| 924 | stats.wake_reason_cnt.cmd_event_wake_cnt_used >= 0 && |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 925 | static_cast<uint32_t>(stats.wake_reason_cnt.cmd_event_wake_cnt_used) <= |
| 926 | kMaxWakeReasonStatsArraySize); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 927 | stats.cmd_event_wake_cnt.resize( |
| 928 | stats.wake_reason_cnt.cmd_event_wake_cnt_used); |
| 929 | stats.wake_reason_cnt.cmd_event_wake_cnt = nullptr; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 930 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 931 | CHECK(stats.wake_reason_cnt.driver_fw_local_wake_cnt_used >= 0 && |
| 932 | static_cast<uint32_t>( |
| 933 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used) <= |
| 934 | kMaxWakeReasonStatsArraySize); |
| 935 | stats.driver_fw_local_wake_cnt.resize( |
| 936 | stats.wake_reason_cnt.driver_fw_local_wake_cnt_used); |
| 937 | stats.wake_reason_cnt.driver_fw_local_wake_cnt = nullptr; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 938 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 939 | return {status, stats}; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | wifi_error WifiLegacyHal::registerRingBufferCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 943 | const std::string& iface_name, |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 944 | const on_ring_buffer_data_callback& on_user_data_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 945 | if (on_ring_buffer_data_internal_callback) { |
| 946 | return WIFI_ERROR_NOT_AVAILABLE; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 947 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 948 | on_ring_buffer_data_internal_callback = |
| 949 | [on_user_data_callback](char* ring_name, char* buffer, int buffer_size, |
| 950 | wifi_ring_buffer_status* status) { |
| 951 | if (status && buffer) { |
| 952 | std::vector<uint8_t> buffer_vector( |
| 953 | reinterpret_cast<uint8_t*>(buffer), |
| 954 | reinterpret_cast<uint8_t*>(buffer) + buffer_size); |
| 955 | on_user_data_callback(ring_name, buffer_vector, *status); |
| 956 | } |
| 957 | }; |
| 958 | wifi_error status = global_func_table_.wifi_set_log_handler( |
| 959 | 0, getIfaceHandle(iface_name), {onAsyncRingBufferData}); |
| 960 | if (status != WIFI_SUCCESS) { |
| 961 | on_ring_buffer_data_internal_callback = nullptr; |
| 962 | } |
| 963 | return status; |
Roshan Pius | adc87cb | 2016-12-14 18:02:56 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 966 | wifi_error WifiLegacyHal::deregisterRingBufferCallbackHandler( |
| 967 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 968 | if (!on_ring_buffer_data_internal_callback) { |
| 969 | return WIFI_ERROR_NOT_AVAILABLE; |
| 970 | } |
| 971 | on_ring_buffer_data_internal_callback = nullptr; |
| 972 | return global_func_table_.wifi_reset_log_handler( |
| 973 | 0, getIfaceHandle(iface_name)); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 977 | WifiLegacyHal::getRingBuffersStatus(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 978 | std::vector<wifi_ring_buffer_status> ring_buffers_status; |
| 979 | ring_buffers_status.resize(kMaxRingBuffers); |
| 980 | uint32_t num_rings = kMaxRingBuffers; |
| 981 | wifi_error status = global_func_table_.wifi_get_ring_buffers_status( |
| 982 | getIfaceHandle(iface_name), &num_rings, ring_buffers_status.data()); |
| 983 | CHECK(num_rings <= kMaxRingBuffers); |
| 984 | ring_buffers_status.resize(num_rings); |
| 985 | return {status, std::move(ring_buffers_status)}; |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 988 | wifi_error WifiLegacyHal::startRingBufferLogging(const std::string& iface_name, |
| 989 | const std::string& ring_name, |
| 990 | uint32_t verbose_level, |
| 991 | uint32_t max_interval_sec, |
| 992 | uint32_t min_data_size) { |
| 993 | return global_func_table_.wifi_start_logging( |
| 994 | getIfaceHandle(iface_name), verbose_level, 0, max_interval_sec, |
| 995 | min_data_size, makeCharVec(ring_name).data()); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 998 | wifi_error WifiLegacyHal::getRingBufferData(const std::string& iface_name, |
| 999 | const std::string& ring_name) { |
| 1000 | return global_func_table_.wifi_get_ring_data(getIfaceHandle(iface_name), |
| 1001 | makeCharVec(ring_name).data()); |
Roshan Pius | 8714a3e | 2016-10-28 10:43:51 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1004 | wifi_error WifiLegacyHal::registerErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1005 | const std::string& iface_name, |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1006 | const on_error_alert_callback& on_user_alert_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1007 | if (on_error_alert_internal_callback) { |
| 1008 | return WIFI_ERROR_NOT_AVAILABLE; |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1009 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1010 | on_error_alert_internal_callback = [on_user_alert_callback]( |
| 1011 | wifi_request_id id, char* buffer, |
| 1012 | int buffer_size, int err_code) { |
| 1013 | if (buffer) { |
| 1014 | CHECK(id == 0); |
| 1015 | on_user_alert_callback( |
| 1016 | err_code, |
| 1017 | std::vector<uint8_t>( |
| 1018 | reinterpret_cast<uint8_t*>(buffer), |
| 1019 | reinterpret_cast<uint8_t*>(buffer) + buffer_size)); |
| 1020 | } |
| 1021 | }; |
| 1022 | wifi_error status = global_func_table_.wifi_set_alert_handler( |
| 1023 | 0, getIfaceHandle(iface_name), {onAsyncErrorAlert}); |
| 1024 | if (status != WIFI_SUCCESS) { |
| 1025 | on_error_alert_internal_callback = nullptr; |
| 1026 | } |
| 1027 | return status; |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1030 | wifi_error WifiLegacyHal::deregisterErrorAlertCallbackHandler( |
| 1031 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1032 | if (!on_error_alert_internal_callback) { |
| 1033 | return WIFI_ERROR_NOT_AVAILABLE; |
| 1034 | } |
| 1035 | on_error_alert_internal_callback = nullptr; |
| 1036 | return global_func_table_.wifi_reset_alert_handler( |
| 1037 | 0, getIfaceHandle(iface_name)); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Roshan Pius | 01f0877 | 2018-01-22 17:56:06 -0800 | [diff] [blame] | 1040 | wifi_error WifiLegacyHal::registerRadioModeChangeCallbackHandler( |
| 1041 | const std::string& iface_name, |
| 1042 | const on_radio_mode_change_callback& on_user_change_callback) { |
| 1043 | if (on_radio_mode_change_internal_callback) { |
| 1044 | return WIFI_ERROR_NOT_AVAILABLE; |
| 1045 | } |
| 1046 | on_radio_mode_change_internal_callback = [on_user_change_callback]( |
| 1047 | wifi_request_id /* id */, |
| 1048 | uint32_t num_macs, |
| 1049 | wifi_mac_info* mac_infos_arr) { |
| 1050 | if (num_macs > 0 && mac_infos_arr) { |
| 1051 | std::vector<WifiMacInfo> mac_infos_vec; |
| 1052 | for (uint32_t i = 0; i < num_macs; i++) { |
| 1053 | WifiMacInfo mac_info; |
| 1054 | mac_info.wlan_mac_id = mac_infos_arr[i].wlan_mac_id; |
| 1055 | mac_info.mac_band = mac_infos_arr[i].mac_band; |
| 1056 | for (int32_t j = 0; j < mac_infos_arr[i].num_iface; j++) { |
| 1057 | WifiIfaceInfo iface_info; |
| 1058 | iface_info.name = mac_infos_arr[i].iface_info[j].iface_name; |
| 1059 | iface_info.channel = mac_infos_arr[i].iface_info[j].channel; |
| 1060 | mac_info.iface_infos.push_back(iface_info); |
| 1061 | } |
| 1062 | mac_infos_vec.push_back(mac_info); |
| 1063 | } |
| 1064 | on_user_change_callback(mac_infos_vec); |
| 1065 | } |
| 1066 | }; |
| 1067 | wifi_error status = global_func_table_.wifi_set_radio_mode_change_handler( |
| 1068 | 0, getIfaceHandle(iface_name), {onAsyncRadioModeChange}); |
| 1069 | if (status != WIFI_SUCCESS) { |
| 1070 | on_radio_mode_change_internal_callback = nullptr; |
| 1071 | } |
| 1072 | return status; |
| 1073 | } |
| 1074 | |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 1075 | wifi_error WifiLegacyHal::registerSubsystemRestartCallbackHandler( |
| 1076 | const on_subsystem_restart_callback& on_restart_callback) { |
| 1077 | if (on_subsystem_restart_internal_callback) { |
| 1078 | return WIFI_ERROR_NOT_AVAILABLE; |
| 1079 | } |
| 1080 | on_subsystem_restart_internal_callback = |
| 1081 | [on_restart_callback](const char* error) { |
| 1082 | on_restart_callback(error); |
| 1083 | }; |
| 1084 | wifi_error status = global_func_table_.wifi_set_subsystem_restart_handler( |
| 1085 | global_handle_, {onAsyncSubsystemRestart}); |
| 1086 | if (status != WIFI_SUCCESS) { |
| 1087 | on_subsystem_restart_internal_callback = nullptr; |
| 1088 | } |
| 1089 | return status; |
| 1090 | } |
| 1091 | |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1092 | wifi_error WifiLegacyHal::startRttRangeRequest( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1093 | const std::string& iface_name, wifi_request_id id, |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1094 | const std::vector<wifi_rtt_config>& rtt_configs, |
| 1095 | const on_rtt_results_callback& on_results_user_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1096 | if (on_rtt_results_internal_callback) { |
| 1097 | return WIFI_ERROR_NOT_AVAILABLE; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1098 | } |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1099 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1100 | on_rtt_results_internal_callback = |
| 1101 | [on_results_user_callback](wifi_request_id id, unsigned num_results, |
| 1102 | wifi_rtt_result* rtt_results[]) { |
| 1103 | if (num_results > 0 && !rtt_results) { |
| 1104 | LOG(ERROR) << "Unexpected nullptr in RTT results"; |
| 1105 | return; |
| 1106 | } |
| 1107 | std::vector<const wifi_rtt_result*> rtt_results_vec; |
| 1108 | std::copy_if(rtt_results, rtt_results + num_results, |
| 1109 | back_inserter(rtt_results_vec), |
| 1110 | [](wifi_rtt_result* rtt_result) { |
| 1111 | return rtt_result != nullptr; |
| 1112 | }); |
| 1113 | on_results_user_callback(id, rtt_results_vec); |
| 1114 | }; |
| 1115 | |
| 1116 | std::vector<wifi_rtt_config> rtt_configs_internal(rtt_configs); |
| 1117 | wifi_error status = global_func_table_.wifi_rtt_range_request( |
| 1118 | id, getIfaceHandle(iface_name), rtt_configs.size(), |
| 1119 | rtt_configs_internal.data(), {onAsyncRttResults}); |
| 1120 | if (status != WIFI_SUCCESS) { |
| 1121 | on_rtt_results_internal_callback = nullptr; |
| 1122 | } |
| 1123 | return status; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | wifi_error WifiLegacyHal::cancelRttRangeRequest( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1127 | const std::string& iface_name, wifi_request_id id, |
| 1128 | const std::vector<std::array<uint8_t, 6>>& mac_addrs) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1129 | if (!on_rtt_results_internal_callback) { |
| 1130 | return WIFI_ERROR_NOT_AVAILABLE; |
| 1131 | } |
| 1132 | static_assert(sizeof(mac_addr) == sizeof(std::array<uint8_t, 6>), |
| 1133 | "MAC address size mismatch"); |
| 1134 | // TODO: How do we handle partial cancels (i.e only a subset of enabled mac |
| 1135 | // addressed are cancelled). |
| 1136 | std::vector<std::array<uint8_t, 6>> mac_addrs_internal(mac_addrs); |
| 1137 | wifi_error status = global_func_table_.wifi_rtt_range_cancel( |
| 1138 | id, getIfaceHandle(iface_name), mac_addrs.size(), |
| 1139 | reinterpret_cast<mac_addr*>(mac_addrs_internal.data())); |
| 1140 | // If the request Id is wrong, don't stop the ongoing range request. Any |
| 1141 | // other error should be treated as the end of rtt ranging. |
| 1142 | if (status != WIFI_ERROR_INVALID_REQUEST_ID) { |
| 1143 | on_rtt_results_internal_callback = nullptr; |
| 1144 | } |
| 1145 | return status; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1148 | std::pair<wifi_error, wifi_rtt_capabilities> WifiLegacyHal::getRttCapabilities( |
| 1149 | const std::string& iface_name) { |
| 1150 | wifi_rtt_capabilities rtt_caps; |
| 1151 | wifi_error status = global_func_table_.wifi_get_rtt_capabilities( |
| 1152 | getIfaceHandle(iface_name), &rtt_caps); |
| 1153 | return {status, rtt_caps}; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1156 | std::pair<wifi_error, wifi_rtt_responder> WifiLegacyHal::getRttResponderInfo( |
| 1157 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1158 | wifi_rtt_responder rtt_responder; |
| 1159 | wifi_error status = global_func_table_.wifi_rtt_get_responder_info( |
| 1160 | getIfaceHandle(iface_name), &rtt_responder); |
| 1161 | return {status, rtt_responder}; |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | wifi_error WifiLegacyHal::enableRttResponder( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1165 | const std::string& iface_name, wifi_request_id id, |
| 1166 | const wifi_channel_info& channel_hint, uint32_t max_duration_secs, |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1167 | const wifi_rtt_responder& info) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1168 | wifi_rtt_responder info_internal(info); |
| 1169 | return global_func_table_.wifi_enable_responder( |
| 1170 | id, getIfaceHandle(iface_name), channel_hint, max_duration_secs, |
| 1171 | &info_internal); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1174 | wifi_error WifiLegacyHal::disableRttResponder(const std::string& iface_name, |
| 1175 | wifi_request_id id) { |
| 1176 | return global_func_table_.wifi_disable_responder( |
| 1177 | id, getIfaceHandle(iface_name)); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1180 | wifi_error WifiLegacyHal::setRttLci(const std::string& iface_name, |
| 1181 | wifi_request_id id, |
| 1182 | const wifi_lci_information& info) { |
| 1183 | wifi_lci_information info_internal(info); |
| 1184 | return global_func_table_.wifi_set_lci(id, getIfaceHandle(iface_name), |
| 1185 | &info_internal); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1188 | wifi_error WifiLegacyHal::setRttLcr(const std::string& iface_name, |
| 1189 | wifi_request_id id, |
| 1190 | const wifi_lcr_information& info) { |
| 1191 | wifi_lcr_information info_internal(info); |
| 1192 | return global_func_table_.wifi_set_lcr(id, getIfaceHandle(iface_name), |
| 1193 | &info_internal); |
Roshan Pius | d8e915a | 2016-10-28 11:23:11 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1196 | wifi_error WifiLegacyHal::nanRegisterCallbackHandlers( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1197 | const std::string& iface_name, const NanCallbackHandlers& user_callbacks) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1198 | on_nan_notify_response_user_callback = user_callbacks.on_notify_response; |
| 1199 | on_nan_event_publish_terminated_user_callback = |
| 1200 | user_callbacks.on_event_publish_terminated; |
| 1201 | on_nan_event_match_user_callback = user_callbacks.on_event_match; |
| 1202 | on_nan_event_match_expired_user_callback = |
| 1203 | user_callbacks.on_event_match_expired; |
| 1204 | on_nan_event_subscribe_terminated_user_callback = |
| 1205 | user_callbacks.on_event_subscribe_terminated; |
| 1206 | on_nan_event_followup_user_callback = user_callbacks.on_event_followup; |
| 1207 | on_nan_event_disc_eng_event_user_callback = |
| 1208 | user_callbacks.on_event_disc_eng_event; |
| 1209 | on_nan_event_disabled_user_callback = user_callbacks.on_event_disabled; |
| 1210 | on_nan_event_tca_user_callback = user_callbacks.on_event_tca; |
| 1211 | on_nan_event_beacon_sdf_payload_user_callback = |
| 1212 | user_callbacks.on_event_beacon_sdf_payload; |
| 1213 | on_nan_event_data_path_request_user_callback = |
| 1214 | user_callbacks.on_event_data_path_request; |
| 1215 | on_nan_event_data_path_confirm_user_callback = |
| 1216 | user_callbacks.on_event_data_path_confirm; |
| 1217 | on_nan_event_data_path_end_user_callback = |
| 1218 | user_callbacks.on_event_data_path_end; |
| 1219 | on_nan_event_transmit_follow_up_user_callback = |
| 1220 | user_callbacks.on_event_transmit_follow_up; |
| 1221 | on_nan_event_range_request_user_callback = |
| 1222 | user_callbacks.on_event_range_request; |
| 1223 | on_nan_event_range_report_user_callback = |
| 1224 | user_callbacks.on_event_range_report; |
Etan Cohen | 1bf15f1 | 2017-12-12 16:15:16 -0800 | [diff] [blame] | 1225 | on_nan_event_schedule_update_user_callback = |
| 1226 | user_callbacks.on_event_schedule_update; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1227 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1228 | return global_func_table_.wifi_nan_register_handler( |
| 1229 | getIfaceHandle(iface_name), |
| 1230 | {onAysncNanNotifyResponse, onAysncNanEventPublishReplied, |
| 1231 | onAysncNanEventPublishTerminated, onAysncNanEventMatch, |
| 1232 | onAysncNanEventMatchExpired, onAysncNanEventSubscribeTerminated, |
| 1233 | onAysncNanEventFollowup, onAysncNanEventDiscEngEvent, |
| 1234 | onAysncNanEventDisabled, onAysncNanEventTca, |
| 1235 | onAysncNanEventBeaconSdfPayload, onAysncNanEventDataPathRequest, |
| 1236 | onAysncNanEventDataPathConfirm, onAysncNanEventDataPathEnd, |
| 1237 | onAysncNanEventTransmitFollowUp, onAysncNanEventRangeRequest, |
Etan Cohen | 1bf15f1 | 2017-12-12 16:15:16 -0800 | [diff] [blame] | 1238 | onAysncNanEventRangeReport, onAsyncNanEventScheduleUpdate}); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1241 | wifi_error WifiLegacyHal::nanEnableRequest(const std::string& iface_name, |
| 1242 | transaction_id id, |
| 1243 | const NanEnableRequest& msg) { |
| 1244 | NanEnableRequest msg_internal(msg); |
| 1245 | return global_func_table_.wifi_nan_enable_request( |
| 1246 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1249 | wifi_error WifiLegacyHal::nanDisableRequest(const std::string& iface_name, |
| 1250 | transaction_id id) { |
| 1251 | return global_func_table_.wifi_nan_disable_request( |
| 1252 | id, getIfaceHandle(iface_name)); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1255 | wifi_error WifiLegacyHal::nanPublishRequest(const std::string& iface_name, |
| 1256 | transaction_id id, |
| 1257 | const NanPublishRequest& msg) { |
| 1258 | NanPublishRequest msg_internal(msg); |
| 1259 | return global_func_table_.wifi_nan_publish_request( |
| 1260 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | wifi_error WifiLegacyHal::nanPublishCancelRequest( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1264 | const std::string& iface_name, transaction_id id, |
| 1265 | const NanPublishCancelRequest& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1266 | NanPublishCancelRequest msg_internal(msg); |
| 1267 | return global_func_table_.wifi_nan_publish_cancel_request( |
| 1268 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1271 | wifi_error WifiLegacyHal::nanSubscribeRequest(const std::string& iface_name, |
| 1272 | transaction_id id, |
| 1273 | const NanSubscribeRequest& msg) { |
| 1274 | NanSubscribeRequest msg_internal(msg); |
| 1275 | return global_func_table_.wifi_nan_subscribe_request( |
| 1276 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | wifi_error WifiLegacyHal::nanSubscribeCancelRequest( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1280 | const std::string& iface_name, transaction_id id, |
| 1281 | const NanSubscribeCancelRequest& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1282 | NanSubscribeCancelRequest msg_internal(msg); |
| 1283 | return global_func_table_.wifi_nan_subscribe_cancel_request( |
| 1284 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | wifi_error WifiLegacyHal::nanTransmitFollowupRequest( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1288 | const std::string& iface_name, transaction_id id, |
| 1289 | const NanTransmitFollowupRequest& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1290 | NanTransmitFollowupRequest msg_internal(msg); |
| 1291 | return global_func_table_.wifi_nan_transmit_followup_request( |
| 1292 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1295 | wifi_error WifiLegacyHal::nanStatsRequest(const std::string& iface_name, |
| 1296 | transaction_id id, |
| 1297 | const NanStatsRequest& msg) { |
| 1298 | NanStatsRequest msg_internal(msg); |
| 1299 | return global_func_table_.wifi_nan_stats_request( |
| 1300 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1303 | wifi_error WifiLegacyHal::nanConfigRequest(const std::string& iface_name, |
| 1304 | transaction_id id, |
| 1305 | const NanConfigRequest& msg) { |
| 1306 | NanConfigRequest msg_internal(msg); |
| 1307 | return global_func_table_.wifi_nan_config_request( |
| 1308 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1311 | wifi_error WifiLegacyHal::nanTcaRequest(const std::string& iface_name, |
| 1312 | transaction_id id, |
| 1313 | const NanTCARequest& msg) { |
| 1314 | NanTCARequest msg_internal(msg); |
| 1315 | return global_func_table_.wifi_nan_tca_request( |
| 1316 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | wifi_error WifiLegacyHal::nanBeaconSdfPayloadRequest( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1320 | const std::string& iface_name, transaction_id id, |
| 1321 | const NanBeaconSdfPayloadRequest& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1322 | NanBeaconSdfPayloadRequest msg_internal(msg); |
| 1323 | return global_func_table_.wifi_nan_beacon_sdf_payload_request( |
| 1324 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | std::pair<wifi_error, NanVersion> WifiLegacyHal::nanGetVersion() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1328 | NanVersion version; |
| 1329 | wifi_error status = |
| 1330 | global_func_table_.wifi_nan_get_version(global_handle_, &version); |
| 1331 | return {status, version}; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1334 | wifi_error WifiLegacyHal::nanGetCapabilities(const std::string& iface_name, |
| 1335 | transaction_id id) { |
| 1336 | return global_func_table_.wifi_nan_get_capabilities( |
| 1337 | id, getIfaceHandle(iface_name)); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | wifi_error WifiLegacyHal::nanDataInterfaceCreate( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1341 | const std::string& iface_name, transaction_id id, |
| 1342 | const std::string& data_iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1343 | return global_func_table_.wifi_nan_data_interface_create( |
| 1344 | id, getIfaceHandle(iface_name), makeCharVec(data_iface_name).data()); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | wifi_error WifiLegacyHal::nanDataInterfaceDelete( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1348 | const std::string& iface_name, transaction_id id, |
| 1349 | const std::string& data_iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1350 | return global_func_table_.wifi_nan_data_interface_delete( |
| 1351 | id, getIfaceHandle(iface_name), makeCharVec(data_iface_name).data()); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | wifi_error WifiLegacyHal::nanDataRequestInitiator( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1355 | const std::string& iface_name, transaction_id id, |
| 1356 | const NanDataPathInitiatorRequest& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1357 | NanDataPathInitiatorRequest msg_internal(msg); |
| 1358 | return global_func_table_.wifi_nan_data_request_initiator( |
| 1359 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | wifi_error WifiLegacyHal::nanDataIndicationResponse( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1363 | const std::string& iface_name, transaction_id id, |
| 1364 | const NanDataPathIndicationResponse& msg) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1365 | NanDataPathIndicationResponse msg_internal(msg); |
| 1366 | return global_func_table_.wifi_nan_data_indication_response( |
| 1367 | id, getIfaceHandle(iface_name), &msg_internal); |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Etan Cohen | c9836f9 | 2017-06-30 13:55:21 -0700 | [diff] [blame] | 1370 | typedef struct { |
| 1371 | u8 num_ndp_instances; |
| 1372 | NanDataPathId ndp_instance_id; |
| 1373 | } NanDataPathEndSingleNdpIdRequest; |
| 1374 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1375 | wifi_error WifiLegacyHal::nanDataEnd(const std::string& iface_name, |
| 1376 | transaction_id id, |
| 1377 | uint32_t ndpInstanceId) { |
| 1378 | NanDataPathEndSingleNdpIdRequest msg; |
| 1379 | msg.num_ndp_instances = 1; |
| 1380 | msg.ndp_instance_id = ndpInstanceId; |
| 1381 | wifi_error status = global_func_table_.wifi_nan_data_end( |
| 1382 | id, getIfaceHandle(iface_name), (NanDataPathEndRequest*)&msg); |
| 1383 | return status; |
Roshan Pius | 2301209 | 2016-10-28 11:27:40 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1386 | wifi_error WifiLegacyHal::setCountryCode(const std::string& iface_name, |
| 1387 | std::array<int8_t, 2> code) { |
| 1388 | std::string code_str(code.data(), code.data() + code.size()); |
| 1389 | return global_func_table_.wifi_set_country_code(getIfaceHandle(iface_name), |
| 1390 | code_str.c_str()); |
Roshan Pius | 32fc12e | 2017-01-25 17:44:42 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1393 | wifi_error WifiLegacyHal::retrieveIfaceHandles() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1394 | wifi_interface_handle* iface_handles = nullptr; |
| 1395 | int num_iface_handles = 0; |
| 1396 | wifi_error status = global_func_table_.wifi_get_ifaces( |
| 1397 | global_handle_, &num_iface_handles, &iface_handles); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1398 | if (status != WIFI_SUCCESS) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1399 | LOG(ERROR) << "Failed to enumerate interface handles"; |
| 1400 | return status; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1401 | } |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 1402 | iface_name_to_handle_.clear(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1403 | for (int i = 0; i < num_iface_handles; ++i) { |
| 1404 | std::array<char, IFNAMSIZ> iface_name_arr = {}; |
| 1405 | status = global_func_table_.wifi_get_iface_name( |
| 1406 | iface_handles[i], iface_name_arr.data(), iface_name_arr.size()); |
| 1407 | if (status != WIFI_SUCCESS) { |
| 1408 | LOG(WARNING) << "Failed to get interface handle name"; |
| 1409 | continue; |
| 1410 | } |
| 1411 | // Assuming the interface name is null terminated since the legacy HAL |
| 1412 | // API does not return a size. |
| 1413 | std::string iface_name(iface_name_arr.data()); |
| 1414 | LOG(INFO) << "Adding interface handle for " << iface_name; |
| 1415 | iface_name_to_handle_[iface_name] = iface_handles[i]; |
| 1416 | } |
| 1417 | return WIFI_SUCCESS; |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | wifi_interface_handle WifiLegacyHal::getIfaceHandle( |
| 1421 | const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1422 | const auto iface_handle_iter = iface_name_to_handle_.find(iface_name); |
| 1423 | if (iface_handle_iter == iface_name_to_handle_.end()) { |
| 1424 | LOG(ERROR) << "Unknown iface name: " << iface_name; |
| 1425 | return nullptr; |
| 1426 | } |
| 1427 | return iface_handle_iter->second; |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void WifiLegacyHal::runEventLoop() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1431 | LOG(DEBUG) << "Starting legacy HAL event loop"; |
| 1432 | global_func_table_.wifi_event_loop(global_handle_); |
| 1433 | const auto lock = hidl_sync_util::acquireGlobalLock(); |
| 1434 | if (!awaiting_event_loop_termination_) { |
| 1435 | LOG(FATAL) |
| 1436 | << "Legacy HAL event loop terminated, but HAL was not stopping"; |
| 1437 | } |
| 1438 | LOG(DEBUG) << "Legacy HAL event loop terminated"; |
| 1439 | awaiting_event_loop_termination_ = false; |
| 1440 | stop_wait_cv_.notify_one(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1443 | std::pair<wifi_error, std::vector<wifi_cached_scan_results>> |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1444 | WifiLegacyHal::getGscanCachedResults(const std::string& iface_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1445 | std::vector<wifi_cached_scan_results> cached_scan_results; |
| 1446 | cached_scan_results.resize(kMaxCachedGscanResults); |
| 1447 | int32_t num_results = 0; |
| 1448 | wifi_error status = global_func_table_.wifi_get_cached_gscan_results( |
| 1449 | getIfaceHandle(iface_name), true /* always flush */, |
| 1450 | cached_scan_results.size(), cached_scan_results.data(), &num_results); |
| 1451 | CHECK(num_results >= 0 && |
| 1452 | static_cast<uint32_t>(num_results) <= kMaxCachedGscanResults); |
| 1453 | cached_scan_results.resize(num_results); |
| 1454 | // Check for invalid IE lengths in these cached scan results and correct it. |
| 1455 | for (auto& cached_scan_result : cached_scan_results) { |
| 1456 | int num_scan_results = cached_scan_result.num_results; |
| 1457 | for (int i = 0; i < num_scan_results; i++) { |
| 1458 | auto& scan_result = cached_scan_result.results[i]; |
| 1459 | if (scan_result.ie_length > 0) { |
| 1460 | LOG(DEBUG) << "Cached scan result has non-zero IE length " |
| 1461 | << scan_result.ie_length; |
| 1462 | scan_result.ie_length = 0; |
| 1463 | } |
| 1464 | } |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1465 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1466 | return {status, std::move(cached_scan_results)}; |
Roshan Pius | 76ff302 | 2016-10-28 10:33:34 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 1469 | wifi_error WifiLegacyHal::createVirtualInterface(const std::string& ifname, |
| 1470 | wifi_interface_type iftype) { |
| 1471 | // Create the interface if it doesn't exist. If interface already exist, |
| 1472 | // Vendor Hal should return WIFI_SUCCESS. |
| 1473 | wifi_error status = global_func_table_.wifi_virtual_interface_create( |
| 1474 | global_handle_, ifname.c_str(), iftype); |
| 1475 | return handleVirtualInterfaceCreateOrDeleteStatus(ifname, status); |
| 1476 | } |
| 1477 | |
| 1478 | wifi_error WifiLegacyHal::deleteVirtualInterface(const std::string& ifname) { |
| 1479 | // Delete the interface if it was created dynamically. |
| 1480 | wifi_error status = global_func_table_.wifi_virtual_interface_delete( |
| 1481 | global_handle_, ifname.c_str()); |
| 1482 | return handleVirtualInterfaceCreateOrDeleteStatus(ifname, status); |
| 1483 | } |
| 1484 | |
| 1485 | wifi_error WifiLegacyHal::handleVirtualInterfaceCreateOrDeleteStatus( |
| 1486 | const std::string& ifname, wifi_error status) { |
| 1487 | if (status == WIFI_SUCCESS) { |
| 1488 | // refresh list of handlers now. |
| 1489 | status = retrieveIfaceHandles(); |
| 1490 | } else if (status == WIFI_ERROR_NOT_SUPPORTED) { |
| 1491 | // Vendor hal does not implement this API. Such vendor implementations |
| 1492 | // are expected to create / delete interface by other means. |
| 1493 | |
| 1494 | // check if interface exists. |
| 1495 | if (if_nametoindex(ifname.c_str())) { |
| 1496 | status = retrieveIfaceHandles(); |
| 1497 | } |
| 1498 | } |
| 1499 | return status; |
| 1500 | } |
| 1501 | |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1502 | wifi_error WifiLegacyHal::getSupportedIfaceName(uint32_t iface_type, |
| 1503 | std::string& ifname) { |
| 1504 | std::array<char, IFNAMSIZ> buffer; |
| 1505 | |
| 1506 | wifi_error res = global_func_table_.wifi_get_supported_iface_name( |
| 1507 | global_handle_, (uint32_t)iface_type, buffer.data(), buffer.size()); |
| 1508 | if (res == WIFI_SUCCESS) ifname = buffer.data(); |
| 1509 | |
| 1510 | return res; |
| 1511 | } |
| 1512 | |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 1513 | wifi_error WifiLegacyHal::multiStaSetPrimaryConnection( |
| 1514 | const std::string& ifname) { |
| 1515 | return global_func_table_.wifi_multi_sta_set_primary_connection( |
| 1516 | global_handle_, getIfaceHandle(ifname)); |
| 1517 | } |
| 1518 | |
| 1519 | wifi_error WifiLegacyHal::multiStaSetUseCase(wifi_multi_sta_use_case use_case) { |
| 1520 | return global_func_table_.wifi_multi_sta_set_use_case(global_handle_, |
| 1521 | use_case); |
| 1522 | } |
| 1523 | |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame^] | 1524 | wifi_error WifiLegacyHal::setCoexUnsafeChannels( |
| 1525 | std::vector<wifi_coex_unsafe_channel> unsafe_channels, |
| 1526 | uint32_t restrictions) { |
| 1527 | return global_func_table_.wifi_set_coex_unsafe_channels( |
| 1528 | global_handle_, unsafe_channels.size(), unsafe_channels.data(), |
| 1529 | restrictions); |
| 1530 | } |
| 1531 | |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1532 | void WifiLegacyHal::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1533 | global_handle_ = nullptr; |
| 1534 | iface_name_to_handle_.clear(); |
| 1535 | on_driver_memory_dump_internal_callback = nullptr; |
| 1536 | on_firmware_memory_dump_internal_callback = nullptr; |
| 1537 | on_gscan_event_internal_callback = nullptr; |
| 1538 | on_gscan_full_result_internal_callback = nullptr; |
| 1539 | on_link_layer_stats_result_internal_callback = nullptr; |
| 1540 | on_rssi_threshold_breached_internal_callback = nullptr; |
| 1541 | on_ring_buffer_data_internal_callback = nullptr; |
| 1542 | on_error_alert_internal_callback = nullptr; |
Roshan Pius | 01f0877 | 2018-01-22 17:56:06 -0800 | [diff] [blame] | 1543 | on_radio_mode_change_internal_callback = nullptr; |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 1544 | on_subsystem_restart_internal_callback = nullptr; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1545 | on_rtt_results_internal_callback = nullptr; |
| 1546 | on_nan_notify_response_user_callback = nullptr; |
| 1547 | on_nan_event_publish_terminated_user_callback = nullptr; |
| 1548 | on_nan_event_match_user_callback = nullptr; |
| 1549 | on_nan_event_match_expired_user_callback = nullptr; |
| 1550 | on_nan_event_subscribe_terminated_user_callback = nullptr; |
| 1551 | on_nan_event_followup_user_callback = nullptr; |
| 1552 | on_nan_event_disc_eng_event_user_callback = nullptr; |
| 1553 | on_nan_event_disabled_user_callback = nullptr; |
| 1554 | on_nan_event_tca_user_callback = nullptr; |
| 1555 | on_nan_event_beacon_sdf_payload_user_callback = nullptr; |
| 1556 | on_nan_event_data_path_request_user_callback = nullptr; |
| 1557 | on_nan_event_data_path_confirm_user_callback = nullptr; |
| 1558 | on_nan_event_data_path_end_user_callback = nullptr; |
| 1559 | on_nan_event_transmit_follow_up_user_callback = nullptr; |
| 1560 | on_nan_event_range_request_user_callback = nullptr; |
| 1561 | on_nan_event_range_report_user_callback = nullptr; |
Etan Cohen | 1bf15f1 | 2017-12-12 16:15:16 -0800 | [diff] [blame] | 1562 | on_nan_event_schedule_update_user_callback = nullptr; |
Roshan Pius | 511cc49 | 2016-10-28 09:54:26 -0700 | [diff] [blame] | 1563 | } |
Roshan Pius | 955542e | 2016-10-28 09:42:44 -0700 | [diff] [blame] | 1564 | |
| 1565 | } // namespace legacy_hal |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1566 | } // namespace implementation |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1567 | } // namespace V1_5 |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 1568 | } // namespace wifi |
| 1569 | } // namespace hardware |
| 1570 | } // namespace android |