blob: 64e17d12064f54e53de53ceaf8034d534bff506b [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
20#include <functional>
Roshan Piusacededb2017-10-06 14:59:26 -070021#include <map>
Roshan Piusaabe5752016-09-29 09:03:59 -070022#include <thread>
Roshan Pius734fea02016-10-11 08:30:28 -070023#include <vector>
Roshan Pius155344b2017-08-11 15:47:42 -070024#include <condition_variable>
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 {
42 uint32_t version;
43 uint32_t max_len;
44};
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 {
55 wifi_radio_stat stats;
56 std::vector<uint32_t> tx_time_per_levels;
57};
58
Roshan Pius7cece412016-10-28 10:38:21 -070059struct LinkLayerStats {
60 wifi_iface_stat iface;
Roshan Piuse42ace22017-03-13 10:44:20 -070061 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 {
71 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;
74};
75
Roshan Pius23012092016-10-28 11:27:40 -070076// NAN response and event callbacks struct.
77struct NanCallbackHandlers {
78 // NotifyResponse invoked to notify the status of the Request.
79 std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
80 // Various event callbacks.
81 std::function<void(const NanPublishTerminatedInd&)>
82 on_event_publish_terminated;
83 std::function<void(const NanMatchInd&)> on_event_match;
84 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
85 std::function<void(const NanSubscribeTerminatedInd&)>
86 on_event_subscribe_terminated;
87 std::function<void(const NanFollowupInd&)> on_event_followup;
88 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
89 std::function<void(const NanDisabledInd&)> on_event_disabled;
90 std::function<void(const NanTCAInd&)> on_event_tca;
91 std::function<void(const NanBeaconSdfPayloadInd&)>
92 on_event_beacon_sdf_payload;
93 std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
94 std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
95 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
96 std::function<void(const NanTransmitFollowupInd&)>
97 on_event_transmit_follow_up;
Etan Cohenc190f932017-02-17 13:06:55 -080098 std::function<void(const NanRangeRequestInd&)>
99 on_event_range_request;
100 std::function<void(const NanRangeReportInd&)>
101 on_event_range_report;
Roshan Pius23012092016-10-28 11:27:40 -0700102};
103
Roshan Pius76ff3022016-10-28 10:33:34 -0700104// Full scan results contain IE info and are hence passed by reference, to
105// preserve the variable length array member |ie_data|. Callee must not retain
106// the pointer.
107using on_gscan_full_result_callback =
108 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
109// These scan results don't contain any IE info, so no need to pass by
110// reference.
111using on_gscan_results_callback = std::function<void(
112 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
113
Roshan Piusd4767542016-12-06 10:04:05 -0800114// Invoked when the rssi value breaches the thresholds set.
115using on_rssi_threshold_breached_callback =
116 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
117
Roshan Piusd8e915a2016-10-28 11:23:11 -0700118// Callback for RTT range request results.
119// Rtt results contain IE info and are hence passed by reference, to
120// preserve the |LCI| and |LCR| pointers. Callee must not retain
121// the pointer.
122using on_rtt_results_callback = std::function<void(
123 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
124
Roshan Pius8714a3e2016-10-28 10:43:51 -0700125// Callback for ring buffer data.
126using on_ring_buffer_data_callback =
127 std::function<void(const std::string&,
128 const std::vector<uint8_t>&,
129 const wifi_ring_buffer_status&)>;
130
Roshan Pius203cb032016-12-14 17:41:20 -0800131// Callback for alerts.
132using on_error_alert_callback =
133 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Piusaabe5752016-09-29 09:03:59 -0700134/**
135 * Class that encapsulates all legacy HAL interactions.
136 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800137 *
138 * Note: aThere will only be a single instance of this class created in the Wifi
139 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700140 */
141class WifiLegacyHal {
142 public:
143 WifiLegacyHal();
Roshan Piusab5c4712016-10-06 14:37:15 -0700144
Roshan Pius97334112016-11-18 14:07:54 -0800145 // Initialize the legacy HAL function table.
146 wifi_error initialize();
147 // Start the legacy HAL and the event looper thread.
Roshan Piusaabe5752016-09-29 09:03:59 -0700148 wifi_error start();
Roshan Pius155344b2017-08-11 15:47:42 -0700149 // Deinitialize the legacy HAL and wait for the event loop thread to exit
150 // using a predefined timeout.
151 wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
152 const std::function<void()>& on_complete_callback);
Roshan Pius4b26c832016-10-03 12:49:58 -0700153 // Wrappers for all the functions in the legacy HAL function table.
Roshan Piusacededb2017-10-06 14:59:26 -0700154 std::pair<wifi_error, std::string> getDriverVersion(
155 const std::string& iface_name);
156 std::pair<wifi_error, std::string> getFirmwareVersion(
157 const std::string& iface_name);
158 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
159 const std::string& iface_name);
160 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
161 const std::string& iface_name);
162 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
163 const std::string& iface_name);
Roshan Pius0a47c182016-10-28 10:23:00 -0700164 // APF functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700165 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
166 const std::string& iface_name);
167 wifi_error setPacketFilter(
168 const std::string& iface_name, const std::vector<uint8_t>& program);
Roshan Pius76ff3022016-10-28 10:33:34 -0700169 // Gscan functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700170 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
171 const std::string& iface_name);
Roshan Pius76ff3022016-10-28 10:33:34 -0700172 // These API's provides a simplified interface over the legacy Gscan API's:
173 // a) All scan events from the legacy HAL API other than the
174 // |WIFI_SCAN_FAILED| are treated as notification of results.
175 // This method then retrieves the cached scan results from the legacy
176 // HAL API and triggers the externally provided |on_results_user_callback|
177 // on success.
178 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results
179 // triggers the externally provided |on_failure_user_callback|.
180 // c) Full scan result event triggers the externally provided
181 // |on_full_result_user_callback|.
182 wifi_error startGscan(
Roshan Piusacededb2017-10-06 14:59:26 -0700183 const std::string& iface_name,
Roshan Pius76ff3022016-10-28 10:33:34 -0700184 wifi_request_id id,
185 const wifi_scan_cmd_params& params,
186 const std::function<void(wifi_request_id)>& on_failure_callback,
187 const on_gscan_results_callback& on_results_callback,
188 const on_gscan_full_result_callback& on_full_result_callback);
Roshan Piusacededb2017-10-06 14:59:26 -0700189 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
Roshan Pius7f4574d2017-02-22 09:48:03 -0800190 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
Roshan Piusacededb2017-10-06 14:59:26 -0700191 const std::string& iface_name, wifi_band band);
192 wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Pius7cece412016-10-28 10:38:21 -0700193 // Link layer stats functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700194 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
195 wifi_error disableLinkLayerStats(const std::string& iface_name);
196 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
197 const std::string& iface_name);
Roshan Piusd4767542016-12-06 10:04:05 -0800198 // RSSI monitor functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700199 wifi_error startRssiMonitoring(
200 const std::string& iface_name, wifi_request_id id, int8_t max_rssi,
201 int8_t min_rssi, const on_rssi_threshold_breached_callback&
202 on_threshold_breached_callback);
203 wifi_error stopRssiMonitoring(
204 const std::string& iface_name, wifi_request_id id);
205 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
206 const std::string& iface_name);
207 wifi_error configureRoaming(
208 const std::string& iface_name, const wifi_roaming_config& config);
209 wifi_error enableFirmwareRoaming(
210 const std::string& iface_name, fw_roaming_state_t state);
211 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
Roshan Pius9a9869a2017-01-11 16:42:16 -0800212 wifi_error startSendingOffloadedPacket(
Roshan Piusacededb2017-10-06 14:59:26 -0700213 const std::string& iface_name,
Roshan Pius9a9869a2017-01-11 16:42:16 -0800214 uint32_t cmd_id,
215 const std::vector<uint8_t>& ip_packet_data,
216 const std::array<uint8_t, 6>& src_address,
217 const std::array<uint8_t, 6>& dst_address,
218 uint32_t period_in_ms);
Roshan Piusacededb2017-10-06 14:59:26 -0700219 wifi_error stopSendingOffloadedPacket(
220 const std::string& iface_name, uint32_t cmd_id);
221 wifi_error setScanningMacOui(
222 const std::string& iface_name, const std::array<uint8_t, 3>& oui);
223 wifi_error selectTxPowerScenario(
224 const std::string& iface_name, wifi_power_scenario scenario);
225 wifi_error resetTxPowerScenario(const std::string& iface_name);
Roshan Pius8714a3e2016-10-28 10:43:51 -0700226 // Logger/debug functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700227 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
228 const std::string& iface_name);
229 wifi_error startPktFateMonitoring(const std::string& iface_name);
230 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
231 const std::string& iface_name);
232 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
233 const std::string& iface_name);
234 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
235 const std::string& iface_name);
Roshan Pius8714a3e2016-10-28 10:43:51 -0700236 wifi_error registerRingBufferCallbackHandler(
Roshan Piusacededb2017-10-06 14:59:26 -0700237 const std::string& iface_name,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700238 const on_ring_buffer_data_callback& on_data_callback);
Roshan Piusacededb2017-10-06 14:59:26 -0700239 wifi_error deregisterRingBufferCallbackHandler(const std::string& iface_name);
Roshan Pius8714a3e2016-10-28 10:43:51 -0700240 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
Roshan Piusacededb2017-10-06 14:59:26 -0700241 getRingBuffersStatus(const std::string& iface_name);
242 wifi_error startRingBufferLogging(
243 const std::string& iface_name, const std::string& ring_name,
244 uint32_t verbose_level, uint32_t max_interval_sec,
245 uint32_t min_data_size);
246 wifi_error getRingBufferData(
247 const std::string& iface_name, const std::string& ring_name);
Roshan Pius203cb032016-12-14 17:41:20 -0800248 wifi_error registerErrorAlertCallbackHandler(
Roshan Piusacededb2017-10-06 14:59:26 -0700249 const std::string& iface_name,
Roshan Pius203cb032016-12-14 17:41:20 -0800250 const on_error_alert_callback& on_alert_callback);
Roshan Piusacededb2017-10-06 14:59:26 -0700251 wifi_error deregisterErrorAlertCallbackHandler(const std::string& iface_name);
Roshan Piusd8e915a2016-10-28 11:23:11 -0700252 // RTT functions.
253 wifi_error startRttRangeRequest(
Roshan Piusacededb2017-10-06 14:59:26 -0700254 const std::string& iface_name,
Roshan Piusd8e915a2016-10-28 11:23:11 -0700255 wifi_request_id id,
256 const std::vector<wifi_rtt_config>& rtt_configs,
257 const on_rtt_results_callback& on_results_callback);
258 wifi_error cancelRttRangeRequest(
Roshan Piusacededb2017-10-06 14:59:26 -0700259 const std::string& iface_name, wifi_request_id id,
260 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
261 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
262 const std::string& iface_name);
263 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
264 const std::string& iface_name);
265 wifi_error enableRttResponder(
266 const std::string& iface_name, wifi_request_id id,
267 const wifi_channel_info& channel_hint, uint32_t max_duration_secs,
268 const wifi_rtt_responder& info);
269 wifi_error disableRttResponder(
270 const std::string& iface_name, wifi_request_id id);
271 wifi_error setRttLci(
272 const std::string& iface_name, wifi_request_id id,
273 const wifi_lci_information& info);
274 wifi_error setRttLcr(
275 const std::string& iface_name, wifi_request_id id,
276 const wifi_lcr_information& info);
Roshan Pius23012092016-10-28 11:27:40 -0700277 // NAN functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700278 wifi_error nanRegisterCallbackHandlers(
279 const std::string& iface_name, const NanCallbackHandlers& callbacks);
280 wifi_error nanEnableRequest(
281 const std::string& iface_name, transaction_id id,
282 const NanEnableRequest& msg);
283 wifi_error nanDisableRequest(
284 const std::string& iface_name, transaction_id id);
285 wifi_error nanPublishRequest(
286 const std::string& iface_name, transaction_id id,
287 const NanPublishRequest& msg);
288 wifi_error nanPublishCancelRequest(
289 const std::string& iface_name, transaction_id id,
290 const NanPublishCancelRequest& msg);
291 wifi_error nanSubscribeRequest(
292 const std::string& iface_name, transaction_id id,
293 const NanSubscribeRequest& msg);
294 wifi_error nanSubscribeCancelRequest(
295 const std::string& iface_name, transaction_id id,
296 const NanSubscribeCancelRequest& msg);
297 wifi_error nanTransmitFollowupRequest(
298 const std::string& iface_name, transaction_id id,
299 const NanTransmitFollowupRequest& msg);
300 wifi_error nanStatsRequest(
301 const std::string& iface_name, transaction_id id,
302 const NanStatsRequest& msg);
303 wifi_error nanConfigRequest(
304 const std::string& iface_name, transaction_id id,
305 const NanConfigRequest& msg);
306 wifi_error nanTcaRequest(
307 const std::string& iface_name, transaction_id id,
308 const NanTCARequest& msg);
309 wifi_error nanBeaconSdfPayloadRequest(
310 const std::string& iface_name, transaction_id id,
311 const NanBeaconSdfPayloadRequest& msg);
Roshan Pius23012092016-10-28 11:27:40 -0700312 std::pair<wifi_error, NanVersion> nanGetVersion();
Roshan Piusacededb2017-10-06 14:59:26 -0700313 wifi_error nanGetCapabilities(
314 const std::string& iface_name, transaction_id id);
315 wifi_error nanDataInterfaceCreate(
316 const std::string& iface_name, transaction_id id,
317 const std::string& data_iface_name);
318 wifi_error nanDataInterfaceDelete(
319 const std::string& iface_name, transaction_id id,
320 const std::string& data_iface_name);
321 wifi_error nanDataRequestInitiator(
322 const std::string& iface_name, transaction_id id,
323 const NanDataPathInitiatorRequest& msg);
Roshan Pius23012092016-10-28 11:27:40 -0700324 wifi_error nanDataIndicationResponse(
Roshan Piusacededb2017-10-06 14:59:26 -0700325 const std::string& iface_name, transaction_id id,
326 const NanDataPathIndicationResponse& msg);
327 wifi_error nanDataEnd(
328 const std::string& iface_name, transaction_id id, uint32_t ndpInstanceId);
Roshan Pius32fc12e2017-01-25 17:44:42 -0800329 // AP functions.
Roshan Piusacededb2017-10-06 14:59:26 -0700330 wifi_error setCountryCode(
331 const std::string& iface_name, std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700332
333 private:
Roshan Piusacededb2017-10-06 14:59:26 -0700334 // Retrieve interface handles for all the available interfaces.
335 wifi_error retrieveIfaceHandles();
336 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
Roshan Piusaabe5752016-09-29 09:03:59 -0700337 // Run the legacy HAL event loop thread.
338 void runEventLoop();
Roshan Pius76ff3022016-10-28 10:33:34 -0700339 // Retrieve the cached gscan results to pass the results back to the external
340 // callbacks.
341 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
Roshan Piusacededb2017-10-06 14:59:26 -0700342 getGscanCachedResults(const std::string& iface_name);
Roshan Pius511cc492016-10-28 09:54:26 -0700343 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700344
Roshan Piusaabe5752016-09-29 09:03:59 -0700345 // Global function table of legacy HAL.
346 wifi_hal_fn global_func_table_;
347 // Opaque handle to be used for all global operations.
348 wifi_handle global_handle_;
Roshan Piusacededb2017-10-06 14:59:26 -0700349 // Map of interface name to handle that is to be used for all interface specific operations.
350 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700351 // Flag to indicate if we have initiated the cleanup of legacy HAL.
Roshan Piusd32a43f2017-03-14 08:30:45 -0700352 std::atomic<bool> awaiting_event_loop_termination_;
Roshan Pius155344b2017-08-11 15:47:42 -0700353 std::condition_variable_any stop_wait_cv_;
Roshan Pius11f93032016-12-09 10:26:17 -0800354 // Flag to indicate if the legacy HAL has been started.
355 bool is_started_;
Roshan Pius97334112016-11-18 14:07:54 -0800356 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700357};
358
Roshan Pius955542e2016-10-28 09:42:44 -0700359} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700360} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700361} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700362} // namespace wifi
363} // namespace hardware
364} // namespace android
365
Roshan Piuse73a5062016-12-12 08:53:34 -0800366#endif // WIFI_LEGACY_HAL_H_