blob: 0cc1cff8cf5cc77d46477d1e2b9a9cc6d1f17173 [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.
Peter Collingbourne78471d92020-12-30 17:12:41 -080039using ::FRAME_TYPE_80211_MGMT;
40using ::FRAME_TYPE_ETHERNET_II;
41using ::FRAME_TYPE_UNKNOWN;
42using ::NAN_CHANNEL_24G_BAND;
43using ::NAN_CHANNEL_5G_BAND_HIGH;
44using ::NAN_CHANNEL_5G_BAND_LOW;
45using ::NAN_DISABLE_RANGE_REPORT;
46using ::NAN_DO_NOT_USE_SRF;
47using ::NAN_DP_CHANNEL_NOT_REQUESTED;
48using ::NAN_DP_CONFIG_NO_SECURITY;
49using ::NAN_DP_CONFIG_SECURITY;
50using ::NAN_DP_END;
51using ::NAN_DP_FORCE_CHANNEL_SETUP;
52using ::NAN_DP_INITIATOR_RESPONSE;
53using ::NAN_DP_INTERFACE_CREATE;
54using ::NAN_DP_INTERFACE_DELETE;
55using ::NAN_DP_REQUEST_ACCEPT;
56using ::NAN_DP_REQUEST_CHANNEL_SETUP;
57using ::NAN_DP_REQUEST_REJECT;
58using ::NAN_DP_RESPONDER_RESPONSE;
59using ::NAN_GET_CAPABILITIES;
60using ::NAN_MATCH_ALG_MATCH_CONTINUOUS;
61using ::NAN_MATCH_ALG_MATCH_NEVER;
62using ::NAN_MATCH_ALG_MATCH_ONCE;
63using ::NAN_PUBLISH_TYPE_SOLICITED;
64using ::NAN_PUBLISH_TYPE_UNSOLICITED;
65using ::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED;
66using ::NAN_RANGING_AUTO_RESPONSE_DISABLE;
67using ::NAN_RANGING_AUTO_RESPONSE_ENABLE;
68using ::NAN_RANGING_DISABLE;
69using ::NAN_RANGING_ENABLE;
70using ::NAN_RESPONSE_BEACON_SDF_PAYLOAD;
71using ::NAN_RESPONSE_CONFIG;
72using ::NAN_RESPONSE_DISABLED;
73using ::NAN_RESPONSE_ENABLED;
74using ::NAN_RESPONSE_ERROR;
75using ::NAN_RESPONSE_PUBLISH;
76using ::NAN_RESPONSE_PUBLISH_CANCEL;
77using ::NAN_RESPONSE_STATS;
78using ::NAN_RESPONSE_SUBSCRIBE;
79using ::NAN_RESPONSE_SUBSCRIBE_CANCEL;
80using ::NAN_RESPONSE_TCA;
81using ::NAN_RESPONSE_TRANSMIT_FOLLOWUP;
82using ::NAN_SECURITY_KEY_INPUT_PASSPHRASE;
83using ::NAN_SECURITY_KEY_INPUT_PASSPHRASE;
84using ::NAN_SECURITY_KEY_INPUT_PMK;
85using ::NAN_SECURITY_KEY_INPUT_PMK;
86using ::NAN_SERVICE_ACCEPT_POLICY_ALL;
87using ::NAN_SERVICE_ACCEPT_POLICY_NONE;
88using ::NAN_SRF_ATTR_BLOOM_FILTER;
89using ::NAN_SRF_ATTR_PARTIAL_MAC_ADDR;
90using ::NAN_SRF_INCLUDE_DO_NOT_RESPOND;
91using ::NAN_SRF_INCLUDE_RESPOND;
92using ::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
93using ::NAN_SSI_REQUIRED_IN_MATCH_IND;
94using ::NAN_STATUS_ALREADY_ENABLED;
95using ::NAN_STATUS_FOLLOWUP_QUEUE_FULL;
96using ::NAN_STATUS_INTERNAL_FAILURE;
97using ::NAN_STATUS_INVALID_NDP_ID;
98using ::NAN_STATUS_INVALID_PARAM;
99using ::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID;
100using ::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID;
101using ::NAN_STATUS_NAN_NOT_ALLOWED;
102using ::NAN_STATUS_NO_OTA_ACK;
103using ::NAN_STATUS_NO_RESOURCE_AVAILABLE;
104using ::NAN_STATUS_PROTOCOL_FAILURE;
105using ::NAN_STATUS_SUCCESS;
106using ::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED;
107using ::NAN_SUBSCRIBE_TYPE_ACTIVE;
108using ::NAN_SUBSCRIBE_TYPE_PASSIVE;
109using ::NAN_TRANSMIT_IN_DW;
110using ::NAN_TRANSMIT_IN_FAW;
111using ::NAN_TX_PRIORITY_HIGH;
112using ::NAN_TX_PRIORITY_NORMAL;
113using ::NAN_TX_TYPE_BROADCAST;
114using ::NAN_TX_TYPE_UNICAST;
115using ::NAN_USE_SRF;
116using ::NanBeaconSdfPayloadInd;
117using ::NanCapabilities;
118using ::NanChannelInfo;
119using ::NanConfigRequest;
120using ::NanDataPathChannelCfg;
121using ::NanDataPathConfirmInd;
122using ::NanDataPathEndInd;
123using ::NanDataPathIndicationResponse;
124using ::NanDataPathInitiatorRequest;
125using ::NanDataPathRequestInd;
126using ::NanDataPathScheduleUpdateInd;
127using ::NanDisabledInd;
128using ::NanDiscEngEventInd;
129using ::NanEnableRequest;
130using ::NanFollowupInd;
131using ::NanMatchAlg;
132using ::NanMatchExpiredInd;
133using ::NanMatchInd;
134using ::NanPublishCancelRequest;
135using ::NanPublishRequest;
136using ::NanPublishTerminatedInd;
137using ::NanPublishType;
138using ::NanRangeReportInd;
139using ::NanRangeRequestInd;
140using ::NanResponseMsg;
141using ::NanSRFType;
142using ::NanStatusType;
143using ::NanSubscribeCancelRequest;
144using ::NanSubscribeRequest;
145using ::NanSubscribeTerminatedInd;
146using ::NanSubscribeType;
147using ::NanTransmitFollowupInd;
148using ::NanTransmitFollowupRequest;
149using ::NanTxType;
150using ::ROAMING_DISABLE;
151using ::ROAMING_ENABLE;
152using ::RTT_PEER_AP;
153using ::RTT_PEER_NAN;
154using ::RTT_PEER_P2P_CLIENT;
155using ::RTT_PEER_P2P_GO;
156using ::RTT_PEER_STA;
157using ::RTT_STATUS_ABORTED;
158using ::RTT_STATUS_FAILURE;
159using ::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL;
160using ::RTT_STATUS_FAIL_BUSY_TRY_LATER;
161using ::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE;
162using ::RTT_STATUS_FAIL_INVALID_TS;
163using ::RTT_STATUS_FAIL_NOT_SCHEDULED_YET;
164using ::RTT_STATUS_FAIL_NO_CAPABILITY;
165using ::RTT_STATUS_FAIL_NO_RSP;
166using ::RTT_STATUS_FAIL_PROTOCOL;
167using ::RTT_STATUS_FAIL_REJECTED;
168using ::RTT_STATUS_FAIL_SCHEDULE;
169using ::RTT_STATUS_FAIL_TM_TIMEOUT;
170using ::RTT_STATUS_INVALID_REQ;
171using ::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED;
172using ::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE;
173using ::RTT_STATUS_NO_WIFI;
174using ::RTT_STATUS_SUCCESS;
175using ::RTT_TYPE_1_SIDED;
176using ::RTT_TYPE_2_SIDED;
177using ::RX_PKT_FATE_DRV_DROP_FILTER;
178using ::RX_PKT_FATE_DRV_DROP_INVALID;
179using ::RX_PKT_FATE_DRV_DROP_NOBUFS;
180using ::RX_PKT_FATE_DRV_DROP_OTHER;
181using ::RX_PKT_FATE_DRV_QUEUED;
182using ::RX_PKT_FATE_FW_DROP_FILTER;
183using ::RX_PKT_FATE_FW_DROP_INVALID;
184using ::RX_PKT_FATE_FW_DROP_NOBUFS;
185using ::RX_PKT_FATE_FW_DROP_OTHER;
186using ::RX_PKT_FATE_FW_QUEUED;
187using ::RX_PKT_FATE_SUCCESS;
188using ::TX_PKT_FATE_ACKED;
189using ::TX_PKT_FATE_DRV_DROP_INVALID;
190using ::TX_PKT_FATE_DRV_DROP_NOBUFS;
191using ::TX_PKT_FATE_DRV_DROP_OTHER;
192using ::TX_PKT_FATE_DRV_QUEUED;
193using ::TX_PKT_FATE_FW_DROP_INVALID;
194using ::TX_PKT_FATE_FW_DROP_NOBUFS;
195using ::TX_PKT_FATE_FW_DROP_OTHER;
196using ::TX_PKT_FATE_FW_QUEUED;
197using ::TX_PKT_FATE_SENT;
198using ::WIFI_AC_BE;
199using ::WIFI_AC_BK;
200using ::WIFI_AC_VI;
201using ::WIFI_AC_VO;
202using ::WIFI_BAND_A;
203using ::WIFI_BAND_ABG;
204using ::WIFI_BAND_ABG_WITH_DFS;
205using ::WIFI_BAND_A_DFS;
206using ::WIFI_BAND_A_WITH_DFS;
207using ::WIFI_BAND_BG;
208using ::WIFI_BAND_UNSPECIFIED;
209using ::WIFI_CHAN_WIDTH_10;
210using ::WIFI_CHAN_WIDTH_160;
211using ::WIFI_CHAN_WIDTH_20;
212using ::WIFI_CHAN_WIDTH_40;
213using ::WIFI_CHAN_WIDTH_5;
214using ::WIFI_CHAN_WIDTH_5;
215using ::WIFI_CHAN_WIDTH_80;
216using ::WIFI_CHAN_WIDTH_80P80;
217using ::WIFI_CHAN_WIDTH_INVALID;
218using ::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED;
219using ::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY;
220using ::WIFI_ERROR_BUSY;
221using ::WIFI_ERROR_INVALID_ARGS;
222using ::WIFI_ERROR_INVALID_REQUEST_ID;
223using ::WIFI_ERROR_NONE;
224using ::WIFI_ERROR_NOT_AVAILABLE;
225using ::WIFI_ERROR_NOT_SUPPORTED;
226using ::WIFI_ERROR_OUT_OF_MEMORY;
227using ::WIFI_ERROR_TIMED_OUT;
228using ::WIFI_ERROR_TOO_MANY_REQUESTS;
229using ::WIFI_ERROR_UNINITIALIZED;
230using ::WIFI_ERROR_UNKNOWN;
231using ::WIFI_INTERFACE_TYPE_AP;
232using ::WIFI_INTERFACE_TYPE_NAN;
233using ::WIFI_INTERFACE_TYPE_P2P;
234using ::WIFI_INTERFACE_TYPE_STA;
235using ::WIFI_LATENCY_MODE_LOW;
236using ::WIFI_LATENCY_MODE_NORMAL;
237using ::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
238using ::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
239using ::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
240using ::WIFI_LOGGER_PACKET_FATE_SUPPORTED;
241using ::WIFI_LOGGER_POWER_EVENT_SUPPORTED;
242using ::WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
243using ::WIFI_MOTION_EXPECTED;
244using ::WIFI_MOTION_NOT_EXPECTED;
245using ::WIFI_MOTION_UNKNOWN;
246using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
247using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
248using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
249using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
250using ::WIFI_POWER_SCENARIO_VOICE_CALL;
251using ::WIFI_RTT_BW_10;
252using ::WIFI_RTT_BW_160;
253using ::WIFI_RTT_BW_20;
254using ::WIFI_RTT_BW_40;
255using ::WIFI_RTT_BW_5;
256using ::WIFI_RTT_BW_80;
257using ::WIFI_RTT_PREAMBLE_HE;
258using ::WIFI_RTT_PREAMBLE_HT;
259using ::WIFI_RTT_PREAMBLE_LEGACY;
260using ::WIFI_RTT_PREAMBLE_VHT;
261using ::WIFI_SCAN_FLAG_INTERRUPTED;
262using ::WIFI_SUCCESS;
263using ::WLAN_MAC_2_4_BAND;
264using ::WLAN_MAC_5_0_BAND;
265using ::WLAN_MAC_6_0_BAND;
266using ::frame_info;
267using ::frame_type;
268using ::fw_roaming_state_t;
269using ::mac_addr;
270using ::rtt_peer_type;
271using ::ssid_t;
272using ::transaction_id;
273using ::wifi_band;
274using ::wifi_cached_scan_results;
275using ::wifi_channel_info;
276using ::wifi_channel_stat;
277using ::wifi_channel_width;
278using ::wifi_coex_restriction;
279using ::wifi_coex_unsafe_channel;
280using ::wifi_error;
281using ::wifi_gscan_capabilities;
282using ::wifi_hal_fn;
283using ::wifi_information_element;
284using ::wifi_interface_type;
285using ::wifi_latency_mode;
286using ::wifi_lci_information;
287using ::wifi_lcr_information;
288using ::wifi_motion_pattern;
289using ::wifi_multi_sta_use_case;
290using ::wifi_power_scenario;
291using ::wifi_rate;
292using ::wifi_request_id;
293using ::wifi_ring_buffer_status;
294using ::wifi_roaming_capabilities;
295using ::wifi_roaming_config;
296using ::wifi_rtt_bw;
297using ::wifi_rtt_capabilities;
298using ::wifi_rtt_config;
299using ::wifi_rtt_preamble;
300using ::wifi_rtt_responder;
301using ::wifi_rtt_result;
302using ::wifi_rtt_status;
303using ::wifi_rtt_type;
304using ::wifi_rx_packet_fate;
305using ::wifi_rx_report;
306using ::wifi_scan_bucket_spec;
307using ::wifi_scan_cmd_params;
308using ::wifi_scan_result;
309using ::wifi_tx_packet_fate;
310using ::wifi_tx_report;
Roshan Piusaabe5752016-09-29 09:03:59 -0700311
Roshan Pius0a47c182016-10-28 10:23:00 -0700312// APF capabilities supported by the iface.
313struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700314 uint32_t version;
315 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -0700316};
317
Roshan Pius7cece412016-10-28 10:38:21 -0700318// WARNING: We don't care about the variable sized members of either
319// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
320// to escape the compiler warnings regarding this.
321#pragma GCC diagnostic push
322#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
323// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
324// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
325// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -0700326struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700327 wifi_radio_stat stats;
328 std::vector<uint32_t> tx_time_per_levels;
Sunil Ravib0343e72018-11-13 15:52:00 -0800329 std::vector<wifi_channel_stat> channel_stats;
Roshan Piuse42ace22017-03-13 10:44:20 -0700330};
331
Roshan Pius7cece412016-10-28 10:38:21 -0700332struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700333 wifi_iface_stat iface;
334 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -0700335};
336#pragma GCC diagnostic pop
337
Roshan Pius8714a3e2016-10-28 10:43:51 -0700338// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
339// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
340// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
341// API. Separate that out into a separate return elements to avoid passing
342// pointers around.
343struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700344 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
345 std::vector<uint32_t> cmd_event_wake_cnt;
346 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -0700347};
348
Roshan Pius23012092016-10-28 11:27:40 -0700349// NAN response and event callbacks struct.
350struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700351 // NotifyResponse invoked to notify the status of the Request.
352 std::function<void(transaction_id, const NanResponseMsg&)>
353 on_notify_response;
354 // Various event callbacks.
355 std::function<void(const NanPublishTerminatedInd&)>
356 on_event_publish_terminated;
357 std::function<void(const NanMatchInd&)> on_event_match;
358 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
359 std::function<void(const NanSubscribeTerminatedInd&)>
360 on_event_subscribe_terminated;
361 std::function<void(const NanFollowupInd&)> on_event_followup;
362 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
363 std::function<void(const NanDisabledInd&)> on_event_disabled;
364 std::function<void(const NanTCAInd&)> on_event_tca;
365 std::function<void(const NanBeaconSdfPayloadInd&)>
366 on_event_beacon_sdf_payload;
367 std::function<void(const NanDataPathRequestInd&)>
368 on_event_data_path_request;
369 std::function<void(const NanDataPathConfirmInd&)>
370 on_event_data_path_confirm;
371 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
372 std::function<void(const NanTransmitFollowupInd&)>
373 on_event_transmit_follow_up;
374 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
375 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Jong Wook Kimda830c92018-07-23 15:29:38 -0700376 std::function<void(const NanDataPathScheduleUpdateInd&)>
377 on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700378};
379
Roshan Pius76ff3022016-10-28 10:33:34 -0700380// Full scan results contain IE info and are hence passed by reference, to
381// preserve the variable length array member |ie_data|. Callee must not retain
382// the pointer.
383using on_gscan_full_result_callback =
384 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
385// These scan results don't contain any IE info, so no need to pass by
386// reference.
387using on_gscan_results_callback = std::function<void(
388 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
389
Roshan Piusd4767542016-12-06 10:04:05 -0800390// Invoked when the rssi value breaches the thresholds set.
391using on_rssi_threshold_breached_callback =
392 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
393
Roshan Piusd8e915a2016-10-28 11:23:11 -0700394// Callback for RTT range request results.
395// Rtt results contain IE info and are hence passed by reference, to
396// preserve the |LCI| and |LCR| pointers. Callee must not retain
397// the pointer.
398using on_rtt_results_callback = std::function<void(
399 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
400
Roshan Pius8714a3e2016-10-28 10:43:51 -0700401// Callback for ring buffer data.
402using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700403 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700404 const wifi_ring_buffer_status&)>;
405
Roshan Pius203cb032016-12-14 17:41:20 -0800406// Callback for alerts.
407using on_error_alert_callback =
408 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800409
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700410// Callback for subsystem restart
411using on_subsystem_restart_callback = std::function<void(const std::string&)>;
412
Roshan Pius01f08772018-01-22 17:56:06 -0800413// Struct for the mac info from the legacy HAL. This is a cleaner version
414// of the |wifi_mac_info| & |wifi_iface_info|.
415typedef struct {
416 std::string name;
417 wifi_channel channel;
418} WifiIfaceInfo;
419
420typedef struct {
421 uint32_t wlan_mac_id;
422 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
423 uint32_t mac_band;
424 /* Represents the connected Wi-Fi interfaces associated with each MAC */
425 std::vector<WifiIfaceInfo> iface_infos;
426} WifiMacInfo;
427
428// Callback for radio mode change
429using on_radio_mode_change_callback =
430 std::function<void(const std::vector<WifiMacInfo>&)>;
431
Kai Shi2ca7a112020-12-15 19:51:28 -0800432// TWT response and event callbacks struct.
433struct TwtCallbackHandlers {
434 // Callback for TWT setup response
435 std::function<void(const TwtSetupResponse&)> on_setup_response;
436 // Callback for TWT teardown completion
437 std::function<void(const TwtTeardownCompletion&)> on_teardown_completion;
438 // Callback for TWT info frame received event
439 std::function<void(const TwtInfoFrameReceived&)> on_info_frame_received;
440 // Callback for TWT notification from the device
441 std::function<void(const TwtDeviceNotify&)> on_device_notify;
442};
443
Roshan Piusaabe5752016-09-29 09:03:59 -0700444/**
445 * Class that encapsulates all legacy HAL interactions.
446 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800447 *
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900448 * Note: There will only be a single instance of this class created in the Wifi
Roshan Pius742bb972017-02-02 09:54:27 -0800449 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700450 */
451class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700452 public:
Jimmy Chen2dddd792019-12-23 17:50:39 +0200453 WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool,
454 const wifi_hal_fn& fn, bool is_primary);
Roshan Pius200a17d2017-11-01 13:03:35 -0700455 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700456
Roshan Piusabcf78f2017-10-06 16:30:38 -0700457 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700458 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700459 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700460 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700461 // Deinitialize the legacy HAL and wait for the event loop thread to exit
462 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700463 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
464 const std::function<void()>& on_complete_callback);
Ahmed ElArabawy48229382019-02-07 22:04:53 -0800465 // Checks if legacy HAL has successfully started
466 bool isStarted();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700467 // Wrappers for all the functions in the legacy HAL function table.
Roshan Pius1cd82a82019-03-25 13:51:28 -0700468 virtual std::pair<wifi_error, std::string> getDriverVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700469 const std::string& iface_name);
Roshan Pius1cd82a82019-03-25 13:51:28 -0700470 virtual std::pair<wifi_error, std::string> getFirmwareVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700471 const std::string& iface_name);
472 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
473 const std::string& iface_name);
474 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
475 const std::string& iface_name);
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200476 std::pair<wifi_error, uint64_t> getSupportedFeatureSet(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700477 const std::string& iface_name);
478 // APF functions.
479 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
480 const std::string& iface_name);
481 wifi_error setPacketFilter(const std::string& iface_name,
482 const std::vector<uint8_t>& program);
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900483 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
484 const std::string& iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700485 // Gscan functions.
486 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
487 const std::string& iface_name);
488 // These API's provides a simplified interface over the legacy Gscan API's:
489 // a) All scan events from the legacy HAL API other than the
490 // |WIFI_SCAN_FAILED| are treated as notification of results.
491 // This method then retrieves the cached scan results from the legacy
492 // HAL API and triggers the externally provided
493 // |on_results_user_callback| on success.
494 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
495 // results
496 // triggers the externally provided |on_failure_user_callback|.
497 // c) Full scan result event triggers the externally provided
498 // |on_full_result_user_callback|.
499 wifi_error startGscan(
500 const std::string& iface_name, wifi_request_id id,
501 const wifi_scan_cmd_params& params,
502 const std::function<void(wifi_request_id)>& on_failure_callback,
503 const on_gscan_results_callback& on_results_callback,
504 const on_gscan_full_result_callback& on_full_result_callback);
505 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
506 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
507 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700508 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700509 // Link layer stats functions.
510 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
511 wifi_error disableLinkLayerStats(const std::string& iface_name);
512 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
513 const std::string& iface_name);
514 // RSSI monitor functions.
515 wifi_error startRssiMonitoring(const std::string& iface_name,
516 wifi_request_id id, int8_t max_rssi,
517 int8_t min_rssi,
518 const on_rssi_threshold_breached_callback&
519 on_threshold_breached_callback);
520 wifi_error stopRssiMonitoring(const std::string& iface_name,
521 wifi_request_id id);
522 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
523 const std::string& iface_name);
524 wifi_error configureRoaming(const std::string& iface_name,
525 const wifi_roaming_config& config);
526 wifi_error enableFirmwareRoaming(const std::string& iface_name,
527 fw_roaming_state_t state);
528 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
529 wifi_error startSendingOffloadedPacket(
Ahmed ElArabawyffbad182019-03-05 17:38:06 -0800530 const std::string& iface_name, uint32_t cmd_id, uint16_t ether_type,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700531 const std::vector<uint8_t>& ip_packet_data,
532 const std::array<uint8_t, 6>& src_address,
533 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
534 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
535 uint32_t cmd_id);
Roshan Pius6036c022019-03-27 10:41:58 -0700536 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
537 wifi_power_scenario scenario);
538 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700539 wifi_error setLatencyMode(const std::string& iface_name,
540 wifi_latency_mode mode);
Kumar Anandf2747e02020-01-10 16:49:13 -0800541 wifi_error setThermalMitigationMode(wifi_thermal_mode mode,
Kumar Anand913d5602019-12-18 16:02:37 -0800542 uint32_t completion_window);
Ahmed ElArabawya1d13652020-01-29 09:22:28 -0800543 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
544 uint32_t access_category);
545 wifi_error resetDscpToAccessCategoryMapping();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700546 // Logger/debug functions.
547 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
548 const std::string& iface_name);
549 wifi_error startPktFateMonitoring(const std::string& iface_name);
550 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
551 const std::string& iface_name);
552 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
553 const std::string& iface_name);
554 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
555 const std::string& iface_name);
556 wifi_error registerRingBufferCallbackHandler(
557 const std::string& iface_name,
558 const on_ring_buffer_data_callback& on_data_callback);
559 wifi_error deregisterRingBufferCallbackHandler(
560 const std::string& iface_name);
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700561 wifi_error registerSubsystemRestartCallbackHandler(
562 const on_subsystem_restart_callback& on_restart_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700563 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
564 getRingBuffersStatus(const std::string& iface_name);
565 wifi_error startRingBufferLogging(const std::string& iface_name,
566 const std::string& ring_name,
567 uint32_t verbose_level,
568 uint32_t max_interval_sec,
569 uint32_t min_data_size);
570 wifi_error getRingBufferData(const std::string& iface_name,
571 const std::string& ring_name);
572 wifi_error registerErrorAlertCallbackHandler(
573 const std::string& iface_name,
574 const on_error_alert_callback& on_alert_callback);
575 wifi_error deregisterErrorAlertCallbackHandler(
576 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800577 // Radio mode functions.
Roshan Piusaceecb02018-03-01 14:54:26 -0800578 virtual wifi_error registerRadioModeChangeCallbackHandler(
Roshan Pius01f08772018-01-22 17:56:06 -0800579 const std::string& iface_name,
580 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700581 // RTT functions.
582 wifi_error startRttRangeRequest(
583 const std::string& iface_name, wifi_request_id id,
584 const std::vector<wifi_rtt_config>& rtt_configs,
585 const on_rtt_results_callback& on_results_callback);
586 wifi_error cancelRttRangeRequest(
587 const std::string& iface_name, wifi_request_id id,
588 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
589 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
590 const std::string& iface_name);
591 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
592 const std::string& iface_name);
593 wifi_error enableRttResponder(const std::string& iface_name,
594 wifi_request_id id,
595 const wifi_channel_info& channel_hint,
596 uint32_t max_duration_secs,
597 const wifi_rtt_responder& info);
598 wifi_error disableRttResponder(const std::string& iface_name,
599 wifi_request_id id);
600 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
601 const wifi_lci_information& info);
602 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
603 const wifi_lcr_information& info);
604 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700605 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700606 const std::string& iface_name, const NanCallbackHandlers& callbacks);
607 wifi_error nanEnableRequest(const std::string& iface_name,
608 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700609 virtual wifi_error nanDisableRequest(const std::string& iface_name,
610 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700611 wifi_error nanPublishRequest(const std::string& iface_name,
612 transaction_id id,
613 const NanPublishRequest& msg);
614 wifi_error nanPublishCancelRequest(const std::string& iface_name,
615 transaction_id id,
616 const NanPublishCancelRequest& msg);
617 wifi_error nanSubscribeRequest(const std::string& iface_name,
618 transaction_id id,
619 const NanSubscribeRequest& msg);
620 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
621 transaction_id id,
622 const NanSubscribeCancelRequest& msg);
623 wifi_error nanTransmitFollowupRequest(
624 const std::string& iface_name, transaction_id id,
625 const NanTransmitFollowupRequest& msg);
626 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
627 const NanStatsRequest& msg);
628 wifi_error nanConfigRequest(const std::string& iface_name,
629 transaction_id id, const NanConfigRequest& msg);
630 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
631 const NanTCARequest& msg);
632 wifi_error nanBeaconSdfPayloadRequest(
633 const std::string& iface_name, transaction_id id,
634 const NanBeaconSdfPayloadRequest& msg);
635 std::pair<wifi_error, NanVersion> nanGetVersion();
636 wifi_error nanGetCapabilities(const std::string& iface_name,
637 transaction_id id);
638 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
639 transaction_id id,
640 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700641 virtual wifi_error nanDataInterfaceDelete(
642 const std::string& iface_name, transaction_id id,
643 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700644 wifi_error nanDataRequestInitiator(const std::string& iface_name,
645 transaction_id id,
646 const NanDataPathInitiatorRequest& msg);
647 wifi_error nanDataIndicationResponse(
648 const std::string& iface_name, transaction_id id,
649 const NanDataPathIndicationResponse& msg);
650 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
651 uint32_t ndpInstanceId);
652 // AP functions.
653 wifi_error setCountryCode(const std::string& iface_name,
654 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700655
Sunil Raviddab4bb2020-02-03 22:45:19 -0800656 // interface functions.
Roshan Pius5ba0a902020-04-14 11:55:42 -0700657 virtual wifi_error createVirtualInterface(const std::string& ifname,
658 wifi_interface_type iftype);
659 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
Jimmy Chen2dddd792019-12-23 17:50:39 +0200660 wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800661
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800662 // STA + STA functions
663 virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);
664 virtual wifi_error multiStaSetUseCase(wifi_multi_sta_use_case use_case);
665
Quang Luong94bcce52020-11-25 17:52:19 -0800666 // Coex functions.
667 virtual wifi_error setCoexUnsafeChannels(
668 std::vector<wifi_coex_unsafe_channel> unsafe_channels,
669 uint32_t restrictions);
670
Kai Shi2ca7a112020-12-15 19:51:28 -0800671 wifi_error setVoipMode(const std::string& iface_name, wifi_voip_mode mode);
672
673 wifi_error twtRegisterHandler(const std::string& iface_name,
674 const TwtCallbackHandlers& handler);
675
676 std::pair<wifi_error, TwtCapabilitySet> twtGetCapability(
677 const std::string& iface_name);
678
679 wifi_error twtSetupRequest(const std::string& iface_name,
680 const TwtSetupRequest& msg);
681
682 wifi_error twtTearDownRequest(const std::string& iface_name,
683 const TwtTeardownRequest& msg);
684
685 wifi_error twtInfoFrameRequest(const std::string& iface_name,
686 const TwtInfoFrameRequest& msg);
687
688 std::pair<wifi_error, TwtStats> twtGetStats(const std::string& iface_name,
689 uint8_t configId);
690
691 wifi_error twtClearStats(const std::string& iface_name, uint8_t configId);
692
Kai Shi0b6341c2021-01-11 20:22:59 -0800693 wifi_error setDtimConfig(const std::string& iface_name,
694 uint32_t multiplier);
695
Roshan Piusabcf78f2017-10-06 16:30:38 -0700696 private:
697 // Retrieve interface handles for all the available interfaces.
698 wifi_error retrieveIfaceHandles();
699 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
700 // Run the legacy HAL event loop thread.
701 void runEventLoop();
702 // Retrieve the cached gscan results to pass the results back to the
703 // external callbacks.
704 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
705 getGscanCachedResults(const std::string& iface_name);
706 void invalidate();
Sunil Raviddab4bb2020-02-03 22:45:19 -0800707 // Handles wifi (error) status of Virtual interface create/delete
708 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(
709 const std::string& ifname, wifi_error status);
Roshan Piusaabe5752016-09-29 09:03:59 -0700710
Roshan Piusabcf78f2017-10-06 16:30:38 -0700711 // Global function table of legacy HAL.
712 wifi_hal_fn global_func_table_;
713 // Opaque handle to be used for all global operations.
714 wifi_handle global_handle_;
715 // Map of interface name to handle that is to be used for all interface
716 // specific operations.
717 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
718 // Flag to indicate if we have initiated the cleanup of legacy HAL.
719 std::atomic<bool> awaiting_event_loop_termination_;
720 std::condition_variable_any stop_wait_cv_;
721 // Flag to indicate if the legacy HAL has been started.
722 bool is_started_;
Roshan Piusc885df02019-05-21 14:49:05 -0700723 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Jimmy Chen2dddd792019-12-23 17:50:39 +0200724 // flag to indicate if this HAL is for the primary chip. This is used
725 // in order to avoid some hard-coded behavior used with older HALs,
726 // such as bring wlan0 interface up/down on start/stop HAL.
727 // it may be removed once vendor HALs are updated.
728 bool is_primary_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700729};
730
Roshan Pius955542e2016-10-28 09:42:44 -0700731} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700732} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +0200733} // namespace V1_5
Roshan Piusaabe5752016-09-29 09:03:59 -0700734} // namespace wifi
735} // namespace hardware
736} // namespace android
737
Roshan Piuse73a5062016-12-12 08:53:34 -0800738#endif // WIFI_LEGACY_HAL_H_