blob: cf2450de8b5664ccfb88f2702310bdd959173bc7 [file] [log] [blame]
Roshan Piusaabe5752016-09-29 09:03:59 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roshan Piuse73a5062016-12-12 08:53:34 -080017#ifndef WIFI_LEGACY_HAL_H_
18#define WIFI_LEGACY_HAL_H_
Roshan Piusaabe5752016-09-29 09:03:59 -070019
Roshan Piusabcf78f2017-10-06 16:30:38 -070020#include <condition_variable>
Roshan Piusaabe5752016-09-29 09:03:59 -070021#include <functional>
Roshan Piusacededb2017-10-06 14:59:26 -070022#include <map>
Roshan Piusaabe5752016-09-29 09:03:59 -070023#include <thread>
Roshan Pius734fea02016-10-11 08:30:28 -070024#include <vector>
Roshan Piusaabe5752016-09-29 09:03:59 -070025
Peter Collingbourne78471d92020-12-30 17:12:41 -080026#include <hardware_legacy/wifi_hal.h>
Roshan Pius97334112016-11-18 14:07:54 -080027#include <wifi_system/interface_tool.h>
28
Roshan Piusaabe5752016-09-29 09:03:59 -070029namespace android {
30namespace hardware {
31namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +020032namespace V1_5 {
Roshan Piusaabe5752016-09-29 09:03:59 -070033namespace implementation {
Roshan Pius955542e2016-10-28 09:42:44 -070034// This is in a separate namespace to prevent typename conflicts between
35// the legacy HAL types and the HIDL interface types.
36namespace legacy_hal {
Peter Collingbourne78471d92020-12-30 17:12:41 -080037// Import all the types defined inside the legacy HAL header files into this
Roshan Pius955542e2016-10-28 09:42:44 -070038// namespace.
Kumar Anand2a630a32021-01-21 14:09:14 -080039using ::frame_info;
40using ::frame_type;
Peter Collingbourne78471d92020-12-30 17:12:41 -080041using ::FRAME_TYPE_80211_MGMT;
42using ::FRAME_TYPE_ETHERNET_II;
43using ::FRAME_TYPE_UNKNOWN;
Kumar Anand2a630a32021-01-21 14:09:14 -080044using ::fw_roaming_state_t;
45using ::mac_addr;
Peter Collingbourne78471d92020-12-30 17:12:41 -080046using ::NAN_CHANNEL_24G_BAND;
47using ::NAN_CHANNEL_5G_BAND_HIGH;
48using ::NAN_CHANNEL_5G_BAND_LOW;
49using ::NAN_DISABLE_RANGE_REPORT;
50using ::NAN_DO_NOT_USE_SRF;
51using ::NAN_DP_CHANNEL_NOT_REQUESTED;
52using ::NAN_DP_CONFIG_NO_SECURITY;
53using ::NAN_DP_CONFIG_SECURITY;
54using ::NAN_DP_END;
55using ::NAN_DP_FORCE_CHANNEL_SETUP;
56using ::NAN_DP_INITIATOR_RESPONSE;
57using ::NAN_DP_INTERFACE_CREATE;
58using ::NAN_DP_INTERFACE_DELETE;
59using ::NAN_DP_REQUEST_ACCEPT;
60using ::NAN_DP_REQUEST_CHANNEL_SETUP;
61using ::NAN_DP_REQUEST_REJECT;
62using ::NAN_DP_RESPONDER_RESPONSE;
63using ::NAN_GET_CAPABILITIES;
64using ::NAN_MATCH_ALG_MATCH_CONTINUOUS;
65using ::NAN_MATCH_ALG_MATCH_NEVER;
66using ::NAN_MATCH_ALG_MATCH_ONCE;
67using ::NAN_PUBLISH_TYPE_SOLICITED;
68using ::NAN_PUBLISH_TYPE_UNSOLICITED;
69using ::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED;
70using ::NAN_RANGING_AUTO_RESPONSE_DISABLE;
71using ::NAN_RANGING_AUTO_RESPONSE_ENABLE;
72using ::NAN_RANGING_DISABLE;
73using ::NAN_RANGING_ENABLE;
74using ::NAN_RESPONSE_BEACON_SDF_PAYLOAD;
75using ::NAN_RESPONSE_CONFIG;
76using ::NAN_RESPONSE_DISABLED;
77using ::NAN_RESPONSE_ENABLED;
78using ::NAN_RESPONSE_ERROR;
79using ::NAN_RESPONSE_PUBLISH;
80using ::NAN_RESPONSE_PUBLISH_CANCEL;
81using ::NAN_RESPONSE_STATS;
82using ::NAN_RESPONSE_SUBSCRIBE;
83using ::NAN_RESPONSE_SUBSCRIBE_CANCEL;
84using ::NAN_RESPONSE_TCA;
85using ::NAN_RESPONSE_TRANSMIT_FOLLOWUP;
86using ::NAN_SECURITY_KEY_INPUT_PASSPHRASE;
Peter Collingbourne78471d92020-12-30 17:12:41 -080087using ::NAN_SECURITY_KEY_INPUT_PMK;
88using ::NAN_SERVICE_ACCEPT_POLICY_ALL;
89using ::NAN_SERVICE_ACCEPT_POLICY_NONE;
90using ::NAN_SRF_ATTR_BLOOM_FILTER;
91using ::NAN_SRF_ATTR_PARTIAL_MAC_ADDR;
92using ::NAN_SRF_INCLUDE_DO_NOT_RESPOND;
93using ::NAN_SRF_INCLUDE_RESPOND;
94using ::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
95using ::NAN_SSI_REQUIRED_IN_MATCH_IND;
96using ::NAN_STATUS_ALREADY_ENABLED;
97using ::NAN_STATUS_FOLLOWUP_QUEUE_FULL;
98using ::NAN_STATUS_INTERNAL_FAILURE;
99using ::NAN_STATUS_INVALID_NDP_ID;
100using ::NAN_STATUS_INVALID_PARAM;
101using ::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID;
102using ::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID;
103using ::NAN_STATUS_NAN_NOT_ALLOWED;
104using ::NAN_STATUS_NO_OTA_ACK;
105using ::NAN_STATUS_NO_RESOURCE_AVAILABLE;
106using ::NAN_STATUS_PROTOCOL_FAILURE;
107using ::NAN_STATUS_SUCCESS;
108using ::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED;
109using ::NAN_SUBSCRIBE_TYPE_ACTIVE;
110using ::NAN_SUBSCRIBE_TYPE_PASSIVE;
111using ::NAN_TRANSMIT_IN_DW;
112using ::NAN_TRANSMIT_IN_FAW;
113using ::NAN_TX_PRIORITY_HIGH;
114using ::NAN_TX_PRIORITY_NORMAL;
115using ::NAN_TX_TYPE_BROADCAST;
116using ::NAN_TX_TYPE_UNICAST;
117using ::NAN_USE_SRF;
118using ::NanBeaconSdfPayloadInd;
119using ::NanCapabilities;
120using ::NanChannelInfo;
121using ::NanConfigRequest;
122using ::NanDataPathChannelCfg;
123using ::NanDataPathConfirmInd;
124using ::NanDataPathEndInd;
125using ::NanDataPathIndicationResponse;
126using ::NanDataPathInitiatorRequest;
127using ::NanDataPathRequestInd;
128using ::NanDataPathScheduleUpdateInd;
129using ::NanDisabledInd;
130using ::NanDiscEngEventInd;
131using ::NanEnableRequest;
132using ::NanFollowupInd;
133using ::NanMatchAlg;
134using ::NanMatchExpiredInd;
135using ::NanMatchInd;
136using ::NanPublishCancelRequest;
137using ::NanPublishRequest;
138using ::NanPublishTerminatedInd;
139using ::NanPublishType;
140using ::NanRangeReportInd;
141using ::NanRangeRequestInd;
142using ::NanResponseMsg;
143using ::NanSRFType;
144using ::NanStatusType;
145using ::NanSubscribeCancelRequest;
146using ::NanSubscribeRequest;
147using ::NanSubscribeTerminatedInd;
148using ::NanSubscribeType;
149using ::NanTransmitFollowupInd;
150using ::NanTransmitFollowupRequest;
151using ::NanTxType;
152using ::ROAMING_DISABLE;
153using ::ROAMING_ENABLE;
154using ::RTT_PEER_AP;
155using ::RTT_PEER_NAN;
156using ::RTT_PEER_P2P_CLIENT;
157using ::RTT_PEER_P2P_GO;
158using ::RTT_PEER_STA;
Kumar Anand2a630a32021-01-21 14:09:14 -0800159using ::rtt_peer_type;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800160using ::RTT_STATUS_ABORTED;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800161using ::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL;
162using ::RTT_STATUS_FAIL_BUSY_TRY_LATER;
163using ::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE;
164using ::RTT_STATUS_FAIL_INVALID_TS;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800165using ::RTT_STATUS_FAIL_NO_CAPABILITY;
166using ::RTT_STATUS_FAIL_NO_RSP;
Kumar Anand2a630a32021-01-21 14:09:14 -0800167using ::RTT_STATUS_FAIL_NOT_SCHEDULED_YET;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800168using ::RTT_STATUS_FAIL_PROTOCOL;
169using ::RTT_STATUS_FAIL_REJECTED;
170using ::RTT_STATUS_FAIL_SCHEDULE;
171using ::RTT_STATUS_FAIL_TM_TIMEOUT;
Kumar Anand2a630a32021-01-21 14:09:14 -0800172using ::RTT_STATUS_FAILURE;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800173using ::RTT_STATUS_INVALID_REQ;
174using ::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED;
175using ::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE;
176using ::RTT_STATUS_NO_WIFI;
177using ::RTT_STATUS_SUCCESS;
178using ::RTT_TYPE_1_SIDED;
179using ::RTT_TYPE_2_SIDED;
180using ::RX_PKT_FATE_DRV_DROP_FILTER;
181using ::RX_PKT_FATE_DRV_DROP_INVALID;
182using ::RX_PKT_FATE_DRV_DROP_NOBUFS;
183using ::RX_PKT_FATE_DRV_DROP_OTHER;
184using ::RX_PKT_FATE_DRV_QUEUED;
185using ::RX_PKT_FATE_FW_DROP_FILTER;
186using ::RX_PKT_FATE_FW_DROP_INVALID;
187using ::RX_PKT_FATE_FW_DROP_NOBUFS;
188using ::RX_PKT_FATE_FW_DROP_OTHER;
189using ::RX_PKT_FATE_FW_QUEUED;
190using ::RX_PKT_FATE_SUCCESS;
Kumar Anand2a630a32021-01-21 14:09:14 -0800191using ::ssid_t;
192using ::transaction_id;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800193using ::TX_PKT_FATE_ACKED;
194using ::TX_PKT_FATE_DRV_DROP_INVALID;
195using ::TX_PKT_FATE_DRV_DROP_NOBUFS;
196using ::TX_PKT_FATE_DRV_DROP_OTHER;
197using ::TX_PKT_FATE_DRV_QUEUED;
198using ::TX_PKT_FATE_FW_DROP_INVALID;
199using ::TX_PKT_FATE_FW_DROP_NOBUFS;
200using ::TX_PKT_FATE_FW_DROP_OTHER;
201using ::TX_PKT_FATE_FW_QUEUED;
202using ::TX_PKT_FATE_SENT;
203using ::WIFI_AC_BE;
204using ::WIFI_AC_BK;
205using ::WIFI_AC_VI;
206using ::WIFI_AC_VO;
Kumar Anand2a630a32021-01-21 14:09:14 -0800207using ::wifi_band;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800208using ::WIFI_BAND_A;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800209using ::WIFI_BAND_A_DFS;
210using ::WIFI_BAND_A_WITH_DFS;
Kumar Anand2a630a32021-01-21 14:09:14 -0800211using ::WIFI_BAND_ABG;
212using ::WIFI_BAND_ABG_WITH_DFS;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800213using ::WIFI_BAND_BG;
214using ::WIFI_BAND_UNSPECIFIED;
Kumar Anand2a630a32021-01-21 14:09:14 -0800215using ::wifi_cached_scan_results;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800216using ::WIFI_CHAN_WIDTH_10;
217using ::WIFI_CHAN_WIDTH_160;
218using ::WIFI_CHAN_WIDTH_20;
219using ::WIFI_CHAN_WIDTH_40;
220using ::WIFI_CHAN_WIDTH_5;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800221using ::WIFI_CHAN_WIDTH_80;
222using ::WIFI_CHAN_WIDTH_80P80;
223using ::WIFI_CHAN_WIDTH_INVALID;
Kumar Anand2a630a32021-01-21 14:09:14 -0800224using ::wifi_channel_info;
225using ::wifi_channel_stat;
226using ::wifi_channel_width;
227using ::wifi_coex_restriction;
228using ::wifi_coex_unsafe_channel;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800229using ::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED;
230using ::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY;
Kumar Anand2a630a32021-01-21 14:09:14 -0800231using ::wifi_error;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800232using ::WIFI_ERROR_BUSY;
233using ::WIFI_ERROR_INVALID_ARGS;
234using ::WIFI_ERROR_INVALID_REQUEST_ID;
235using ::WIFI_ERROR_NONE;
236using ::WIFI_ERROR_NOT_AVAILABLE;
237using ::WIFI_ERROR_NOT_SUPPORTED;
238using ::WIFI_ERROR_OUT_OF_MEMORY;
239using ::WIFI_ERROR_TIMED_OUT;
240using ::WIFI_ERROR_TOO_MANY_REQUESTS;
241using ::WIFI_ERROR_UNINITIALIZED;
242using ::WIFI_ERROR_UNKNOWN;
Kumar Anand2a630a32021-01-21 14:09:14 -0800243using ::wifi_gscan_capabilities;
244using ::wifi_hal_fn;
245using ::wifi_information_element;
246using ::WIFI_INTERFACE_IBSS;
247using ::WIFI_INTERFACE_MESH;
248using ::wifi_interface_mode;
249using ::WIFI_INTERFACE_NAN;
250using ::WIFI_INTERFACE_P2P_CLIENT;
251using ::WIFI_INTERFACE_P2P_GO;
252using ::WIFI_INTERFACE_SOFTAP;
253using ::WIFI_INTERFACE_STA;
254using ::WIFI_INTERFACE_TDLS;
255using ::wifi_interface_type;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800256using ::WIFI_INTERFACE_TYPE_AP;
257using ::WIFI_INTERFACE_TYPE_NAN;
258using ::WIFI_INTERFACE_TYPE_P2P;
259using ::WIFI_INTERFACE_TYPE_STA;
Kumar Anand2a630a32021-01-21 14:09:14 -0800260using ::WIFI_INTERFACE_UNKNOWN;
261using ::wifi_latency_mode;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800262using ::WIFI_LATENCY_MODE_LOW;
263using ::WIFI_LATENCY_MODE_NORMAL;
Kumar Anand2a630a32021-01-21 14:09:14 -0800264using ::wifi_lci_information;
265using ::wifi_lcr_information;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800266using ::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
267using ::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
268using ::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
269using ::WIFI_LOGGER_PACKET_FATE_SUPPORTED;
270using ::WIFI_LOGGER_POWER_EVENT_SUPPORTED;
271using ::WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
272using ::WIFI_MOTION_EXPECTED;
273using ::WIFI_MOTION_NOT_EXPECTED;
Kumar Anand2a630a32021-01-21 14:09:14 -0800274using ::wifi_motion_pattern;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800275using ::WIFI_MOTION_UNKNOWN;
Kumar Anand2a630a32021-01-21 14:09:14 -0800276using ::wifi_multi_sta_use_case;
277using ::wifi_power_scenario;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800278using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
279using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
280using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
281using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
282using ::WIFI_POWER_SCENARIO_VOICE_CALL;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800283using ::wifi_rate;
284using ::wifi_request_id;
285using ::wifi_ring_buffer_status;
286using ::wifi_roaming_capabilities;
287using ::wifi_roaming_config;
288using ::wifi_rtt_bw;
Kumar Anand2a630a32021-01-21 14:09:14 -0800289using ::WIFI_RTT_BW_10;
290using ::WIFI_RTT_BW_160;
291using ::WIFI_RTT_BW_20;
292using ::WIFI_RTT_BW_40;
293using ::WIFI_RTT_BW_5;
294using ::WIFI_RTT_BW_80;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800295using ::wifi_rtt_capabilities;
296using ::wifi_rtt_config;
297using ::wifi_rtt_preamble;
Kumar Anand2a630a32021-01-21 14:09:14 -0800298using ::WIFI_RTT_PREAMBLE_HE;
299using ::WIFI_RTT_PREAMBLE_HT;
300using ::WIFI_RTT_PREAMBLE_LEGACY;
301using ::WIFI_RTT_PREAMBLE_VHT;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800302using ::wifi_rtt_responder;
303using ::wifi_rtt_result;
304using ::wifi_rtt_status;
305using ::wifi_rtt_type;
306using ::wifi_rx_packet_fate;
307using ::wifi_rx_report;
308using ::wifi_scan_bucket_spec;
309using ::wifi_scan_cmd_params;
Kumar Anand2a630a32021-01-21 14:09:14 -0800310using ::WIFI_SCAN_FLAG_INTERRUPTED;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800311using ::wifi_scan_result;
Kumar Anand2a630a32021-01-21 14:09:14 -0800312using ::WIFI_SUCCESS;
Peter Collingbourne78471d92020-12-30 17:12:41 -0800313using ::wifi_tx_packet_fate;
314using ::wifi_tx_report;
Kumar Anand2a630a32021-01-21 14:09:14 -0800315using ::wifi_usable_channel;
Kumar Anandaea86e02021-02-10 16:22:31 -0800316using ::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE;
317using ::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY;
Kumar Anand2a630a32021-01-21 14:09:14 -0800318using ::WLAN_MAC_2_4_BAND;
319using ::WLAN_MAC_5_0_BAND;
320using ::WLAN_MAC_60_0_BAND;
321using ::WLAN_MAC_6_0_BAND;
Roshan Piusaabe5752016-09-29 09:03:59 -0700322
Roshan Pius0a47c182016-10-28 10:23:00 -0700323// APF capabilities supported by the iface.
324struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700325 uint32_t version;
326 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -0700327};
328
Roshan Pius7cece412016-10-28 10:38:21 -0700329// WARNING: We don't care about the variable sized members of either
330// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
331// to escape the compiler warnings regarding this.
332#pragma GCC diagnostic push
333#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
334// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
335// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
336// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -0700337struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700338 wifi_radio_stat stats;
339 std::vector<uint32_t> tx_time_per_levels;
Sunil Ravib0343e72018-11-13 15:52:00 -0800340 std::vector<wifi_channel_stat> channel_stats;
Roshan Piuse42ace22017-03-13 10:44:20 -0700341};
342
Mingguang Xu41242be2021-02-19 18:16:01 -0800343struct WifiPeerInfo {
344 wifi_peer_info peer_info;
345 std::vector<wifi_rate_stat> rate_stats;
346};
347
Roshan Pius7cece412016-10-28 10:38:21 -0700348struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700349 wifi_iface_stat iface;
350 std::vector<LinkLayerRadioStats> radios;
Mingguang Xu41242be2021-02-19 18:16:01 -0800351 std::vector<WifiPeerInfo> peers;
Roshan Pius7cece412016-10-28 10:38:21 -0700352};
353#pragma GCC diagnostic pop
354
Roshan Pius8714a3e2016-10-28 10:43:51 -0700355// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
356// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
357// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
358// API. Separate that out into a separate return elements to avoid passing
359// pointers around.
360struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700361 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
362 std::vector<uint32_t> cmd_event_wake_cnt;
363 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -0700364};
365
Roshan Pius23012092016-10-28 11:27:40 -0700366// NAN response and event callbacks struct.
367struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700368 // NotifyResponse invoked to notify the status of the Request.
369 std::function<void(transaction_id, const NanResponseMsg&)>
370 on_notify_response;
371 // Various event callbacks.
372 std::function<void(const NanPublishTerminatedInd&)>
373 on_event_publish_terminated;
374 std::function<void(const NanMatchInd&)> on_event_match;
375 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
376 std::function<void(const NanSubscribeTerminatedInd&)>
377 on_event_subscribe_terminated;
378 std::function<void(const NanFollowupInd&)> on_event_followup;
379 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
380 std::function<void(const NanDisabledInd&)> on_event_disabled;
381 std::function<void(const NanTCAInd&)> on_event_tca;
382 std::function<void(const NanBeaconSdfPayloadInd&)>
383 on_event_beacon_sdf_payload;
384 std::function<void(const NanDataPathRequestInd&)>
385 on_event_data_path_request;
386 std::function<void(const NanDataPathConfirmInd&)>
387 on_event_data_path_confirm;
388 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
389 std::function<void(const NanTransmitFollowupInd&)>
390 on_event_transmit_follow_up;
391 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
392 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Jong Wook Kimda830c92018-07-23 15:29:38 -0700393 std::function<void(const NanDataPathScheduleUpdateInd&)>
394 on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700395};
396
Roshan Pius76ff3022016-10-28 10:33:34 -0700397// Full scan results contain IE info and are hence passed by reference, to
398// preserve the variable length array member |ie_data|. Callee must not retain
399// the pointer.
400using on_gscan_full_result_callback =
401 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
402// These scan results don't contain any IE info, so no need to pass by
403// reference.
404using on_gscan_results_callback = std::function<void(
405 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
406
Roshan Piusd4767542016-12-06 10:04:05 -0800407// Invoked when the rssi value breaches the thresholds set.
408using on_rssi_threshold_breached_callback =
409 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
410
Roshan Piusd8e915a2016-10-28 11:23:11 -0700411// Callback for RTT range request results.
412// Rtt results contain IE info and are hence passed by reference, to
413// preserve the |LCI| and |LCR| pointers. Callee must not retain
414// the pointer.
415using on_rtt_results_callback = std::function<void(
416 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
417
Roshan Pius8714a3e2016-10-28 10:43:51 -0700418// Callback for ring buffer data.
419using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700420 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700421 const wifi_ring_buffer_status&)>;
422
Roshan Pius203cb032016-12-14 17:41:20 -0800423// Callback for alerts.
424using on_error_alert_callback =
425 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800426
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700427// Callback for subsystem restart
428using on_subsystem_restart_callback = std::function<void(const std::string&)>;
429
Roshan Pius01f08772018-01-22 17:56:06 -0800430// Struct for the mac info from the legacy HAL. This is a cleaner version
431// of the |wifi_mac_info| & |wifi_iface_info|.
432typedef struct {
433 std::string name;
434 wifi_channel channel;
435} WifiIfaceInfo;
436
437typedef struct {
438 uint32_t wlan_mac_id;
439 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
440 uint32_t mac_band;
441 /* Represents the connected Wi-Fi interfaces associated with each MAC */
442 std::vector<WifiIfaceInfo> iface_infos;
443} WifiMacInfo;
444
445// Callback for radio mode change
446using on_radio_mode_change_callback =
447 std::function<void(const std::vector<WifiMacInfo>&)>;
448
Kai Shi2ca7a112020-12-15 19:51:28 -0800449// TWT response and event callbacks struct.
450struct TwtCallbackHandlers {
451 // Callback for TWT setup response
452 std::function<void(const TwtSetupResponse&)> on_setup_response;
453 // Callback for TWT teardown completion
454 std::function<void(const TwtTeardownCompletion&)> on_teardown_completion;
455 // Callback for TWT info frame received event
456 std::function<void(const TwtInfoFrameReceived&)> on_info_frame_received;
457 // Callback for TWT notification from the device
458 std::function<void(const TwtDeviceNotify&)> on_device_notify;
459};
460
Roshan Piusaabe5752016-09-29 09:03:59 -0700461/**
462 * Class that encapsulates all legacy HAL interactions.
463 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800464 *
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900465 * Note: There will only be a single instance of this class created in the Wifi
Roshan Pius742bb972017-02-02 09:54:27 -0800466 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700467 */
468class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700469 public:
Jimmy Chen2dddd792019-12-23 17:50:39 +0200470 WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool,
471 const wifi_hal_fn& fn, bool is_primary);
Roshan Pius200a17d2017-11-01 13:03:35 -0700472 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700473
Roshan Piusabcf78f2017-10-06 16:30:38 -0700474 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700475 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700476 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700477 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700478 // Deinitialize the legacy HAL and wait for the event loop thread to exit
479 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700480 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
481 const std::function<void()>& on_complete_callback);
Ahmed ElArabawy48229382019-02-07 22:04:53 -0800482 // Checks if legacy HAL has successfully started
483 bool isStarted();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700484 // Wrappers for all the functions in the legacy HAL function table.
Roshan Pius1cd82a82019-03-25 13:51:28 -0700485 virtual std::pair<wifi_error, std::string> getDriverVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700486 const std::string& iface_name);
Roshan Pius1cd82a82019-03-25 13:51:28 -0700487 virtual std::pair<wifi_error, std::string> getFirmwareVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700488 const std::string& iface_name);
489 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
490 const std::string& iface_name);
491 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
492 const std::string& iface_name);
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200493 std::pair<wifi_error, uint64_t> getSupportedFeatureSet(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700494 const std::string& iface_name);
495 // APF functions.
496 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
497 const std::string& iface_name);
498 wifi_error setPacketFilter(const std::string& iface_name,
499 const std::vector<uint8_t>& program);
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900500 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
501 const std::string& iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700502 // Gscan functions.
503 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
504 const std::string& iface_name);
505 // These API's provides a simplified interface over the legacy Gscan API's:
506 // a) All scan events from the legacy HAL API other than the
507 // |WIFI_SCAN_FAILED| are treated as notification of results.
508 // This method then retrieves the cached scan results from the legacy
509 // HAL API and triggers the externally provided
510 // |on_results_user_callback| on success.
511 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
512 // results
513 // triggers the externally provided |on_failure_user_callback|.
514 // c) Full scan result event triggers the externally provided
515 // |on_full_result_user_callback|.
516 wifi_error startGscan(
517 const std::string& iface_name, wifi_request_id id,
518 const wifi_scan_cmd_params& params,
519 const std::function<void(wifi_request_id)>& on_failure_callback,
520 const on_gscan_results_callback& on_results_callback,
521 const on_gscan_full_result_callback& on_full_result_callback);
522 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
523 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
524 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700525 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700526 // Link layer stats functions.
527 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
528 wifi_error disableLinkLayerStats(const std::string& iface_name);
529 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
530 const std::string& iface_name);
531 // RSSI monitor functions.
532 wifi_error startRssiMonitoring(const std::string& iface_name,
533 wifi_request_id id, int8_t max_rssi,
534 int8_t min_rssi,
535 const on_rssi_threshold_breached_callback&
536 on_threshold_breached_callback);
537 wifi_error stopRssiMonitoring(const std::string& iface_name,
538 wifi_request_id id);
539 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
540 const std::string& iface_name);
541 wifi_error configureRoaming(const std::string& iface_name,
542 const wifi_roaming_config& config);
543 wifi_error enableFirmwareRoaming(const std::string& iface_name,
544 fw_roaming_state_t state);
545 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
546 wifi_error startSendingOffloadedPacket(
Ahmed ElArabawyffbad182019-03-05 17:38:06 -0800547 const std::string& iface_name, uint32_t cmd_id, uint16_t ether_type,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700548 const std::vector<uint8_t>& ip_packet_data,
549 const std::array<uint8_t, 6>& src_address,
550 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
551 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
552 uint32_t cmd_id);
Roshan Pius6036c022019-03-27 10:41:58 -0700553 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
554 wifi_power_scenario scenario);
555 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700556 wifi_error setLatencyMode(const std::string& iface_name,
557 wifi_latency_mode mode);
Kumar Anandf2747e02020-01-10 16:49:13 -0800558 wifi_error setThermalMitigationMode(wifi_thermal_mode mode,
Kumar Anand913d5602019-12-18 16:02:37 -0800559 uint32_t completion_window);
Ahmed ElArabawya1d13652020-01-29 09:22:28 -0800560 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
561 uint32_t access_category);
562 wifi_error resetDscpToAccessCategoryMapping();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700563 // Logger/debug functions.
564 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
565 const std::string& iface_name);
566 wifi_error startPktFateMonitoring(const std::string& iface_name);
567 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
568 const std::string& iface_name);
569 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
570 const std::string& iface_name);
571 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
572 const std::string& iface_name);
573 wifi_error registerRingBufferCallbackHandler(
574 const std::string& iface_name,
575 const on_ring_buffer_data_callback& on_data_callback);
576 wifi_error deregisterRingBufferCallbackHandler(
577 const std::string& iface_name);
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700578 wifi_error registerSubsystemRestartCallbackHandler(
579 const on_subsystem_restart_callback& on_restart_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700580 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
581 getRingBuffersStatus(const std::string& iface_name);
582 wifi_error startRingBufferLogging(const std::string& iface_name,
583 const std::string& ring_name,
584 uint32_t verbose_level,
585 uint32_t max_interval_sec,
586 uint32_t min_data_size);
587 wifi_error getRingBufferData(const std::string& iface_name,
588 const std::string& ring_name);
589 wifi_error registerErrorAlertCallbackHandler(
590 const std::string& iface_name,
591 const on_error_alert_callback& on_alert_callback);
592 wifi_error deregisterErrorAlertCallbackHandler(
593 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800594 // Radio mode functions.
Roshan Piusaceecb02018-03-01 14:54:26 -0800595 virtual wifi_error registerRadioModeChangeCallbackHandler(
Roshan Pius01f08772018-01-22 17:56:06 -0800596 const std::string& iface_name,
597 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700598 // RTT functions.
599 wifi_error startRttRangeRequest(
600 const std::string& iface_name, wifi_request_id id,
601 const std::vector<wifi_rtt_config>& rtt_configs,
602 const on_rtt_results_callback& on_results_callback);
603 wifi_error cancelRttRangeRequest(
604 const std::string& iface_name, wifi_request_id id,
605 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
606 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
607 const std::string& iface_name);
608 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
609 const std::string& iface_name);
610 wifi_error enableRttResponder(const std::string& iface_name,
611 wifi_request_id id,
612 const wifi_channel_info& channel_hint,
613 uint32_t max_duration_secs,
614 const wifi_rtt_responder& info);
615 wifi_error disableRttResponder(const std::string& iface_name,
616 wifi_request_id id);
617 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
618 const wifi_lci_information& info);
619 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
620 const wifi_lcr_information& info);
621 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700622 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700623 const std::string& iface_name, const NanCallbackHandlers& callbacks);
624 wifi_error nanEnableRequest(const std::string& iface_name,
625 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700626 virtual wifi_error nanDisableRequest(const std::string& iface_name,
627 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700628 wifi_error nanPublishRequest(const std::string& iface_name,
629 transaction_id id,
630 const NanPublishRequest& msg);
631 wifi_error nanPublishCancelRequest(const std::string& iface_name,
632 transaction_id id,
633 const NanPublishCancelRequest& msg);
634 wifi_error nanSubscribeRequest(const std::string& iface_name,
635 transaction_id id,
636 const NanSubscribeRequest& msg);
637 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
638 transaction_id id,
639 const NanSubscribeCancelRequest& msg);
640 wifi_error nanTransmitFollowupRequest(
641 const std::string& iface_name, transaction_id id,
642 const NanTransmitFollowupRequest& msg);
643 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
644 const NanStatsRequest& msg);
645 wifi_error nanConfigRequest(const std::string& iface_name,
646 transaction_id id, const NanConfigRequest& msg);
647 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
648 const NanTCARequest& msg);
649 wifi_error nanBeaconSdfPayloadRequest(
650 const std::string& iface_name, transaction_id id,
651 const NanBeaconSdfPayloadRequest& msg);
652 std::pair<wifi_error, NanVersion> nanGetVersion();
653 wifi_error nanGetCapabilities(const std::string& iface_name,
654 transaction_id id);
655 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
656 transaction_id id,
657 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700658 virtual wifi_error nanDataInterfaceDelete(
659 const std::string& iface_name, transaction_id id,
660 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700661 wifi_error nanDataRequestInitiator(const std::string& iface_name,
662 transaction_id id,
663 const NanDataPathInitiatorRequest& msg);
664 wifi_error nanDataIndicationResponse(
665 const std::string& iface_name, transaction_id id,
666 const NanDataPathIndicationResponse& msg);
667 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
668 uint32_t ndpInstanceId);
669 // AP functions.
670 wifi_error setCountryCode(const std::string& iface_name,
671 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700672
Sunil Raviddab4bb2020-02-03 22:45:19 -0800673 // interface functions.
Roshan Pius5ba0a902020-04-14 11:55:42 -0700674 virtual wifi_error createVirtualInterface(const std::string& ifname,
675 wifi_interface_type iftype);
676 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
Jimmy Chen2dddd792019-12-23 17:50:39 +0200677 wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800678
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800679 // STA + STA functions
680 virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);
681 virtual wifi_error multiStaSetUseCase(wifi_multi_sta_use_case use_case);
682
Quang Luong94bcce52020-11-25 17:52:19 -0800683 // Coex functions.
684 virtual wifi_error setCoexUnsafeChannels(
685 std::vector<wifi_coex_unsafe_channel> unsafe_channels,
686 uint32_t restrictions);
687
Kai Shi2ca7a112020-12-15 19:51:28 -0800688 wifi_error setVoipMode(const std::string& iface_name, wifi_voip_mode mode);
689
690 wifi_error twtRegisterHandler(const std::string& iface_name,
691 const TwtCallbackHandlers& handler);
692
693 std::pair<wifi_error, TwtCapabilitySet> twtGetCapability(
694 const std::string& iface_name);
695
696 wifi_error twtSetupRequest(const std::string& iface_name,
697 const TwtSetupRequest& msg);
698
699 wifi_error twtTearDownRequest(const std::string& iface_name,
700 const TwtTeardownRequest& msg);
701
702 wifi_error twtInfoFrameRequest(const std::string& iface_name,
703 const TwtInfoFrameRequest& msg);
704
705 std::pair<wifi_error, TwtStats> twtGetStats(const std::string& iface_name,
706 uint8_t configId);
707
708 wifi_error twtClearStats(const std::string& iface_name, uint8_t configId);
709
Kai Shi0b6341c2021-01-11 20:22:59 -0800710 wifi_error setDtimConfig(const std::string& iface_name,
711 uint32_t multiplier);
712
Kumar Anand2a630a32021-01-21 14:09:14 -0800713 // Retrieve the list of usable channels in the requested bands
714 // for the requested modes
715 std::pair<wifi_error, std::vector<wifi_usable_channel>> getUsableChannels(
Kumar Anandaea86e02021-02-10 16:22:31 -0800716 uint32_t band_mask, uint32_t iface_mode_mask, uint32_t filter_mask);
Kumar Anand2a630a32021-01-21 14:09:14 -0800717
Roshan Piusabcf78f2017-10-06 16:30:38 -0700718 private:
719 // Retrieve interface handles for all the available interfaces.
720 wifi_error retrieveIfaceHandles();
721 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
722 // Run the legacy HAL event loop thread.
723 void runEventLoop();
724 // Retrieve the cached gscan results to pass the results back to the
725 // external callbacks.
726 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
727 getGscanCachedResults(const std::string& iface_name);
728 void invalidate();
Sunil Raviddab4bb2020-02-03 22:45:19 -0800729 // Handles wifi (error) status of Virtual interface create/delete
730 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(
731 const std::string& ifname, wifi_error status);
Roshan Piusaabe5752016-09-29 09:03:59 -0700732
Roshan Piusabcf78f2017-10-06 16:30:38 -0700733 // Global function table of legacy HAL.
734 wifi_hal_fn global_func_table_;
735 // Opaque handle to be used for all global operations.
736 wifi_handle global_handle_;
737 // Map of interface name to handle that is to be used for all interface
738 // specific operations.
739 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
740 // Flag to indicate if we have initiated the cleanup of legacy HAL.
741 std::atomic<bool> awaiting_event_loop_termination_;
742 std::condition_variable_any stop_wait_cv_;
743 // Flag to indicate if the legacy HAL has been started.
744 bool is_started_;
Roshan Piusc885df02019-05-21 14:49:05 -0700745 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Jimmy Chen2dddd792019-12-23 17:50:39 +0200746 // flag to indicate if this HAL is for the primary chip. This is used
747 // in order to avoid some hard-coded behavior used with older HALs,
748 // such as bring wlan0 interface up/down on start/stop HAL.
749 // it may be removed once vendor HALs are updated.
750 bool is_primary_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700751};
752
Roshan Pius955542e2016-10-28 09:42:44 -0700753} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700754} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +0200755} // namespace V1_5
Roshan Piusaabe5752016-09-29 09:03:59 -0700756} // namespace wifi
757} // namespace hardware
758} // namespace android
759
Roshan Piuse73a5062016-12-12 08:53:34 -0800760#endif // WIFI_LEGACY_HAL_H_