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