1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIFI_LEGACY_HAL_H_
#define WIFI_LEGACY_HAL_H_
#include <condition_variable>
#include <functional>
#include <map>
#include <thread>
#include <vector>
#include <hardware_legacy/wifi_hal.h>
#include <wifi_system/interface_tool.h>
namespace android {
namespace hardware {
namespace wifi {
namespace V1_6 {
namespace implementation {
// This is in a separate namespace to prevent typename conflicts between
// the legacy HAL types and the HIDL interface types.
namespace legacy_hal {
// Import all the types defined inside the legacy HAL header files into this
// namespace.
using ::frame_info;
using ::frame_type;
using ::FRAME_TYPE_80211_MGMT;
using ::FRAME_TYPE_ETHERNET_II;
using ::FRAME_TYPE_UNKNOWN;
using ::fw_roaming_state_t;
using ::mac_addr;
using ::NAN_CHANNEL_24G_BAND;
using ::NAN_CHANNEL_5G_BAND_HIGH;
using ::NAN_CHANNEL_5G_BAND_LOW;
using ::NAN_DISABLE_RANGE_REPORT;
using ::NAN_DO_NOT_USE_SRF;
using ::NAN_DP_CHANNEL_NOT_REQUESTED;
using ::NAN_DP_CONFIG_NO_SECURITY;
using ::NAN_DP_CONFIG_SECURITY;
using ::NAN_DP_END;
using ::NAN_DP_FORCE_CHANNEL_SETUP;
using ::NAN_DP_INITIATOR_RESPONSE;
using ::NAN_DP_INTERFACE_CREATE;
using ::NAN_DP_INTERFACE_DELETE;
using ::NAN_DP_REQUEST_ACCEPT;
using ::NAN_DP_REQUEST_CHANNEL_SETUP;
using ::NAN_DP_REQUEST_REJECT;
using ::NAN_DP_RESPONDER_RESPONSE;
using ::NAN_GET_CAPABILITIES;
using ::NAN_MATCH_ALG_MATCH_CONTINUOUS;
using ::NAN_MATCH_ALG_MATCH_NEVER;
using ::NAN_MATCH_ALG_MATCH_ONCE;
using ::NAN_PUBLISH_TYPE_SOLICITED;
using ::NAN_PUBLISH_TYPE_UNSOLICITED;
using ::NAN_PUBLISH_TYPE_UNSOLICITED_SOLICITED;
using ::NAN_RANGING_AUTO_RESPONSE_DISABLE;
using ::NAN_RANGING_AUTO_RESPONSE_ENABLE;
using ::NAN_RANGING_DISABLE;
using ::NAN_RANGING_ENABLE;
using ::NAN_RESPONSE_BEACON_SDF_PAYLOAD;
using ::NAN_RESPONSE_CONFIG;
using ::NAN_RESPONSE_DISABLED;
using ::NAN_RESPONSE_ENABLED;
using ::NAN_RESPONSE_ERROR;
using ::NAN_RESPONSE_PUBLISH;
using ::NAN_RESPONSE_PUBLISH_CANCEL;
using ::NAN_RESPONSE_STATS;
using ::NAN_RESPONSE_SUBSCRIBE;
using ::NAN_RESPONSE_SUBSCRIBE_CANCEL;
using ::NAN_RESPONSE_TCA;
using ::NAN_RESPONSE_TRANSMIT_FOLLOWUP;
using ::NAN_SECURITY_KEY_INPUT_PASSPHRASE;
using ::NAN_SECURITY_KEY_INPUT_PMK;
using ::NAN_SERVICE_ACCEPT_POLICY_ALL;
using ::NAN_SERVICE_ACCEPT_POLICY_NONE;
using ::NAN_SRF_ATTR_BLOOM_FILTER;
using ::NAN_SRF_ATTR_PARTIAL_MAC_ADDR;
using ::NAN_SRF_INCLUDE_DO_NOT_RESPOND;
using ::NAN_SRF_INCLUDE_RESPOND;
using ::NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
using ::NAN_SSI_REQUIRED_IN_MATCH_IND;
using ::NAN_STATUS_ALREADY_ENABLED;
using ::NAN_STATUS_FOLLOWUP_QUEUE_FULL;
using ::NAN_STATUS_INTERNAL_FAILURE;
using ::NAN_STATUS_INVALID_NDP_ID;
using ::NAN_STATUS_INVALID_PARAM;
using ::NAN_STATUS_INVALID_PUBLISH_SUBSCRIBE_ID;
using ::NAN_STATUS_INVALID_REQUESTOR_INSTANCE_ID;
using ::NAN_STATUS_NAN_NOT_ALLOWED;
using ::NAN_STATUS_NO_OTA_ACK;
using ::NAN_STATUS_NO_RESOURCE_AVAILABLE;
using ::NAN_STATUS_PROTOCOL_FAILURE;
using ::NAN_STATUS_SUCCESS;
using ::NAN_STATUS_UNSUPPORTED_CONCURRENCY_NAN_DISABLED;
using ::NAN_SUBSCRIBE_TYPE_ACTIVE;
using ::NAN_SUBSCRIBE_TYPE_PASSIVE;
using ::NAN_TRANSMIT_IN_DW;
using ::NAN_TRANSMIT_IN_FAW;
using ::NAN_TX_PRIORITY_HIGH;
using ::NAN_TX_PRIORITY_NORMAL;
using ::NAN_TX_TYPE_BROADCAST;
using ::NAN_TX_TYPE_UNICAST;
using ::NAN_USE_SRF;
using ::NanBeaconSdfPayloadInd;
using ::NanCapabilities;
using ::NanChannelInfo;
using ::NanConfigRequest;
using ::NanDataPathChannelCfg;
using ::NanDataPathConfirmInd;
using ::NanDataPathEndInd;
using ::NanDataPathIndicationResponse;
using ::NanDataPathInitiatorRequest;
using ::NanDataPathRequestInd;
using ::NanDataPathScheduleUpdateInd;
using ::NanDisabledInd;
using ::NanDiscEngEventInd;
using ::NanEnableRequest;
using ::NanFollowupInd;
using ::NanMatchAlg;
using ::NanMatchExpiredInd;
using ::NanMatchInd;
using ::NanPublishCancelRequest;
using ::NanPublishRequest;
using ::NanPublishTerminatedInd;
using ::NanPublishType;
using ::NanRangeReportInd;
using ::NanRangeRequestInd;
using ::NanResponseMsg;
using ::NanSRFType;
using ::NanStatusType;
using ::NanSubscribeCancelRequest;
using ::NanSubscribeRequest;
using ::NanSubscribeTerminatedInd;
using ::NanSubscribeType;
using ::NanTransmitFollowupInd;
using ::NanTransmitFollowupRequest;
using ::NanTxType;
using ::ROAMING_DISABLE;
using ::ROAMING_ENABLE;
using ::RTT_PEER_AP;
using ::RTT_PEER_NAN;
using ::RTT_PEER_P2P_CLIENT;
using ::RTT_PEER_P2P_GO;
using ::RTT_PEER_STA;
using ::rtt_peer_type;
using ::RTT_STATUS_ABORTED;
using ::RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL;
using ::RTT_STATUS_FAIL_BUSY_TRY_LATER;
using ::RTT_STATUS_FAIL_FTM_PARAM_OVERRIDE;
using ::RTT_STATUS_FAIL_INVALID_TS;
using ::RTT_STATUS_FAIL_NO_CAPABILITY;
using ::RTT_STATUS_FAIL_NO_RSP;
using ::RTT_STATUS_FAIL_NOT_SCHEDULED_YET;
using ::RTT_STATUS_FAIL_PROTOCOL;
using ::RTT_STATUS_FAIL_REJECTED;
using ::RTT_STATUS_FAIL_SCHEDULE;
using ::RTT_STATUS_FAIL_TM_TIMEOUT;
using ::RTT_STATUS_FAILURE;
using ::RTT_STATUS_INVALID_REQ;
using ::RTT_STATUS_NAN_RANGING_CONCURRENCY_NOT_SUPPORTED;
using ::RTT_STATUS_NAN_RANGING_PROTOCOL_FAILURE;
using ::RTT_STATUS_NO_WIFI;
using ::RTT_STATUS_SUCCESS;
using ::RTT_TYPE_1_SIDED;
using ::RTT_TYPE_2_SIDED;
using ::RX_PKT_FATE_DRV_DROP_FILTER;
using ::RX_PKT_FATE_DRV_DROP_INVALID;
using ::RX_PKT_FATE_DRV_DROP_NOBUFS;
using ::RX_PKT_FATE_DRV_DROP_OTHER;
using ::RX_PKT_FATE_DRV_QUEUED;
using ::RX_PKT_FATE_FW_DROP_FILTER;
using ::RX_PKT_FATE_FW_DROP_INVALID;
using ::RX_PKT_FATE_FW_DROP_NOBUFS;
using ::RX_PKT_FATE_FW_DROP_OTHER;
using ::RX_PKT_FATE_FW_QUEUED;
using ::RX_PKT_FATE_SUCCESS;
using ::ssid_t;
using ::transaction_id;
using ::TX_PKT_FATE_ACKED;
using ::TX_PKT_FATE_DRV_DROP_INVALID;
using ::TX_PKT_FATE_DRV_DROP_NOBUFS;
using ::TX_PKT_FATE_DRV_DROP_OTHER;
using ::TX_PKT_FATE_DRV_QUEUED;
using ::TX_PKT_FATE_FW_DROP_INVALID;
using ::TX_PKT_FATE_FW_DROP_NOBUFS;
using ::TX_PKT_FATE_FW_DROP_OTHER;
using ::TX_PKT_FATE_FW_QUEUED;
using ::TX_PKT_FATE_SENT;
using ::WIFI_AC_BE;
using ::WIFI_AC_BK;
using ::WIFI_AC_VI;
using ::WIFI_AC_VO;
using ::wifi_band;
using ::WIFI_BAND_A;
using ::WIFI_BAND_A_DFS;
using ::WIFI_BAND_A_WITH_DFS;
using ::WIFI_BAND_ABG;
using ::WIFI_BAND_ABG_WITH_DFS;
using ::WIFI_BAND_BG;
using ::WIFI_BAND_UNSPECIFIED;
using ::wifi_cached_scan_results;
using ::WIFI_CHAN_WIDTH_10;
using ::WIFI_CHAN_WIDTH_160;
using ::WIFI_CHAN_WIDTH_20;
using ::WIFI_CHAN_WIDTH_40;
using ::WIFI_CHAN_WIDTH_5;
using ::WIFI_CHAN_WIDTH_80;
using ::WIFI_CHAN_WIDTH_80P80;
using ::WIFI_CHAN_WIDTH_INVALID;
using ::wifi_channel_info;
using ::wifi_channel_stat;
using ::wifi_channel_width;
using ::wifi_coex_restriction;
using ::wifi_coex_unsafe_channel;
using ::WIFI_DUAL_STA_NON_TRANSIENT_UNBIASED;
using ::WIFI_DUAL_STA_TRANSIENT_PREFER_PRIMARY;
using ::wifi_error;
using ::WIFI_ERROR_BUSY;
using ::WIFI_ERROR_INVALID_ARGS;
using ::WIFI_ERROR_INVALID_REQUEST_ID;
using ::WIFI_ERROR_NONE;
using ::WIFI_ERROR_NOT_AVAILABLE;
using ::WIFI_ERROR_NOT_SUPPORTED;
using ::WIFI_ERROR_OUT_OF_MEMORY;
using ::WIFI_ERROR_TIMED_OUT;
using ::WIFI_ERROR_TOO_MANY_REQUESTS;
using ::WIFI_ERROR_UNINITIALIZED;
using ::WIFI_ERROR_UNKNOWN;
using ::wifi_gscan_capabilities;
using ::wifi_hal_fn;
using ::wifi_information_element;
using ::WIFI_INTERFACE_IBSS;
using ::WIFI_INTERFACE_MESH;
using ::wifi_interface_mode;
using ::WIFI_INTERFACE_NAN;
using ::WIFI_INTERFACE_P2P_CLIENT;
using ::WIFI_INTERFACE_P2P_GO;
using ::WIFI_INTERFACE_SOFTAP;
using ::WIFI_INTERFACE_STA;
using ::WIFI_INTERFACE_TDLS;
using ::wifi_interface_type;
using ::WIFI_INTERFACE_TYPE_AP;
using ::WIFI_INTERFACE_TYPE_NAN;
using ::WIFI_INTERFACE_TYPE_P2P;
using ::WIFI_INTERFACE_TYPE_STA;
using ::WIFI_INTERFACE_UNKNOWN;
using ::wifi_latency_mode;
using ::WIFI_LATENCY_MODE_LOW;
using ::WIFI_LATENCY_MODE_NORMAL;
using ::wifi_lci_information;
using ::wifi_lcr_information;
using ::WIFI_LOGGER_CONNECT_EVENT_SUPPORTED;
using ::WIFI_LOGGER_DRIVER_DUMP_SUPPORTED;
using ::WIFI_LOGGER_MEMORY_DUMP_SUPPORTED;
using ::WIFI_LOGGER_PACKET_FATE_SUPPORTED;
using ::WIFI_LOGGER_POWER_EVENT_SUPPORTED;
using ::WIFI_LOGGER_WAKE_LOCK_SUPPORTED;
using ::WIFI_MOTION_EXPECTED;
using ::WIFI_MOTION_NOT_EXPECTED;
using ::wifi_motion_pattern;
using ::WIFI_MOTION_UNKNOWN;
using ::wifi_multi_sta_use_case;
using ::wifi_power_scenario;
using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_OFF;
using ::WIFI_POWER_SCENARIO_ON_BODY_CELL_ON;
using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_OFF;
using ::WIFI_POWER_SCENARIO_ON_HEAD_CELL_ON;
using ::WIFI_POWER_SCENARIO_VOICE_CALL;
using ::wifi_rate;
using ::wifi_request_id;
using ::wifi_ring_buffer_status;
using ::wifi_roaming_capabilities;
using ::wifi_roaming_config;
using ::wifi_rtt_bw;
using ::WIFI_RTT_BW_10;
using ::WIFI_RTT_BW_160;
using ::WIFI_RTT_BW_20;
using ::WIFI_RTT_BW_40;
using ::WIFI_RTT_BW_5;
using ::WIFI_RTT_BW_80;
using ::wifi_rtt_capabilities;
using ::wifi_rtt_config;
using ::wifi_rtt_preamble;
using ::WIFI_RTT_PREAMBLE_HE;
using ::WIFI_RTT_PREAMBLE_HT;
using ::WIFI_RTT_PREAMBLE_LEGACY;
using ::WIFI_RTT_PREAMBLE_VHT;
using ::wifi_rtt_responder;
using ::wifi_rtt_result;
using ::wifi_rtt_status;
using ::wifi_rtt_type;
using ::wifi_rx_packet_fate;
using ::wifi_rx_report;
using ::wifi_scan_bucket_spec;
using ::wifi_scan_cmd_params;
using ::WIFI_SCAN_FLAG_INTERRUPTED;
using ::wifi_scan_result;
using ::WIFI_SUCCESS;
using ::wifi_tx_packet_fate;
using ::wifi_tx_report;
using ::wifi_usable_channel;
using ::WIFI_USABLE_CHANNEL_FILTER_CELLULAR_COEXISTENCE;
using ::WIFI_USABLE_CHANNEL_FILTER_CONCURRENCY;
using ::WLAN_MAC_2_4_BAND;
using ::WLAN_MAC_5_0_BAND;
using ::WLAN_MAC_60_0_BAND;
using ::WLAN_MAC_6_0_BAND;
// APF capabilities supported by the iface.
struct PacketFilterCapabilities {
uint32_t version;
uint32_t max_len;
};
// WARNING: We don't care about the variable sized members of either
// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
// to escape the compiler warnings regarding this.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
// into a separate return element to avoid passing pointers around.
struct LinkLayerRadioStats {
wifi_radio_stat stats;
std::vector<uint32_t> tx_time_per_levels;
std::vector<wifi_channel_stat> channel_stats;
};
struct WifiPeerInfo {
wifi_peer_info peer_info;
std::vector<wifi_rate_stat> rate_stats;
};
struct LinkLayerStats {
wifi_iface_stat iface;
std::vector<LinkLayerRadioStats> radios;
std::vector<WifiPeerInfo> peers;
};
#pragma GCC diagnostic pop
// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
// API. Separate that out into a separate return elements to avoid passing
// pointers around.
struct WakeReasonStats {
WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
std::vector<uint32_t> cmd_event_wake_cnt;
std::vector<uint32_t> driver_fw_local_wake_cnt;
};
// NAN response and event callbacks struct.
struct NanCallbackHandlers {
// NotifyResponse invoked to notify the status of the Request.
std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
// Various event callbacks.
std::function<void(const NanPublishTerminatedInd&)> on_event_publish_terminated;
std::function<void(const NanMatchInd&)> on_event_match;
std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
std::function<void(const NanSubscribeTerminatedInd&)> on_event_subscribe_terminated;
std::function<void(const NanFollowupInd&)> on_event_followup;
std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
std::function<void(const NanDisabledInd&)> on_event_disabled;
std::function<void(const NanTCAInd&)> on_event_tca;
std::function<void(const NanBeaconSdfPayloadInd&)> on_event_beacon_sdf_payload;
std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
std::function<void(const NanTransmitFollowupInd&)> on_event_transmit_follow_up;
std::function<void(const NanRangeRequestInd&)> on_event_range_request;
std::function<void(const NanRangeReportInd&)> on_event_range_report;
std::function<void(const NanDataPathScheduleUpdateInd&)> on_event_schedule_update;
};
// Full scan results contain IE info and are hence passed by reference, to
// preserve the variable length array member |ie_data|. Callee must not retain
// the pointer.
using on_gscan_full_result_callback =
std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
// These scan results don't contain any IE info, so no need to pass by
// reference.
using on_gscan_results_callback =
std::function<void(wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
// Invoked when the rssi value breaches the thresholds set.
using on_rssi_threshold_breached_callback =
std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
// Callback for RTT range request results.
// Rtt results contain IE info and are hence passed by reference, to
// preserve the |LCI| and |LCR| pointers. Callee must not retain
// the pointer.
using on_rtt_results_callback =
std::function<void(wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
// Callback for ring buffer data.
using on_ring_buffer_data_callback = std::function<void(
const std::string&, const std::vector<uint8_t>&, const wifi_ring_buffer_status&)>;
// Callback for alerts.
using on_error_alert_callback = std::function<void(int32_t, const std::vector<uint8_t>&)>;
// Callback for subsystem restart
using on_subsystem_restart_callback = std::function<void(const std::string&)>;
// Struct for the mac info from the legacy HAL. This is a cleaner version
// of the |wifi_mac_info| & |wifi_iface_info|.
typedef struct {
std::string name;
wifi_channel channel;
} WifiIfaceInfo;
typedef struct {
uint32_t wlan_mac_id;
/* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
uint32_t mac_band;
/* Represents the connected Wi-Fi interfaces associated with each MAC */
std::vector<WifiIfaceInfo> iface_infos;
} WifiMacInfo;
// Callback for radio mode change
using on_radio_mode_change_callback = std::function<void(const std::vector<WifiMacInfo>&)>;
// TWT response and event callbacks struct.
struct TwtCallbackHandlers {
// Callback for TWT setup response
std::function<void(const TwtSetupResponse&)> on_setup_response;
// Callback for TWT teardown completion
std::function<void(const TwtTeardownCompletion&)> on_teardown_completion;
// Callback for TWT info frame received event
std::function<void(const TwtInfoFrameReceived&)> on_info_frame_received;
// Callback for TWT notification from the device
std::function<void(const TwtDeviceNotify&)> on_device_notify;
};
/**
* Class that encapsulates all legacy HAL interactions.
* This class manages the lifetime of the event loop thread used by legacy HAL.
*
* Note: There will only be a single instance of this class created in the Wifi
* object and will be valid for the lifetime of the process.
*/
class WifiLegacyHal {
public:
WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool, const wifi_hal_fn& fn,
bool is_primary);
virtual ~WifiLegacyHal() = default;
// Initialize the legacy HAL function table.
virtual wifi_error initialize();
// Start the legacy HAL and the event looper thread.
virtual wifi_error start();
// Deinitialize the legacy HAL and wait for the event loop thread to exit
// using a predefined timeout.
virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
const std::function<void()>& on_complete_callback);
virtual wifi_error waitForDriverReady();
// Checks if legacy HAL has successfully started
bool isStarted();
// Wrappers for all the functions in the legacy HAL function table.
virtual std::pair<wifi_error, std::string> getDriverVersion(const std::string& iface_name);
virtual std::pair<wifi_error, std::string> getFirmwareVersion(const std::string& iface_name);
std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
const std::string& iface_name);
std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
const std::string& iface_name);
std::pair<wifi_error, uint64_t> getSupportedFeatureSet(const std::string& iface_name);
// APF functions.
std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
const std::string& iface_name);
wifi_error setPacketFilter(const std::string& iface_name, const std::vector<uint8_t>& program);
std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
const std::string& iface_name);
// Gscan functions.
std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
const std::string& iface_name);
// These API's provides a simplified interface over the legacy Gscan API's:
// a) All scan events from the legacy HAL API other than the
// |WIFI_SCAN_FAILED| are treated as notification of results.
// This method then retrieves the cached scan results from the legacy
// HAL API and triggers the externally provided
// |on_results_user_callback| on success.
// b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
// results
// triggers the externally provided |on_failure_user_callback|.
// c) Full scan result event triggers the externally provided
// |on_full_result_user_callback|.
wifi_error startGscan(const std::string& iface_name, wifi_request_id id,
const wifi_scan_cmd_params& params,
const std::function<void(wifi_request_id)>& on_failure_callback,
const on_gscan_results_callback& on_results_callback,
const on_gscan_full_result_callback& on_full_result_callback);
wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
const std::string& iface_name, wifi_band band);
virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
// Link layer stats functions.
wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
wifi_error disableLinkLayerStats(const std::string& iface_name);
std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(const std::string& iface_name);
// RSSI monitor functions.
wifi_error startRssiMonitoring(
const std::string& iface_name, wifi_request_id id, int8_t max_rssi, int8_t min_rssi,
const on_rssi_threshold_breached_callback& on_threshold_breached_callback);
wifi_error stopRssiMonitoring(const std::string& iface_name, wifi_request_id id);
std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
const std::string& iface_name);
wifi_error configureRoaming(const std::string& iface_name, const wifi_roaming_config& config);
wifi_error enableFirmwareRoaming(const std::string& iface_name, fw_roaming_state_t state);
wifi_error configureNdOffload(const std::string& iface_name, bool enable);
wifi_error startSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id,
uint16_t ether_type,
const std::vector<uint8_t>& ip_packet_data,
const std::array<uint8_t, 6>& src_address,
const std::array<uint8_t, 6>& dst_address,
uint32_t period_in_ms);
wifi_error stopSendingOffloadedPacket(const std::string& iface_name, uint32_t cmd_id);
virtual wifi_error selectTxPowerScenario(const std::string& iface_name,
wifi_power_scenario scenario);
virtual wifi_error resetTxPowerScenario(const std::string& iface_name);
wifi_error setLatencyMode(const std::string& iface_name, wifi_latency_mode mode);
wifi_error setThermalMitigationMode(wifi_thermal_mode mode, uint32_t completion_window);
wifi_error setDscpToAccessCategoryMapping(uint32_t start, uint32_t end,
uint32_t access_category);
wifi_error resetDscpToAccessCategoryMapping();
// Logger/debug functions.
std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(const std::string& iface_name);
wifi_error startPktFateMonitoring(const std::string& iface_name);
std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(const std::string& iface_name);
std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(const std::string& iface_name);
std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(const std::string& iface_name);
wifi_error registerRingBufferCallbackHandler(
const std::string& iface_name, const on_ring_buffer_data_callback& on_data_callback);
wifi_error deregisterRingBufferCallbackHandler(const std::string& iface_name);
wifi_error registerSubsystemRestartCallbackHandler(
const on_subsystem_restart_callback& on_restart_callback);
std::pair<wifi_error, std::vector<wifi_ring_buffer_status>> getRingBuffersStatus(
const std::string& iface_name);
wifi_error startRingBufferLogging(const std::string& iface_name, const std::string& ring_name,
uint32_t verbose_level, uint32_t max_interval_sec,
uint32_t min_data_size);
wifi_error getRingBufferData(const std::string& iface_name, const std::string& ring_name);
wifi_error registerErrorAlertCallbackHandler(const std::string& iface_name,
const on_error_alert_callback& on_alert_callback);
wifi_error deregisterErrorAlertCallbackHandler(const std::string& iface_name);
// Radio mode functions.
virtual wifi_error registerRadioModeChangeCallbackHandler(
const std::string& iface_name,
const on_radio_mode_change_callback& on_user_change_callback);
// RTT functions.
wifi_error startRttRangeRequest(const std::string& iface_name, wifi_request_id id,
const std::vector<wifi_rtt_config>& rtt_configs,
const on_rtt_results_callback& on_results_callback);
wifi_error cancelRttRangeRequest(const std::string& iface_name, wifi_request_id id,
const std::vector<std::array<uint8_t, 6>>& mac_addrs);
std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(const std::string& iface_name);
std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(const std::string& iface_name);
wifi_error enableRttResponder(const std::string& iface_name, wifi_request_id id,
const wifi_channel_info& channel_hint, uint32_t max_duration_secs,
const wifi_rtt_responder& info);
wifi_error disableRttResponder(const std::string& iface_name, wifi_request_id id);
wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
const wifi_lci_information& info);
wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
const wifi_lcr_information& info);
// NAN functions.
virtual wifi_error nanRegisterCallbackHandlers(const std::string& iface_name,
const NanCallbackHandlers& callbacks);
wifi_error nanEnableRequest(const std::string& iface_name, transaction_id id,
const NanEnableRequest& msg);
virtual wifi_error nanDisableRequest(const std::string& iface_name, transaction_id id);
wifi_error nanPublishRequest(const std::string& iface_name, transaction_id id,
const NanPublishRequest& msg);
wifi_error nanPublishCancelRequest(const std::string& iface_name, transaction_id id,
const NanPublishCancelRequest& msg);
wifi_error nanSubscribeRequest(const std::string& iface_name, transaction_id id,
const NanSubscribeRequest& msg);
wifi_error nanSubscribeCancelRequest(const std::string& iface_name, transaction_id id,
const NanSubscribeCancelRequest& msg);
wifi_error nanTransmitFollowupRequest(const std::string& iface_name, transaction_id id,
const NanTransmitFollowupRequest& msg);
wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
const NanStatsRequest& msg);
wifi_error nanConfigRequest(const std::string& iface_name, transaction_id id,
const NanConfigRequest& msg);
wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
const NanTCARequest& msg);
wifi_error nanBeaconSdfPayloadRequest(const std::string& iface_name, transaction_id id,
const NanBeaconSdfPayloadRequest& msg);
std::pair<wifi_error, NanVersion> nanGetVersion();
wifi_error nanGetCapabilities(const std::string& iface_name, transaction_id id);
wifi_error nanDataInterfaceCreate(const std::string& iface_name, transaction_id id,
const std::string& data_iface_name);
virtual wifi_error nanDataInterfaceDelete(const std::string& iface_name, transaction_id id,
const std::string& data_iface_name);
wifi_error nanDataRequestInitiator(const std::string& iface_name, transaction_id id,
const NanDataPathInitiatorRequest& msg);
wifi_error nanDataIndicationResponse(const std::string& iface_name, transaction_id id,
const NanDataPathIndicationResponse& msg);
wifi_error nanDataEnd(const std::string& iface_name, transaction_id id, uint32_t ndpInstanceId);
// AP functions.
wifi_error setCountryCode(const std::string& iface_name, std::array<int8_t, 2> code);
// interface functions.
virtual wifi_error createVirtualInterface(const std::string& ifname,
wifi_interface_type iftype);
virtual wifi_error deleteVirtualInterface(const std::string& ifname);
wifi_error getSupportedIfaceName(uint32_t iface_type, std::string& ifname);
// STA + STA functions
virtual wifi_error multiStaSetPrimaryConnection(const std::string& ifname);
virtual wifi_error multiStaSetUseCase(wifi_multi_sta_use_case use_case);
// Coex functions.
virtual wifi_error setCoexUnsafeChannels(std::vector<wifi_coex_unsafe_channel> unsafe_channels,
uint32_t restrictions);
wifi_error setVoipMode(const std::string& iface_name, wifi_voip_mode mode);
wifi_error twtRegisterHandler(const std::string& iface_name,
const TwtCallbackHandlers& handler);
std::pair<wifi_error, TwtCapabilitySet> twtGetCapability(const std::string& iface_name);
wifi_error twtSetupRequest(const std::string& iface_name, const TwtSetupRequest& msg);
wifi_error twtTearDownRequest(const std::string& iface_name, const TwtTeardownRequest& msg);
wifi_error twtInfoFrameRequest(const std::string& iface_name, const TwtInfoFrameRequest& msg);
std::pair<wifi_error, TwtStats> twtGetStats(const std::string& iface_name, uint8_t configId);
wifi_error twtClearStats(const std::string& iface_name, uint8_t configId);
wifi_error setDtimConfig(const std::string& iface_name, uint32_t multiplier);
// Retrieve the list of usable channels in the requested bands
// for the requested modes
std::pair<wifi_error, std::vector<wifi_usable_channel>> getUsableChannels(
uint32_t band_mask, uint32_t iface_mode_mask, uint32_t filter_mask);
wifi_error triggerSubsystemRestart();
private:
// Retrieve interface handles for all the available interfaces.
wifi_error retrieveIfaceHandles();
wifi_interface_handle getIfaceHandle(const std::string& iface_name);
// Run the legacy HAL event loop thread.
void runEventLoop();
// Retrieve the cached gscan results to pass the results back to the
// external callbacks.
std::pair<wifi_error, std::vector<wifi_cached_scan_results>> getGscanCachedResults(
const std::string& iface_name);
void invalidate();
// Handles wifi (error) status of Virtual interface create/delete
wifi_error handleVirtualInterfaceCreateOrDeleteStatus(const std::string& ifname,
wifi_error status);
// Global function table of legacy HAL.
wifi_hal_fn global_func_table_;
// Opaque handle to be used for all global operations.
wifi_handle global_handle_;
// Map of interface name to handle that is to be used for all interface
// specific operations.
std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
// Flag to indicate if we have initiated the cleanup of legacy HAL.
std::atomic<bool> awaiting_event_loop_termination_;
std::condition_variable_any stop_wait_cv_;
// Flag to indicate if the legacy HAL has been started.
bool is_started_;
std::weak_ptr<wifi_system::InterfaceTool> iface_tool_;
// flag to indicate if this HAL is for the primary chip. This is used
// in order to avoid some hard-coded behavior used with older HALs,
// such as bring wlan0 interface up/down on start/stop HAL.
// it may be removed once vendor HALs are updated.
bool is_primary_;
};
} // namespace legacy_hal
} // namespace implementation
} // namespace V1_6
} // namespace wifi
} // namespace hardware
} // namespace android
#endif // WIFI_LEGACY_HAL_H_
|