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