blob: 62b773eb1599408cd65811ce1ea9049563364790 [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
17#ifndef WIFI_LEGACY_WIFI_HAL_H_
18#define WIFI_LEGACY_WIFI_HAL_H_
19
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 Piusaabe5752016-09-29 09:03:59 -070024namespace android {
25namespace hardware {
26namespace wifi {
27namespace V1_0 {
28namespace implementation {
Roshan Pius955542e2016-10-28 09:42:44 -070029// This is in a separate namespace to prevent typename conflicts between
30// the legacy HAL types and the HIDL interface types.
31namespace legacy_hal {
32// Wrap all the types defined inside the legacy HAL header files inside this
33// namespace.
34#include <hardware_legacy/wifi_hal.h>
Roshan Piusaabe5752016-09-29 09:03:59 -070035
Roshan Pius0a47c182016-10-28 10:23:00 -070036// APF capabilities supported by the iface.
37struct PacketFilterCapabilities {
38 uint32_t version;
39 uint32_t max_len;
40};
41
Roshan Pius7cece412016-10-28 10:38:21 -070042// WARNING: We don't care about the variable sized members of either
43// |wifi_iface_stat|, |wifi_radio_stat| structures. So, using the pragma
44// to escape the compiler warnings regarding this.
45#pragma GCC diagnostic push
46#pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
47// The |wifi_radio_stat.tx_time_per_levels| stats is provided as a pointer in
48// |wifi_radio_stat| structure in the legacy HAL API. Separate that out
49// into a separate return element to avoid passing pointers around.
50struct LinkLayerStats {
51 wifi_iface_stat iface;
52 wifi_radio_stat radio;
53 std::vector<uint32_t> radio_tx_time_per_levels;
54};
55#pragma GCC diagnostic pop
56
Roshan Pius8714a3e2016-10-28 10:43:51 -070057// The |WLAN_DRIVER_WAKE_REASON_CNT.cmd_event_wake_cnt| and
58// |WLAN_DRIVER_WAKE_REASON_CNT.driver_fw_local_wake_cnt| stats is provided
59// as a pointer in |WLAN_DRIVER_WAKE_REASON_CNT| structure in the legacy HAL
60// API. Separate that out into a separate return elements to avoid passing
61// pointers around.
62struct WakeReasonStats {
63 WLAN_DRIVER_WAKE_REASON_CNT wake_reason_cnt;
64 std::vector<uint32_t> cmd_event_wake_cnt;
65 std::vector<uint32_t> driver_fw_local_wake_cnt;
66};
67
Roshan Pius23012092016-10-28 11:27:40 -070068// NAN response and event callbacks struct.
69struct NanCallbackHandlers {
70 // NotifyResponse invoked to notify the status of the Request.
71 std::function<void(transaction_id, const NanResponseMsg&)> on_notify_response;
72 // Various event callbacks.
73 std::function<void(const NanPublishTerminatedInd&)>
74 on_event_publish_terminated;
75 std::function<void(const NanMatchInd&)> on_event_match;
76 std::function<void(const NanMatchExpiredInd&)> on_event_match_expired;
77 std::function<void(const NanSubscribeTerminatedInd&)>
78 on_event_subscribe_terminated;
79 std::function<void(const NanFollowupInd&)> on_event_followup;
80 std::function<void(const NanDiscEngEventInd&)> on_event_disc_eng_event;
81 std::function<void(const NanDisabledInd&)> on_event_disabled;
82 std::function<void(const NanTCAInd&)> on_event_tca;
83 std::function<void(const NanBeaconSdfPayloadInd&)>
84 on_event_beacon_sdf_payload;
85 std::function<void(const NanDataPathRequestInd&)> on_event_data_path_request;
86 std::function<void(const NanDataPathConfirmInd&)> on_event_data_path_confirm;
87 std::function<void(const NanDataPathEndInd&)> on_event_data_path_end;
88 std::function<void(const NanTransmitFollowupInd&)>
89 on_event_transmit_follow_up;
90};
91
Roshan Pius76ff3022016-10-28 10:33:34 -070092// Full scan results contain IE info and are hence passed by reference, to
93// preserve the variable length array member |ie_data|. Callee must not retain
94// the pointer.
95using on_gscan_full_result_callback =
96 std::function<void(wifi_request_id, const wifi_scan_result*, uint32_t)>;
97// These scan results don't contain any IE info, so no need to pass by
98// reference.
99using on_gscan_results_callback = std::function<void(
100 wifi_request_id, const std::vector<wifi_cached_scan_results>&)>;
101
Roshan Piusd8e915a2016-10-28 11:23:11 -0700102// Callback for RTT range request results.
103// Rtt results contain IE info and are hence passed by reference, to
104// preserve the |LCI| and |LCR| pointers. Callee must not retain
105// the pointer.
106using on_rtt_results_callback = std::function<void(
107 wifi_request_id, const std::vector<const wifi_rtt_result*>&)>;
108
Roshan Pius8714a3e2016-10-28 10:43:51 -0700109// Callback for ring buffer data.
110using on_ring_buffer_data_callback =
111 std::function<void(const std::string&,
112 const std::vector<uint8_t>&,
113 const wifi_ring_buffer_status&)>;
114
Roshan Piusaabe5752016-09-29 09:03:59 -0700115/**
116 * Class that encapsulates all legacy HAL interactions.
117 * This class manages the lifetime of the event loop thread used by legacy HAL.
118 */
119class WifiLegacyHal {
120 public:
121 WifiLegacyHal();
Roshan Piusab5c4712016-10-06 14:37:15 -0700122 // Names to use for the different types of iface.
123 std::string getApIfaceName();
124 std::string getNanIfaceName();
125 std::string getP2pIfaceName();
126 std::string getStaIfaceName();
127
Roshan Piusaabe5752016-09-29 09:03:59 -0700128 // Initialize the legacy HAL and start the event looper thread.
129 wifi_error start();
130 // Deinitialize the legacy HAL and stop the event looper thread.
131 wifi_error stop(const std::function<void()>& on_complete_callback);
Roshan Pius4b26c832016-10-03 12:49:58 -0700132 // Wrappers for all the functions in the legacy HAL function table.
Roshan Piusab5c4712016-10-06 14:37:15 -0700133 std::pair<wifi_error, std::string> getDriverVersion();
134 std::pair<wifi_error, std::string> getFirmwareVersion();
Roshan Pius3c868522016-10-27 12:43:49 -0700135 std::pair<wifi_error, std::vector<uint8_t>> requestDriverMemoryDump();
136 std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump();
Roshan Pius0a47c182016-10-28 10:23:00 -0700137 std::pair<wifi_error, uint32_t> getSupportedFeatureSet();
138 // APF functions.
139 std::pair<wifi_error, PacketFilterCapabilities> getPacketFilterCapabilities();
140 wifi_error setPacketFilter(const std::vector<uint8_t>& program);
Roshan Pius76ff3022016-10-28 10:33:34 -0700141 // Gscan functions.
142 std::pair<wifi_error, wifi_gscan_capabilities> getGscanCapabilities();
143 // These API's provides a simplified interface over the legacy Gscan API's:
144 // a) All scan events from the legacy HAL API other than the
145 // |WIFI_SCAN_FAILED| are treated as notification of results.
146 // This method then retrieves the cached scan results from the legacy
147 // HAL API and triggers the externally provided |on_results_user_callback|
148 // on success.
149 // b) |WIFI_SCAN_FAILED| scan event or failure to retrieve cached scan results
150 // triggers the externally provided |on_failure_user_callback|.
151 // c) Full scan result event triggers the externally provided
152 // |on_full_result_user_callback|.
153 wifi_error startGscan(
154 wifi_request_id id,
155 const wifi_scan_cmd_params& params,
156 const std::function<void(wifi_request_id)>& on_failure_callback,
157 const on_gscan_results_callback& on_results_callback,
158 const on_gscan_full_result_callback& on_full_result_callback);
159 wifi_error stopGscan(wifi_request_id id);
160 std::pair<wifi_error, std::vector<uint32_t>> getValidFrequenciesForGscan(
161 wifi_band band);
Roshan Pius7cece412016-10-28 10:38:21 -0700162 // Link layer stats functions.
163 wifi_error enableLinkLayerStats(bool debug);
164 wifi_error disableLinkLayerStats();
165 std::pair<wifi_error, LinkLayerStats> getLinkLayerStats();
Roshan Pius8714a3e2016-10-28 10:43:51 -0700166 // Logger/debug functions.
167 std::pair<wifi_error, uint32_t> getLoggerSupportedFeatureSet();
168 wifi_error startPktFateMonitoring();
169 std::pair<wifi_error, std::vector<wifi_tx_report>> getTxPktFates();
170 std::pair<wifi_error, std::vector<wifi_rx_report>> getRxPktFates();
171 std::pair<wifi_error, WakeReasonStats> getWakeReasonStats();
172 wifi_error registerRingBufferCallbackHandler(
173 const on_ring_buffer_data_callback& on_data_callback);
174 std::pair<wifi_error, std::vector<wifi_ring_buffer_status>>
175 getRingBuffersStatus();
176 wifi_error startRingBufferLogging(const std::string& ring_name,
177 uint32_t verbose_level,
178 uint32_t max_interval_sec,
179 uint32_t min_data_size);
180 wifi_error getRingBufferData(const std::string& ring_name);
Roshan Piusd8e915a2016-10-28 11:23:11 -0700181 // RTT functions.
182 wifi_error startRttRangeRequest(
183 wifi_request_id id,
184 const std::vector<wifi_rtt_config>& rtt_configs,
185 const on_rtt_results_callback& on_results_callback);
186 wifi_error cancelRttRangeRequest(
187 wifi_request_id id, const std::vector<std::array<uint8_t, 6>>& mac_addrs);
188 std::pair<wifi_error, wifi_rtt_capabilities> getRttCapabilities();
189 std::pair<wifi_error, wifi_rtt_responder> getRttResponderInfo();
190 wifi_error enableRttResponder(wifi_request_id id,
191 const wifi_channel_info& channel_hint,
192 uint32_t max_duration_secs,
193 const wifi_rtt_responder& info);
194 wifi_error disableRttResponder(wifi_request_id id);
195 wifi_error setRttLci(wifi_request_id id, const wifi_lci_information& info);
196 wifi_error setRttLcr(wifi_request_id id, const wifi_lcr_information& info);
Roshan Pius23012092016-10-28 11:27:40 -0700197 // NAN functions.
198 wifi_error nanRegisterCallbackHandlers(const NanCallbackHandlers& callbacks);
199 wifi_error nanEnableRequest(transaction_id id, const NanEnableRequest& msg);
200 wifi_error nanDisableRequest(transaction_id id);
201 wifi_error nanPublishRequest(transaction_id id, const NanPublishRequest& msg);
202 wifi_error nanPublishCancelRequest(transaction_id id,
203 const NanPublishCancelRequest& msg);
204 wifi_error nanSubscribeRequest(transaction_id id,
205 const NanSubscribeRequest& msg);
206 wifi_error nanSubscribeCancelRequest(transaction_id id,
207 const NanSubscribeCancelRequest& msg);
208 wifi_error nanTransmitFollowupRequest(transaction_id id,
209 const NanTransmitFollowupRequest& msg);
210 wifi_error nanStatsRequest(transaction_id id, const NanStatsRequest& msg);
211 wifi_error nanConfigRequest(transaction_id id, const NanConfigRequest& msg);
212 wifi_error nanTcaRequest(transaction_id id, const NanTCARequest& msg);
213 wifi_error nanBeaconSdfPayloadRequest(transaction_id id,
214 const NanBeaconSdfPayloadRequest& msg);
215 std::pair<wifi_error, NanVersion> nanGetVersion();
216 wifi_error nanGetCapabilities(transaction_id id);
217 wifi_error nanDataInterfaceCreate(transaction_id id,
218 const std::string& iface_name);
219 wifi_error nanDataInterfaceDelete(transaction_id id,
220 const std::string& iface_name);
221 wifi_error nanDataRequestInitiator(transaction_id id,
222 const NanDataPathInitiatorRequest& msg);
223 wifi_error nanDataIndicationResponse(
224 transaction_id id, const NanDataPathIndicationResponse& msg);
225 wifi_error nanDataEnd(transaction_id id, const NanDataPathEndRequest& msg);
Roshan Piusaabe5752016-09-29 09:03:59 -0700226
227 private:
Roshan Piusaabe5752016-09-29 09:03:59 -0700228 // Retrieve the interface handle to be used for the "wlan" interface.
229 wifi_error retrieveWlanInterfaceHandle();
230 // Run the legacy HAL event loop thread.
231 void runEventLoop();
Roshan Pius76ff3022016-10-28 10:33:34 -0700232 // Retrieve the cached gscan results to pass the results back to the external
233 // callbacks.
234 std::pair<wifi_error, std::vector<wifi_cached_scan_results>>
235 getGscanCachedResults();
Roshan Pius511cc492016-10-28 09:54:26 -0700236 void invalidate();
Roshan Piusaabe5752016-09-29 09:03:59 -0700237
238 // Event loop thread used by legacy HAL.
239 std::thread event_loop_thread_;
240 // Global function table of legacy HAL.
241 wifi_hal_fn global_func_table_;
242 // Opaque handle to be used for all global operations.
243 wifi_handle global_handle_;
244 // Opaque handle to be used for all wlan0 interface specific operations.
245 wifi_interface_handle wlan_interface_handle_;
246 // Flag to indicate if we have initiated the cleanup of legacy HAL.
247 bool awaiting_event_loop_termination_;
248};
249
Roshan Pius955542e2016-10-28 09:42:44 -0700250} // namespace legacy_hal
Roshan Piusaabe5752016-09-29 09:03:59 -0700251} // namespace implementation
252} // namespace V1_0
253} // namespace wifi
254} // namespace hardware
255} // namespace android
256
257#endif // WIFI_LEGACY_WIFI_HAL_H_