blob: 00dfeefb9a145814602e6495cc842fc4db41bf9b [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
Roshan Pius97334112016-11-18 14:07:54 -080026#include <wifi_system/interface_tool.h>
27
Josh Gao7715d502018-07-19 11:14:49 -070028// HACK: The include inside the namespace below also transitively includes a
29// bunch of libc headers into the namespace, which leads to functions like
30// socketpair being defined in android::hardware::wifi::V1_1::implementation::legacy_hal.
31// Include this one particular header as a hacky workaround until that's fixed.
32#include <sys/socket.h>
33
Roshan Piusaabe5752016-09-29 09:03:59 -070034namespace android {
35namespace hardware {
36namespace wifi {
Etan Cohen6ce50902017-09-14 07:30:57 -070037namespace V1_2 {
Roshan Piusaabe5752016-09-29 09:03:59 -070038namespace implementation {
Roshan Pius955542e2016-10-28 09:42:44 -070039// This is in a separate namespace to prevent typename conflicts between
40// the legacy HAL types and the HIDL interface types.
41namespace legacy_hal {
42// Wrap all the types defined inside the legacy HAL header files inside this
43// namespace.
44#include <hardware_legacy/wifi_hal.h>
Roshan Piusaabe5752016-09-29 09:03:59 -070045
Roshan Pius0a47c182016-10-28 10:23:00 -070046// APF capabilities supported by the iface.
47struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -070048 uint32_t version;
49 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -070050};
51
Roshan Pius7cece412016-10-28 10:38:21 -070052// WARNING: We don't care about the variable sized members of either
53// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
54// to escape the compiler warnings regarding this.
55#pragma GCC diagnostic push
56#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
57// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
58// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
59// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -070060struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070061 wifi_radio_stat stats;
62 std::vector<uint32_t> tx_time_per_levels;
Roshan Piuse42ace22017-03-13 10:44:20 -070063};
64
Roshan Pius7cece412016-10-28 10:38:21 -070065struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070066 wifi_iface_stat iface;
67 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -070068};
69#pragma GCC diagnostic pop
70
Roshan Pius8714a3e2016-10-28 10:43:51 -070071// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
72// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
73// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
74// API. Separate that out into a separate return elements to avoid passing
75// pointers around.
76struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070077 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
78 std::vector<uint32_t> cmd_event_wake_cnt;
79 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -070080};
81
Roshan Pius23012092016-10-28 11:27:40 -070082// NAN response and event callbacks struct.
83struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -070084 // NotifyResponse invoked to notify the status of the Request.
85 std::function<void(transaction_id, const NanResponseMsg&)>
86 on_notify_response;
87 // Various event callbacks.
88 std::function<void(const NanPublishTerminatedInd&)>
89 on_event_publish_terminated;
90 std::function<void(const NanMatchInd&)> on_event_match;
91 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
92 std::function<void(const NanSubscribeTerminatedInd&)>
93 on_event_subscribe_terminated;
94 std::function<void(const NanFollowupInd&)> on_event_followup;
95 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
96 std::function<void(const NanDisabledInd&)> on_event_disabled;
97 std::function<void(const NanTCAInd&)> on_event_tca;
98 std::function<void(const NanBeaconSdfPayloadInd&)>
99 on_event_beacon_sdf_payload;
100 std::function<void(const NanDataPathRequestInd&)>
101 on_event_data_path_request;
102 std::function<void(const NanDataPathConfirmInd&)>
103 on_event_data_path_confirm;
104 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
105 std::function<void(const NanTransmitFollowupInd&)>
106 on_event_transmit_follow_up;
107 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
108 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Etan Cohen1bf15f12017-12-12 16:15:16 -0800109 std::function<void(const NanDataPathScheduleUpdateInd&)> on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700110};
111
Roshan Pius76ff3022016-10-28 10:33:34 -0700112// Full scan results contain IE info and are hence passed by reference, to
113// preserve the variable length array member |ie_data|. Callee must not retain
114// the pointer.
115using on_gscan_full_result_callback =
116 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
117// These scan results don't contain any IE info, so no need to pass by
118// reference.
119using on_gscan_results_callback = std::function<void(
120 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
121
Roshan Piusd4767542016-12-06 10:04:05 -0800122// Invoked when the rssi value breaches the thresholds set.
123using on_rssi_threshold_breached_callback =
124 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
125
Roshan Piusd8e915a2016-10-28 11:23:11 -0700126// Callback for RTT range request results.
127// Rtt results contain IE info and are hence passed by reference, to
128// preserve the |LCI| and |LCR| pointers. Callee must not retain
129// the pointer.
130using on_rtt_results_callback = std::function<void(
131 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
132
Roshan Pius8714a3e2016-10-28 10:43:51 -0700133// Callback for ring buffer data.
134using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700135 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700136 const wifi_ring_buffer_status&)>;
137
Roshan Pius203cb032016-12-14 17:41:20 -0800138// Callback for alerts.
139using on_error_alert_callback =
140 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800141
142// Struct for the mac info from the legacy HAL. This is a cleaner version
143// of the |wifi_mac_info| & |wifi_iface_info|.
144typedef struct {
145 std::string name;
146 wifi_channel channel;
147} WifiIfaceInfo;
148
149typedef struct {
150 uint32_t wlan_mac_id;
151 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
152 uint32_t mac_band;
153 /* Represents the connected Wi-Fi interfaces associated with each MAC */
154 std::vector<WifiIfaceInfo> iface_infos;
155} WifiMacInfo;
156
157// Callback for radio mode change
158using on_radio_mode_change_callback =
159 std::function<void(const std::vector<WifiMacInfo>&)>;
160
Roshan Piusaabe5752016-09-29 09:03:59 -0700161/**
162 * Class that encapsulates all legacy HAL interactions.
163 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800164 *
Bernie Innocenti7e6f71a2018-03-07 00:17:50 +0900165 * Note: There will only be a single instance of this class created in the Wifi
Roshan Pius742bb972017-02-02 09:54:27 -0800166 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700167 */
168class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700169 public:
170 WifiLegacyHal();
Roshan Pius200a17d2017-11-01 13:03:35 -0700171 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700172
Roshan Piusabcf78f2017-10-06 16:30:38 -0700173 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700174 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700175 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700176 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700177 // Deinitialize the legacy HAL and wait for the event loop thread to exit
178 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700179 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
180 const std::function<void()>& on_complete_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700181 // Wrappers for all the functions in the legacy HAL function table.
182 std::pair<wifi_error, std::string> getDriverVersion(
183 const std::string& iface_name);
184 std::pair<wifi_error, std::string> getFirmwareVersion(
185 const std::string& iface_name);
186 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
187 const std::string& iface_name);
188 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
189 const std::string& iface_name);
190 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
191 const std::string& iface_name);
192 // APF functions.
193 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
194 const std::string& iface_name);
195 wifi_error setPacketFilter(const std::string& iface_name,
196 const std::vector<uint8_t>& program);
Bernie Innocenti7e6f71a2018-03-07 00:17:50 +0900197 std::pair<wifi_error, std::vector<uint8_t>> readApfPacketFilterData(
198 const std::string& iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700199 // Gscan functions.
200 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
201 const std::string& iface_name);
202 // These API's provides a simplified interface over the legacy Gscan API's:
203 // a) All scan events from the legacy HAL API other than the
204 // |WIFI_SCAN_FAILED| are treated as notification of results.
205 // This method then retrieves the cached scan results from the legacy
206 // HAL API and triggers the externally provided
207 // |on_results_user_callback| on success.
208 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
209 // results
210 // triggers the externally provided |on_failure_user_callback|.
211 // c) Full scan result event triggers the externally provided
212 // |on_full_result_user_callback|.
213 wifi_error startGscan(
214 const std::string& iface_name, wifi_request_id id,
215 const wifi_scan_cmd_params& params,
216 const std::function<void(wifi_request_id)>& on_failure_callback,
217 const on_gscan_results_callback& on_results_callback,
218 const on_gscan_full_result_callback& on_full_result_callback);
219 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
220 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
221 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700222 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700223 // Link layer stats functions.
224 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
225 wifi_error disableLinkLayerStats(const std::string& iface_name);
226 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
227 const std::string& iface_name);
228 // RSSI monitor functions.
229 wifi_error startRssiMonitoring(const std::string& iface_name,
230 wifi_request_id id, int8_t max_rssi,
231 int8_t min_rssi,
232 const on_rssi_threshold_breached_callback&
233 on_threshold_breached_callback);
234 wifi_error stopRssiMonitoring(const std::string& iface_name,
235 wifi_request_id id);
236 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
237 const std::string& iface_name);
238 wifi_error configureRoaming(const std::string& iface_name,
239 const wifi_roaming_config& config);
240 wifi_error enableFirmwareRoaming(const std::string& iface_name,
241 fw_roaming_state_t state);
242 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
243 wifi_error startSendingOffloadedPacket(
244 const std::string& iface_name, uint32_t cmd_id,
245 const std::vector<uint8_t>& ip_packet_data,
246 const std::array<uint8_t, 6>& src_address,
247 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
248 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
249 uint32_t cmd_id);
250 wifi_error setScanningMacOui(const std::string& iface_name,
251 const std::array<uint8_t, 3>& oui);
252 wifi_error selectTxPowerScenario(const std::string& iface_name,
253 wifi_power_scenario scenario);
254 wifi_error resetTxPowerScenario(const std::string& iface_name);
255 // Logger/debug functions.
256 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
257 const std::string& iface_name);
258 wifi_error startPktFateMonitoring(const std::string& iface_name);
259 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
260 const std::string& iface_name);
261 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
262 const std::string& iface_name);
263 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
264 const std::string& iface_name);
265 wifi_error registerRingBufferCallbackHandler(
266 const std::string& iface_name,
267 const on_ring_buffer_data_callback& on_data_callback);
268 wifi_error deregisterRingBufferCallbackHandler(
269 const std::string& iface_name);
270 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
271 getRingBuffersStatus(const std::string& iface_name);
272 wifi_error startRingBufferLogging(const std::string& iface_name,
273 const std::string& ring_name,
274 uint32_t verbose_level,
275 uint32_t max_interval_sec,
276 uint32_t min_data_size);
277 wifi_error getRingBufferData(const std::string& iface_name,
278 const std::string& ring_name);
279 wifi_error registerErrorAlertCallbackHandler(
280 const std::string& iface_name,
281 const on_error_alert_callback& on_alert_callback);
282 wifi_error deregisterErrorAlertCallbackHandler(
283 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800284 // Radio mode functions.
Roshan Piusaceecb02018-03-01 14:54:26 -0800285 virtual wifi_error registerRadioModeChangeCallbackHandler(
Roshan Pius01f08772018-01-22 17:56:06 -0800286 const std::string& iface_name,
287 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700288 // RTT functions.
289 wifi_error startRttRangeRequest(
290 const std::string& iface_name, wifi_request_id id,
291 const std::vector<wifi_rtt_config>& rtt_configs,
292 const on_rtt_results_callback& on_results_callback);
293 wifi_error cancelRttRangeRequest(
294 const std::string& iface_name, wifi_request_id id,
295 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
296 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
297 const std::string& iface_name);
298 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
299 const std::string& iface_name);
300 wifi_error enableRttResponder(const std::string& iface_name,
301 wifi_request_id id,
302 const wifi_channel_info& channel_hint,
303 uint32_t max_duration_secs,
304 const wifi_rtt_responder& info);
305 wifi_error disableRttResponder(const std::string& iface_name,
306 wifi_request_id id);
307 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
308 const wifi_lci_information& info);
309 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
310 const wifi_lcr_information& info);
311 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700312 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700313 const std::string& iface_name, const NanCallbackHandlers& callbacks);
314 wifi_error nanEnableRequest(const std::string& iface_name,
315 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700316 virtual wifi_error nanDisableRequest(const std::string& iface_name,
317 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700318 wifi_error nanPublishRequest(const std::string& iface_name,
319 transaction_id id,
320 const NanPublishRequest& msg);
321 wifi_error nanPublishCancelRequest(const std::string& iface_name,
322 transaction_id id,
323 const NanPublishCancelRequest& msg);
324 wifi_error nanSubscribeRequest(const std::string& iface_name,
325 transaction_id id,
326 const NanSubscribeRequest& msg);
327 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
328 transaction_id id,
329 const NanSubscribeCancelRequest& msg);
330 wifi_error nanTransmitFollowupRequest(
331 const std::string& iface_name, transaction_id id,
332 const NanTransmitFollowupRequest& msg);
333 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
334 const NanStatsRequest& msg);
335 wifi_error nanConfigRequest(const std::string& iface_name,
336 transaction_id id, const NanConfigRequest& msg);
337 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
338 const NanTCARequest& msg);
339 wifi_error nanBeaconSdfPayloadRequest(
340 const std::string& iface_name, transaction_id id,
341 const NanBeaconSdfPayloadRequest& msg);
342 std::pair<wifi_error, NanVersion> nanGetVersion();
343 wifi_error nanGetCapabilities(const std::string& iface_name,
344 transaction_id id);
345 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
346 transaction_id id,
347 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700348 virtual wifi_error nanDataInterfaceDelete(
349 const std::string& iface_name, transaction_id id,
350 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700351 wifi_error nanDataRequestInitiator(const std::string& iface_name,
352 transaction_id id,
353 const NanDataPathInitiatorRequest& msg);
354 wifi_error nanDataIndicationResponse(
355 const std::string& iface_name, transaction_id id,
356 const NanDataPathIndicationResponse& msg);
357 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
358 uint32_t ndpInstanceId);
359 // AP functions.
360 wifi_error setCountryCode(const std::string& iface_name,
361 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700362
Roshan Piusabcf78f2017-10-06 16:30:38 -0700363 private:
364 // Retrieve interface handles for all the available interfaces.
365 wifi_error retrieveIfaceHandles();
366 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
367 // Run the legacy HAL event loop thread.
368 void runEventLoop();
369 // Retrieve the cached gscan results to pass the results back to the
370 // external callbacks.
371 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
372 getGscanCachedResults(const std::string& iface_name);
373 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700374
Roshan Piusabcf78f2017-10-06 16:30:38 -0700375 // Global function table of legacy HAL.
376 wifi_hal_fn global_func_table_;
377 // Opaque handle to be used for all global operations.
378 wifi_handle global_handle_;
379 // Map of interface name to handle that is to be used for all interface
380 // specific operations.
381 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
382 // Flag to indicate if we have initiated the cleanup of legacy HAL.
383 std::atomic<bool> awaiting_event_loop_termination_;
384 std::condition_variable_any stop_wait_cv_;
385 // Flag to indicate if the legacy HAL has been started.
386 bool is_started_;
387 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700388};
389
Roshan Pius955542e2016-10-28 09:42:44 -0700390} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700391} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700392} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700393} // namespace wifi
394} // namespace hardware
395} // namespace android
396
Roshan Piuse73a5062016-12-12 08:53:34 -0800397#endif // WIFI_LEGACY_HAL_H_