blob: aee183d429d9fff8fb2a751b483c4ed6009f50f8 [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 }
Gabriel Biren2ccf70f2024-02-14 22:52:58 +0000438 aidl_struct_util::logAidlLinkLayerStatsSize(aidl_stats);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000439 return {aidl_stats, ndk::ScopedAStatus::ok()};
440}
441
442ndk::ScopedAStatus WifiStaIface::startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi,
443 int32_t min_rssi) {
444 std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
445 const auto& on_threshold_breached_callback =
446 [weak_ptr_this](legacy_hal::wifi_request_id id, std::array<uint8_t, ETH_ALEN> bssid,
447 int8_t rssi) {
448 const auto shared_ptr_this = weak_ptr_this.lock();
449 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
450 LOG(ERROR) << "Callback invoked on an invalid object";
451 return;
452 }
453 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
454 if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) {
455 LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback";
456 }
457 }
458 };
459 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring(
460 ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback);
461 return createWifiStatusFromLegacyError(legacy_status);
462}
463
464ndk::ScopedAStatus WifiStaIface::stopRssiMonitoringInternal(int32_t cmd_id) {
465 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id);
466 return createWifiStatusFromLegacyError(legacy_status);
467}
468
469std::pair<StaRoamingCapabilities, ndk::ScopedAStatus>
470WifiStaIface::getRoamingCapabilitiesInternal() {
471 legacy_hal::wifi_error legacy_status;
472 legacy_hal::wifi_roaming_capabilities legacy_caps;
473 std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_);
474 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
475 return {StaRoamingCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
476 }
477 StaRoamingCapabilities aidl_caps;
478 if (!aidl_struct_util::convertLegacyRoamingCapabilitiesToAidl(legacy_caps, &aidl_caps)) {
479 return {StaRoamingCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
480 }
481 return {aidl_caps, ndk::ScopedAStatus::ok()};
482}
483
484ndk::ScopedAStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) {
485 legacy_hal::wifi_roaming_config legacy_config;
486 if (!aidl_struct_util::convertAidlRoamingConfigToLegacy(config, &legacy_config)) {
487 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
488 }
489 legacy_hal::wifi_error legacy_status =
490 legacy_hal_.lock()->configureRoaming(ifname_, legacy_config);
491 return createWifiStatusFromLegacyError(legacy_status);
492}
493
494ndk::ScopedAStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) {
495 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming(
496 ifname_, aidl_struct_util::convertAidlRoamingStateToLegacy(state));
497 return createWifiStatusFromLegacyError(legacy_status);
498}
499
500ndk::ScopedAStatus WifiStaIface::enableNdOffloadInternal(bool enable) {
501 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable);
502 return createWifiStatusFromLegacyError(legacy_status);
503}
504
505ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePacketsInternal(
506 int32_t cmd_id, const std::vector<uint8_t>& ip_packet_data, char16_t ether_type,
507 const std::array<uint8_t, 6>& src_address, const std::array<uint8_t, 6>& dst_address,
508 int32_t period_in_ms) {
509 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket(
510 ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms);
511 return createWifiStatusFromLegacyError(legacy_status);
512}
513
514ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(int32_t cmd_id) {
515 legacy_hal::wifi_error legacy_status =
516 legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id);
517 return createWifiStatusFromLegacyError(legacy_status);
518}
519
520ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoringInternal() {
521 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_);
522 return createWifiStatusFromLegacyError(legacy_status);
523}
524
525std::pair<std::vector<WifiDebugTxPacketFateReport>, ndk::ScopedAStatus>
526WifiStaIface::getDebugTxPacketFatesInternal() {
527 legacy_hal::wifi_error legacy_status;
528 std::vector<legacy_hal::wifi_tx_report> legacy_fates;
529 std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_);
530 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
531 return {std::vector<WifiDebugTxPacketFateReport>(),
532 createWifiStatusFromLegacyError(legacy_status)};
533 }
534 std::vector<WifiDebugTxPacketFateReport> aidl_fates;
535 if (!aidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToAidl(legacy_fates,
536 &aidl_fates)) {
537 return {std::vector<WifiDebugTxPacketFateReport>(),
538 createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
539 }
540 return {aidl_fates, ndk::ScopedAStatus::ok()};
541}
542
543std::pair<std::vector<WifiDebugRxPacketFateReport>, ndk::ScopedAStatus>
544WifiStaIface::getDebugRxPacketFatesInternal() {
545 legacy_hal::wifi_error legacy_status;
546 std::vector<legacy_hal::wifi_rx_report> legacy_fates;
547 std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_);
548 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
549 return {std::vector<WifiDebugRxPacketFateReport>(),
550 createWifiStatusFromLegacyError(legacy_status)};
551 }
552 std::vector<WifiDebugRxPacketFateReport> aidl_fates;
553 if (!aidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToAidl(legacy_fates,
554 &aidl_fates)) {
555 return {std::vector<WifiDebugRxPacketFateReport>(),
556 createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
557 }
558 return {aidl_fates, ndk::ScopedAStatus::ok()};
559}
560
561ndk::ScopedAStatus WifiStaIface::setMacAddressInternal(const std::array<uint8_t, 6>& mac) {
562 bool status = iface_util_.lock()->setMacAddress(ifname_, mac);
563 if (!status) {
564 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
565 }
566 return ndk::ScopedAStatus::ok();
567}
568
569std::pair<std::array<uint8_t, 6>, ndk::ScopedAStatus> WifiStaIface::getFactoryMacAddressInternal() {
570 std::array<uint8_t, 6> mac = iface_util_.lock()->getFactoryMacAddress(ifname_);
571 if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) {
572 return {mac, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
573 }
574 return {mac, ndk::ScopedAStatus::ok()};
575}
576
577ndk::ScopedAStatus WifiStaIface::setScanModeInternal(bool enable) {
Ye Jiao50274f72023-01-17 14:53:22 +0800578 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setScanMode(ifname_, enable);
579 return createWifiStatusFromLegacyError(legacy_status);
Gabriel Birenf3262f92022-07-15 23:25:39 +0000580}
581
Kai Shi6d02d402022-11-17 16:34:05 -0800582ndk::ScopedAStatus WifiStaIface::setDtimMultiplierInternal(const int multiplier) {
583 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDtimConfig(ifname_, multiplier);
584 return createWifiStatusFromLegacyError(legacy_status);
585}
586
Kai Shi7d0e5e92023-11-20 19:23:36 -0800587std::pair<CachedScanData, ndk::ScopedAStatus> WifiStaIface::getCachedScanDataInternal() {
588 legacy_hal::WifiCachedScanReport cached_scan_report;
589 legacy_hal::wifi_error legacy_status =
590 legacy_hal_.lock()->getWifiCachedScanResults(ifname_, cached_scan_report);
591 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
592 return {CachedScanData{}, createWifiStatusFromLegacyError(legacy_status)};
593 }
594 CachedScanData aidl_scan_data;
595 if (!aidl_struct_util::convertCachedScanReportToAidl(cached_scan_report, &aidl_scan_data)) {
596 return {CachedScanData{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)};
597 }
598
599 return {aidl_scan_data, ndk::ScopedAStatus::ok()};
600}
601
maheshkkv39903822023-11-28 15:31:53 -0800602std::pair<TwtCapabilities, ndk::ScopedAStatus> WifiStaIface::twtGetCapabilitiesInternal() {
603 legacy_hal::wifi_twt_capabilities legacyHaltwtCapabilities;
604 legacy_hal::wifi_error legacy_status;
605 std::tie(legacyHaltwtCapabilities, legacy_status) =
606 legacy_hal_.lock()->twtGetCapabilities(ifname_);
607 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
608 return {TwtCapabilities{}, createWifiStatusFromLegacyError(legacy_status)};
609 }
610 TwtCapabilities aidlTwtCapabilities;
611 if (!aidl_struct_util::convertTwtCapabilitiesToAidl(legacyHaltwtCapabilities,
612 &aidlTwtCapabilities)) {
613 return {TwtCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)};
614 }
615 return {aidlTwtCapabilities, ndk::ScopedAStatus::ok()};
616}
617
618ndk::ScopedAStatus WifiStaIface::twtSessionSetupInternal(int32_t cmdId,
619 const TwtRequest& aidlTwtRequest) {
620 legacy_hal::wifi_twt_request legacyHalTwtRequest;
621 if (!aidl_struct_util::convertAidlTwtRequestToLegacy(aidlTwtRequest, &legacyHalTwtRequest)) {
622 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
623 }
624 std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
625
626 // onTwtFailure callback
627 const auto& on_twt_failure = [weak_ptr_this](legacy_hal::wifi_request_id id,
628 legacy_hal::wifi_twt_error_code error_code) {
629 const auto shared_ptr_this = weak_ptr_this.lock();
630 IWifiStaIfaceEventCallback::TwtErrorCode aidl_error_code =
631 aidl_struct_util::convertLegacyHalTwtErrorCodeToAidl(error_code);
632 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
633 LOG(ERROR) << "Callback invoked on an invalid object";
634 return;
635 }
636 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
637 if (!callback->onTwtFailure(id, aidl_error_code).isOk()) {
638 LOG(ERROR) << "Failed to invoke onTwtFailure callback";
639 }
640 }
641 };
642 // onTwtSessionCreate callback
643 const auto& on_twt_session_create = [weak_ptr_this](legacy_hal::wifi_request_id id,
644 legacy_hal::wifi_twt_session twt_session) {
645 const auto shared_ptr_this = weak_ptr_this.lock();
646 TwtSession aidl_twt_session;
647 if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
648 LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
649 return;
650 }
651
652 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
653 LOG(ERROR) << "Callback invoked on an invalid object";
654 return;
655 }
656 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
657 if (!callback->onTwtSessionCreate(id, aidl_twt_session).isOk()) {
658 LOG(ERROR) << "Failed to invoke onTwtSessionCreate callback";
659 }
660 }
661 };
662 // onTwtSessionUpdate callback
663 const auto& on_twt_session_update = [weak_ptr_this](legacy_hal::wifi_request_id id,
664 legacy_hal::wifi_twt_session twt_session) {
665 const auto shared_ptr_this = weak_ptr_this.lock();
666 TwtSession aidl_twt_session;
667 if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
668 LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
669 return;
670 }
671
672 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
673 LOG(ERROR) << "Callback invoked on an invalid object";
674 return;
675 }
676 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
677 if (!callback->onTwtSessionUpdate(id, aidl_twt_session).isOk()) {
678 LOG(ERROR) << "Failed to invoke onTwtSessionUpdate callback";
679 }
680 }
681 };
682 // onTwtSessionTeardown callback
683 const auto& on_twt_session_teardown =
684 [weak_ptr_this](legacy_hal::wifi_request_id id, int session_id,
685 legacy_hal::wifi_twt_teardown_reason_code reason_code) {
686 const auto shared_ptr_this = weak_ptr_this.lock();
687 IWifiStaIfaceEventCallback::TwtTeardownReasonCode aidl_reason_code =
688 aidl_struct_util::convertLegacyHalTwtReasonCodeToAidl(reason_code);
689 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
690 LOG(ERROR) << "Callback invoked on an invalid object";
691 return;
692 }
693 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
694 if (!callback->onTwtSessionTeardown(id, session_id, aidl_reason_code).isOk()) {
695 LOG(ERROR) << "Failed to invoke onTwtSessionTeardown callback";
696 }
697 }
698 };
699 // onTwtSessionStats callback
700 const auto& on_twt_session_stats = [weak_ptr_this](legacy_hal::wifi_request_id id,
701 int session_id,
702 legacy_hal::wifi_twt_session_stats stats) {
703 const auto shared_ptr_this = weak_ptr_this.lock();
704 TwtSessionStats aidl_session_stats;
705 if (!aidl_struct_util::convertLegacyHalTwtSessionStatsToAidl(stats, &aidl_session_stats)) {
706 LOG(ERROR) << "convertLegacyHalTwtSessionStatsToAidl failed";
707 return;
708 }
709 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
710 LOG(ERROR) << "Callback invoked on an invalid object";
711 return;
712 }
713 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
714 if (!callback->onTwtSessionStats(id, session_id, aidl_session_stats).isOk()) {
715 LOG(ERROR) << "Failed to invoke onTwtSessionStats callback";
716 }
717 }
718 };
719 // onTwtSessionSuspend callback
720 const auto& on_twt_session_suspend = [weak_ptr_this](legacy_hal::wifi_request_id id,
721 int session_id) {
722 const auto shared_ptr_this = weak_ptr_this.lock();
723 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
724 LOG(ERROR) << "Callback invoked on an invalid object";
725 return;
726 }
727 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
728 if (!callback->onTwtSessionSuspend(id, session_id).isOk()) {
729 LOG(ERROR) << "Failed to invoke onTwtSessionSuspend callback";
730 }
731 }
732 };
733 // onTwtSessionResume callback
734 const auto& on_twt_session_resume = [weak_ptr_this](legacy_hal::wifi_request_id id,
735 int session_id) {
736 const auto shared_ptr_this = weak_ptr_this.lock();
737 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
738 LOG(ERROR) << "Callback invoked on an invalid object";
739 return;
740 }
741 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
742 if (!callback->onTwtSessionResume(id, session_id).isOk()) {
743 LOG(ERROR) << "Failed to invoke onTwtSessionResume callback";
744 }
745 }
746 };
747
748 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->twtSessionSetup(
749 ifname_, cmdId, legacyHalTwtRequest, on_twt_failure, on_twt_session_create,
750 on_twt_session_update, on_twt_session_teardown, on_twt_session_stats,
751 on_twt_session_suspend, on_twt_session_resume);
752 return createWifiStatusFromLegacyError(legacy_status);
753}
754
755ndk::ScopedAStatus WifiStaIface::twtSessionUpdateInternal(int32_t cmdId, int32_t sessionId,
756 const TwtRequest& aidlTwtRequest) {
757 legacy_hal::wifi_twt_request legacyHalTwtRequest;
758 if (!aidl_struct_util::convertAidlTwtRequestToLegacy(aidlTwtRequest, &legacyHalTwtRequest)) {
759 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
760 }
761 legacy_hal::wifi_error legacy_status =
762 legacy_hal_.lock()->twtSessionUpdate(ifname_, cmdId, sessionId, legacyHalTwtRequest);
763 return createWifiStatusFromLegacyError(legacy_status);
764}
765
766ndk::ScopedAStatus WifiStaIface::twtSessionSuspendInternal(int32_t cmdId, int32_t sessionId) {
767 legacy_hal::wifi_error legacy_status =
768 legacy_hal_.lock()->twtSessionSuspend(ifname_, cmdId, sessionId);
769 return createWifiStatusFromLegacyError(legacy_status);
770}
771
772ndk::ScopedAStatus WifiStaIface::twtSessionResumeInternal(int32_t cmdId, int32_t sessionId) {
773 legacy_hal::wifi_error legacy_status =
774 legacy_hal_.lock()->twtSessionResume(ifname_, cmdId, sessionId);
775 return createWifiStatusFromLegacyError(legacy_status);
776}
777
778ndk::ScopedAStatus WifiStaIface::twtSessionTeardownInternal(int32_t cmdId, int32_t sessionId) {
779 legacy_hal::wifi_error legacy_status =
780 legacy_hal_.lock()->twtSessionTeardown(ifname_, cmdId, sessionId);
781 return createWifiStatusFromLegacyError(legacy_status);
782}
783
784ndk::ScopedAStatus WifiStaIface::twtSessionGetStatsInternal(int32_t cmdId, int32_t sessionId) {
785 legacy_hal::wifi_error legacy_status =
786 legacy_hal_.lock()->twtSessionGetStats(ifname_, cmdId, sessionId);
787 return createWifiStatusFromLegacyError(legacy_status);
788}
789
Gabriel Birenf3262f92022-07-15 23:25:39 +0000790} // namespace wifi
791} // namespace hardware
792} // namespace android
793} // namespace aidl