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