blob: 468d8d7d0850553af72e800a0b075ed96658b748 [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;
315using ::WIFI_MOTION_EXPECTED;
316using ::WIFI_MOTION_NOT_EXPECTED;
317using ::wifi_motion_pattern;
318using ::WIFI_MOTION_UNKNOWN;
319using ::wifi_multi_sta_use_case;
320using ::wifi_power_scenario;
321using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
322using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
323using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
324using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
325using ::WIFI_POWER_SCENARIO_VOICE_CALL;
326using ::wifi_radio_combination;
327using ::wifi_radio_combination_matrix;
328using ::wifi_radio_configuration;
329using ::wifi_rate;
330using ::wifi_request_id;
331using ::wifi_ring_buffer_status;
332using ::wifi_roaming_capabilities;
333using ::wifi_roaming_config;
334using ::wifi_rtt_bw;
335using ::WIFI_RTT_BW_10;
336using ::WIFI_RTT_BW_160;
337using ::WIFI_RTT_BW_20;
338using ::WIFI_RTT_BW_320;
339using ::WIFI_RTT_BW_40;
340using ::WIFI_RTT_BW_5;
341using ::WIFI_RTT_BW_80;
Sunil Ravif8fc2372022-11-10 18:37:41 +0000342using ::WIFI_RTT_BW_UNSPECIFIED;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000343using ::wifi_rtt_capabilities;
344using ::wifi_rtt_config;
345using ::wifi_rtt_preamble;
346using ::WIFI_RTT_PREAMBLE_EHT;
347using ::WIFI_RTT_PREAMBLE_HE;
348using ::WIFI_RTT_PREAMBLE_HT;
349using ::WIFI_RTT_PREAMBLE_LEGACY;
350using ::WIFI_RTT_PREAMBLE_VHT;
351using ::wifi_rtt_responder;
352using ::wifi_rtt_result;
Sunil Ravif8fc2372022-11-10 18:37:41 +0000353using ::wifi_rtt_result_v2;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000354using ::wifi_rtt_status;
355using ::wifi_rtt_type;
356using ::wifi_rx_packet_fate;
357using ::wifi_rx_report;
358using ::wifi_scan_bucket_spec;
359using ::wifi_scan_cmd_params;
360using ::WIFI_SCAN_FLAG_INTERRUPTED;
361using ::wifi_scan_result;
362using ::WIFI_SUCCESS;
363using ::wifi_tx_packet_fate;
364using ::wifi_tx_report;
365using ::wifi_usable_channel;
366using ::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE;
367using ::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY;
368using ::WLAN_MAC_2_4_BAND;
369using ::WLAN_MAC_5_0_BAND;
370using ::WLAN_MAC_60_0_BAND;
371using ::WLAN_MAC_6_0_BAND;
372
373// APF capabilities supported by the iface.
374struct PacketFilterCapabilities {
375 uint32_t version;
376 uint32_t max_len;
377};
378
379// WARNING: We don't care about the variable sized members of either
380// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
381// to escape the compiler warnings regarding this.
382#pragma GCC diagnostic push
383#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
384// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
385// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
386// into a separate return element to avoid passing pointers around.
387struct LinkLayerRadioStats {
388 wifi_radio_stat stats;
389 std::vector<uint32_t> tx_time_per_levels;
390 std::vector<wifi_channel_stat> channel_stats;
391};
392
393struct WifiPeerInfo {
394 wifi_peer_info peer_info;
395 std::vector<wifi_rate_stat> rate_stats;
396};
397
398struct LinkLayerStats {
399 wifi_iface_stat iface;
400 std::vector<LinkLayerRadioStats> radios;
401 std::vector<WifiPeerInfo> peers;
Mahesh KKV5f30d332022-10-26 14:07:44 -0700402 bool valid;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000403};
Mahesh KKV5f30d332022-10-26 14:07:44 -0700404
405struct LinkStats {
406 wifi_link_stat stat;
407 std::vector<WifiPeerInfo> peers;
408};
409
410struct LinkLayerMlStats {
411 wifi_iface_ml_stat iface;
412 std::vector<LinkStats> links;
413 std::vector<LinkLayerRadioStats> radios;
414 bool valid;
415};
416
Gabriel Birenf3262f92022-07-15 23:25:39 +0000417#pragma GCC diagnostic pop
418
419// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
420// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
421// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
422// API. Separate that out into a separate return elements to avoid passing
423// pointers around.
424struct WakeReasonStats {
425 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
426 std::vector<uint32_t> cmd_event_wake_cnt;
427 std::vector<uint32_t> driver_fw_local_wake_cnt;
428};
429
430// NAN response and event callbacks struct.
431struct NanCallbackHandlers {
432 // NotifyResponse invoked to notify the status of the Request.
433 std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
434 // Various event callbacks.
435 std::function<void(const NanPublishTerminatedInd&)> on_event_publish_terminated;
436 std::function<void(const NanMatchInd&)> on_event_match;
437 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
438 std::function<void(const NanSubscribeTerminatedInd&)> on_event_subscribe_terminated;
439 std::function<void(const NanFollowupInd&)> on_event_followup;
440 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
441 std::function<void(const NanDisabledInd&)> on_event_disabled;
442 std::function<void(const NanTCAInd&)> on_event_tca;
443 std::function<void(const NanBeaconSdfPayloadInd&)> on_event_beacon_sdf_payload;
444 std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
445 std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
446 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
447 std::function<void(const NanTransmitFollowupInd&)> on_event_transmit_follow_up;
448 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
449 std::function<void(const NanRangeReportInd&)> on_event_range_report;
450 std::function<void(const NanDataPathScheduleUpdateInd&)> on_event_schedule_update;
Nate Jiang38e8db52022-12-02 17:30:27 -0800451 std::function<void(const NanPairingRequestInd&)> on_event_pairing_request;
452 std::function<void(const NanPairingConfirmInd&)> on_event_pairing_confirm;
453 std::function<void(const NanBootstrappingRequestInd&)> on_event_bootstrapping_request;
454 std::function<void(const NanBootstrappingConfirmInd&)> on_event_bootstrapping_confirm;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000455};
456
457// Full scan results contain IE info and are hence passed by reference, to
458// preserve the variable length array member |ie_data|. Callee must not retain
459// the pointer.
460using on_gscan_full_result_callback =
461 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
462// These scan results don't contain any IE info, so no need to pass by
463// reference.
464using on_gscan_results_callback =
465 std::function<void(wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
466
467// Invoked when the rssi value breaches the thresholds set.
468using on_rssi_threshold_breached_callback =
469 std::function<void(wifi_request_id, std::array<uint8_t, ETH_ALEN>, int8_t)>;
470
471// Callback for RTT range request results.
472// Rtt results contain IE info and are hence passed by reference, to
473// preserve the |LCI| and |LCR| pointers. Callee must not retain
474// the pointer.
475using on_rtt_results_callback =
476 std::function<void(wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
Sunil Ravif8fc2372022-11-10 18:37:41 +0000477using on_rtt_results_callback_v2 =
478 std::function<void(wifi_request_id, const std::vector<const wifi_rtt_result_v2*>&)>;
Gabriel Birenf3262f92022-07-15 23:25:39 +0000479
480// Callback for ring buffer data.
481using on_ring_buffer_data_callback = std::function<void(
482 const std::string&, const std::vector<uint8_t>&, const wifi_ring_buffer_status&)>;
483
484// Callback for alerts.
485using on_error_alert_callback = std::function<void(int32_t, const std::vector<uint8_t>&)>;
486
487// Callback for subsystem restart
488using on_subsystem_restart_callback = std::function<void(const std::string&)>;
489
490// Struct for the mac info from the legacy HAL. This is a cleaner version
491// of the |wifi_mac_info| & |wifi_iface_info|.
492typedef struct {
493 std::string name;
494 wifi_channel channel;
495} WifiIfaceInfo;
496
497typedef struct {
498 uint32_t wlan_mac_id;
499 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
500 uint32_t mac_band;
501 /* Represents the connected Wi-Fi interfaces associated with each MAC */
502 std::vector<WifiIfaceInfo> iface_infos;
503} WifiMacInfo;
504
505// Callback for radio mode change
506using on_radio_mode_change_callback = std::function<void(const std::vector<WifiMacInfo>&)>;
507
508// TWT response and event callbacks struct.
509struct TwtCallbackHandlers {
510 // Callback for TWT setup response
511 std::function<void(const TwtSetupResponse&)> on_setup_response;
512 // Callback for TWT teardown completion
513 std::function<void(const TwtTeardownCompletion&)> on_teardown_completion;
514 // Callback for TWT info frame received event
515 std::function<void(const TwtInfoFrameReceived&)> on_info_frame_received;
516 // Callback for TWT notification from the device
517 std::function<void(const TwtDeviceNotify&)> on_device_notify;
518};
519
520// CHRE response and event callbacks struct.
521struct ChreCallbackHandlers {
522 // Callback for CHRE NAN RTT
523 std::function<void(chre_nan_rtt_state)> on_wifi_chre_nan_rtt_state;
524};
525
526// Cached Scan Results response and event callbacks struct.
527struct CachedScanResultsCallbackHandlers {
528 // Callback for Cached Scan Results
529 std::function<void(wifi_cached_scan_report*)> on_cached_scan_results;
530};
531
532/**
533 * Class that encapsulates all legacy HAL interactions.
534 * This class manages the lifetime of the event loop thread used by legacy HAL.
535 *
536 * Note: There will only be a single instance of this class created in the Wifi
537 * object and will be valid for the lifetime of the process.
538 */
539class WifiLegacyHal {
540 public:
541 WifiLegacyHal(const std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool,
542 const wifi_hal_fn& fn, bool is_primary);
543 virtual ~WifiLegacyHal() = default;
544
545 // Initialize the legacy HAL function table.
546 virtual wifi_error initialize();
547 // Start the legacy HAL and the event looper thread.
548 virtual wifi_error start();
549 // Deinitialize the legacy HAL and wait for the event loop thread to exit
550 // using a predefined timeout.
551 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
552 const std::function<void()>& on_complete_callback);
553 virtual wifi_error waitForDriverReady();
554 // Checks if legacy HAL has successfully started
555 bool isStarted();
556 // Wrappers for all the functions in the legacy HAL function table.
557 virtual std::pair<wifi_error, std::string> getDriverVersion(const std::string& iface_name);
558 virtual std::pair<wifi_error, std::string> getFirmwareVersion(const std::string& iface_name);
559 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
560 const std::string& iface_name);
561 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
562 const std::string& iface_name);
563 virtual std::pair<wifi_error, uint64_t> getSupportedFeatureSet(const std::string& iface_name);
564 // APF functions.
565 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
566 const std::string& iface_name);
567 wifi_error setPacketFilter(const std::string& iface_name, const std::vector<uint8_t>& program);
568 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
569 const std::string& iface_name);
570 // Gscan functions.
571 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
572 const std::string& iface_name);
573 // These API's provides a simplified interface over the legacy Gscan API's:
574 // a) All scan events from the legacy HAL API other than the
575 // |WIFI_SCAN_FAILED| are treated as notification of results.
576 // This method then retrieves the cached scan results from the legacy
577 // HAL API and triggers the externally provided
578 // |on_results_user_callback| on success.
579 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
580 // results
581 // Triggers the externally provided |on_failure_user_callback|.
582 // c) Full scan result event triggers the externally provided
583 // |on_full_result_user_callback|.
584 wifi_error startGscan(const std::string& iface_name, wifi_request_id id,
585 const wifi_scan_cmd_params& params,
586 const std::function<void(wifi_request_id)>& on_failure_callback,
587 const on_gscan_results_callback& on_results_callback,
588 const on_gscan_full_result_callback& on_full_result_callback);
589 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
590 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
591 const std::string& iface_name, wifi_band band);
592 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
593 // Link layer stats functions.
594 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
595 wifi_error disableLinkLayerStats(const std::string& iface_name);
Mahesh KKV5f30d332022-10-26 14:07:44 -0700596 wifi_error getLinkLayerStats(const std::string& iface_name,
597 legacy_hal::LinkLayerStats& legacy_stats,
598 legacy_hal::LinkLayerMlStats& legacy_ml_stats);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000599 // RSSI monitor functions.
600 wifi_error startRssiMonitoring(
601 const std::string& iface_name, wifi_request_id id, int8_t max_rssi, int8_t min_rssi,
602 const on_rssi_threshold_breached_callback& on_threshold_breached_callback);
603 wifi_error stopRssiMonitoring(const std::string& iface_name, wifi_request_id id);
604 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
605 const std::string& iface_name);
606 wifi_error configureRoaming(const std::string& iface_name, const wifi_roaming_config& config);
607 wifi_error enableFirmwareRoaming(const std::string& iface_name, fw_roaming_state_t state);
608 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
609 wifi_error startSendingOffloadedPacket(const std::string& iface_name, int32_t cmd_id,
610 uint16_t ether_type,
611 const std::vector<uint8_t>& ip_packet_data,
612 const std::array<uint8_t, 6>& src_address,
613 const std::array<uint8_t, 6>& dst_address,
614 int32_t period_in_ms);
615 wifi_error stopSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id);
616 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
617 wifi_power_scenario scenario);
618 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
619 wifi_error setLatencyMode(const std::string& iface_name, wifi_latency_mode mode);
620 wifi_error setThermalMitigationMode(wifi_thermal_mode mode, uint32_t completion_window);
621 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
622 uint32_t access_category);
623 wifi_error resetDscpToAccessCategoryMapping();
624 // Logger/debug functions.
625 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(const std::string& iface_name);
626 wifi_error startPktFateMonitoring(const std::string& iface_name);
627 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(const std::string& iface_name);
628 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(const std::string& iface_name);
629 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(const std::string& iface_name);
630 wifi_error registerRingBufferCallbackHandler(
631 const std::string& iface_name, const on_ring_buffer_data_callback& on_data_callback);
632 wifi_error deregisterRingBufferCallbackHandler(const std::string& iface_name);
633 virtual wifi_error registerSubsystemRestartCallbackHandler(
634 const on_subsystem_restart_callback& on_restart_callback);
635 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> getRingBuffersStatus(
636 const std::string& iface_name);
637 wifi_error startRingBufferLogging(const std::string& iface_name, const std::string& ring_name,
638 uint32_t verbose_level, uint32_t max_interval_sec,
639 uint32_t min_data_size);
640 wifi_error getRingBufferData(const std::string& iface_name, const std::string& ring_name);
641 wifi_error registerErrorAlertCallbackHandler(const std::string& iface_name,
642 const on_error_alert_callback& on_alert_callback);
643 wifi_error deregisterErrorAlertCallbackHandler(const std::string& iface_name);
644 // Radio mode functions.
645 virtual wifi_error registerRadioModeChangeCallbackHandler(
646 const std::string& iface_name,
647 const on_radio_mode_change_callback& on_user_change_callback);
648 // RTT functions.
649 wifi_error startRttRangeRequest(const std::string& iface_name, wifi_request_id id,
650 const std::vector<wifi_rtt_config>& rtt_configs,
Sunil Ravif8fc2372022-11-10 18:37:41 +0000651 const on_rtt_results_callback& on_results_callback,
652 const on_rtt_results_callback_v2& on_results_callback_v2);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000653 wifi_error cancelRttRangeRequest(const std::string& iface_name, wifi_request_id id,
654 const std::vector<std::array<uint8_t, ETH_ALEN>>& mac_addrs);
655 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(const std::string& iface_name);
656 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(const std::string& iface_name);
657 wifi_error enableRttResponder(const std::string& iface_name, wifi_request_id id,
658 const wifi_channel_info& channel_hint, uint32_t max_duration_secs,
659 const wifi_rtt_responder& info);
660 wifi_error disableRttResponder(const std::string& iface_name, wifi_request_id id);
661 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
662 const wifi_lci_information& info);
663 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
664 const wifi_lcr_information& info);
665 // NAN functions.
666 virtual wifi_error nanRegisterCallbackHandlers(const std::string& iface_name,
667 const NanCallbackHandlers& callbacks);
668 wifi_error nanEnableRequest(const std::string& iface_name, transaction_id id,
669 const NanEnableRequest& msg);
670 virtual wifi_error nanDisableRequest(const std::string& iface_name, transaction_id id);
671 wifi_error nanPublishRequest(const std::string& iface_name, transaction_id id,
672 const NanPublishRequest& msg);
673 wifi_error nanPublishCancelRequest(const std::string& iface_name, transaction_id id,
674 const NanPublishCancelRequest& msg);
675 wifi_error nanSubscribeRequest(const std::string& iface_name, transaction_id id,
676 const NanSubscribeRequest& msg);
677 wifi_error nanSubscribeCancelRequest(const std::string& iface_name, transaction_id id,
678 const NanSubscribeCancelRequest& msg);
679 wifi_error nanTransmitFollowupRequest(const std::string& iface_name, transaction_id id,
680 const NanTransmitFollowupRequest& msg);
681 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
682 const NanStatsRequest& msg);
683 wifi_error nanConfigRequest(const std::string& iface_name, transaction_id id,
684 const NanConfigRequest& msg);
685 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
686 const NanTCARequest& msg);
687 wifi_error nanBeaconSdfPayloadRequest(const std::string& iface_name, transaction_id id,
688 const NanBeaconSdfPayloadRequest& msg);
689 std::pair<wifi_error, NanVersion> nanGetVersion();
690 wifi_error nanGetCapabilities(const std::string& iface_name, transaction_id id);
691 wifi_error nanDataInterfaceCreate(const std::string& iface_name, transaction_id id,
692 const std::string& data_iface_name);
693 virtual wifi_error nanDataInterfaceDelete(const std::string& iface_name, transaction_id id,
694 const std::string& data_iface_name);
695 wifi_error nanDataRequestInitiator(const std::string& iface_name, transaction_id id,
696 const NanDataPathInitiatorRequest& msg);
697 wifi_error nanDataIndicationResponse(const std::string& iface_name, transaction_id id,
698 const NanDataPathIndicationResponse& msg);
Nate Jiang38e8db52022-12-02 17:30:27 -0800699 wifi_error nanPairingRequest(const std::string& iface_name, transaction_id id,
700 const NanPairingRequest& msg);
701 wifi_error nanPairingIndicationResponse(const std::string& iface_name, transaction_id id,
702 const NanPairingIndicationResponse& msg);
703 wifi_error nanBootstrappingRequest(const std::string& iface_name, transaction_id id,
704 const NanBootstrappingRequest& msg);
705 wifi_error nanBootstrappingIndicationResponse(const std::string& iface_name, transaction_id id,
706 const NanBootstrappingIndicationResponse& msg);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000707 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id, uint32_t ndpInstanceId);
Nate Jiangbae6fdd2023-02-10 17:16:40 -0800708 wifi_error nanPairingEnd(const std::string& iface_name, transaction_id id, uint32_t pairingId);
Phill Hayers02a97242022-12-15 16:05:14 +0000709 wifi_error nanSuspendRequest(const std::string& iface_name, transaction_id id,
710 const NanSuspendRequest& msg);
711 wifi_error nanResumeRequest(const std::string& iface_name, transaction_id id,
712 const NanResumeRequest& msg);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000713 // AP functions.
714 wifi_error setCountryCode(const std::string& iface_name, const std::array<uint8_t, 2> code);
715
716 // Interface functions.
717 virtual wifi_error createVirtualInterface(const std::string& ifname,
718 wifi_interface_type iftype);
719 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
720 virtual wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
721
722 // STA + STA functions
723 virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);
724 virtual wifi_error multiStaSetUseCase(wifi_multi_sta_use_case use_case);
725
726 // Coex functions.
727 virtual wifi_error setCoexUnsafeChannels(std::vector<wifi_coex_unsafe_channel> unsafe_channels,
728 uint32_t restrictions);
729
730 wifi_error setVoipMode(const std::string& iface_name, wifi_voip_mode mode);
731
732 wifi_error twtRegisterHandler(const std::string& iface_name,
733 const TwtCallbackHandlers& handler);
734
735 std::pair<wifi_error, TwtCapabilitySet> twtGetCapability(const std::string& iface_name);
736
737 wifi_error twtSetupRequest(const std::string& iface_name, const TwtSetupRequest& msg);
738
739 wifi_error twtTearDownRequest(const std::string& iface_name, const TwtTeardownRequest& msg);
740
741 wifi_error twtInfoFrameRequest(const std::string& iface_name, const TwtInfoFrameRequest& msg);
742
743 std::pair<wifi_error, TwtStats> twtGetStats(const std::string& iface_name, uint8_t configId);
744
745 wifi_error twtClearStats(const std::string& iface_name, uint8_t configId);
746
Ye Jiao50274f72023-01-17 14:53:22 +0800747 wifi_error setScanMode(const std::string& iface_name, bool enable);
748
Gabriel Birenf3262f92022-07-15 23:25:39 +0000749 wifi_error setDtimConfig(const std::string& iface_name, uint32_t multiplier);
750
751 // Retrieve the list of usable channels in the requested bands
752 // for the requested modes
753 std::pair<wifi_error, std::vector<wifi_usable_channel>> getUsableChannels(
754 uint32_t band_mask, uint32_t iface_mode_mask, uint32_t filter_mask);
755
756 wifi_error triggerSubsystemRestart();
757
758 wifi_error setIndoorState(bool isIndoor);
759
760 std::pair<wifi_error, wifi_radio_combination_matrix*> getSupportedRadioCombinationsMatrix();
761
762 // CHRE NAN RTT function
763 wifi_error chreNanRttRequest(const std::string& iface_name, bool enable);
764
765 wifi_error chreRegisterHandler(const std::string& iface_name,
766 const ChreCallbackHandlers& handler);
767
768 wifi_error enableWifiTxPowerLimits(const std::string& iface_name, bool enable);
769 wifi_error getWifiCachedScanResults(const std::string& iface_name,
770 const CachedScanResultsCallbackHandlers& handler);
Mahesh KKVc84d3772022-12-02 16:53:28 -0800771 std::pair<wifi_error, wifi_chip_capabilities> getWifiChipCapabilities();
Shuibing Daie5fbcab2022-12-19 15:37:19 -0800772 wifi_error enableStaChannelForPeerNetwork(uint32_t channelCategoryEnableFlag);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000773
774 private:
775 // Retrieve interface handles for all the available interfaces.
776 wifi_error retrieveIfaceHandles();
777 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
778 // Run the legacy HAL event loop thread.
779 void runEventLoop();
780 // Retrieve the cached gscan results to pass the results back to the
781 // external callbacks.
782 std::pair<wifi_error, std::vector<wifi_cached_scan_results>> getGscanCachedResults(
783 const std::string& iface_name);
784 void invalidate();
785 // Handles wifi (error) status of Virtual interface create/delete
786 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(const std::string& ifname,
787 wifi_error status);
Mahesh KKV5f30d332022-10-26 14:07:44 -0700788 wifi_link_stat* copyLinkStat(wifi_link_stat* stat_ptr, std::vector<LinkStats> stats);
789 wifi_peer_info* copyPeerInfo(wifi_peer_info* peer_ptr, std::vector<WifiPeerInfo> peers);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000790
791 // Global function table of legacy HAL.
792 wifi_hal_fn global_func_table_;
793 // Opaque handle to be used for all global operations.
794 wifi_handle global_handle_;
795 // Map of interface name to handle that is to be used for all interface
796 // specific operations.
797 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
798 // Flag to indicate if we have initiated the cleanup of legacy HAL.
799 std::atomic<bool> awaiting_event_loop_termination_;
800 std::condition_variable_any stop_wait_cv_;
801 // Flag to indicate if the legacy HAL has been started.
802 bool is_started_;
803 std::weak_ptr<::android::wifi_system::InterfaceTool> iface_tool_;
804 // Flag to indicate if this HAL is for the primary chip. This is used
805 // in order to avoid some hard-coded behavior used with older HALs,
806 // such as bring wlan0 interface up/down on start/stop HAL.
807 // it may be removed once vendor HALs are updated.
808 bool is_primary_;
809};
810
811} // namespace legacy_hal
812} // namespace wifi
813} // namespace hardware
814} // namespace android
815} // namespace aidl
816
817#endif // WIFI_LEGACY_HAL_H_