blob: f0509dc19eb76e9e6c462396d06c10a529b2fbe4 [file] [log] [blame]
Gabriel Birenf3262f92022-07-15 23:25:39 +00001/*
2 * Copyright (C) 2022 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#include "wifi_sta_iface.h"
18
19#include <android-base/logging.h>
20
21#include "aidl_return_util.h"
22#include "aidl_struct_util.h"
23#include "wifi_status_util.h"
24
25namespace aidl {
26namespace android {
27namespace hardware {
28namespace wifi {
29using aidl_return_util::validateAndCall;
30
31WifiStaIface::WifiStaIface(const std::string& ifname,
32 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
33 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
34 : ifname_(ifname), legacy_hal_(legacy_hal), iface_util_(iface_util), is_valid_(true) {
35 // Turn on DFS channel usage for STA iface.
36 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDfsFlag(ifname_, true);
37 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
38 LOG(ERROR) << "Failed to set DFS flag; DFS channels may be unavailable.";
39 }
40}
41
42std::shared_ptr<WifiStaIface> WifiStaIface::create(
43 const std::string& ifname, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
44 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util) {
45 std::shared_ptr<WifiStaIface> ptr =
46 ndk::SharedRefBase::make<WifiStaIface>(ifname, legacy_hal, iface_util);
47 std::weak_ptr<WifiStaIface> weak_ptr_this(ptr);
48 ptr->setWeakPtr(weak_ptr_this);
49 return ptr;
50}
51
52void WifiStaIface::invalidate() {
53 legacy_hal_.reset();
54 event_cb_handler_.invalidate();
55 is_valid_ = false;
56}
57
58void WifiStaIface::setWeakPtr(std::weak_ptr<WifiStaIface> ptr) {
59 weak_ptr_this_ = ptr;
60}
61
62bool WifiStaIface::isValid() {
63 return is_valid_;
64}
65
66std::string WifiStaIface::getName() {
67 return ifname_;
68}
69
70std::set<std::shared_ptr<IWifiStaIfaceEventCallback>> WifiStaIface::getEventCallbacks() {
71 return event_cb_handler_.getCallbacks();
72}
73
74ndk::ScopedAStatus WifiStaIface::getName(std::string* _aidl_return) {
75 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
76 &WifiStaIface::getNameInternal, _aidl_return);
77}
78
79ndk::ScopedAStatus WifiStaIface::registerEventCallback(
80 const std::shared_ptr<IWifiStaIfaceEventCallback>& in_callback) {
81 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
82 &WifiStaIface::registerEventCallbackInternal, in_callback);
83}
84
Gabriel Biren2f862492023-03-09 19:13:07 +000085ndk::ScopedAStatus WifiStaIface::getFeatureSet(int32_t* _aidl_return) {
Gabriel Birenf3262f92022-07-15 23:25:39 +000086 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
Gabriel Biren2f862492023-03-09 19:13:07 +000087 &WifiStaIface::getFeatureSetInternal, _aidl_return);
Gabriel Birenf3262f92022-07-15 23:25:39 +000088}
89
90ndk::ScopedAStatus WifiStaIface::getApfPacketFilterCapabilities(
91 StaApfPacketFilterCapabilities* _aidl_return) {
92 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
93 &WifiStaIface::getApfPacketFilterCapabilitiesInternal, _aidl_return);
94}
95
96ndk::ScopedAStatus WifiStaIface::installApfPacketFilter(const std::vector<uint8_t>& in_program) {
97 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
98 &WifiStaIface::installApfPacketFilterInternal, in_program);
99}
100
101ndk::ScopedAStatus WifiStaIface::readApfPacketFilterData(std::vector<uint8_t>* _aidl_return) {
102 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
103 &WifiStaIface::readApfPacketFilterDataInternal, _aidl_return);
104}
105
106ndk::ScopedAStatus WifiStaIface::getBackgroundScanCapabilities(
107 StaBackgroundScanCapabilities* _aidl_return) {
108 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
109 &WifiStaIface::getBackgroundScanCapabilitiesInternal, _aidl_return);
110}
111
Gabriel Birenf3262f92022-07-15 23:25:39 +0000112ndk::ScopedAStatus WifiStaIface::startBackgroundScan(int32_t in_cmdId,
113 const StaBackgroundScanParameters& in_params) {
114 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
115 &WifiStaIface::startBackgroundScanInternal, in_cmdId, in_params);
116}
117
118ndk::ScopedAStatus WifiStaIface::stopBackgroundScan(int32_t in_cmdId) {
119 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
120 &WifiStaIface::stopBackgroundScanInternal, in_cmdId);
121}
122
123ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollection(bool in_debug) {
124 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
125 &WifiStaIface::enableLinkLayerStatsCollectionInternal, in_debug);
126}
127
128ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollection() {
129 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
130 &WifiStaIface::disableLinkLayerStatsCollectionInternal);
131}
132
133ndk::ScopedAStatus WifiStaIface::getLinkLayerStats(StaLinkLayerStats* _aidl_return) {
134 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
135 &WifiStaIface::getLinkLayerStatsInternal, _aidl_return);
136}
137
138ndk::ScopedAStatus WifiStaIface::startRssiMonitoring(int32_t in_cmdId, int32_t in_maxRssi,
139 int32_t in_minRssi) {
140 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
141 &WifiStaIface::startRssiMonitoringInternal, in_cmdId, in_maxRssi,
142 in_minRssi);
143}
144
145ndk::ScopedAStatus WifiStaIface::stopRssiMonitoring(int32_t in_cmdId) {
146 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
147 &WifiStaIface::stopRssiMonitoringInternal, in_cmdId);
148}
149
150ndk::ScopedAStatus WifiStaIface::getRoamingCapabilities(StaRoamingCapabilities* _aidl_return) {
151 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
152 &WifiStaIface::getRoamingCapabilitiesInternal, _aidl_return);
153}
154
155ndk::ScopedAStatus WifiStaIface::configureRoaming(const StaRoamingConfig& in_config) {
156 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
157 &WifiStaIface::configureRoamingInternal, in_config);
158}
159
160ndk::ScopedAStatus WifiStaIface::setRoamingState(StaRoamingState in_state) {
161 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
162 &WifiStaIface::setRoamingStateInternal, in_state);
163}
164
165ndk::ScopedAStatus WifiStaIface::enableNdOffload(bool in_enable) {
166 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
167 &WifiStaIface::enableNdOffloadInternal, in_enable);
168}
169
170ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePackets(
171 int32_t in_cmdId, const std::vector<uint8_t>& in_ipPacketData, char16_t in_etherType,
172 const std::array<uint8_t, 6>& in_srcAddress, const std::array<uint8_t, 6>& in_dstAddress,
173 int32_t in_periodInMs) {
174 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
175 &WifiStaIface::startSendingKeepAlivePacketsInternal, in_cmdId,
176 in_ipPacketData, in_etherType, in_srcAddress, in_dstAddress,
177 in_periodInMs);
178}
179
180ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePackets(int32_t in_cmdId) {
181 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
182 &WifiStaIface::stopSendingKeepAlivePacketsInternal, in_cmdId);
183}
184
185ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoring() {
186 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
187 &WifiStaIface::startDebugPacketFateMonitoringInternal);
188}
189
190ndk::ScopedAStatus WifiStaIface::getDebugTxPacketFates(
191 std::vector<WifiDebugTxPacketFateReport>* _aidl_return) {
192 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
193 &WifiStaIface::getDebugTxPacketFatesInternal, _aidl_return);
194}
195
196ndk::ScopedAStatus WifiStaIface::getDebugRxPacketFates(
197 std::vector<WifiDebugRxPacketFateReport>* _aidl_return) {
198 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
199 &WifiStaIface::getDebugRxPacketFatesInternal, _aidl_return);
200}
201
202ndk::ScopedAStatus WifiStaIface::setMacAddress(const std::array<uint8_t, 6>& in_mac) {
203 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
204 &WifiStaIface::setMacAddressInternal, in_mac);
205}
206
207ndk::ScopedAStatus WifiStaIface::getFactoryMacAddress(std::array<uint8_t, 6>* _aidl_return) {
208 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
209 &WifiStaIface::getFactoryMacAddressInternal, _aidl_return);
210}
211
212ndk::ScopedAStatus WifiStaIface::setScanMode(bool in_enable) {
213 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
214 &WifiStaIface::setScanModeInternal, in_enable);
215}
216
Kai Shi6d02d402022-11-17 16:34:05 -0800217ndk::ScopedAStatus WifiStaIface::setDtimMultiplier(int32_t in_multiplier) {
218 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
219 &WifiStaIface::setDtimMultiplierInternal, in_multiplier);
220}
221
Kai Shi7d0e5e92023-11-20 19:23:36 -0800222ndk::ScopedAStatus WifiStaIface::getCachedScanData(CachedScanData* _aidl_return) {
223 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
224 &WifiStaIface::getCachedScanDataInternal, _aidl_return);
225}
226
maheshkkv39903822023-11-28 15:31:53 -0800227ndk::ScopedAStatus WifiStaIface::twtGetCapabilities(TwtCapabilities* _aidl_return) {
228 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
229 &WifiStaIface::twtGetCapabilitiesInternal, _aidl_return);
230}
231
232ndk::ScopedAStatus WifiStaIface::twtSessionSetup(int32_t in_cmdId,
233 const TwtRequest& in_twtRequest) {
234 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
235 &WifiStaIface::twtSessionSetupInternal, in_cmdId, in_twtRequest);
236}
237
238ndk::ScopedAStatus WifiStaIface::twtSessionUpdate(int32_t in_cmdId, int32_t in_sessionId,
239 const TwtRequest& in_twtRequest) {
240 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
241 &WifiStaIface::twtSessionUpdateInternal, in_cmdId, in_sessionId,
242 in_twtRequest);
243}
244
245ndk::ScopedAStatus WifiStaIface::twtSessionSuspend(int32_t in_cmdId, int32_t in_sessionId) {
246 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
247 &WifiStaIface::twtSessionSuspendInternal, in_cmdId, in_sessionId);
248}
249
250ndk::ScopedAStatus WifiStaIface::twtSessionResume(int32_t in_cmdId, int32_t in_sessionId) {
251 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
252 &WifiStaIface::twtSessionResumeInternal, in_cmdId, in_sessionId);
253}
254
255ndk::ScopedAStatus WifiStaIface::twtSessionTeardown(int32_t in_cmdId, int32_t in_sessionId) {
256 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
257 &WifiStaIface::twtSessionTeardownInternal, in_cmdId, in_sessionId);
258}
259
260ndk::ScopedAStatus WifiStaIface::twtSessionGetStats(int32_t in_cmdId, int32_t in_sessionId) {
261 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID,
262 &WifiStaIface::twtSessionGetStatsInternal, in_cmdId, in_sessionId);
263}
264
Gabriel Birenf3262f92022-07-15 23:25:39 +0000265std::pair<std::string, ndk::ScopedAStatus> WifiStaIface::getNameInternal() {
266 return {ifname_, ndk::ScopedAStatus::ok()};
267}
268
269ndk::ScopedAStatus WifiStaIface::registerEventCallbackInternal(
270 const std::shared_ptr<IWifiStaIfaceEventCallback>& callback) {
271 if (!event_cb_handler_.addCallback(callback)) {
272 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
273 }
274 return ndk::ScopedAStatus::ok();
275}
276
Gabriel Biren2f862492023-03-09 19:13:07 +0000277std::pair<int32_t, ndk::ScopedAStatus> WifiStaIface::getFeatureSetInternal() {
Gabriel Birenf3262f92022-07-15 23:25:39 +0000278 legacy_hal::wifi_error legacy_status;
279 uint64_t legacy_feature_set;
280 std::tie(legacy_status, legacy_feature_set) =
281 legacy_hal_.lock()->getSupportedFeatureSet(ifname_);
282 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Gabriel Biren3b86a782023-02-04 00:42:53 +0000283 return {0, createWifiStatusFromLegacyError(legacy_status)};
Gabriel Birenf3262f92022-07-15 23:25:39 +0000284 }
Gabriel Biren2f862492023-03-09 19:13:07 +0000285 uint32_t aidl_feature_set;
286 if (!aidl_struct_util::convertLegacyStaIfaceFeaturesToAidl(legacy_feature_set,
287 &aidl_feature_set)) {
Gabriel Biren3b86a782023-02-04 00:42:53 +0000288 return {0, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
Gabriel Birenf3262f92022-07-15 23:25:39 +0000289 }
Gabriel Biren2f862492023-03-09 19:13:07 +0000290 return {aidl_feature_set, ndk::ScopedAStatus::ok()};
Gabriel Birenf3262f92022-07-15 23:25:39 +0000291}
292
293std::pair<StaApfPacketFilterCapabilities, ndk::ScopedAStatus>
294WifiStaIface::getApfPacketFilterCapabilitiesInternal() {
295 legacy_hal::wifi_error legacy_status;
296 legacy_hal::PacketFilterCapabilities legacy_caps;
297 std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getPacketFilterCapabilities(ifname_);
298 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
299 return {StaApfPacketFilterCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
300 }
301 StaApfPacketFilterCapabilities aidl_caps;
302 if (!aidl_struct_util::convertLegacyApfCapabilitiesToAidl(legacy_caps, &aidl_caps)) {
303 return {StaApfPacketFilterCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
304 }
305 return {aidl_caps, ndk::ScopedAStatus::ok()};
306}
307
308ndk::ScopedAStatus WifiStaIface::installApfPacketFilterInternal(
309 const std::vector<uint8_t>& program) {
310 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setPacketFilter(ifname_, program);
311 return createWifiStatusFromLegacyError(legacy_status);
312}
313
314std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
315WifiStaIface::readApfPacketFilterDataInternal() {
316 const std::pair<legacy_hal::wifi_error, std::vector<uint8_t>> legacy_status_and_data =
317 legacy_hal_.lock()->readApfPacketFilterData(ifname_);
318 return {std::move(legacy_status_and_data.second),
319 createWifiStatusFromLegacyError(legacy_status_and_data.first)};
320}
321
322std::pair<StaBackgroundScanCapabilities, ndk::ScopedAStatus>
323WifiStaIface::getBackgroundScanCapabilitiesInternal() {
324 legacy_hal::wifi_error legacy_status;
325 legacy_hal::wifi_gscan_capabilities legacy_caps;
326 std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getGscanCapabilities(ifname_);
327 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
328 return {StaBackgroundScanCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
329 }
330 StaBackgroundScanCapabilities aidl_caps;
331 if (!aidl_struct_util::convertLegacyGscanCapabilitiesToAidl(legacy_caps, &aidl_caps)) {
332 return {StaBackgroundScanCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
333 }
334 return {aidl_caps, ndk::ScopedAStatus::ok()};
335}
336
Gabriel Birenf3262f92022-07-15 23:25:39 +0000337ndk::ScopedAStatus WifiStaIface::startBackgroundScanInternal(
338 int32_t cmd_id, const StaBackgroundScanParameters& params) {
339 legacy_hal::wifi_scan_cmd_params legacy_params;
340 if (!aidl_struct_util::convertAidlGscanParamsToLegacy(params, &legacy_params)) {
341 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
342 }
343 std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
344 const auto& on_failure_callback = [weak_ptr_this](legacy_hal::wifi_request_id id) {
345 const auto shared_ptr_this = weak_ptr_this.lock();
346 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
347 LOG(ERROR) << "Callback invoked on an invalid object";
348 return;
349 }
350 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
351 if (!callback->onBackgroundScanFailure(id).isOk()) {
352 LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback";
353 }
354 }
355 };
356 const auto& on_results_callback =
357 [weak_ptr_this](legacy_hal::wifi_request_id id,
358 const std::vector<legacy_hal::wifi_cached_scan_results>& results) {
359 const auto shared_ptr_this = weak_ptr_this.lock();
360 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
361 LOG(ERROR) << "Callback invoked on an invalid object";
362 return;
363 }
364 std::vector<StaScanData> aidl_scan_datas;
365 if (!aidl_struct_util::convertLegacyVectorOfCachedGscanResultsToAidl(
366 results, &aidl_scan_datas)) {
367 LOG(ERROR) << "Failed to convert scan results to AIDL structs";
368 return;
369 }
370 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
371 if (!callback->onBackgroundScanResults(id, aidl_scan_datas).isOk()) {
372 LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback";
373 }
374 }
375 };
376 const auto& on_full_result_callback = [weak_ptr_this](
377 legacy_hal::wifi_request_id id,
378 const legacy_hal::wifi_scan_result* result,
379 uint32_t buckets_scanned) {
380 const auto shared_ptr_this = weak_ptr_this.lock();
381 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
382 LOG(ERROR) << "Callback invoked on an invalid object";
383 return;
384 }
385 StaScanResult aidl_scan_result;
386 if (!aidl_struct_util::convertLegacyGscanResultToAidl(*result, true, &aidl_scan_result)) {
387 LOG(ERROR) << "Failed to convert full scan results to AIDL structs";
388 return;
389 }
390 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
391 if (!callback->onBackgroundFullScanResult(id, buckets_scanned, aidl_scan_result)
392 .isOk()) {
393 LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback";
394 }
395 }
396 };
397 legacy_hal::wifi_error legacy_status =
398 legacy_hal_.lock()->startGscan(ifname_, cmd_id, legacy_params, on_failure_callback,
399 on_results_callback, on_full_result_callback);
400 return createWifiStatusFromLegacyError(legacy_status);
401}
402
403ndk::ScopedAStatus WifiStaIface::stopBackgroundScanInternal(int32_t cmd_id) {
404 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(ifname_, cmd_id);
405 return createWifiStatusFromLegacyError(legacy_status);
406}
407
408ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) {
409 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableLinkLayerStats(ifname_, debug);
410 return createWifiStatusFromLegacyError(legacy_status);
411}
412
413ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() {
414 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableLinkLayerStats(ifname_);
415 return createWifiStatusFromLegacyError(legacy_status);
416}
417
418std::pair<StaLinkLayerStats, ndk::ScopedAStatus> WifiStaIface::getLinkLayerStatsInternal() {
419 legacy_hal::wifi_error legacy_status;
Mahesh KKV5f30d332022-10-26 14:07:44 -0700420 legacy_hal::LinkLayerStats legacy_stats{};
421 legacy_hal::LinkLayerMlStats legacy_ml_stats{};
422 legacy_status = legacy_hal_.lock()->getLinkLayerStats(ifname_, legacy_stats, legacy_ml_stats);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000423 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
424 return {StaLinkLayerStats{}, createWifiStatusFromLegacyError(legacy_status)};
425 }
426 StaLinkLayerStats aidl_stats;
Mahesh KKV5f30d332022-10-26 14:07:44 -0700427 if (legacy_stats.valid) {
428 if (!aidl_struct_util::convertLegacyLinkLayerStatsToAidl(legacy_stats, &aidl_stats)) {
429 return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
430 }
431 } else if (legacy_ml_stats.valid) {
432 if (!aidl_struct_util::convertLegacyLinkLayerMlStatsToAidl(legacy_ml_stats, &aidl_stats)) {
433 return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
434 }
435 } else {
Gabriel Birenf3262f92022-07-15 23:25:39 +0000436 return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
437 }
438 return {aidl_stats, ndk::ScopedAStatus::ok()};
439}
440
441ndk::ScopedAStatus WifiStaIface::startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi,
442 int32_t min_rssi) {
443 std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
444 const auto& on_threshold_breached_callback =
445 [weak_ptr_this](legacy_hal::wifi_request_id id, std::array<uint8_t, ETH_ALEN> bssid,
446 int8_t rssi) {
447 const auto shared_ptr_this = weak_ptr_this.lock();
448 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
449 LOG(ERROR) << "Callback invoked on an invalid object";
450 return;
451 }
452 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
453 if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) {
454 LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback";
455 }
456 }
457 };
458 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring(
459 ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback);
460 return createWifiStatusFromLegacyError(legacy_status);
461}
462
463ndk::ScopedAStatus WifiStaIface::stopRssiMonitoringInternal(int32_t cmd_id) {
464 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id);
465 return createWifiStatusFromLegacyError(legacy_status);
466}
467
468std::pair<StaRoamingCapabilities, ndk::ScopedAStatus>
469WifiStaIface::getRoamingCapabilitiesInternal() {
470 legacy_hal::wifi_error legacy_status;
471 legacy_hal::wifi_roaming_capabilities legacy_caps;
472 std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_);
473 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
474 return {StaRoamingCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
475 }
476 StaRoamingCapabilities aidl_caps;
477 if (!aidl_struct_util::convertLegacyRoamingCapabilitiesToAidl(legacy_caps, &aidl_caps)) {
478 return {StaRoamingCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
479 }
480 return {aidl_caps, ndk::ScopedAStatus::ok()};
481}
482
483ndk::ScopedAStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) {
484 legacy_hal::wifi_roaming_config legacy_config;
485 if (!aidl_struct_util::convertAidlRoamingConfigToLegacy(config, &legacy_config)) {
486 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
487 }
488 legacy_hal::wifi_error legacy_status =
489 legacy_hal_.lock()->configureRoaming(ifname_, legacy_config);
490 return createWifiStatusFromLegacyError(legacy_status);
491}
492
493ndk::ScopedAStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) {
494 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming(
495 ifname_, aidl_struct_util::convertAidlRoamingStateToLegacy(state));
496 return createWifiStatusFromLegacyError(legacy_status);
497}
498
499ndk::ScopedAStatus WifiStaIface::enableNdOffloadInternal(bool enable) {
500 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable);
501 return createWifiStatusFromLegacyError(legacy_status);
502}
503
504ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePacketsInternal(
505 int32_t cmd_id, const std::vector<uint8_t>& ip_packet_data, char16_t ether_type,
506 const std::array<uint8_t, 6>& src_address, const std::array<uint8_t, 6>& dst_address,
507 int32_t period_in_ms) {
508 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket(
509 ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms);
510 return createWifiStatusFromLegacyError(legacy_status);
511}
512
513ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(int32_t cmd_id) {
514 legacy_hal::wifi_error legacy_status =
515 legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id);
516 return createWifiStatusFromLegacyError(legacy_status);
517}
518
519ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoringInternal() {
520 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_);
521 return createWifiStatusFromLegacyError(legacy_status);
522}
523
524std::pair<std::vector<WifiDebugTxPacketFateReport>, ndk::ScopedAStatus>
525WifiStaIface::getDebugTxPacketFatesInternal() {
526 legacy_hal::wifi_error legacy_status;
527 std::vector<legacy_hal::wifi_tx_report> legacy_fates;
528 std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_);
529 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
530 return {std::vector<WifiDebugTxPacketFateReport>(),
531 createWifiStatusFromLegacyError(legacy_status)};
532 }
533 std::vector<WifiDebugTxPacketFateReport> aidl_fates;
534 if (!aidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToAidl(legacy_fates,
535 &aidl_fates)) {
536 return {std::vector<WifiDebugTxPacketFateReport>(),
537 createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
538 }
539 return {aidl_fates, ndk::ScopedAStatus::ok()};
540}
541
542std::pair<std::vector<WifiDebugRxPacketFateReport>, ndk::ScopedAStatus>
543WifiStaIface::getDebugRxPacketFatesInternal() {
544 legacy_hal::wifi_error legacy_status;
545 std::vector<legacy_hal::wifi_rx_report> legacy_fates;
546 std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_);
547 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
548 return {std::vector<WifiDebugRxPacketFateReport>(),
549 createWifiStatusFromLegacyError(legacy_status)};
550 }
551 std::vector<WifiDebugRxPacketFateReport> aidl_fates;
552 if (!aidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToAidl(legacy_fates,
553 &aidl_fates)) {
554 return {std::vector<WifiDebugRxPacketFateReport>(),
555 createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
556 }
557 return {aidl_fates, ndk::ScopedAStatus::ok()};
558}
559
560ndk::ScopedAStatus WifiStaIface::setMacAddressInternal(const std::array<uint8_t, 6>& mac) {
561 bool status = iface_util_.lock()->setMacAddress(ifname_, mac);
562 if (!status) {
563 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
564 }
565 return ndk::ScopedAStatus::ok();
566}
567
568std::pair<std::array<uint8_t, 6>, ndk::ScopedAStatus> WifiStaIface::getFactoryMacAddressInternal() {
569 std::array<uint8_t, 6> mac = iface_util_.lock()->getFactoryMacAddress(ifname_);
570 if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) {
571 return {mac, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
572 }
573 return {mac, ndk::ScopedAStatus::ok()};
574}
575
576ndk::ScopedAStatus WifiStaIface::setScanModeInternal(bool enable) {
Ye Jiao50274f72023-01-17 14:53:22 +0800577 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setScanMode(ifname_, enable);
578 return createWifiStatusFromLegacyError(legacy_status);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000579}
580
Kai Shi6d02d402022-11-17 16:34:05 -0800581ndk::ScopedAStatus WifiStaIface::setDtimMultiplierInternal(const int multiplier) {
582 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDtimConfig(ifname_, multiplier);
583 return createWifiStatusFromLegacyError(legacy_status);
584}
585
Kai Shi7d0e5e92023-11-20 19:23:36 -0800586std::pair<CachedScanData, ndk::ScopedAStatus> WifiStaIface::getCachedScanDataInternal() {
587 legacy_hal::WifiCachedScanReport cached_scan_report;
588 legacy_hal::wifi_error legacy_status =
589 legacy_hal_.lock()->getWifiCachedScanResults(ifname_, cached_scan_report);
590 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
591 return {CachedScanData{}, createWifiStatusFromLegacyError(legacy_status)};
592 }
593 CachedScanData aidl_scan_data;
594 if (!aidl_struct_util::convertCachedScanReportToAidl(cached_scan_report, &aidl_scan_data)) {
595 return {CachedScanData{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
596 }
597
598 return {aidl_scan_data, ndk::ScopedAStatus::ok()};
599}
600
maheshkkv39903822023-11-28 15:31:53 -0800601std::pair<TwtCapabilities, ndk::ScopedAStatus> WifiStaIface::twtGetCapabilitiesInternal() {
602 legacy_hal::wifi_twt_capabilities legacyHaltwtCapabilities;
603 legacy_hal::wifi_error legacy_status;
604 std::tie(legacyHaltwtCapabilities, legacy_status) =
605 legacy_hal_.lock()->twtGetCapabilities(ifname_);
606 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
607 return {TwtCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
608 }
609 TwtCapabilities aidlTwtCapabilities;
610 if (!aidl_struct_util::convertTwtCapabilitiesToAidl(legacyHaltwtCapabilities,
611 &aidlTwtCapabilities)) {
612 return {TwtCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)};
613 }
614 return {aidlTwtCapabilities, ndk::ScopedAStatus::ok()};
615}
616
617ndk::ScopedAStatus WifiStaIface::twtSessionSetupInternal(int32_t cmdId,
618 const TwtRequest& aidlTwtRequest) {
619 legacy_hal::wifi_twt_request legacyHalTwtRequest;
620 if (!aidl_struct_util::convertAidlTwtRequestToLegacy(aidlTwtRequest, &legacyHalTwtRequest)) {
621 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
622 }
623 std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
624
625 // onTwtFailure callback
626 const auto& on_twt_failure = [weak_ptr_this](legacy_hal::wifi_request_id id,
627 legacy_hal::wifi_twt_error_code error_code) {
628 const auto shared_ptr_this = weak_ptr_this.lock();
629 IWifiStaIfaceEventCallback::TwtErrorCode aidl_error_code =
630 aidl_struct_util::convertLegacyHalTwtErrorCodeToAidl(error_code);
631 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
632 LOG(ERROR) << "Callback invoked on an invalid object";
633 return;
634 }
635 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
636 if (!callback->onTwtFailure(id, aidl_error_code).isOk()) {
637 LOG(ERROR) << "Failed to invoke onTwtFailure callback";
638 }
639 }
640 };
641 // onTwtSessionCreate callback
642 const auto& on_twt_session_create = [weak_ptr_this](legacy_hal::wifi_request_id id,
643 legacy_hal::wifi_twt_session twt_session) {
644 const auto shared_ptr_this = weak_ptr_this.lock();
645 TwtSession aidl_twt_session;
646 if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
647 LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
648 return;
649 }
650
651 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
652 LOG(ERROR) << "Callback invoked on an invalid object";
653 return;
654 }
655 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
656 if (!callback->onTwtSessionCreate(id, aidl_twt_session).isOk()) {
657 LOG(ERROR) << "Failed to invoke onTwtSessionCreate callback";
658 }
659 }
660 };
661 // onTwtSessionUpdate callback
662 const auto& on_twt_session_update = [weak_ptr_this](legacy_hal::wifi_request_id id,
663 legacy_hal::wifi_twt_session twt_session) {
664 const auto shared_ptr_this = weak_ptr_this.lock();
665 TwtSession aidl_twt_session;
666 if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
667 LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
668 return;
669 }
670
671 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
672 LOG(ERROR) << "Callback invoked on an invalid object";
673 return;
674 }
675 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
676 if (!callback->onTwtSessionUpdate(id, aidl_twt_session).isOk()) {
677 LOG(ERROR) << "Failed to invoke onTwtSessionUpdate callback";
678 }
679 }
680 };
681 // onTwtSessionTeardown callback
682 const auto& on_twt_session_teardown =
683 [weak_ptr_this](legacy_hal::wifi_request_id id, int session_id,
684 legacy_hal::wifi_twt_teardown_reason_code reason_code) {
685 const auto shared_ptr_this = weak_ptr_this.lock();
686 IWifiStaIfaceEventCallback::TwtTeardownReasonCode aidl_reason_code =
687 aidl_struct_util::convertLegacyHalTwtReasonCodeToAidl(reason_code);
688 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
689 LOG(ERROR) << "Callback invoked on an invalid object";
690 return;
691 }
692 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
693 if (!callback->onTwtSessionTeardown(id, session_id, aidl_reason_code).isOk()) {
694 LOG(ERROR) << "Failed to invoke onTwtSessionTeardown callback";
695 }
696 }
697 };
698 // onTwtSessionStats callback
699 const auto& on_twt_session_stats = [weak_ptr_this](legacy_hal::wifi_request_id id,
700 int session_id,
701 legacy_hal::wifi_twt_session_stats stats) {
702 const auto shared_ptr_this = weak_ptr_this.lock();
703 TwtSessionStats aidl_session_stats;
704 if (!aidl_struct_util::convertLegacyHalTwtSessionStatsToAidl(stats, &aidl_session_stats)) {
705 LOG(ERROR) << "convertLegacyHalTwtSessionStatsToAidl failed";
706 return;
707 }
708 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
709 LOG(ERROR) << "Callback invoked on an invalid object";
710 return;
711 }
712 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
713 if (!callback->onTwtSessionStats(id, session_id, aidl_session_stats).isOk()) {
714 LOG(ERROR) << "Failed to invoke onTwtSessionStats callback";
715 }
716 }
717 };
718 // onTwtSessionSuspend callback
719 const auto& on_twt_session_suspend = [weak_ptr_this](legacy_hal::wifi_request_id id,
720 int session_id) {
721 const auto shared_ptr_this = weak_ptr_this.lock();
722 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
723 LOG(ERROR) << "Callback invoked on an invalid object";
724 return;
725 }
726 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
727 if (!callback->onTwtSessionSuspend(id, session_id).isOk()) {
728 LOG(ERROR) << "Failed to invoke onTwtSessionSuspend callback";
729 }
730 }
731 };
732 // onTwtSessionResume callback
733 const auto& on_twt_session_resume = [weak_ptr_this](legacy_hal::wifi_request_id id,
734 int session_id) {
735 const auto shared_ptr_this = weak_ptr_this.lock();
736 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
737 LOG(ERROR) << "Callback invoked on an invalid object";
738 return;
739 }
740 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
741 if (!callback->onTwtSessionResume(id, session_id).isOk()) {
742 LOG(ERROR) << "Failed to invoke onTwtSessionResume callback";
743 }
744 }
745 };
746
747 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->twtSessionSetup(
748 ifname_, cmdId, legacyHalTwtRequest, on_twt_failure, on_twt_session_create,
749 on_twt_session_update, on_twt_session_teardown, on_twt_session_stats,
750 on_twt_session_suspend, on_twt_session_resume);
751 return createWifiStatusFromLegacyError(legacy_status);
752}
753
754ndk::ScopedAStatus WifiStaIface::twtSessionUpdateInternal(int32_t cmdId, int32_t sessionId,
755 const TwtRequest& aidlTwtRequest) {
756 legacy_hal::wifi_twt_request legacyHalTwtRequest;
757 if (!aidl_struct_util::convertAidlTwtRequestToLegacy(aidlTwtRequest, &legacyHalTwtRequest)) {
758 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
759 }
760 legacy_hal::wifi_error legacy_status =
761 legacy_hal_.lock()->twtSessionUpdate(ifname_, cmdId, sessionId, legacyHalTwtRequest);
762 return createWifiStatusFromLegacyError(legacy_status);
763}
764
765ndk::ScopedAStatus WifiStaIface::twtSessionSuspendInternal(int32_t cmdId, int32_t sessionId) {
766 legacy_hal::wifi_error legacy_status =
767 legacy_hal_.lock()->twtSessionSuspend(ifname_, cmdId, sessionId);
768 return createWifiStatusFromLegacyError(legacy_status);
769}
770
771ndk::ScopedAStatus WifiStaIface::twtSessionResumeInternal(int32_t cmdId, int32_t sessionId) {
772 legacy_hal::wifi_error legacy_status =
773 legacy_hal_.lock()->twtSessionResume(ifname_, cmdId, sessionId);
774 return createWifiStatusFromLegacyError(legacy_status);
775}
776
777ndk::ScopedAStatus WifiStaIface::twtSessionTeardownInternal(int32_t cmdId, int32_t sessionId) {
778 legacy_hal::wifi_error legacy_status =
779 legacy_hal_.lock()->twtSessionTeardown(ifname_, cmdId, sessionId);
780 return createWifiStatusFromLegacyError(legacy_status);
781}
782
783ndk::ScopedAStatus WifiStaIface::twtSessionGetStatsInternal(int32_t cmdId, int32_t sessionId) {
784 legacy_hal::wifi_error legacy_status =
785 legacy_hal_.lock()->twtSessionGetStats(ifname_, cmdId, sessionId);
786 return createWifiStatusFromLegacyError(legacy_status);
787}
788
Gabriel Birenf3262f92022-07-15 23:25:39 +0000789} // namespace wifi
790} // namespace hardware
791} // namespace android
792} // namespace aidl