blob: da88f6b420bb7426721af38d58291af1ab13df53 [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 Piusaabe5752016-09-29 09:03:59 -0700135/**
136 * Class that encapsulates all legacy HAL interactions.
137 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800138 *
139 * Note: aThere will only be a single instance of this class created in the Wifi
140 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700141 */
142class WifiLegacyHal {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700143 public:
144 WifiLegacyHal();
Roshan Pius200a17d2017-11-01 13:03:35 -0700145 virtual ~WifiLegacyHal() = default;
Roshan Piusab5c4712016-10-06 14:37:15 -0700146
Roshan Piusabcf78f2017-10-06 16:30:38 -0700147 // Initialize the legacy HAL function table.
Roshan Pius200a17d2017-11-01 13:03:35 -0700148 virtual wifi_error initialize();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700149 // Start the legacy HAL and the event looper thread.
Roshan Pius200a17d2017-11-01 13:03:35 -0700150 virtual wifi_error start();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700151 // Deinitialize the legacy HAL and wait for the event loop thread to exit
152 // using a predefined timeout.
Roshan Pius200a17d2017-11-01 13:03:35 -0700153 virtual wifi_error stop(std::unique_lock<std::recursive_mutex>* lock,
154 const std::function<void()>& on_complete_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700155 // Wrappers for all the functions in the legacy HAL function table.
156 std::pair<wifi_error, std::string> getDriverVersion(
157 const std::string& iface_name);
158 std::pair<wifi_error, std::string> getFirmwareVersion(
159 const std::string& iface_name);
160 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump(
161 const std::string& iface_name);
162 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump(
163 const std::string& iface_name);
164 std::pair<wifi_error, uint32_t> getSupportedFeatureSet(
165 const std::string& iface_name);
166 // APF functions.
167 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities(
168 const std::string& iface_name);
169 wifi_error setPacketFilter(const std::string& iface_name,
170 const std::vector<uint8_t>& program);
171 // Gscan functions.
172 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities(
173 const std::string& iface_name);
174 // These API's provides a simplified interface over the legacy Gscan API's:
175 // a) All scan events from the legacy HAL API other than the
176 // |WIFI_SCAN_FAILED| are treated as notification of results.
177 // This method then retrieves the cached scan results from the legacy
178 // HAL API and triggers the externally provided
179 // |on_results_user_callback| on success.
180 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan
181 // results
182 // triggers the externally provided |on_failure_user_callback|.
183 // c) Full scan result event triggers the externally provided
184 // |on_full_result_user_callback|.
185 wifi_error startGscan(
186 const std::string& iface_name, wifi_request_id id,
187 const wifi_scan_cmd_params& params,
188 const std::function<void(wifi_request_id)>& on_failure_callback,
189 const on_gscan_results_callback& on_results_callback,
190 const on_gscan_full_result_callback& on_full_result_callback);
191 wifi_error stopGscan(const std::string& iface_name, wifi_request_id id);
192 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
193 const std::string& iface_name, wifi_band band);
Roshan Pius200a17d2017-11-01 13:03:35 -0700194 virtual wifi_error setDfsFlag(const std::string& iface_name, bool dfs_on);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700195 // Link layer stats functions.
196 wifi_error enableLinkLayerStats(const std::string& iface_name, bool debug);
197 wifi_error disableLinkLayerStats(const std::string& iface_name);
198 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats(
199 const std::string& iface_name);
200 // RSSI monitor functions.
201 wifi_error startRssiMonitoring(const std::string& iface_name,
202 wifi_request_id id, int8_t max_rssi,
203 int8_t min_rssi,
204 const on_rssi_threshold_breached_callback&
205 on_threshold_breached_callback);
206 wifi_error stopRssiMonitoring(const std::string& iface_name,
207 wifi_request_id id);
208 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities(
209 const std::string& iface_name);
210 wifi_error configureRoaming(const std::string& iface_name,
211 const wifi_roaming_config& config);
212 wifi_error enableFirmwareRoaming(const std::string& iface_name,
213 fw_roaming_state_t state);
214 wifi_error configureNdOffload(const std::string& iface_name, bool enable);
215 wifi_error startSendingOffloadedPacket(
216 const std::string& iface_name, uint32_t cmd_id,
217 const std::vector<uint8_t>& ip_packet_data,
218 const std::array<uint8_t, 6>& src_address,
219 const std::array<uint8_t, 6>& dst_address, uint32_t period_in_ms);
220 wifi_error stopSendingOffloadedPacket(const std::string& iface_name,
221 uint32_t cmd_id);
222 wifi_error setScanningMacOui(const std::string& iface_name,
223 const std::array<uint8_t, 3>& oui);
224 wifi_error selectTxPowerScenario(const std::string& iface_name,
225 wifi_power_scenario scenario);
226 wifi_error resetTxPowerScenario(const std::string& iface_name);
227 // Logger/debug functions.
228 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet(
229 const std::string& iface_name);
230 wifi_error startPktFateMonitoring(const std::string& iface_name);
231 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates(
232 const std::string& iface_name);
233 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates(
234 const std::string& iface_name);
235 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats(
236 const std::string& iface_name);
237 wifi_error registerRingBufferCallbackHandler(
238 const std::string& iface_name,
239 const on_ring_buffer_data_callback& on_data_callback);
240 wifi_error deregisterRingBufferCallbackHandler(
241 const std::string& iface_name);
242 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
243 getRingBuffersStatus(const std::string& iface_name);
244 wifi_error startRingBufferLogging(const std::string& iface_name,
245 const std::string& ring_name,
246 uint32_t verbose_level,
247 uint32_t max_interval_sec,
248 uint32_t min_data_size);
249 wifi_error getRingBufferData(const std::string& iface_name,
250 const std::string& ring_name);
251 wifi_error registerErrorAlertCallbackHandler(
252 const std::string& iface_name,
253 const on_error_alert_callback& on_alert_callback);
254 wifi_error deregisterErrorAlertCallbackHandler(
255 const std::string& iface_name);
256 // RTT functions.
257 wifi_error startRttRangeRequest(
258 const std::string& iface_name, wifi_request_id id,
259 const std::vector<wifi_rtt_config>& rtt_configs,
260 const on_rtt_results_callback& on_results_callback);
261 wifi_error cancelRttRangeRequest(
262 const std::string& iface_name, wifi_request_id id,
263 const std::vector<std::array<uint8_t, 6>>& mac_addrs);
264 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities(
265 const std::string& iface_name);
266 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo(
267 const std::string& iface_name);
268 wifi_error enableRttResponder(const std::string& iface_name,
269 wifi_request_id id,
270 const wifi_channel_info& channel_hint,
271 uint32_t max_duration_secs,
272 const wifi_rtt_responder& info);
273 wifi_error disableRttResponder(const std::string& iface_name,
274 wifi_request_id id);
275 wifi_error setRttLci(const std::string& iface_name, wifi_request_id id,
276 const wifi_lci_information& info);
277 wifi_error setRttLcr(const std::string& iface_name, wifi_request_id id,
278 const wifi_lcr_information& info);
279 // NAN functions.
Roshan Pius200a17d2017-11-01 13:03:35 -0700280 virtual wifi_error nanRegisterCallbackHandlers(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700281 const std::string& iface_name, const NanCallbackHandlers& callbacks);
282 wifi_error nanEnableRequest(const std::string& iface_name,
283 transaction_id id, const NanEnableRequest& msg);
Roshan Pius200a17d2017-11-01 13:03:35 -0700284 virtual wifi_error nanDisableRequest(const std::string& iface_name,
285 transaction_id id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700286 wifi_error nanPublishRequest(const std::string& iface_name,
287 transaction_id id,
288 const NanPublishRequest& msg);
289 wifi_error nanPublishCancelRequest(const std::string& iface_name,
290 transaction_id id,
291 const NanPublishCancelRequest& msg);
292 wifi_error nanSubscribeRequest(const std::string& iface_name,
293 transaction_id id,
294 const NanSubscribeRequest& msg);
295 wifi_error nanSubscribeCancelRequest(const std::string& iface_name,
296 transaction_id id,
297 const NanSubscribeCancelRequest& msg);
298 wifi_error nanTransmitFollowupRequest(
299 const std::string& iface_name, transaction_id id,
300 const NanTransmitFollowupRequest& msg);
301 wifi_error nanStatsRequest(const std::string& iface_name, transaction_id id,
302 const NanStatsRequest& msg);
303 wifi_error nanConfigRequest(const std::string& iface_name,
304 transaction_id id, const NanConfigRequest& msg);
305 wifi_error nanTcaRequest(const std::string& iface_name, transaction_id id,
306 const NanTCARequest& msg);
307 wifi_error nanBeaconSdfPayloadRequest(
308 const std::string& iface_name, transaction_id id,
309 const NanBeaconSdfPayloadRequest& msg);
310 std::pair<wifi_error, NanVersion> nanGetVersion();
311 wifi_error nanGetCapabilities(const std::string& iface_name,
312 transaction_id id);
313 wifi_error nanDataInterfaceCreate(const std::string& iface_name,
314 transaction_id id,
315 const std::string& data_iface_name);
Roshan Pius200a17d2017-11-01 13:03:35 -0700316 virtual wifi_error nanDataInterfaceDelete(
317 const std::string& iface_name, transaction_id id,
318 const std::string& data_iface_name);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700319 wifi_error nanDataRequestInitiator(const std::string& iface_name,
320 transaction_id id,
321 const NanDataPathInitiatorRequest& msg);
322 wifi_error nanDataIndicationResponse(
323 const std::string& iface_name, transaction_id id,
324 const NanDataPathIndicationResponse& msg);
325 wifi_error nanDataEnd(const std::string& iface_name, transaction_id id,
326 uint32_t ndpInstanceId);
327 // AP functions.
328 wifi_error setCountryCode(const std::string& iface_name,
329 std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700330
Roshan Piusabcf78f2017-10-06 16:30:38 -0700331 private:
332 // Retrieve interface handles for all the available interfaces.
333 wifi_error retrieveIfaceHandles();
334 wifi_interface_handle getIfaceHandle(const std::string& iface_name);
335 // Run the legacy HAL event loop thread.
336 void runEventLoop();
337 // Retrieve the cached gscan results to pass the results back to the
338 // external callbacks.
339 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
340 getGscanCachedResults(const std::string& iface_name);
341 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700342
Roshan Piusabcf78f2017-10-06 16:30:38 -0700343 // Global function table of legacy HAL.
344 wifi_hal_fn global_func_table_;
345 // Opaque handle to be used for all global operations.
346 wifi_handle global_handle_;
347 // Map of interface name to handle that is to be used for all interface
348 // specific operations.
349 std::map<std::string, wifi_interface_handle> iface_name_to_handle_;
350 // Flag to indicate if we have initiated the cleanup of legacy HAL.
351 std::atomic<bool> awaiting_event_loop_termination_;
352 std::condition_variable_any stop_wait_cv_;
353 // Flag to indicate if the legacy HAL has been started.
354 bool is_started_;
355 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700356};
357
Roshan Pius955542e2016-10-28 09:42:44 -0700358} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700359} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700360} // namespace V1_2
Roshan Piusaabe5752016-09-29 09:03:59 -0700361} // namespace wifi
362} // namespace hardware
363} // namespace android
364
Roshan Piuse73a5062016-12-12 08:53:34 -0800365#endif // WIFI_LEGACY_HAL_H_