blob: f79e62a962a430ffcdf458199321978172a8172a [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>
21#include <thread>
Roshan Pius734fea02016-10-11 08:30:28 -070022#include <vector>
Roshan Piusaabe5752016-09-29 09:03:59 -070023
Roshan Pius97334112016-11-18 14:07:54 -080024#include <wifi_system/interface_tool.h>
25
Roshan Piusaabe5752016-09-29 09:03:59 -070026namespace android {
27namespace hardware {
28namespace wifi {
29namespace V1_0 {
30namespace implementation {
Roshan Pius955542e2016-10-28 09:42:44 -070031// This is in a separate namespace to prevent typename conflicts between
32// the legacy HAL types and the HIDL interface types.
33namespace legacy_hal {
34// Wrap all the types defined inside the legacy HAL header files inside this
35// namespace.
36#include <hardware_legacy/wifi_hal.h>
Roshan Piusaabe5752016-09-29 09:03:59 -070037
Roshan Pius0a47c182016-10-28 10:23:00 -070038// APF capabilities supported by the iface.
39struct PacketFilterCapabilities {
40 uint32_t version;
41 uint32_t max_len;
42};
43
Roshan Pius7cece412016-10-28 10:38:21 -070044// WARNING: We don't care about the variable sized members of either
45// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
46// to escape the compiler warnings regarding this.
47#pragma GCC diagnostic push
48#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
49// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
50// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
51// into a separate return element to avoid passing pointers around.
Roshan Piuse42ace22017-03-13 10:44:20 -070052struct LinkLayerRadioStats {
53 wifi_radio_stat stats;
54 std::vector<uint32_t> tx_time_per_levels;
55};
56
Roshan Pius7cece412016-10-28 10:38:21 -070057struct LinkLayerStats {
58 wifi_iface_stat iface;
Roshan Piuse42ace22017-03-13 10:44:20 -070059 std::vector<LinkLayerRadioStats> radios;
Roshan Pius7cece412016-10-28 10:38:21 -070060};
61#pragma GCC diagnostic pop
62
Roshan Pius8714a3e2016-10-28 10:43:51 -070063// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
64// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
65// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
66// API. Separate that out into a separate return elements to avoid passing
67// pointers around.
68struct WakeReasonStats {
69 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
70 std::vector<uint32_t> cmd_event_wake_cnt;
71 std::vector<uint32_t> driver_fw_local_wake_cnt;
72};
73
Roshan Pius23012092016-10-28 11:27:40 -070074// NAN response and event callbacks struct.
75struct NanCallbackHandlers {
76 // NotifyResponse invoked to notify the status of the Request.
77 std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
78 // Various event callbacks.
79 std::function<void(const NanPublishTerminatedInd&)>
80 on_event_publish_terminated;
81 std::function<void(const NanMatchInd&)> on_event_match;
82 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
83 std::function<void(const NanSubscribeTerminatedInd&)>
84 on_event_subscribe_terminated;
85 std::function<void(const NanFollowupInd&)> on_event_followup;
86 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
87 std::function<void(const NanDisabledInd&)> on_event_disabled;
88 std::function<void(const NanTCAInd&)> on_event_tca;
89 std::function<void(const NanBeaconSdfPayloadInd&)>
90 on_event_beacon_sdf_payload;
91 std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
92 std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
93 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
94 std::function<void(const NanTransmitFollowupInd&)>
95 on_event_transmit_follow_up;
Etan Cohenc190f932017-02-17 13:06:55 -080096 std::function<void(const NanRangeRequestInd&)>
97 on_event_range_request;
98 std::function<void(const NanRangeReportInd&)>
99 on_event_range_report;
Roshan Pius23012092016-10-28 11:27:40 -0700100};
101
Roshan Pius76ff3022016-10-28 10:33:34 -0700102// Full scan results contain IE info and are hence passed by reference, to
103// preserve the variable length array member |ie_data|. Callee must not retain
104// the pointer.
105using on_gscan_full_result_callback =
106 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
107// These scan results don't contain any IE info, so no need to pass by
108// reference.
109using on_gscan_results_callback = std::function<void(
110 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
111
Roshan Piusd4767542016-12-06 10:04:05 -0800112// Invoked when the rssi value breaches the thresholds set.
113using on_rssi_threshold_breached_callback =
114 std::function<void(wifi_request_id, std::array<uint8_t, 6>, int8_t)>;
115
Roshan Piusd8e915a2016-10-28 11:23:11 -0700116// Callback for RTT range request results.
117// Rtt results contain IE info and are hence passed by reference, to
118// preserve the |LCI| and |LCR| pointers. Callee must not retain
119// the pointer.
120using on_rtt_results_callback = std::function<void(
121 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
122
Roshan Pius8714a3e2016-10-28 10:43:51 -0700123// Callback for ring buffer data.
124using on_ring_buffer_data_callback =
125 std::function<void(const std::string&,
126 const std::vector<uint8_t>&,
127 const wifi_ring_buffer_status&)>;
128
Roshan Pius203cb032016-12-14 17:41:20 -0800129// Callback for alerts.
130using on_error_alert_callback =
131 std::function<void(int32_t, const std::vector<uint8_t>&)>;
Roshan Piusaabe5752016-09-29 09:03:59 -0700132/**
133 * Class that encapsulates all legacy HAL interactions.
134 * This class manages the lifetime of the event loop thread used by legacy HAL.
Roshan Pius742bb972017-02-02 09:54:27 -0800135 *
136 * Note: aThere will only be a single instance of this class created in the Wifi
137 * object and will be valid for the lifetime of the process.
Roshan Piusaabe5752016-09-29 09:03:59 -0700138 */
139class WifiLegacyHal {
140 public:
141 WifiLegacyHal();
Roshan Piusab5c4712016-10-06 14:37:15 -0700142 // Names to use for the different types of iface.
143 std::string getApIfaceName();
144 std::string getNanIfaceName();
145 std::string getP2pIfaceName();
146 std::string getStaIfaceName();
147
Roshan Pius97334112016-11-18 14:07:54 -0800148 // Initialize the legacy HAL function table.
149 wifi_error initialize();
150 // Start the legacy HAL and the event looper thread.
Roshan Piusaabe5752016-09-29 09:03:59 -0700151 wifi_error start();
152 // Deinitialize the legacy HAL and stop the event looper thread.
153 wifi_error stop(const std::function<void()>& on_complete_callback);
Roshan Pius4b26c832016-10-03 12:49:58 -0700154 // Wrappers for all the functions in the legacy HAL function table.
Roshan Piusab5c4712016-10-06 14:37:15 -0700155 std::pair<wifi_error, std::string> getDriverVersion();
156 std::pair<wifi_error, std::string> getFirmwareVersion();
Roshan Pius3c868522016-10-27 12:43:49 -0700157 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump();
158 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump();
Roshan Pius0a47c182016-10-28 10:23:00 -0700159 std::pair<wifi_error, uint32_t> getSupportedFeatureSet();
160 // APF functions.
161 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities();
162 wifi_error setPacketFilter(const std::vector<uint8_t>& program);
Roshan Pius76ff3022016-10-28 10:33:34 -0700163 // Gscan functions.
164 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities();
165 // These API's provides a simplified interface over the legacy Gscan API's:
166 // a) All scan events from the legacy HAL API other than the
167 // |WIFI_SCAN_FAILED| are treated as notification of results.
168 // This method then retrieves the cached scan results from the legacy
169 // HAL API and triggers the externally provided |on_results_user_callback|
170 // on success.
171 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results
172 // triggers the externally provided |on_failure_user_callback|.
173 // c) Full scan result event triggers the externally provided
174 // |on_full_result_user_callback|.
175 wifi_error startGscan(
176 wifi_request_id id,
177 const wifi_scan_cmd_params& params,
178 const std::function<void(wifi_request_id)>& on_failure_callback,
179 const on_gscan_results_callback& on_results_callback,
180 const on_gscan_full_result_callback& on_full_result_callback);
181 wifi_error stopGscan(wifi_request_id id);
Roshan Pius7f4574d2017-02-22 09:48:03 -0800182 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForBand(
Roshan Pius76ff3022016-10-28 10:33:34 -0700183 wifi_band band);
Roshan Pius7cece412016-10-28 10:38:21 -0700184 // Link layer stats functions.
185 wifi_error enableLinkLayerStats(bool debug);
186 wifi_error disableLinkLayerStats();
187 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats();
Roshan Piusd4767542016-12-06 10:04:05 -0800188 // RSSI monitor functions.
189 wifi_error startRssiMonitoring(wifi_request_id id,
190 int8_t max_rssi,
191 int8_t min_rssi,
192 const on_rssi_threshold_breached_callback&
193 on_threshold_breached_callback);
194 wifi_error stopRssiMonitoring(wifi_request_id id);
Roshan Pius26801cb2016-12-13 14:25:45 -0800195 std::pair<wifi_error, wifi_roaming_capabilities> getRoamingCapabilities();
Roshan Pius26801cb2016-12-13 14:25:45 -0800196 wifi_error configureRoaming(const wifi_roaming_config& config);
Roshan Piusaf727c02017-01-11 15:37:25 -0800197 wifi_error enableFirmwareRoaming(fw_roaming_state_t state);
198 wifi_error configureNdOffload(bool enable);
Roshan Pius9a9869a2017-01-11 16:42:16 -0800199 wifi_error startSendingOffloadedPacket(
200 uint32_t cmd_id,
201 const std::vector<uint8_t>& ip_packet_data,
202 const std::array<uint8_t, 6>& src_address,
203 const std::array<uint8_t, 6>& dst_address,
204 uint32_t period_in_ms);
205 wifi_error stopSendingOffloadedPacket(uint32_t cmd_id);
Roshan Pius795bb812017-02-01 13:09:08 -0800206 wifi_error setScanningMacOui(const std::array<uint8_t, 3>& oui);
Roshan Pius8714a3e2016-10-28 10:43:51 -0700207 // Logger/debug functions.
208 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet();
209 wifi_error startPktFateMonitoring();
210 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates();
211 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates();
212 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats();
213 wifi_error registerRingBufferCallbackHandler(
214 const on_ring_buffer_data_callback& on_data_callback);
Roshan Piusadc87cb2016-12-14 18:02:56 -0800215 wifi_error deregisterRingBufferCallbackHandler();
Roshan Pius8714a3e2016-10-28 10:43:51 -0700216 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
217 getRingBuffersStatus();
218 wifi_error startRingBufferLogging(const std::string& ring_name,
219 uint32_t verbose_level,
220 uint32_t max_interval_sec,
221 uint32_t min_data_size);
222 wifi_error getRingBufferData(const std::string& ring_name);
Roshan Pius203cb032016-12-14 17:41:20 -0800223 wifi_error registerErrorAlertCallbackHandler(
224 const on_error_alert_callback& on_alert_callback);
225 wifi_error deregisterErrorAlertCallbackHandler();
Roshan Piusd8e915a2016-10-28 11:23:11 -0700226 // RTT functions.
227 wifi_error startRttRangeRequest(
228 wifi_request_id id,
229 const std::vector<wifi_rtt_config>& rtt_configs,
230 const on_rtt_results_callback& on_results_callback);
231 wifi_error cancelRttRangeRequest(
232 wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs);
233 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities();
234 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo();
235 wifi_error enableRttResponder(wifi_request_id id,
236 const wifi_channel_info& channel_hint,
237 uint32_t max_duration_secs,
238 const wifi_rtt_responder& info);
239 wifi_error disableRttResponder(wifi_request_id id);
240 wifi_error setRttLci(wifi_request_id id, const wifi_lci_information& info);
241 wifi_error setRttLcr(wifi_request_id id, const wifi_lcr_information& info);
Roshan Pius23012092016-10-28 11:27:40 -0700242 // NAN functions.
243 wifi_error nanRegisterCallbackHandlers(const NanCallbackHandlers& callbacks);
244 wifi_error nanEnableRequest(transaction_id id, const NanEnableRequest& msg);
245 wifi_error nanDisableRequest(transaction_id id);
246 wifi_error nanPublishRequest(transaction_id id, const NanPublishRequest& msg);
247 wifi_error nanPublishCancelRequest(transaction_id id,
248 const NanPublishCancelRequest& msg);
249 wifi_error nanSubscribeRequest(transaction_id id,
250 const NanSubscribeRequest& msg);
251 wifi_error nanSubscribeCancelRequest(transaction_id id,
252 const NanSubscribeCancelRequest& msg);
253 wifi_error nanTransmitFollowupRequest(transaction_id id,
254 const NanTransmitFollowupRequest& msg);
255 wifi_error nanStatsRequest(transaction_id id, const NanStatsRequest& msg);
256 wifi_error nanConfigRequest(transaction_id id, const NanConfigRequest& msg);
257 wifi_error nanTcaRequest(transaction_id id, const NanTCARequest& msg);
258 wifi_error nanBeaconSdfPayloadRequest(transaction_id id,
259 const NanBeaconSdfPayloadRequest& msg);
260 std::pair<wifi_error, NanVersion> nanGetVersion();
261 wifi_error nanGetCapabilities(transaction_id id);
262 wifi_error nanDataInterfaceCreate(transaction_id id,
263 const std::string& iface_name);
264 wifi_error nanDataInterfaceDelete(transaction_id id,
265 const std::string& iface_name);
266 wifi_error nanDataRequestInitiator(transaction_id id,
267 const NanDataPathInitiatorRequest& msg);
268 wifi_error nanDataIndicationResponse(
269 transaction_id id, const NanDataPathIndicationResponse& msg);
270 wifi_error nanDataEnd(transaction_id id, const NanDataPathEndRequest& msg);
Roshan Pius32fc12e2017-01-25 17:44:42 -0800271 // AP functions.
272 wifi_error setCountryCode(std::array<int8_t, 2> code);
Roshan Piusaabe5752016-09-29 09:03:59 -0700273
274 private:
Roshan Piusaabe5752016-09-29 09:03:59 -0700275 // Retrieve the interface handle to be used for the "wlan" interface.
276 wifi_error retrieveWlanInterfaceHandle();
277 // Run the legacy HAL event loop thread.
278 void runEventLoop();
Roshan Pius76ff3022016-10-28 10:33:34 -0700279 // Retrieve the cached gscan results to pass the results back to the external
280 // callbacks.
281 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
282 getGscanCachedResults();
Roshan Pius511cc492016-10-28 09:54:26 -0700283 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700284
Roshan Piusaabe5752016-09-29 09:03:59 -0700285 // Global function table of legacy HAL.
286 wifi_hal_fn global_func_table_;
287 // Opaque handle to be used for all global operations.
288 wifi_handle global_handle_;
289 // Opaque handle to be used for all wlan0 interface specific operations.
290 wifi_interface_handle wlan_interface_handle_;
291 // Flag to indicate if we have initiated the cleanup of legacy HAL.
292 bool awaiting_event_loop_termination_;
Roshan Pius11f93032016-12-09 10:26:17 -0800293 // Flag to indicate if the legacy HAL has been started.
294 bool is_started_;
Roshan Pius97334112016-11-18 14:07:54 -0800295 wifi_system::InterfaceTool iface_tool_;
Roshan Piusaabe5752016-09-29 09:03:59 -0700296};
297
Roshan Pius955542e2016-10-28 09:42:44 -0700298} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700299} // namespace implementation
300} // namespace V1_0
301} // namespace wifi
302} // namespace hardware
303} // namespace android
304
Roshan Piuse73a5062016-12-12 08:53:34 -0800305#endif // WIFI_LEGACY_HAL_H_