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