blob: 1652ae98f46e02eea69f172ed0d12f03c52cdafb [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;
274using ::wifi_channel_width;
275using ::wifi_error;
276using ::wifi_gscan_capabilities;
277using ::wifi_information_element;
278using ::wifi_interface_type;
279using ::wifi_latency_mode;
280using ::wifi_lci_information;
281using ::wifi_lcr_information;
282using ::wifi_motion_pattern;
283using ::wifi_power_scenario;
284using ::wifi_rate;
285using ::wifi_request_id;
286using ::wifi_ring_buffer_status;
287using ::wifi_roaming_capabilities;
288using ::wifi_roaming_config;
289using ::wifi_rtt_bw;
290using ::wifi_rtt_capabilities;
291using ::wifi_rtt_config;
292using ::wifi_rtt_preamble;
293using ::wifi_rtt_responder;
294using ::wifi_rtt_result;
295using ::wifi_rtt_status;
296using ::wifi_rtt_type;
297using ::wifi_rx_packet_fate;
298using ::wifi_rx_report;
299using ::wifi_scan_bucket_spec;
300using ::wifi_scan_cmd_params;
301using ::wifi_scan_result;
302using ::wifi_tx_packet_fate;
303using ::wifi_tx_report;
Roshan Piusaabe5752016-09-29 09:03:59 -0700304
Roshan Pius0a47c182016-10-28 10:23:00 -0700305// APF capabilities supported by the iface.
306struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700307 uint32_t version;
308 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -0700309};
310
Roshan Pius7cece412016-10-28 10:38:21 -0700311// WARNING: We don't care about the variable sized members of either
312// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
313// to escape the compiler warnings regarding this.
314#pragma GCC diagnostic push
315#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
316// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
317// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
318// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -0700319struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700320 wifi_radio_stat stats;
321 std::vector<uint32_t> tx_time_per_levels;
Sunil Ravib0343e72018-11-13 15:52:00 -0800322 std::vector<wifi_channel_stat> channel_stats;
Roshan Piuse42ace22017-03-13 10:44:20 -0700323};
324
Roshan Pius7cece412016-10-28 10:38:21 -0700325struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700326 wifi_iface_stat iface;
327 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -0700328};
329#pragma GCC diagnostic pop
330
Roshan Pius8714a3e2016-10-28 10:43:51 -0700331// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
332// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
333// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
334// API. Separate that out into a separate return elements to avoid passing
335// pointers around.
336struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700337 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
338 std::vector<uint32_t> cmd_event_wake_cnt;
339 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -0700340};
341
Roshan Pius23012092016-10-28 11:27:40 -0700342// NAN response and event callbacks struct.
343struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700344 // NotifyResponse invoked to notify the status of the Request.
345 std::function<void(transaction_id, const NanResponseMsg&)>
346 on_notify_response;
347 // Various event callbacks.
348 std::function<void(const NanPublishTerminatedInd&)>
349 on_event_publish_terminated;
350 std::function<void(const NanMatchInd&)> on_event_match;
351 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
352 std::function<void(const NanSubscribeTerminatedInd&)>
353 on_event_subscribe_terminated;
354 std::function<void(const NanFollowupInd&)> on_event_followup;
355 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
356 std::function<void(const NanDisabledInd&)> on_event_disabled;
357 std::function<void(const NanTCAInd&)> on_event_tca;
358 std::function<void(const NanBeaconSdfPayloadInd&)>
359 on_event_beacon_sdf_payload;
360 std::function<void(const NanDataPathRequestInd&)>
361 on_event_data_path_request;
362 std::function<void(const NanDataPathConfirmInd&)>
363 on_event_data_path_confirm;
364 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
365 std::function<void(const NanTransmitFollowupInd&)>
366 on_event_transmit_follow_up;
367 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
368 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Jong Wook Kimda830c92018-07-23 15:29:38 -0700369 std::function<void(const NanDataPathScheduleUpdateInd&)>
370 on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700371};
372
Roshan Pius76ff3022016-10-28 10:33:34 -0700373// Full scan results contain IE info and are hence passed by reference, to
374// preserve the variable length array member |ie_data|. Callee must not retain
375// the pointer.
376using on_gscan_full_result_callback =
377 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
378// These scan results don't contain any IE info, so no need to pass by
379// reference.
380using on_gscan_results_callback = std::function<void(
381 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
382
Roshan Piusd4767542016-12-06 10:04:05 -0800383// Invoked when the rssi value breaches the thresholds set.
384using on_rssi_threshold_breached_callback =
385 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
386
Roshan Piusd8e915a2016-10-28 11:23:11 -0700387// Callback for RTT range request results.
388// Rtt results contain IE info and are hence passed by reference, to
389// preserve the |LCI| and |LCR| pointers. Callee must not retain
390// the pointer.
391using on_rtt_results_callback = std::function<void(
392 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
393
Roshan Pius8714a3e2016-10-28 10:43:51 -0700394// Callback for ring buffer data.
395using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700396 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700397 const wifi_ring_buffer_status&)>;
398
Roshan Pius203cb032016-12-14 17:41:20 -0800399// Callback for alerts.
400using on_error_alert_callback =
401 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800402
403// Struct for the mac info from the legacy HAL. This is a cleaner version
404// of the |wifi_mac_info| & |wifi_iface_info|.
405typedef struct {
406 std::string name;
407 wifi_channel channel;
408} WifiIfaceInfo;
409
410typedef struct {
411 uint32_t wlan_mac_id;
412 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
413 uint32_t mac_band;
414 /* Represents the connected Wi-Fi interfaces associated with each MAC */
415 std::vector<WifiIfaceInfo> iface_infos;
416} WifiMacInfo;
417
418// Callback for radio mode change
419using on_radio_mode_change_callback =
420 std::function<void(const std::vector<WifiMacInfo>&)>;
421
Roshan Piusaabe5752016-09-29 09:03:59 -0700422/**
423 * Class that encapsulates all legacy HAL interactions.
424 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800425 *
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900426 * Note: There will only be a single instance of this class created in the Wifi
Roshan Pius742bb972017-02-02 09:54:27 -0800427 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700428 */
429class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700430 public:
Roshan Piusc885df02019-05-21 14:49:05 -0700431 WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool);
Roshan Pius200a17d2017-11-01 13:03:35 -0700432 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700433
Roshan Piusabcf78f2017-10-06 16:30:38 -0700434 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700435 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700436 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700437 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700438 // Deinitialize the legacy HAL and wait for the event loop thread to exit
439 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700440 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
441 const std::function<void()>& on_complete_callback);
Ahmed ElArabawy48229382019-02-07 22:04:53 -0800442 // Checks if legacy HAL has successfully started
443 bool isStarted();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700444 // Wrappers for all the functions in the legacy HAL function table.
Roshan Pius1cd82a82019-03-25 13:51:28 -0700445 virtual std::pair<wifi_error, std::string> getDriverVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700446 const std::string& iface_name);
Roshan Pius1cd82a82019-03-25 13:51:28 -0700447 virtual std::pair<wifi_error, std::string> getFirmwareVersion(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700448 const std::string& iface_name);
449 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
450 const std::string& iface_name);
451 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
452 const std::string& iface_name);
453 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
454 const std::string& iface_name);
455 // APF functions.
456 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
457 const std::string& iface_name);
458 wifi_error setPacketFilter(const std::string& iface_name,
459 const std::vector<uint8_t>& program);
Bernie Innocentiefbb9c32018-03-07 00:17:50 +0900460 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
461 const std::string& iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700462 // Gscan functions.
463 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
464 const std::string& iface_name);
465 // These API's provides a simplified interface over the legacy Gscan API's:
466 // a) All scan events from the legacy HAL API other than the
467 // |WIFI_SCAN_FAILED| are treated as notification of results.
468 // This method then retrieves the cached scan results from the legacy
469 // HAL API and triggers the externally provided
470 // |on_results_user_callback| on success.
471 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
472 // results
473 // triggers the externally provided |on_failure_user_callback|.
474 // c) Full scan result event triggers the externally provided
475 // |on_full_result_user_callback|.
476 wifi_error startGscan(
477 const std::string& iface_name, wifi_request_id id,
478 const wifi_scan_cmd_params& params,
479 const std::function<void(wifi_request_id)>& on_failure_callback,
480 const on_gscan_results_callback& on_results_callback,
481 const on_gscan_full_result_callback& on_full_result_callback);
482 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
483 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
484 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700485 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700486 // Link layer stats functions.
487 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
488 wifi_error disableLinkLayerStats(const std::string& iface_name);
489 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
490 const std::string& iface_name);
491 // RSSI monitor functions.
492 wifi_error startRssiMonitoring(const std::string& iface_name,
493 wifi_request_id id, int8_t max_rssi,
494 int8_t min_rssi,
495 const on_rssi_threshold_breached_callback&
496 on_threshold_breached_callback);
497 wifi_error stopRssiMonitoring(const std::string& iface_name,
498 wifi_request_id id);
499 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
500 const std::string& iface_name);
501 wifi_error configureRoaming(const std::string& iface_name,
502 const wifi_roaming_config& config);
503 wifi_error enableFirmwareRoaming(const std::string& iface_name,
504 fw_roaming_state_t state);
505 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
506 wifi_error startSendingOffloadedPacket(
Ahmed ElArabawyffbad182019-03-05 17:38:06 -0800507 const std::string& iface_name, uint32_t cmd_id, uint16_t ether_type,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700508 const std::vector<uint8_t>& ip_packet_data,
509 const std::array<uint8_t, 6>& src_address,
510 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
511 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
512 uint32_t cmd_id);
Roshan Pius6036c022019-03-27 10:41:58 -0700513 virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
514 wifi_power_scenario scenario);
515 virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700516 wifi_error setLatencyMode(const std::string& iface_name,
517 wifi_latency_mode mode);
Kumar Anandf2747e02020-01-10 16:49:13 -0800518 wifi_error setThermalMitigationMode(wifi_thermal_mode mode,
Kumar Anand913d5602019-12-18 16:02:37 -0800519 uint32_t completion_window);
Ahmed ElArabawya1d13652020-01-29 09:22:28 -0800520 wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
521 uint32_t access_category);
522 wifi_error resetDscpToAccessCategoryMapping();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700523 // Logger/debug functions.
524 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
525 const std::string& iface_name);
526 wifi_error startPktFateMonitoring(const std::string& iface_name);
527 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
528 const std::string& iface_name);
529 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
530 const std::string& iface_name);
531 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
532 const std::string& iface_name);
533 wifi_error registerRingBufferCallbackHandler(
534 const std::string& iface_name,
535 const on_ring_buffer_data_callback& on_data_callback);
536 wifi_error deregisterRingBufferCallbackHandler(
537 const std::string& iface_name);
538 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
539 getRingBuffersStatus(const std::string& iface_name);
540 wifi_error startRingBufferLogging(const std::string& iface_name,
541 const std::string& ring_name,
542 uint32_t verbose_level,
543 uint32_t max_interval_sec,
544 uint32_t min_data_size);
545 wifi_error getRingBufferData(const std::string& iface_name,
546 const std::string& ring_name);
547 wifi_error registerErrorAlertCallbackHandler(
548 const std::string& iface_name,
549 const on_error_alert_callback& on_alert_callback);
550 wifi_error deregisterErrorAlertCallbackHandler(
551 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800552 // Radio mode functions.
Roshan Piusaceecb02018-03-01 14:54:26 -0800553 virtual wifi_error registerRadioModeChangeCallbackHandler(
Roshan Pius01f08772018-01-22 17:56:06 -0800554 const std::string& iface_name,
555 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700556 // RTT functions.
557 wifi_error startRttRangeRequest(
558 const std::string& iface_name, wifi_request_id id,
559 const std::vector<wifi_rtt_config>& rtt_configs,
560 const on_rtt_results_callback& on_results_callback);
561 wifi_error cancelRttRangeRequest(
562 const std::string& iface_name, wifi_request_id id,
563 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
564 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
565 const std::string& iface_name);
566 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
567 const std::string& iface_name);
568 wifi_error enableRttResponder(const std::string& iface_name,
569 wifi_request_id id,
570 const wifi_channel_info& channel_hint,
571 uint32_t max_duration_secs,
572 const wifi_rtt_responder& info);
573 wifi_error disableRttResponder(const std::string& iface_name,
574 wifi_request_id id);
575 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
576 const wifi_lci_information& info);
577 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
578 const wifi_lcr_information& info);
579 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700580 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700581 const std::string& iface_name, const NanCallbackHandlers& callbacks);
582 wifi_error nanEnableRequest(const std::string& iface_name,
583 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700584 virtual wifi_error nanDisableRequest(const std::string& iface_name,
585 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700586 wifi_error nanPublishRequest(const std::string& iface_name,
587 transaction_id id,
588 const NanPublishRequest& msg);
589 wifi_error nanPublishCancelRequest(const std::string& iface_name,
590 transaction_id id,
591 const NanPublishCancelRequest& msg);
592 wifi_error nanSubscribeRequest(const std::string& iface_name,
593 transaction_id id,
594 const NanSubscribeRequest& msg);
595 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
596 transaction_id id,
597 const NanSubscribeCancelRequest& msg);
598 wifi_error nanTransmitFollowupRequest(
599 const std::string& iface_name, transaction_id id,
600 const NanTransmitFollowupRequest& msg);
601 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
602 const NanStatsRequest& msg);
603 wifi_error nanConfigRequest(const std::string& iface_name,
604 transaction_id id, const NanConfigRequest& msg);
605 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
606 const NanTCARequest& msg);
607 wifi_error nanBeaconSdfPayloadRequest(
608 const std::string& iface_name, transaction_id id,
609 const NanBeaconSdfPayloadRequest& msg);
610 std::pair<wifi_error, NanVersion> nanGetVersion();
611 wifi_error nanGetCapabilities(const std::string& iface_name,
612 transaction_id id);
613 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
614 transaction_id id,
615 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700616 virtual wifi_error nanDataInterfaceDelete(
617 const std::string& iface_name, transaction_id id,
618 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700619 wifi_error nanDataRequestInitiator(const std::string& iface_name,
620 transaction_id id,
621 const NanDataPathInitiatorRequest& msg);
622 wifi_error nanDataIndicationResponse(
623 const std::string& iface_name, transaction_id id,
624 const NanDataPathIndicationResponse& msg);
625 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
626 uint32_t ndpInstanceId);
627 // AP functions.
628 wifi_error setCountryCode(const std::string& iface_name,
629 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700630
Sunil Raviddab4bb2020-02-03 22:45:19 -0800631 // interface functions.
Roshan Pius5ba0a902020-04-14 11:55:42 -0700632 virtual wifi_error createVirtualInterface(const std::string& ifname,
633 wifi_interface_type iftype);
634 virtual wifi_error deleteVirtualInterface(const std::string& ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800635
Roshan Piusabcf78f2017-10-06 16:30:38 -0700636 private:
637 // Retrieve interface handles for all the available interfaces.
638 wifi_error retrieveIfaceHandles();
639 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
640 // Run the legacy HAL event loop thread.
641 void runEventLoop();
642 // Retrieve the cached gscan results to pass the results back to the
643 // external callbacks.
644 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
645 getGscanCachedResults(const std::string& iface_name);
646 void invalidate();
Sunil Raviddab4bb2020-02-03 22:45:19 -0800647 // Handles wifi (error) status of Virtual interface create/delete
648 wifi_error handleVirtualInterfaceCreateOrDeleteStatus(
649 const std::string& ifname, wifi_error status);
Roshan Piusaabe5752016-09-29 09:03:59 -0700650
Roshan Piusabcf78f2017-10-06 16:30:38 -0700651 // Global function table of legacy HAL.
652 wifi_hal_fn global_func_table_;
653 // Opaque handle to be used for all global operations.
654 wifi_handle global_handle_;
655 // Map of interface name to handle that is to be used for all interface
656 // specific operations.
657 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
658 // Flag to indicate if we have initiated the cleanup of legacy HAL.
659 std::atomic<bool> awaiting_event_loop_termination_;
660 std::condition_variable_any stop_wait_cv_;
661 // Flag to indicate if the legacy HAL has been started.
662 bool is_started_;
Roshan Piusc885df02019-05-21 14:49:05 -0700663 std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700664};
665
Roshan Pius955542e2016-10-28 09:42:44 -0700666} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700667} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -0700668} // namespace V1_4
Roshan Piusaabe5752016-09-29 09:03:59 -0700669} // namespace wifi
670} // namespace hardware
671} // namespace android
672
Roshan Piuse73a5062016-12-12 08:53:34 -0800673#endif // WIFI_LEGACY_HAL_H_