blob: 64a3f0ada108f340fceef7fa277b084bb93b0ef6 [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;
Roshan Pius23012092016-10-28 11:27:40 -0700103};
104
Roshan Pius76ff3022016-10-28 10:33:34 -0700105// Full scan results contain IE info and are hence passed by reference, to
106// preserve the variable length array member |ie_data|. Callee must not retain
107// the pointer.
108using on_gscan_full_result_callback =
109 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
110// These scan results don't contain any IE info, so no need to pass by
111// reference.
112using on_gscan_results_callback = std::function<void(
113 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
114
Roshan Piusd4767542016-12-06 10:04:05 -0800115// Invoked when the rssi value breaches the thresholds set.
116using on_rssi_threshold_breached_callback =
117 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
118
Roshan Piusd8e915a2016-10-28 11:23:11 -0700119// Callback for RTT range request results.
120// Rtt results contain IE info and are hence passed by reference, to
121// preserve the |LCI| and |LCR| pointers. Callee must not retain
122// the pointer.
123using on_rtt_results_callback = std::function<void(
124 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
125
Roshan Pius8714a3e2016-10-28 10:43:51 -0700126// Callback for ring buffer data.
127using on_ring_buffer_data_callback =
Roshan Piusabcf78f2017-10-06 16:30:38 -0700128 std::function<void(const std::string&, const std::vector<uint8_t>&,
Roshan Pius8714a3e2016-10-28 10:43:51 -0700129 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 {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700142 public:
143 WifiLegacyHal();
Roshan Pius200a17d2017-11-01 13:03:35 -0700144 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700145
Roshan Piusabcf78f2017-10-06 16:30:38 -0700146 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700147 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700148 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700149 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700150 // Deinitialize the legacy HAL and wait for the event loop thread to exit
151 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700152 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
153 const std::function<void()>& on_complete_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700154 // Wrappers for all the functions in the legacy HAL function table.
155 std::pair<wifi_error, std::string> getDriverVersion(
156 const std::string& iface_name);
157 std::pair<wifi_error, std::string> getFirmwareVersion(
158 const std::string& iface_name);
159 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
160 const std::string& iface_name);
161 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
162 const std::string& iface_name);
163 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
164 const std::string& iface_name);
165 // APF functions.
166 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
167 const std::string& iface_name);
168 wifi_error setPacketFilter(const std::string& iface_name,
169 const std::vector<uint8_t>& program);
170 // Gscan functions.
171 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
172 const std::string& iface_name);
173 // These API's provides a simplified interface over the legacy Gscan API's:
174 // a) All scan events from the legacy HAL API other than the
175 // |WIFI_SCAN_FAILED| are treated as notification of results.
176 // This method then retrieves the cached scan results from the legacy
177 // HAL API and triggers the externally provided
178 // |on_results_user_callback| on success.
179 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
180 // results
181 // triggers the externally provided |on_failure_user_callback|.
182 // c) Full scan result event triggers the externally provided
183 // |on_full_result_user_callback|.
184 wifi_error startGscan(
185 const std::string& iface_name, wifi_request_id id,
186 const wifi_scan_cmd_params& params,
187 const std::function<void(wifi_request_id)>& on_failure_callback,
188 const on_gscan_results_callback& on_results_callback,
189 const on_gscan_full_result_callback& on_full_result_callback);
190 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
191 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
192 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700193 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700194 // Link layer stats functions.
195 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
196 wifi_error disableLinkLayerStats(const std::string& iface_name);
197 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
198 const std::string& iface_name);
199 // RSSI monitor functions.
200 wifi_error startRssiMonitoring(const std::string& iface_name,
201 wifi_request_id id, int8_t max_rssi,
202 int8_t min_rssi,
203 const on_rssi_threshold_breached_callback&
204 on_threshold_breached_callback);
205 wifi_error stopRssiMonitoring(const std::string& iface_name,
206 wifi_request_id id);
207 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
208 const std::string& iface_name);
209 wifi_error configureRoaming(const std::string& iface_name,
210 const wifi_roaming_config& config);
211 wifi_error enableFirmwareRoaming(const std::string& iface_name,
212 fw_roaming_state_t state);
213 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
214 wifi_error startSendingOffloadedPacket(
215 const std::string& iface_name, uint32_t cmd_id,
216 const std::vector<uint8_t>& ip_packet_data,
217 const std::array<uint8_t, 6>& src_address,
218 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
219 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
220 uint32_t cmd_id);
221 wifi_error setScanningMacOui(const std::string& iface_name,
222 const std::array<uint8_t, 3>& oui);
223 wifi_error selectTxPowerScenario(const std::string& iface_name,
224 wifi_power_scenario scenario);
225 wifi_error resetTxPowerScenario(const std::string& iface_name);
226 // Logger/debug functions.
227 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);
236 wifi_error registerRingBufferCallbackHandler(
237 const std::string& iface_name,
238 const on_ring_buffer_data_callback& on_data_callback);
239 wifi_error deregisterRingBufferCallbackHandler(
240 const std::string& iface_name);
241 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
242 getRingBuffersStatus(const std::string& iface_name);
243 wifi_error startRingBufferLogging(const std::string& iface_name,
244 const std::string& ring_name,
245 uint32_t verbose_level,
246 uint32_t max_interval_sec,
247 uint32_t min_data_size);
248 wifi_error getRingBufferData(const std::string& iface_name,
249 const std::string& ring_name);
250 wifi_error registerErrorAlertCallbackHandler(
251 const std::string& iface_name,
252 const on_error_alert_callback& on_alert_callback);
253 wifi_error deregisterErrorAlertCallbackHandler(
254 const std::string& iface_name);
255 // RTT functions.
256 wifi_error startRttRangeRequest(
257 const std::string& iface_name, wifi_request_id id,
258 const std::vector<wifi_rtt_config>& rtt_configs,
259 const on_rtt_results_callback& on_results_callback);
260 wifi_error cancelRttRangeRequest(
261 const std::string& iface_name, wifi_request_id id,
262 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
263 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
264 const std::string& iface_name);
265 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
266 const std::string& iface_name);
267 wifi_error enableRttResponder(const std::string& iface_name,
268 wifi_request_id id,
269 const wifi_channel_info& channel_hint,
270 uint32_t max_duration_secs,
271 const wifi_rtt_responder& info);
272 wifi_error disableRttResponder(const std::string& iface_name,
273 wifi_request_id id);
274 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
275 const wifi_lci_information& info);
276 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
277 const wifi_lcr_information& info);
278 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700279 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700280 const std::string& iface_name, const NanCallbackHandlers& callbacks);
281 wifi_error nanEnableRequest(const std::string& iface_name,
282 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700283 virtual wifi_error nanDisableRequest(const std::string& iface_name,
284 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700285 wifi_error nanPublishRequest(const std::string& iface_name,
286 transaction_id id,
287 const NanPublishRequest& msg);
288 wifi_error nanPublishCancelRequest(const std::string& iface_name,
289 transaction_id id,
290 const NanPublishCancelRequest& msg);
291 wifi_error nanSubscribeRequest(const std::string& iface_name,
292 transaction_id id,
293 const NanSubscribeRequest& msg);
294 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
295 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(const std::string& iface_name, transaction_id id,
301 const NanStatsRequest& msg);
302 wifi_error nanConfigRequest(const std::string& iface_name,
303 transaction_id id, const NanConfigRequest& msg);
304 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
305 const NanTCARequest& msg);
306 wifi_error nanBeaconSdfPayloadRequest(
307 const std::string& iface_name, transaction_id id,
308 const NanBeaconSdfPayloadRequest& msg);
309 std::pair<wifi_error, NanVersion> nanGetVersion();
310 wifi_error nanGetCapabilities(const std::string& iface_name,
311 transaction_id id);
312 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
313 transaction_id id,
314 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700315 virtual wifi_error nanDataInterfaceDelete(
316 const std::string& iface_name, transaction_id id,
317 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700318 wifi_error nanDataRequestInitiator(const std::string& iface_name,
319 transaction_id id,
320 const NanDataPathInitiatorRequest& msg);
321 wifi_error nanDataIndicationResponse(
322 const std::string& iface_name, transaction_id id,
323 const NanDataPathIndicationResponse& msg);
324 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
325 uint32_t ndpInstanceId);
326 // AP functions.
327 wifi_error setCountryCode(const std::string& iface_name,
328 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700329
Roshan Piusabcf78f2017-10-06 16:30:38 -0700330 private:
331 // Retrieve interface handles for all the available interfaces.
332 wifi_error retrieveIfaceHandles();
333 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
334 // Run the legacy HAL event loop thread.
335 void runEventLoop();
336 // Retrieve the cached gscan results to pass the results back to the
337 // external callbacks.
338 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
339 getGscanCachedResults(const std::string& iface_name);
340 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700341
Roshan Piusabcf78f2017-10-06 16:30:38 -0700342 // Global function table of legacy HAL.
343 wifi_hal_fn global_func_table_;
344 // Opaque handle to be used for all global operations.
345 wifi_handle global_handle_;
346 // Map of interface name to handle that is to be used for all interface
347 // specific operations.
348 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
349 // Flag to indicate if we have initiated the cleanup of legacy HAL.
350 std::atomic<bool> awaiting_event_loop_termination_;
351 std::condition_variable_any stop_wait_cv_;
352 // Flag to indicate if the legacy HAL has been started.
353 bool is_started_;
354 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700355};
356
Roshan Pius955542e2016-10-28 09:42:44 -0700357} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700358} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700359} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700360} // namespace wifi
361} // namespace hardware
362} // namespace android
363
Roshan Piuse73a5062016-12-12 08:53:34 -0800364#endif // WIFI_LEGACY_HAL_H_