blob: 33ed359baab3e67847ebc8e4ff09570d357da907 [file] [log] [blame]
Gabriel Birenf3262f92022-07-15 23:25:39 +00001/*
2 * Copyright (C) 2022 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#ifndef WIFI_LEGACY_HAL_H_
18#define WIFI_LEGACY_HAL_H_
19
20#include <hardware_legacy/wifi_hal.h>
21#include <wifi_system/interface_tool.h>
22
23#include <condition_variable>
24#include <functional>
25#include <map>
26#include <mutex>
27#include <thread>
28#include <vector>
29
30namespace aidl {
31namespace android {
32namespace hardware {
33namespace wifi {
34// This is in a separate namespace to prevent typename conflicts between
35// the legacy HAL types and the AIDL interface types.
36namespace legacy_hal {
37// Import all the types defined inside the legacy HAL header files into this
38// namespace.
39using ::chre_nan_rtt_state;
40using ::frame_info;
41using ::frame_type;
42using ::FRAME_TYPE_80211_MGMT;
43using ::FRAME_TYPE_ETHERNET_II;
44using ::FRAME_TYPE_UNKNOWN;
45using ::fw_roaming_state_t;
46using ::mac_addr;
47using ::NAN_CHANNEL_24G_BAND;
48using ::NAN_CHANNEL_5G_BAND_HIGH;
49using ::NAN_CHANNEL_5G_BAND_LOW;
50using ::NAN_DISABLE_RANGE_REPORT;
51using ::NAN_DO_NOT_USE_SRF;
52using ::NAN_DP_CHANNEL_NOT_REQUESTED;
53using ::NAN_DP_CONFIG_NO_SECURITY;
54using ::NAN_DP_CONFIG_SECURITY;
55using ::NAN_DP_END;
56using ::NAN_DP_FORCE_CHANNEL_SETUP;
57using ::NAN_DP_INITIATOR_RESPONSE;
58using ::NAN_DP_INTERFACE_CREATE;
59using ::NAN_DP_INTERFACE_DELETE;
60using ::NAN_DP_REQUEST_ACCEPT;
61using ::NAN_DP_REQUEST_CHANNEL_SETUP;
62using ::NAN_DP_REQUEST_REJECT;
63using ::NAN_DP_RESPONDER_RESPONSE;
64using ::NAN_GET_CAPABILITIES;
65using ::NAN_MATCH_ALG_MATCH_CONTINUOUS;
66using ::NAN_MATCH_ALG_MATCH_NEVER;
67using ::NAN_MATCH_ALG_MATCH_ONCE;
68using ::NAN_PUBLISH_TYPE_SOLICITED;
69using ::NAN_PUBLISH_TYPE_UNSOLICITED;
70using ::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED;
71using ::NAN_RANGING_AUTO_RESPONSE_DISABLE;
72using ::NAN_RANGING_AUTO_RESPONSE_ENABLE;
73using ::NAN_RANGING_DISABLE;
74using ::NAN_RANGING_ENABLE;
75using ::NAN_RESPONSE_BEACON_SDF_PAYLOAD;
76using ::NAN_RESPONSE_CONFIG;
77using ::NAN_RESPONSE_DISABLED;
78using ::NAN_RESPONSE_ENABLED;
79using ::NAN_RESPONSE_ERROR;
80using ::NAN_RESPONSE_PUBLISH;
81using ::NAN_RESPONSE_PUBLISH_CANCEL;
82using ::NAN_RESPONSE_STATS;
83using ::NAN_RESPONSE_SUBSCRIBE;
84using ::NAN_RESPONSE_SUBSCRIBE_CANCEL;
85using ::NAN_RESPONSE_TCA;
86using ::NAN_RESPONSE_TRANSMIT_FOLLOWUP;
87using ::NAN_SECURITY_KEY_INPUT_PASSPHRASE;
88using ::NAN_SECURITY_KEY_INPUT_PMK;
89using ::NAN_SERVICE_ACCEPT_POLICY_ALL;
90using ::NAN_SERVICE_ACCEPT_POLICY_NONE;
91using ::NAN_SRF_ATTR_BLOOM_FILTER;
92using ::NAN_SRF_ATTR_PARTIAL_MAC_ADDR;
93using ::NAN_SRF_INCLUDE_DO_NOT_RESPOND;
94using ::NAN_SRF_INCLUDE_RESPOND;
95using ::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
96using ::NAN_SSI_REQUIRED_IN_MATCH_IND;
97using ::NAN_STATUS_ALREADY_ENABLED;
98using ::NAN_STATUS_FOLLOWUP_QUEUE_FULL;
99using ::NAN_STATUS_INTERNAL_FAILURE;
100using ::NAN_STATUS_INVALID_NDP_ID;
101using ::NAN_STATUS_INVALID_PARAM;
102using ::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID;
103using ::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID;
104using ::NAN_STATUS_NAN_NOT_ALLOWED;
105using ::NAN_STATUS_NO_OTA_ACK;
106using ::NAN_STATUS_NO_RESOURCE_AVAILABLE;
107using ::NAN_STATUS_PROTOCOL_FAILURE;
108using ::NAN_STATUS_SUCCESS;
109using ::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED;
110using ::NAN_SUBSCRIBE_TYPE_ACTIVE;
111using ::NAN_SUBSCRIBE_TYPE_PASSIVE;
112using ::NAN_TRANSMIT_IN_DW;
113using ::NAN_TRANSMIT_IN_FAW;
114using ::NAN_TX_PRIORITY_HIGH;
115using ::NAN_TX_PRIORITY_NORMAL;
116using ::NAN_TX_TYPE_BROADCAST;
117using ::NAN_TX_TYPE_UNICAST;
118using ::NAN_USE_SRF;
119using ::NanBeaconSdfPayloadInd;
120using ::NanCapabilities;
121using ::NanChannelInfo;
122using ::NanConfigRequest;
123using ::NanDataPathChannelCfg;
124using ::NanDataPathConfirmInd;
125using ::NanDataPathEndInd;
126using ::NanDataPathIndicationResponse;
127using ::NanDataPathInitiatorRequest;
128using ::NanDataPathRequestInd;
129using ::NanDataPathScheduleUpdateInd;
130using ::NanDisabledInd;
131using ::NanDiscEngEventInd;
132using ::NanEnableRequest;
133using ::NanFollowupInd;
134using ::NanMatchAlg;
135using ::NanMatchExpiredInd;
136using ::NanMatchInd;
137using ::NanPublishCancelRequest;
138using ::NanPublishRequest;
139using ::NanPublishTerminatedInd;
140using ::NanPublishType;
141using ::NanRangeReportInd;
142using ::NanRangeRequestInd;
143using ::NanResponseMsg;
144using ::NanSRFType;
145using ::NanStatusType;
146using ::NanSubscribeCancelRequest;
147using ::NanSubscribeRequest;
148using ::NanSubscribeTerminatedInd;
149using ::NanSubscribeType;
150using ::NanTransmitFollowupInd;
151using ::NanTransmitFollowupRequest;
152using ::NanTxType;
153using ::ROAMING_DISABLE;
154using ::ROAMING_ENABLE;
155using ::RTT_PEER_AP;
156using ::RTT_PEER_NAN;
157using ::RTT_PEER_P2P_CLIENT;
158using ::RTT_PEER_P2P_GO;
159using ::RTT_PEER_STA;
160using ::rtt_peer_type;
161using ::RTT_STATUS_ABORTED;
162using ::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL;
163using ::RTT_STATUS_FAIL_BUSY_TRY_LATER;
164using ::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE;
165using ::RTT_STATUS_FAIL_INVALID_TS;
166using ::RTT_STATUS_FAIL_NO_CAPABILITY;
167using ::RTT_STATUS_FAIL_NO_RSP;
168using ::RTT_STATUS_FAIL_NOT_SCHEDULED_YET;
169using ::RTT_STATUS_FAIL_PROTOCOL;
170using ::RTT_STATUS_FAIL_REJECTED;
171using ::RTT_STATUS_FAIL_SCHEDULE;
172using ::RTT_STATUS_FAIL_TM_TIMEOUT;
173using ::RTT_STATUS_FAILURE;
174using ::RTT_STATUS_INVALID_REQ;
175using ::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED;
176using ::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE;
177using ::RTT_STATUS_NO_WIFI;
178using ::RTT_STATUS_SUCCESS;
179using ::RTT_TYPE_1_SIDED;
180using ::RTT_TYPE_2_SIDED;
181using ::RX_PKT_FATE_DRV_DROP_FILTER;
182using ::RX_PKT_FATE_DRV_DROP_INVALID;
183using ::RX_PKT_FATE_DRV_DROP_NOBUFS;
184using ::RX_PKT_FATE_DRV_DROP_OTHER;
185using ::RX_PKT_FATE_DRV_QUEUED;
186using ::RX_PKT_FATE_FW_DROP_FILTER;
187using ::RX_PKT_FATE_FW_DROP_INVALID;
188using ::RX_PKT_FATE_FW_DROP_NOBUFS;
189using ::RX_PKT_FATE_FW_DROP_OTHER;
190using ::RX_PKT_FATE_FW_QUEUED;
191using ::RX_PKT_FATE_SUCCESS;
192using ::ssid_t;
193using ::transaction_id;
194using ::TX_PKT_FATE_ACKED;
195using ::TX_PKT_FATE_DRV_DROP_INVALID;
196using ::TX_PKT_FATE_DRV_DROP_NOBUFS;
197using ::TX_PKT_FATE_DRV_DROP_OTHER;
198using ::TX_PKT_FATE_DRV_QUEUED;
199using ::TX_PKT_FATE_FW_DROP_INVALID;
200using ::TX_PKT_FATE_FW_DROP_NOBUFS;
201using ::TX_PKT_FATE_FW_DROP_OTHER;
202using ::TX_PKT_FATE_FW_QUEUED;
203using ::TX_PKT_FATE_SENT;
204using ::WIFI_AC_BE;
205using ::WIFI_AC_BK;
206using ::WIFI_AC_VI;
207using ::WIFI_AC_VO;
208using ::WIFI_ANTENNA_1X1;
209using ::WIFI_ANTENNA_2X2;
210using ::WIFI_ANTENNA_3X3;
211using ::WIFI_ANTENNA_4X4;
212using ::WIFI_ANTENNA_UNSPECIFIED;
213using ::wifi_band;
214using ::WIFI_BAND_A;
215using ::WIFI_BAND_A_DFS;
216using ::WIFI_BAND_A_WITH_DFS;
217using ::WIFI_BAND_ABG;
218using ::WIFI_BAND_ABG_WITH_DFS;
219using ::WIFI_BAND_BG;
220using ::WIFI_BAND_UNSPECIFIED;
221using ::wifi_cached_scan_report;
222using ::wifi_cached_scan_results;
223using ::WIFI_CHAN_WIDTH_10;
224using ::WIFI_CHAN_WIDTH_160;
225using ::WIFI_CHAN_WIDTH_20;
226using ::WIFI_CHAN_WIDTH_320;
227using ::WIFI_CHAN_WIDTH_40;
228using ::WIFI_CHAN_WIDTH_5;
229using ::WIFI_CHAN_WIDTH_80;
230using ::WIFI_CHAN_WIDTH_80P80;
231using ::WIFI_CHAN_WIDTH_INVALID;
232using ::wifi_channel_info;
233using ::wifi_channel_stat;
234using ::wifi_channel_width;
Mahesh KKVc84d3772022-12-02 16:53:28 -0800235using ::wifi_chip_capabilities;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000236using ::wifi_coex_restriction;
237using ::wifi_coex_unsafe_channel;
238using ::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED;
239using ::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY;
240using ::wifi_error;
241using ::WIFI_ERROR_BUSY;
242using ::WIFI_ERROR_INVALID_ARGS;
243using ::WIFI_ERROR_INVALID_REQUEST_ID;
244using ::WIFI_ERROR_NONE;
245using ::WIFI_ERROR_NOT_AVAILABLE;
246using ::WIFI_ERROR_NOT_SUPPORTED;
247using ::WIFI_ERROR_OUT_OF_MEMORY;
248using ::WIFI_ERROR_TIMED_OUT;
249using ::WIFI_ERROR_TOO_MANY_REQUESTS;
250using ::WIFI_ERROR_UNINITIALIZED;
251using ::WIFI_ERROR_UNKNOWN;
252using ::wifi_gscan_capabilities;
253using ::wifi_hal_fn;
254using ::wifi_information_element;
255using ::WIFI_INTERFACE_IBSS;
256using ::WIFI_INTERFACE_MESH;
257using ::wifi_interface_mode;
258using ::WIFI_INTERFACE_NAN;
259using ::WIFI_INTERFACE_P2P_CLIENT;
260using ::WIFI_INTERFACE_P2P_GO;
261using ::WIFI_INTERFACE_SOFTAP;
262using ::WIFI_INTERFACE_STA;
263using ::WIFI_INTERFACE_TDLS;
264using ::wifi_interface_type;
265using ::WIFI_INTERFACE_TYPE_AP;
266using ::WIFI_INTERFACE_TYPE_NAN;
267using ::WIFI_INTERFACE_TYPE_P2P;
268using ::WIFI_INTERFACE_TYPE_STA;
269using ::WIFI_INTERFACE_UNKNOWN;
270using ::wifi_latency_mode;
271using ::WIFI_LATENCY_MODE_LOW;
272using ::WIFI_LATENCY_MODE_NORMAL;
273using ::wifi_lci_information;
274using ::wifi_lcr_information;
275using ::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
276using ::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
277using ::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
278using ::WIFI_LOGGER_PACKET_FATE_SUPPORTED;
279using ::WIFI_LOGGER_POWER_EVENT_SUPPORTED;
280using ::WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
281using ::WIFI_MOTION_EXPECTED;
282using ::WIFI_MOTION_NOT_EXPECTED;
283using ::wifi_motion_pattern;
284using ::WIFI_MOTION_UNKNOWN;
285using ::wifi_multi_sta_use_case;
286using ::wifi_power_scenario;
287using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
288using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
289using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
290using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
291using ::WIFI_POWER_SCENARIO_VOICE_CALL;
292using ::wifi_radio_combination;
293using ::wifi_radio_combination_matrix;
294using ::wifi_radio_configuration;
295using ::wifi_rate;
296using ::wifi_request_id;
297using ::wifi_ring_buffer_status;
298using ::wifi_roaming_capabilities;
299using ::wifi_roaming_config;
300using ::wifi_rtt_bw;
301using ::WIFI_RTT_BW_10;
302using ::WIFI_RTT_BW_160;
303using ::WIFI_RTT_BW_20;
304using ::WIFI_RTT_BW_320;
305using ::WIFI_RTT_BW_40;
306using ::WIFI_RTT_BW_5;
307using ::WIFI_RTT_BW_80;
308using ::wifi_rtt_capabilities;
309using ::wifi_rtt_config;
310using ::wifi_rtt_preamble;
311using ::WIFI_RTT_PREAMBLE_EHT;
312using ::WIFI_RTT_PREAMBLE_HE;
313using ::WIFI_RTT_PREAMBLE_HT;
314using ::WIFI_RTT_PREAMBLE_LEGACY;
315using ::WIFI_RTT_PREAMBLE_VHT;
316using ::wifi_rtt_responder;
317using ::wifi_rtt_result;
318using ::wifi_rtt_status;
319using ::wifi_rtt_type;
320using ::wifi_rx_packet_fate;
321using ::wifi_rx_report;
322using ::wifi_scan_bucket_spec;
323using ::wifi_scan_cmd_params;
324using ::WIFI_SCAN_FLAG_INTERRUPTED;
325using ::wifi_scan_result;
326using ::WIFI_SUCCESS;
327using ::wifi_tx_packet_fate;
328using ::wifi_tx_report;
329using ::wifi_usable_channel;
330using ::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE;
331using ::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY;
332using ::WLAN_MAC_2_4_BAND;
333using ::WLAN_MAC_5_0_BAND;
334using ::WLAN_MAC_60_0_BAND;
335using ::WLAN_MAC_6_0_BAND;
336
337// APF capabilities supported by the iface.
338struct PacketFilterCapabilities {
339 uint32_t version;
340 uint32_t max_len;
341};
342
343// WARNING: We don't care about the variable sized members of either
344// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
345// to escape the compiler warnings regarding this.
346#pragma GCC diagnostic push
347#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
348// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
349// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
350// into a separate return element to avoid passing pointers around.
351struct LinkLayerRadioStats {
352 wifi_radio_stat stats;
353 std::vector<uint32_t> tx_time_per_levels;
354 std::vector<wifi_channel_stat> channel_stats;
355};
356
357struct WifiPeerInfo {
358 wifi_peer_info peer_info;
359 std::vector<wifi_rate_stat> rate_stats;
360};
361
362struct LinkLayerStats {
363 wifi_iface_stat iface;
364 std::vector<LinkLayerRadioStats> radios;
365 std::vector<WifiPeerInfo> peers;
366};
367#pragma GCC diagnostic pop
368
369// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
370// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
371// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
372// API. Separate that out into a separate return elements to avoid passing
373// pointers around.
374struct WakeReasonStats {
375 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
376 std::vector<uint32_t> cmd_event_wake_cnt;
377 std::vector<uint32_t> driver_fw_local_wake_cnt;
378};
379
380// NAN response and event callbacks struct.
381struct NanCallbackHandlers {
382 // NotifyResponse invoked to notify the status of the Request.
383 std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
384 // Various event callbacks.
385 std::function<void(const NanPublishTerminatedInd&)> on_event_publish_terminated;
386 std::function<void(const NanMatchInd&)> on_event_match;
387 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
388 std::function<void(const NanSubscribeTerminatedInd&)> on_event_subscribe_terminated;
389 std::function<void(const NanFollowupInd&)> on_event_followup;
390 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
391 std::function<void(const NanDisabledInd&)> on_event_disabled;
392 std::function<void(const NanTCAInd&)> on_event_tca;
393 std::function<void(const NanBeaconSdfPayloadInd&)> on_event_beacon_sdf_payload;
394 std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
395 std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
396 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
397 std::function<void(const NanTransmitFollowupInd&)> on_event_transmit_follow_up;
398 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
399 std::function<void(const NanRangeReportInd&)> on_event_range_report;
400 std::function<void(const NanDataPathScheduleUpdateInd&)> on_event_schedule_update;
401};
402
403// Full scan results contain IE info and are hence passed by reference, to
404// preserve the variable length array member |ie_data|. Callee must not retain
405// the pointer.
406using on_gscan_full_result_callback =
407 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
408// These scan results don't contain any IE info, so no need to pass by
409// reference.
410using on_gscan_results_callback =
411 std::function<void(wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
412
413// Invoked when the rssi value breaches the thresholds set.
414using on_rssi_threshold_breached_callback =
415 std::function<void(wifi_request_id, std::array<uint8_t, ETH_ALEN>, int8_t)>;
416
417// Callback for RTT range request results.
418// Rtt results contain IE info and are hence passed by reference, to
419// preserve the |LCI| and |LCR| pointers. Callee must not retain
420// the pointer.
421using on_rtt_results_callback =
422 std::function<void(wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
423
424// Callback for ring buffer data.
425using on_ring_buffer_data_callback = std::function<void(
426 const std::string&, const std::vector<uint8_t>&, const wifi_ring_buffer_status&)>;
427
428// Callback for alerts.
429using on_error_alert_callback = std::function<void(int32_t, const std::vector<uint8_t>&)>;
430
431// Callback for subsystem restart
432using on_subsystem_restart_callback = std::function<void(const std::string&)>;
433
434// Struct for the mac info from the legacy HAL. This is a cleaner version
435// of the |wifi_mac_info| & |wifi_iface_info|.
436typedef struct {
437 std::string name;
438 wifi_channel channel;
439} WifiIfaceInfo;
440
441typedef struct {
442 uint32_t wlan_mac_id;
443 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
444 uint32_t mac_band;
445 /* Represents the connected Wi-Fi interfaces associated with each MAC */
446 std::vector<WifiIfaceInfo> iface_infos;
447} WifiMacInfo;
448
449// Callback for radio mode change
450using on_radio_mode_change_callback = std::function<void(const std::vector<WifiMacInfo>&)>;
451
452// TWT response and event callbacks struct.
453struct TwtCallbackHandlers {
454 // Callback for TWT setup response
455 std::function<void(const TwtSetupResponse&)> on_setup_response;
456 // Callback for TWT teardown completion
457 std::function<void(const TwtTeardownCompletion&)> on_teardown_completion;
458 // Callback for TWT info frame received event
459 std::function<void(const TwtInfoFrameReceived&)> on_info_frame_received;
460 // Callback for TWT notification from the device
461 std::function<void(const TwtDeviceNotify&)> on_device_notify;
462};
463
464// CHRE response and event callbacks struct.
465struct ChreCallbackHandlers {
466 // Callback for CHRE NAN RTT
467 std::function<void(chre_nan_rtt_state)> on_wifi_chre_nan_rtt_state;
468};
469
470// Cached Scan Results response and event callbacks struct.
471struct CachedScanResultsCallbackHandlers {
472 // Callback for Cached Scan Results
473 std::function<void(wifi_cached_scan_report*)> on_cached_scan_results;
474};
475
476/**
477 * Class that encapsulates all legacy HAL interactions.
478 * This class manages the lifetime of the event loop thread used by legacy HAL.
479 *
480 * Note: There will only be a single instance of this class created in the Wifi
481 * object and will be valid for the lifetime of the process.
482 */
483class WifiLegacyHal {
484 public:
485 WifiLegacyHal(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool,
486 const wifi_hal_fn& fn, bool is_primary);
487 virtual ~WifiLegacyHal() = default;
488
489 // Initialize the legacy HAL function table.
490 virtual wifi_error initialize();
491 // Start the legacy HAL and the event looper thread.
492 virtual wifi_error start();
493 // Deinitialize the legacy HAL and wait for the event loop thread to exit
494 // using a predefined timeout.
495 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
496 const std::function<void()>& on_complete_callback);
497 virtual wifi_error waitForDriverReady();
498 // Checks if legacy HAL has successfully started
499 bool isStarted();
500 // Wrappers for all the functions in the legacy HAL function table.
501 virtual std::pair<wifi_error, std::string> getDriverVersion(const std::string& iface_name);
502 virtual std::pair<wifi_error, std::string> getFirmwareVersion(const std::string& iface_name);
503 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
504 const std::string& iface_name);
505 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
506 const std::string& iface_name);
507 virtual std::pair<wifi_error, uint64_t> getSupportedFeatureSet(const std::string& iface_name);
508 // APF functions.
509 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
510 const std::string& iface_name);
511 wifi_error setPacketFilter(const std::string& iface_name, const std::vector<uint8_t>& program);
512 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
513 const std::string& iface_name);
514 // Gscan functions.
515 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
516 const std::string& iface_name);
517 // These API's provides a simplified interface over the legacy Gscan API's:
518 // a) All scan events from the legacy HAL API other than the
519 // |WIFI_SCAN_FAILED| are treated as notification of results.
520 // This method then retrieves the cached scan results from the legacy
521 // HAL API and triggers the externally provided
522 // |on_results_user_callback| on success.
523 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
524 // results
525 // Triggers the externally provided |on_failure_user_callback|.
526 // c) Full scan result event triggers the externally provided
527 // |on_full_result_user_callback|.
528 wifi_error startGscan(const std::string& iface_name, wifi_request_id id,
529 const wifi_scan_cmd_params& params,
530 const std::function<void(wifi_request_id)>& on_failure_callback,
531 const on_gscan_results_callback& on_results_callback,
532 const on_gscan_full_result_callback& on_full_result_callback);
533 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
534 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
535 const std::string& iface_name, wifi_band band);
536 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
537 // Link layer stats functions.
538 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
539 wifi_error disableLinkLayerStats(const std::string& iface_name);
540 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(const std::string& iface_name);
541 // RSSI monitor functions.
542 wifi_error startRssiMonitoring(
543 const std::string& iface_name, wifi_request_id id, int8_t max_rssi, int8_t min_rssi,
544 const on_rssi_threshold_breached_callback& on_threshold_breached_callback);
545 wifi_error stopRssiMonitoring(const std::string& iface_name, wifi_request_id id);
546 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
547 const std::string& iface_name);
548 wifi_error configureRoaming(const std::string& iface_name, const wifi_roaming_config& config);
549 wifi_error enableFirmwareRoaming(const std::string& iface_name, fw_roaming_state_t state);
550 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
551 wifi_error startSendingOffloadedPacket(const std::string& iface_name, int32_t cmd_id,
552 uint16_t ether_type,
553 const std::vector<uint8_t>& ip_packet_data,
554 const std::array<uint8_t, 6>& src_address,
555 const std::array<uint8_t, 6>& dst_address,
556 int32_t period_in_ms);
557 wifi_error stopSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id);
558 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
559 wifi_power_scenario scenario);
560 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
561 wifi_error setLatencyMode(const std::string& iface_name, wifi_latency_mode mode);
562 wifi_error setThermalMitigationMode(wifi_thermal_mode mode, uint32_t completion_window);
563 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
564 uint32_t access_category);
565 wifi_error resetDscpToAccessCategoryMapping();
566 // Logger/debug functions.
567 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(const std::string& iface_name);
568 wifi_error startPktFateMonitoring(const std::string& iface_name);
569 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(const std::string& iface_name);
570 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(const std::string& iface_name);
571 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(const std::string& iface_name);
572 wifi_error registerRingBufferCallbackHandler(
573 const std::string& iface_name, const on_ring_buffer_data_callback& on_data_callback);
574 wifi_error deregisterRingBufferCallbackHandler(const std::string& iface_name);
575 virtual wifi_error registerSubsystemRestartCallbackHandler(
576 const on_subsystem_restart_callback& on_restart_callback);
577 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> getRingBuffersStatus(
578 const std::string& iface_name);
579 wifi_error startRingBufferLogging(const std::string& iface_name, const std::string& ring_name,
580 uint32_t verbose_level, uint32_t max_interval_sec,
581 uint32_t min_data_size);
582 wifi_error getRingBufferData(const std::string& iface_name, const std::string& ring_name);
583 wifi_error registerErrorAlertCallbackHandler(const std::string& iface_name,
584 const on_error_alert_callback& on_alert_callback);
585 wifi_error deregisterErrorAlertCallbackHandler(const std::string& iface_name);
586 // Radio mode functions.
587 virtual wifi_error registerRadioModeChangeCallbackHandler(
588 const std::string& iface_name,
589 const on_radio_mode_change_callback& on_user_change_callback);
590 // RTT functions.
591 wifi_error startRttRangeRequest(const std::string& iface_name, wifi_request_id id,
592 const std::vector<wifi_rtt_config>& rtt_configs,
593 const on_rtt_results_callback& on_results_callback);
594 wifi_error cancelRttRangeRequest(const std::string& iface_name, wifi_request_id id,
595 const std::vector<std::array<uint8_t, ETH_ALEN>>& mac_addrs);
596 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(const std::string& iface_name);
597 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(const std::string& iface_name);
598 wifi_error enableRttResponder(const std::string& iface_name, wifi_request_id id,
599 const wifi_channel_info& channel_hint, uint32_t max_duration_secs,
600 const wifi_rtt_responder& info);
601 wifi_error disableRttResponder(const std::string& iface_name, wifi_request_id id);
602 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
603 const wifi_lci_information& info);
604 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
605 const wifi_lcr_information& info);
606 // NAN functions.
607 virtual wifi_error nanRegisterCallbackHandlers(const std::string& iface_name,
608 const NanCallbackHandlers& callbacks);
609 wifi_error nanEnableRequest(const std::string& iface_name, transaction_id id,
610 const NanEnableRequest& msg);
611 virtual wifi_error nanDisableRequest(const std::string& iface_name, transaction_id id);
612 wifi_error nanPublishRequest(const std::string& iface_name, transaction_id id,
613 const NanPublishRequest& msg);
614 wifi_error nanPublishCancelRequest(const std::string& iface_name, transaction_id id,
615 const NanPublishCancelRequest& msg);
616 wifi_error nanSubscribeRequest(const std::string& iface_name, transaction_id id,
617 const NanSubscribeRequest& msg);
618 wifi_error nanSubscribeCancelRequest(const std::string& iface_name, transaction_id id,
619 const NanSubscribeCancelRequest& msg);
620 wifi_error nanTransmitFollowupRequest(const std::string& iface_name, transaction_id id,
621 const NanTransmitFollowupRequest& msg);
622 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
623 const NanStatsRequest& msg);
624 wifi_error nanConfigRequest(const std::string& iface_name, transaction_id id,
625 const NanConfigRequest& msg);
626 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
627 const NanTCARequest& msg);
628 wifi_error nanBeaconSdfPayloadRequest(const std::string& iface_name, transaction_id id,
629 const NanBeaconSdfPayloadRequest& msg);
630 std::pair<wifi_error, NanVersion> nanGetVersion();
631 wifi_error nanGetCapabilities(const std::string& iface_name, transaction_id id);
632 wifi_error nanDataInterfaceCreate(const std::string& iface_name, transaction_id id,
633 const std::string& data_iface_name);
634 virtual wifi_error nanDataInterfaceDelete(const std::string& iface_name, transaction_id id,
635 const std::string& data_iface_name);
636 wifi_error nanDataRequestInitiator(const std::string& iface_name, transaction_id id,
637 const NanDataPathInitiatorRequest& msg);
638 wifi_error nanDataIndicationResponse(const std::string& iface_name, transaction_id id,
639 const NanDataPathIndicationResponse& msg);
640 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id, uint32_t ndpInstanceId);
641 // AP functions.
642 wifi_error setCountryCode(const std::string& iface_name, const std::array<uint8_t, 2> code);
643
644 // Interface functions.
645 virtual wifi_error createVirtualInterface(const std::string& ifname,
646 wifi_interface_type iftype);
647 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
648 virtual wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
649
650 // STA + STA functions
651 virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);
652 virtual wifi_error multiStaSetUseCase(wifi_multi_sta_use_case use_case);
653
654 // Coex functions.
655 virtual wifi_error setCoexUnsafeChannels(std::vector<wifi_coex_unsafe_channel> unsafe_channels,
656 uint32_t restrictions);
657
658 wifi_error setVoipMode(const std::string& iface_name, wifi_voip_mode mode);
659
660 wifi_error twtRegisterHandler(const std::string& iface_name,
661 const TwtCallbackHandlers& handler);
662
663 std::pair<wifi_error, TwtCapabilitySet> twtGetCapability(const std::string& iface_name);
664
665 wifi_error twtSetupRequest(const std::string& iface_name, const TwtSetupRequest& msg);
666
667 wifi_error twtTearDownRequest(const std::string& iface_name, const TwtTeardownRequest& msg);
668
669 wifi_error twtInfoFrameRequest(const std::string& iface_name, const TwtInfoFrameRequest& msg);
670
671 std::pair<wifi_error, TwtStats> twtGetStats(const std::string& iface_name, uint8_t configId);
672
673 wifi_error twtClearStats(const std::string& iface_name, uint8_t configId);
674
675 wifi_error setDtimConfig(const std::string& iface_name, uint32_t multiplier);
676
677 // Retrieve the list of usable channels in the requested bands
678 // for the requested modes
679 std::pair<wifi_error, std::vector<wifi_usable_channel>> getUsableChannels(
680 uint32_t band_mask, uint32_t iface_mode_mask, uint32_t filter_mask);
681
682 wifi_error triggerSubsystemRestart();
683
684 wifi_error setIndoorState(bool isIndoor);
685
686 std::pair<wifi_error, wifi_radio_combination_matrix*> getSupportedRadioCombinationsMatrix();
687
688 // CHRE NAN RTT function
689 wifi_error chreNanRttRequest(const std::string& iface_name, bool enable);
690
691 wifi_error chreRegisterHandler(const std::string& iface_name,
692 const ChreCallbackHandlers& handler);
693
694 wifi_error enableWifiTxPowerLimits(const std::string& iface_name, bool enable);
695 wifi_error getWifiCachedScanResults(const std::string& iface_name,
696 const CachedScanResultsCallbackHandlers& handler);
Mahesh KKVc84d3772022-12-02 16:53:28 -0800697 std::pair<wifi_error, wifi_chip_capabilities> getWifiChipCapabilities();
Gabriel Birenf3262f92022-07-15 23:25:39 +0000698
699 private:
700 // Retrieve interface handles for all the available interfaces.
701 wifi_error retrieveIfaceHandles();
702 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
703 // Run the legacy HAL event loop thread.
704 void runEventLoop();
705 // Retrieve the cached gscan results to pass the results back to the
706 // external callbacks.
707 std::pair<wifi_error, std::vector<wifi_cached_scan_results>> getGscanCachedResults(
708 const std::string& iface_name);
709 void invalidate();
710 // Handles wifi (error) status of Virtual interface create/delete
711 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(const std::string& ifname,
712 wifi_error status);
713
714 // Global function table of legacy HAL.
715 wifi_hal_fn global_func_table_;
716 // Opaque handle to be used for all global operations.
717 wifi_handle global_handle_;
718 // Map of interface name to handle that is to be used for all interface
719 // specific operations.
720 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
721 // Flag to indicate if we have initiated the cleanup of legacy HAL.
722 std::atomic<bool> awaiting_event_loop_termination_;
723 std::condition_variable_any stop_wait_cv_;
724 // Flag to indicate if the legacy HAL has been started.
725 bool is_started_;
726 std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_;
727 // Flag to indicate if this HAL is for the primary chip. This is used
728 // in order to avoid some hard-coded behavior used with older HALs,
729 // such as bring wlan0 interface up/down on start/stop HAL.
730 // it may be removed once vendor HALs are updated.
731 bool is_primary_;
732};
733
734} // namespace legacy_hal
735} // namespace wifi
736} // namespace hardware
737} // namespace android
738} // namespace aidl
739
740#endif // WIFI_LEGACY_HAL_H_