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