blob: 193928b6b68b9a3857eb91f2492b8ae3f9c9e1cb [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 Piusab5c4712016-10-06 14:37:15 -0700144
Roshan Piusabcf78f2017-10-06 16:30:38 -0700145 // Initialize the legacy HAL function table.
146 wifi_error initialize();
147 // Start the legacy HAL and the event looper thread.
148 wifi_error start();
149 // 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);
153 // Wrappers for all the functions in the legacy HAL function table.
154 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);
164 // APF functions.
165 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
166 const std::string& iface_name);
167 wifi_error setPacketFilter(const std::string& iface_name,
168 const std::vector<uint8_t>& program);
169 // Gscan functions.
170 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
171 const std::string& iface_name);
172 // 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
177 // |on_results_user_callback| on success.
178 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
179 // results
180 // triggers the externally provided |on_failure_user_callback|.
181 // c) Full scan result event triggers the externally provided
182 // |on_full_result_user_callback|.
183 wifi_error startGscan(
184 const std::string& iface_name, 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);
189 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
190 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
191 const std::string& iface_name, wifi_band band);
192 wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
193 // Link layer stats functions.
194 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);
198 // RSSI monitor functions.
199 wifi_error startRssiMonitoring(const std::string& iface_name,
200 wifi_request_id id, int8_t max_rssi,
201 int8_t min_rssi,
202 const on_rssi_threshold_breached_callback&
203 on_threshold_breached_callback);
204 wifi_error stopRssiMonitoring(const std::string& iface_name,
205 wifi_request_id id);
206 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
207 const std::string& iface_name);
208 wifi_error configureRoaming(const std::string& iface_name,
209 const wifi_roaming_config& config);
210 wifi_error enableFirmwareRoaming(const std::string& iface_name,
211 fw_roaming_state_t state);
212 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
213 wifi_error startSendingOffloadedPacket(
214 const std::string& iface_name, 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, uint32_t period_in_ms);
218 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
219 uint32_t cmd_id);
220 wifi_error setScanningMacOui(const std::string& iface_name,
221 const std::array<uint8_t, 3>& oui);
222 wifi_error selectTxPowerScenario(const std::string& iface_name,
223 wifi_power_scenario scenario);
224 wifi_error resetTxPowerScenario(const std::string& iface_name);
225 // Logger/debug functions.
226 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
227 const std::string& iface_name);
228 wifi_error startPktFateMonitoring(const std::string& iface_name);
229 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
230 const std::string& iface_name);
231 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
232 const std::string& iface_name);
233 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
234 const std::string& iface_name);
235 wifi_error registerRingBufferCallbackHandler(
236 const std::string& iface_name,
237 const on_ring_buffer_data_callback& on_data_callback);
238 wifi_error deregisterRingBufferCallbackHandler(
239 const std::string& iface_name);
240 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
241 getRingBuffersStatus(const std::string& iface_name);
242 wifi_error startRingBufferLogging(const std::string& iface_name,
243 const std::string& ring_name,
244 uint32_t verbose_level,
245 uint32_t max_interval_sec,
246 uint32_t min_data_size);
247 wifi_error getRingBufferData(const std::string& iface_name,
248 const std::string& ring_name);
249 wifi_error registerErrorAlertCallbackHandler(
250 const std::string& iface_name,
251 const on_error_alert_callback& on_alert_callback);
252 wifi_error deregisterErrorAlertCallbackHandler(
253 const std::string& iface_name);
254 // RTT functions.
255 wifi_error startRttRangeRequest(
256 const std::string& iface_name, wifi_request_id id,
257 const std::vector<wifi_rtt_config>& rtt_configs,
258 const on_rtt_results_callback& on_results_callback);
259 wifi_error cancelRttRangeRequest(
260 const std::string& iface_name, wifi_request_id id,
261 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
262 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
263 const std::string& iface_name);
264 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
265 const std::string& iface_name);
266 wifi_error enableRttResponder(const std::string& iface_name,
267 wifi_request_id id,
268 const wifi_channel_info& channel_hint,
269 uint32_t max_duration_secs,
270 const wifi_rtt_responder& info);
271 wifi_error disableRttResponder(const std::string& iface_name,
272 wifi_request_id id);
273 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
274 const wifi_lci_information& info);
275 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
276 const wifi_lcr_information& info);
277 // NAN functions.
278 wifi_error nanRegisterCallbackHandlers(
279 const std::string& iface_name, const NanCallbackHandlers& callbacks);
280 wifi_error nanEnableRequest(const std::string& iface_name,
281 transaction_id id, const NanEnableRequest& msg);
282 wifi_error nanDisableRequest(const std::string& iface_name,
283 transaction_id id);
284 wifi_error nanPublishRequest(const std::string& iface_name,
285 transaction_id id,
286 const NanPublishRequest& msg);
287 wifi_error nanPublishCancelRequest(const std::string& iface_name,
288 transaction_id id,
289 const NanPublishCancelRequest& msg);
290 wifi_error nanSubscribeRequest(const std::string& iface_name,
291 transaction_id id,
292 const NanSubscribeRequest& msg);
293 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
294 transaction_id id,
295 const NanSubscribeCancelRequest& msg);
296 wifi_error nanTransmitFollowupRequest(
297 const std::string& iface_name, transaction_id id,
298 const NanTransmitFollowupRequest& msg);
299 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
300 const NanStatsRequest& msg);
301 wifi_error nanConfigRequest(const std::string& iface_name,
302 transaction_id id, const NanConfigRequest& msg);
303 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
304 const NanTCARequest& msg);
305 wifi_error nanBeaconSdfPayloadRequest(
306 const std::string& iface_name, transaction_id id,
307 const NanBeaconSdfPayloadRequest& msg);
308 std::pair<wifi_error, NanVersion> nanGetVersion();
309 wifi_error nanGetCapabilities(const std::string& iface_name,
310 transaction_id id);
311 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
312 transaction_id id,
313 const std::string& data_iface_name);
314 wifi_error nanDataInterfaceDelete(const std::string& iface_name,
315 transaction_id id,
316 const std::string& data_iface_name);
317 wifi_error nanDataRequestInitiator(const std::string& iface_name,
318 transaction_id id,
319 const NanDataPathInitiatorRequest& msg);
320 wifi_error nanDataIndicationResponse(
321 const std::string& iface_name, transaction_id id,
322 const NanDataPathIndicationResponse& msg);
323 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
324 uint32_t ndpInstanceId);
325 // AP functions.
326 wifi_error setCountryCode(const std::string& iface_name,
327 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700328
Roshan Piusabcf78f2017-10-06 16:30:38 -0700329 private:
330 // Retrieve interface handles for all the available interfaces.
331 wifi_error retrieveIfaceHandles();
332 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
333 // Run the legacy HAL event loop thread.
334 void runEventLoop();
335 // Retrieve the cached gscan results to pass the results back to the
336 // external callbacks.
337 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
338 getGscanCachedResults(const std::string& iface_name);
339 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700340
Roshan Piusabcf78f2017-10-06 16:30:38 -0700341 // Global function table of legacy HAL.
342 wifi_hal_fn global_func_table_;
343 // Opaque handle to be used for all global operations.
344 wifi_handle global_handle_;
345 // Map of interface name to handle that is to be used for all interface
346 // specific operations.
347 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
348 // Flag to indicate if we have initiated the cleanup of legacy HAL.
349 std::atomic<bool> awaiting_event_loop_termination_;
350 std::condition_variable_any stop_wait_cv_;
351 // Flag to indicate if the legacy HAL has been started.
352 bool is_started_;
353 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700354};
355
Roshan Pius955542e2016-10-28 09:42:44 -0700356} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700357} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700358} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700359} // namespace wifi
360} // namespace hardware
361} // namespace android
362
Roshan Piuse73a5062016-12-12 08:53:34 -0800363#endif // WIFI_LEGACY_HAL_H_