blob: bd68bcd2099b7046374fd6b18aa582fd7cb0e5bd [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
Roshan Piusaabe5752016-09-29 09:03:59 -070028namespace android {
29namespace hardware {
30namespace wifi {
Etan Cohen6ce50902017-09-14 07:30:57 -070031namespace V1_2 {
Roshan Piusaabe5752016-09-29 09:03:59 -070032namespace implementation {
Roshan Pius955542e2016-10-28 09:42:44 -070033// This is in a separate namespace to prevent typename conflicts between
34// the legacy HAL types and the HIDL interface types.
35namespace legacy_hal {
36// Wrap all the types defined inside the legacy HAL header files inside this
37// namespace.
38#include <hardware_legacy/wifi_hal.h>
Roshan Piusaabe5752016-09-29 09:03:59 -070039
Roshan Pius0a47c182016-10-28 10:23:00 -070040// APF capabilities supported by the iface.
41struct PacketFilterCapabilities {
Roshan Piusabcf78f2017-10-06 16:30:38 -070042 uint32_t version;
43 uint32_t max_len;
Roshan Pius0a47c182016-10-28 10:23:00 -070044};
45
Roshan Pius7cece412016-10-28 10:38:21 -070046// WARNING: We don't care about the variable sized members of either
47// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
48// to escape the compiler warnings regarding this.
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
51// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
52// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
53// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -070054struct LinkLayerRadioStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070055 wifi_radio_stat stats;
56 std::vector<uint32_t> tx_time_per_levels;
Roshan Piuse42ace22017-03-13 10:44:20 -070057};
58
Roshan Pius7cece412016-10-28 10:38:21 -070059struct LinkLayerStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070060 wifi_iface_stat iface;
61 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -070062};
63#pragma GCC diagnostic pop
64
Roshan Pius8714a3e2016-10-28 10:43:51 -070065// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
66// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
67// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
68// API. Separate that out into a separate return elements to avoid passing
69// pointers around.
70struct WakeReasonStats {
Roshan Piusabcf78f2017-10-06 16:30:38 -070071 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
72 std::vector<uint32_t> cmd_event_wake_cnt;
73 std::vector<uint32_t> driver_fw_local_wake_cnt;
Roshan Pius8714a3e2016-10-28 10:43:51 -070074};
75
Roshan Pius23012092016-10-28 11:27:40 -070076// NAN response and event callbacks struct.
77struct NanCallbackHandlers {
Roshan Piusabcf78f2017-10-06 16:30:38 -070078 // NotifyResponse invoked to notify the status of the Request.
79 std::function<void(transaction_id, const NanResponseMsg&)>
80 on_notify_response;
81 // Various event callbacks.
82 std::function<void(const NanPublishTerminatedInd&)>
83 on_event_publish_terminated;
84 std::function<void(const NanMatchInd&)> on_event_match;
85 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
86 std::function<void(const NanSubscribeTerminatedInd&)>
87 on_event_subscribe_terminated;
88 std::function<void(const NanFollowupInd&)> on_event_followup;
89 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
90 std::function<void(const NanDisabledInd&)> on_event_disabled;
91 std::function<void(const NanTCAInd&)> on_event_tca;
92 std::function<void(const NanBeaconSdfPayloadInd&)>
93 on_event_beacon_sdf_payload;
94 std::function<void(const NanDataPathRequestInd&)>
95 on_event_data_path_request;
96 std::function<void(const NanDataPathConfirmInd&)>
97 on_event_data_path_confirm;
98 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
99 std::function<void(const NanTransmitFollowupInd&)>
100 on_event_transmit_follow_up;
101 std::function<void(const NanRangeRequestInd&)> on_event_range_request;
102 std::function<void(const NanRangeReportInd&)> on_event_range_report;
Etan Cohen1bf15f12017-12-12 16:15:16 -0800103 std::function<void(const NanDataPathScheduleUpdateInd&)> on_event_schedule_update;
Roshan Pius23012092016-10-28 11:27:40 -0700104};
105
Roshan Pius76ff3022016-10-28 10:33:34 -0700106// Full scan results contain IE info and are hence passed by reference, to
107// preserve the variable length array member |ie_data|. Callee must not retain
108// the pointer.
109using on_gscan_full_result_callback =
110 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
111// These scan results don't contain any IE info, so no need to pass by
112// reference.
113using on_gscan_results_callback = std::function<void(
114 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
115
Roshan Piusd4767542016-12-06 10:04:05 -0800116// Invoked when the rssi value breaches the thresholds set.
117using on_rssi_threshold_breached_callback =
118 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
119
Roshan Piusd8e915a2016-10-28 11:23:11 -0700120// Callback for RTT range request results.
121// Rtt results contain IE info and are hence passed by reference, to
122// preserve the |LCI| and |LCR| pointers. Callee must not retain
123// the pointer.
124using on_rtt_results_callback = std::function<void(
125 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
126
Roshan Pius8714a3e2016-10-28 10:43:51 -0700127// Callback for ring buffer data.
128using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700129 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700130 const wifi_ring_buffer_status&)>;
131
Roshan Pius203cb032016-12-14 17:41:20 -0800132// Callback for alerts.
133using on_error_alert_callback =
134 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Pius01f08772018-01-22 17:56:06 -0800135
136// Struct for the mac info from the legacy HAL. This is a cleaner version
137// of the |wifi_mac_info| & |wifi_iface_info|.
138typedef struct {
139 std::string name;
140 wifi_channel channel;
141} WifiIfaceInfo;
142
143typedef struct {
144 uint32_t wlan_mac_id;
145 /* BIT MASK of BIT(WLAN_MAC*) as represented by wlan_mac_band */
146 uint32_t mac_band;
147 /* Represents the connected Wi-Fi interfaces associated with each MAC */
148 std::vector<WifiIfaceInfo> iface_infos;
149} WifiMacInfo;
150
151// Callback for radio mode change
152using on_radio_mode_change_callback =
153 std::function<void(const std::vector<WifiMacInfo>&)>;
154
Roshan Piusaabe5752016-09-29 09:03:59 -0700155/**
156 * Class that encapsulates all legacy HAL interactions.
157 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800158 *
159 * Note: aThere will only be a single instance of this class created in the Wifi
160 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700161 */
162class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700163 public:
164 WifiLegacyHal();
Roshan Pius200a17d2017-11-01 13:03:35 -0700165 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700166
Roshan Piusabcf78f2017-10-06 16:30:38 -0700167 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700168 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700169 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700170 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700171 // Deinitialize the legacy HAL and wait for the event loop thread to exit
172 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700173 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
174 const std::function<void()>& on_complete_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700175 // Wrappers for all the functions in the legacy HAL function table.
176 std::pair<wifi_error, std::string> getDriverVersion(
177 const std::string& iface_name);
178 std::pair<wifi_error, std::string> getFirmwareVersion(
179 const std::string& iface_name);
180 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
181 const std::string& iface_name);
182 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
183 const std::string& iface_name);
184 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
185 const std::string& iface_name);
186 // APF functions.
187 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
188 const std::string& iface_name);
189 wifi_error setPacketFilter(const std::string& iface_name,
190 const std::vector<uint8_t>& program);
191 // Gscan functions.
192 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
193 const std::string& iface_name);
194 // These API's provides a simplified interface over the legacy Gscan API's:
195 // a) All scan events from the legacy HAL API other than the
196 // |WIFI_SCAN_FAILED| are treated as notification of results.
197 // This method then retrieves the cached scan results from the legacy
198 // HAL API and triggers the externally provided
199 // |on_results_user_callback| on success.
200 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
201 // results
202 // triggers the externally provided |on_failure_user_callback|.
203 // c) Full scan result event triggers the externally provided
204 // |on_full_result_user_callback|.
205 wifi_error startGscan(
206 const std::string& iface_name, wifi_request_id id,
207 const wifi_scan_cmd_params& params,
208 const std::function<void(wifi_request_id)>& on_failure_callback,
209 const on_gscan_results_callback& on_results_callback,
210 const on_gscan_full_result_callback& on_full_result_callback);
211 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
212 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
213 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700214 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700215 // Link layer stats functions.
216 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
217 wifi_error disableLinkLayerStats(const std::string& iface_name);
218 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
219 const std::string& iface_name);
220 // RSSI monitor functions.
221 wifi_error startRssiMonitoring(const std::string& iface_name,
222 wifi_request_id id, int8_t max_rssi,
223 int8_t min_rssi,
224 const on_rssi_threshold_breached_callback&
225 on_threshold_breached_callback);
226 wifi_error stopRssiMonitoring(const std::string& iface_name,
227 wifi_request_id id);
228 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
229 const std::string& iface_name);
230 wifi_error configureRoaming(const std::string& iface_name,
231 const wifi_roaming_config& config);
232 wifi_error enableFirmwareRoaming(const std::string& iface_name,
233 fw_roaming_state_t state);
234 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
235 wifi_error startSendingOffloadedPacket(
236 const std::string& iface_name, uint32_t cmd_id,
237 const std::vector<uint8_t>& ip_packet_data,
238 const std::array<uint8_t, 6>& src_address,
239 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
240 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
241 uint32_t cmd_id);
242 wifi_error setScanningMacOui(const std::string& iface_name,
243 const std::array<uint8_t, 3>& oui);
244 wifi_error selectTxPowerScenario(const std::string& iface_name,
245 wifi_power_scenario scenario);
246 wifi_error resetTxPowerScenario(const std::string& iface_name);
247 // Logger/debug functions.
248 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
249 const std::string& iface_name);
250 wifi_error startPktFateMonitoring(const std::string& iface_name);
251 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
252 const std::string& iface_name);
253 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
254 const std::string& iface_name);
255 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
256 const std::string& iface_name);
257 wifi_error registerRingBufferCallbackHandler(
258 const std::string& iface_name,
259 const on_ring_buffer_data_callback& on_data_callback);
260 wifi_error deregisterRingBufferCallbackHandler(
261 const std::string& iface_name);
262 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
263 getRingBuffersStatus(const std::string& iface_name);
264 wifi_error startRingBufferLogging(const std::string& iface_name,
265 const std::string& ring_name,
266 uint32_t verbose_level,
267 uint32_t max_interval_sec,
268 uint32_t min_data_size);
269 wifi_error getRingBufferData(const std::string& iface_name,
270 const std::string& ring_name);
271 wifi_error registerErrorAlertCallbackHandler(
272 const std::string& iface_name,
273 const on_error_alert_callback& on_alert_callback);
274 wifi_error deregisterErrorAlertCallbackHandler(
275 const std::string& iface_name);
Roshan Pius01f08772018-01-22 17:56:06 -0800276 // Radio mode functions.
277 wifi_error registerRadioModeChangeCallbackHandler(
278 const std::string& iface_name,
279 const on_radio_mode_change_callback& on_user_change_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700280 // RTT functions.
281 wifi_error startRttRangeRequest(
282 const std::string& iface_name, wifi_request_id id,
283 const std::vector<wifi_rtt_config>& rtt_configs,
284 const on_rtt_results_callback& on_results_callback);
285 wifi_error cancelRttRangeRequest(
286 const std::string& iface_name, wifi_request_id id,
287 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
288 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
289 const std::string& iface_name);
290 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
291 const std::string& iface_name);
292 wifi_error enableRttResponder(const std::string& iface_name,
293 wifi_request_id id,
294 const wifi_channel_info& channel_hint,
295 uint32_t max_duration_secs,
296 const wifi_rtt_responder& info);
297 wifi_error disableRttResponder(const std::string& iface_name,
298 wifi_request_id id);
299 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
300 const wifi_lci_information& info);
301 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
302 const wifi_lcr_information& info);
303 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700304 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700305 const std::string& iface_name, const NanCallbackHandlers& callbacks);
306 wifi_error nanEnableRequest(const std::string& iface_name,
307 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700308 virtual wifi_error nanDisableRequest(const std::string& iface_name,
309 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700310 wifi_error nanPublishRequest(const std::string& iface_name,
311 transaction_id id,
312 const NanPublishRequest& msg);
313 wifi_error nanPublishCancelRequest(const std::string& iface_name,
314 transaction_id id,
315 const NanPublishCancelRequest& msg);
316 wifi_error nanSubscribeRequest(const std::string& iface_name,
317 transaction_id id,
318 const NanSubscribeRequest& msg);
319 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
320 transaction_id id,
321 const NanSubscribeCancelRequest& msg);
322 wifi_error nanTransmitFollowupRequest(
323 const std::string& iface_name, transaction_id id,
324 const NanTransmitFollowupRequest& msg);
325 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
326 const NanStatsRequest& msg);
327 wifi_error nanConfigRequest(const std::string& iface_name,
328 transaction_id id, const NanConfigRequest& msg);
329 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
330 const NanTCARequest& msg);
331 wifi_error nanBeaconSdfPayloadRequest(
332 const std::string& iface_name, transaction_id id,
333 const NanBeaconSdfPayloadRequest& msg);
334 std::pair<wifi_error, NanVersion> nanGetVersion();
335 wifi_error nanGetCapabilities(const std::string& iface_name,
336 transaction_id id);
337 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
338 transaction_id id,
339 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700340 virtual wifi_error nanDataInterfaceDelete(
341 const std::string& iface_name, transaction_id id,
342 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700343 wifi_error nanDataRequestInitiator(const std::string& iface_name,
344 transaction_id id,
345 const NanDataPathInitiatorRequest& msg);
346 wifi_error nanDataIndicationResponse(
347 const std::string& iface_name, transaction_id id,
348 const NanDataPathIndicationResponse& msg);
349 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
350 uint32_t ndpInstanceId);
351 // AP functions.
352 wifi_error setCountryCode(const std::string& iface_name,
353 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700354
Roshan Piusabcf78f2017-10-06 16:30:38 -0700355 private:
356 // Retrieve interface handles for all the available interfaces.
357 wifi_error retrieveIfaceHandles();
358 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
359 // Run the legacy HAL event loop thread.
360 void runEventLoop();
361 // Retrieve the cached gscan results to pass the results back to the
362 // external callbacks.
363 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
364 getGscanCachedResults(const std::string& iface_name);
365 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700366
Roshan Piusabcf78f2017-10-06 16:30:38 -0700367 // Global function table of legacy HAL.
368 wifi_hal_fn global_func_table_;
369 // Opaque handle to be used for all global operations.
370 wifi_handle global_handle_;
371 // Map of interface name to handle that is to be used for all interface
372 // specific operations.
373 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
374 // Flag to indicate if we have initiated the cleanup of legacy HAL.
375 std::atomic<bool> awaiting_event_loop_termination_;
376 std::condition_variable_any stop_wait_cv_;
377 // Flag to indicate if the legacy HAL has been started.
378 bool is_started_;
379 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700380};
381
Roshan Pius955542e2016-10-28 09:42:44 -0700382} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700383} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700384} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700385} // namespace wifi
386} // namespace hardware
387} // namespace android
388
Roshan Piuse73a5062016-12-12 08:53:34 -0800389#endif // WIFI_LEGACY_HAL_H_