blob: 822f83aca3a5819240f9ad4ffaf625703a99ba4b [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 Collingbourned84225b2020-12-23 13:41:26 -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 {
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070032namespace V1_4 {
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 Collingbourned84225b2020-12-23 13:41:26 -080037// Import all the types defined inside the legacy HAL header files into this
Roshan Pius955542e2016-10-28 09:42:44 -070038// namespace.
Peter Collingbourned84225b2020-12-23 13:41:26 -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_ERROR_BUSY;
219using ::WIFI_ERROR_INVALID_ARGS;
220using ::WIFI_ERROR_INVALID_REQUEST_ID;
221using ::WIFI_ERROR_NONE;
222using ::WIFI_ERROR_NOT_AVAILABLE;
223using ::WIFI_ERROR_NOT_SUPPORTED;
224using ::WIFI_ERROR_OUT_OF_MEMORY;
225using ::WIFI_ERROR_TIMED_OUT;
226using ::WIFI_ERROR_TOO_MANY_REQUESTS;
227using ::WIFI_ERROR_UNINITIALIZED;
228using ::WIFI_ERROR_UNKNOWN;
229using ::WIFI_INTERFACE_TYPE_AP;
230using ::WIFI_INTERFACE_TYPE_NAN;
231using ::WIFI_INTERFACE_TYPE_P2P;
232using ::WIFI_INTERFACE_TYPE_STA;
233using ::WIFI_LATENCY_MODE_LOW;
234using ::WIFI_LATENCY_MODE_NORMAL;
235using ::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
236using ::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
237using ::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
238using ::WIFI_LOGGER_PACKET_FATE_SUPPORTED;
239using ::WIFI_LOGGER_POWER_EVENT_SUPPORTED;
240using ::WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
241using ::WIFI_MOTION_EXPECTED;
242using ::WIFI_MOTION_NOT_EXPECTED;
243using ::WIFI_MOTION_UNKNOWN;
244using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
245using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
246using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
247using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
248using ::WIFI_POWER_SCENARIO_VOICE_CALL;
249using ::WIFI_RTT_BW_10;
250using ::WIFI_RTT_BW_160;
251using ::WIFI_RTT_BW_20;
252using ::WIFI_RTT_BW_40;
253using ::WIFI_RTT_BW_5;
254using ::WIFI_RTT_BW_80;
255using ::WIFI_RTT_PREAMBLE_HE;
256using ::WIFI_RTT_PREAMBLE_HT;
257using ::WIFI_RTT_PREAMBLE_LEGACY;
258using ::WIFI_RTT_PREAMBLE_VHT;
259using ::WIFI_SCAN_FLAG_INTERRUPTED;
260using ::WIFI_SUCCESS;
261using ::WLAN_MAC_2_4_BAND;
262using ::WLAN_MAC_5_0_BAND;
263using ::WLAN_MAC_6_0_BAND;
264using ::frame_info;
265using ::frame_type;
266using ::fw_roaming_state_t;
267using ::mac_addr;
268using ::rtt_peer_type;
269using ::ssid_t;
270using ::transaction_id;
271using ::wifi_band;
272using ::wifi_cached_scan_results;
273using ::wifi_channel_info;
Peter Collingbourne0c4836f2021-01-25 10:19:51 -0800274using ::wifi_channel_stat;
Peter Collingbourned84225b2020-12-23 13:41:26 -0800275using ::wifi_channel_width;
276using ::wifi_error;
277using ::wifi_gscan_capabilities;
278using ::wifi_information_element;
279using ::wifi_interface_type;
280using ::wifi_latency_mode;
281using ::wifi_lci_information;
282using ::wifi_lcr_information;
283using ::wifi_motion_pattern;
284using ::wifi_power_scenario;
285using ::wifi_rate;
286using ::wifi_request_id;
287using ::wifi_ring_buffer_status;
288using ::wifi_roaming_capabilities;
289using ::wifi_roaming_config;
290using ::wifi_rtt_bw;
291using ::wifi_rtt_capabilities;
292using ::wifi_rtt_config;
293using ::wifi_rtt_preamble;
294using ::wifi_rtt_responder;
295using ::wifi_rtt_result;
296using ::wifi_rtt_status;
297using ::wifi_rtt_type;
298using ::wifi_rx_packet_fate;
299using ::wifi_rx_report;
300using ::wifi_scan_bucket_spec;
301using ::wifi_scan_cmd_params;
302using ::wifi_scan_result;
303using ::wifi_tx_packet_fate;
304using ::wifi_tx_report;
Roshan Piusaabe5752016-09-29 09:03:59 -0700305
Roshan Pius0a47c182016-10-28 10:23:00 -0700306// APF capabilities supported by the iface.
307struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700308 uint32_t version;
309 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -0700310};
311
Roshan Pius7cece412016-10-28 10:38:21 -0700312// WARNING: We don't care about the variable sized members of either
313// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
314// to escape the compiler warnings regarding this.
315#pragma GCC diagnostic push
316#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
317// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
318// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
319// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -0700320struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700321 wifi_radio_stat stats;
322 std::vector<uint32_t> tx_time_per_levels;
Sunil Ravib0343e72018-11-13 15:52:00 -0800323 std::vector<wifi_channel_stat> channel_stats;
Roshan Piuse42ace22017-03-13 10:44:20 -0700324};
325
Roshan Pius7cece412016-10-28 10:38:21 -0700326struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700327 wifi_iface_stat iface;
328 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -0700329};
330#pragma GCC diagnostic pop
331
Roshan Pius8714a3e2016-10-28 10:43:51 -0700332// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
333// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
334// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
335// API. Separate that out into a separate return elements to avoid passing
336// pointers around.
337struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700338 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
339 std::vector<uint32_t> cmd_event_wake_cnt;
340 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -0700341};
342
Roshan Pius23012092016-10-28 11:27:40 -0700343// NAN response and event callbacks struct.
344struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700345 // NotifyResponse invoked to notify the status of the Request.
346 std::function<void(transaction_id, const NanResponseMsg&)>
347 on_notify_response;
348 // Various event callbacks.
349 std::function<void(const NanPublishTerminatedInd&)>
350 on_event_publish_terminated;
351 std::function<void(const NanMatchInd&)> on_event_match;
352 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
353 std::function<void(const NanSubscribeTerminatedInd&)>
354 on_event_subscribe_terminated;
355 std::function<void(const NanFollowupInd&)> on_event_followup;
356 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
357 std::function<void(const NanDisabledInd&)> on_event_disabled;
358 std::function<void(const NanTCAInd&)> on_event_tca;
359 std::function<void(const NanBeaconSdfPayloadInd&)>
360 on_event_beacon_sdf_payload;
361 std::function<void(const NanDataPathRequestInd&)>
362 on_event_data_path_request;
363 std::function<void(const NanDataPathConfirmInd&)>
364 on_event_data_path_confirm;
365 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
366 std::function<void(const NanTransmitFollowupInd&)>
367 on_event_transmit_follow_up;
368 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
369 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Jong Wook Kimda830c92018-07-23 15:29:38 -0700370 std::function<void(const NanDataPathScheduleUpdateInd&)>
371 on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700372};
373
Roshan Pius76ff3022016-10-28 10:33:34 -0700374// Full scan results contain IE info and are hence passed by reference, to
375// preserve the variable length array member |ie_data|. Callee must not retain
376// the pointer.
377using on_gscan_full_result_callback =
378 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
379// These scan results don't contain any IE info, so no need to pass by
380// reference.
381using on_gscan_results_callback = std::function<void(
382 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
383
Roshan Piusd4767542016-12-06 10:04:05 -0800384// Invoked when the rssi value breaches the thresholds set.
385using on_rssi_threshold_breached_callback =
386 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
387
Roshan Piusd8e915a2016-10-28 11:23:11 -0700388// Callback for RTT range request results.
389// Rtt results contain IE info and are hence passed by reference, to
390// preserve the |LCI| and |LCR| pointers. Callee must not retain
391// the pointer.
392using on_rtt_results_callback = std::function<void(
393 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
394
Roshan Pius8714a3e2016-10-28 10:43:51 -0700395// Callback for ring buffer data.
396using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700397 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700398 const wifi_ring_buffer_status&)>;
399
Roshan Pius203cb032016-12-14 17:41:20 -0800400// Callback for alerts.
401using on_error_alert_callback =
402 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800403
404// Struct for the mac info from the legacy HAL. This is a cleaner version
405// of the |wifi_mac_info| & |wifi_iface_info|.
406typedef struct {
407 std::string name;
408 wifi_channel channel;
409} WifiIfaceInfo;
410
411typedef struct {
412 uint32_t wlan_mac_id;
413 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
414 uint32_t mac_band;
415 /* Represents the connected Wi-Fi interfaces associated with each MAC */
416 std::vector<WifiIfaceInfo> iface_infos;
417} WifiMacInfo;
418
419// Callback for radio mode change
420using on_radio_mode_change_callback =
421 std::function<void(const std::vector<WifiMacInfo>&)>;
422
Roshan Piusaabe5752016-09-29 09:03:59 -0700423/**
424 * Class that encapsulates all legacy HAL interactions.
425 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800426 *
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900427 * Note: There will only be a single instance of this class created in the Wifi
Roshan Pius742bb972017-02-02 09:54:27 -0800428 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700429 */
430class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700431 public:
Roshan Piusc885df02019-05-21 14:49:05 -0700432 WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
Roshan Pius200a17d2017-11-01 13:03:35 -0700433 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700434
Roshan Piusabcf78f2017-10-06 16:30:38 -0700435 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700436 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700437 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700438 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700439 // Deinitialize the legacy HAL and wait for the event loop thread to exit
440 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700441 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
442 const std::function<void()>& on_complete_callback);
Ahmed ElArabawy48229382019-02-07 22:04:53 -0800443 // Checks if legacy HAL has successfully started
444 bool isStarted();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700445 // Wrappers for all the functions in the legacy HAL function table.
Roshan Pius1cd82a82019-03-25 13:51:28 -0700446 virtual std::pair<wifi_error, std::string> getDriverVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700447 const std::string& iface_name);
Roshan Pius1cd82a82019-03-25 13:51:28 -0700448 virtual std::pair<wifi_error, std::string> getFirmwareVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700449 const std::string& iface_name);
450 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
451 const std::string& iface_name);
452 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
453 const std::string& iface_name);
454 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
455 const std::string& iface_name);
456 // APF functions.
457 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
458 const std::string& iface_name);
459 wifi_error setPacketFilter(const std::string& iface_name,
460 const std::vector<uint8_t>& program);
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900461 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
462 const std::string& iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700463 // Gscan functions.
464 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
465 const std::string& iface_name);
466 // These API's provides a simplified interface over the legacy Gscan API's:
467 // a) All scan events from the legacy HAL API other than the
468 // |WIFI_SCAN_FAILED| are treated as notification of results.
469 // This method then retrieves the cached scan results from the legacy
470 // HAL API and triggers the externally provided
471 // |on_results_user_callback| on success.
472 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
473 // results
474 // triggers the externally provided |on_failure_user_callback|.
475 // c) Full scan result event triggers the externally provided
476 // |on_full_result_user_callback|.
477 wifi_error startGscan(
478 const std::string& iface_name, wifi_request_id id,
479 const wifi_scan_cmd_params& params,
480 const std::function<void(wifi_request_id)>& on_failure_callback,
481 const on_gscan_results_callback& on_results_callback,
482 const on_gscan_full_result_callback& on_full_result_callback);
483 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
484 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
485 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700486 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700487 // Link layer stats functions.
488 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
489 wifi_error disableLinkLayerStats(const std::string& iface_name);
490 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
491 const std::string& iface_name);
492 // RSSI monitor functions.
493 wifi_error startRssiMonitoring(const std::string& iface_name,
494 wifi_request_id id, int8_t max_rssi,
495 int8_t min_rssi,
496 const on_rssi_threshold_breached_callback&
497 on_threshold_breached_callback);
498 wifi_error stopRssiMonitoring(const std::string& iface_name,
499 wifi_request_id id);
500 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
501 const std::string& iface_name);
502 wifi_error configureRoaming(const std::string& iface_name,
503 const wifi_roaming_config& config);
504 wifi_error enableFirmwareRoaming(const std::string& iface_name,
505 fw_roaming_state_t state);
506 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
507 wifi_error startSendingOffloadedPacket(
Ahmed ElArabawyffbad182019-03-05 17:38:06 -0800508 const std::string& iface_name, uint32_t cmd_id, uint16_t ether_type,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700509 const std::vector<uint8_t>& ip_packet_data,
510 const std::array<uint8_t, 6>& src_address,
511 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
512 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
513 uint32_t cmd_id);
Roshan Pius6036c022019-03-27 10:41:58 -0700514 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
515 wifi_power_scenario scenario);
516 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700517 wifi_error setLatencyMode(const std::string& iface_name,
518 wifi_latency_mode mode);
Kumar Anandf2747e02020-01-10 16:49:13 -0800519 wifi_error setThermalMitigationMode(wifi_thermal_mode mode,
Kumar Anand913d5602019-12-18 16:02:37 -0800520 uint32_t completion_window);
Ahmed ElArabawya1d13652020-01-29 09:22:28 -0800521 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
522 uint32_t access_category);
523 wifi_error resetDscpToAccessCategoryMapping();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700524 // Logger/debug functions.
525 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
526 const std::string& iface_name);
527 wifi_error startPktFateMonitoring(const std::string& iface_name);
528 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
529 const std::string& iface_name);
530 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
531 const std::string& iface_name);
532 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
533 const std::string& iface_name);
534 wifi_error registerRingBufferCallbackHandler(
535 const std::string& iface_name,
536 const on_ring_buffer_data_callback& on_data_callback);
537 wifi_error deregisterRingBufferCallbackHandler(
538 const std::string& iface_name);
539 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
540 getRingBuffersStatus(const std::string& iface_name);
541 wifi_error startRingBufferLogging(const std::string& iface_name,
542 const std::string& ring_name,
543 uint32_t verbose_level,
544 uint32_t max_interval_sec,
545 uint32_t min_data_size);
546 wifi_error getRingBufferData(const std::string& iface_name,
547 const std::string& ring_name);
548 wifi_error registerErrorAlertCallbackHandler(
549 const std::string& iface_name,
550 const on_error_alert_callback& on_alert_callback);
551 wifi_error deregisterErrorAlertCallbackHandler(
552 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800553 // Radio mode functions.
Roshan Piusaceecb02018-03-01 14:54:26 -0800554 virtual wifi_error registerRadioModeChangeCallbackHandler(
Roshan Pius01f08772018-01-22 17:56:06 -0800555 const std::string& iface_name,
556 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700557 // RTT functions.
558 wifi_error startRttRangeRequest(
559 const std::string& iface_name, wifi_request_id id,
560 const std::vector<wifi_rtt_config>& rtt_configs,
561 const on_rtt_results_callback& on_results_callback);
562 wifi_error cancelRttRangeRequest(
563 const std::string& iface_name, wifi_request_id id,
564 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
565 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
566 const std::string& iface_name);
567 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
568 const std::string& iface_name);
569 wifi_error enableRttResponder(const std::string& iface_name,
570 wifi_request_id id,
571 const wifi_channel_info& channel_hint,
572 uint32_t max_duration_secs,
573 const wifi_rtt_responder& info);
574 wifi_error disableRttResponder(const std::string& iface_name,
575 wifi_request_id id);
576 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
577 const wifi_lci_information& info);
578 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
579 const wifi_lcr_information& info);
580 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700581 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700582 const std::string& iface_name, const NanCallbackHandlers& callbacks);
583 wifi_error nanEnableRequest(const std::string& iface_name,
584 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700585 virtual wifi_error nanDisableRequest(const std::string& iface_name,
586 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700587 wifi_error nanPublishRequest(const std::string& iface_name,
588 transaction_id id,
589 const NanPublishRequest& msg);
590 wifi_error nanPublishCancelRequest(const std::string& iface_name,
591 transaction_id id,
592 const NanPublishCancelRequest& msg);
593 wifi_error nanSubscribeRequest(const std::string& iface_name,
594 transaction_id id,
595 const NanSubscribeRequest& msg);
596 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
597 transaction_id id,
598 const NanSubscribeCancelRequest& msg);
599 wifi_error nanTransmitFollowupRequest(
600 const std::string& iface_name, transaction_id id,
601 const NanTransmitFollowupRequest& msg);
602 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
603 const NanStatsRequest& msg);
604 wifi_error nanConfigRequest(const std::string& iface_name,
605 transaction_id id, const NanConfigRequest& msg);
606 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
607 const NanTCARequest& msg);
608 wifi_error nanBeaconSdfPayloadRequest(
609 const std::string& iface_name, transaction_id id,
610 const NanBeaconSdfPayloadRequest& msg);
611 std::pair<wifi_error, NanVersion> nanGetVersion();
612 wifi_error nanGetCapabilities(const std::string& iface_name,
613 transaction_id id);
614 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
615 transaction_id id,
616 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700617 virtual wifi_error nanDataInterfaceDelete(
618 const std::string& iface_name, transaction_id id,
619 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700620 wifi_error nanDataRequestInitiator(const std::string& iface_name,
621 transaction_id id,
622 const NanDataPathInitiatorRequest& msg);
623 wifi_error nanDataIndicationResponse(
624 const std::string& iface_name, transaction_id id,
625 const NanDataPathIndicationResponse& msg);
626 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
627 uint32_t ndpInstanceId);
628 // AP functions.
629 wifi_error setCountryCode(const std::string& iface_name,
630 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700631
Sunil Raviddab4bb2020-02-03 22:45:19 -0800632 // interface functions.
Roshan Pius5ba0a902020-04-14 11:55:42 -0700633 virtual wifi_error createVirtualInterface(const std::string& ifname,
634 wifi_interface_type iftype);
635 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800636
Roshan Piusabcf78f2017-10-06 16:30:38 -0700637 private:
638 // Retrieve interface handles for all the available interfaces.
639 wifi_error retrieveIfaceHandles();
640 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
641 // Run the legacy HAL event loop thread.
642 void runEventLoop();
643 // Retrieve the cached gscan results to pass the results back to the
644 // external callbacks.
645 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
646 getGscanCachedResults(const std::string& iface_name);
647 void invalidate();
Sunil Raviddab4bb2020-02-03 22:45:19 -0800648 // Handles wifi (error) status of Virtual interface create/delete
649 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(
650 const std::string& ifname, wifi_error status);
Roshan Piusaabe5752016-09-29 09:03:59 -0700651
Roshan Piusabcf78f2017-10-06 16:30:38 -0700652 // Global function table of legacy HAL.
653 wifi_hal_fn global_func_table_;
654 // Opaque handle to be used for all global operations.
655 wifi_handle global_handle_;
656 // Map of interface name to handle that is to be used for all interface
657 // specific operations.
658 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
659 // Flag to indicate if we have initiated the cleanup of legacy HAL.
660 std::atomic<bool> awaiting_event_loop_termination_;
661 std::condition_variable_any stop_wait_cv_;
662 // Flag to indicate if the legacy HAL has been started.
663 bool is_started_;
Roshan Piusc885df02019-05-21 14:49:05 -0700664 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700665};
666
Roshan Pius955542e2016-10-28 09:42:44 -0700667} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700668} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -0700669} // namespace V1_4
Roshan Piusaabe5752016-09-29 09:03:59 -0700670} // namespace wifi
671} // namespace hardware
672} // namespace android
673
Roshan Piuse73a5062016-12-12 08:53:34 -0800674#endif // WIFI_LEGACY_HAL_H_