Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | namespace aidl { |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace wifi { |
| 29 | using aidl_return_util::validateAndCall; |
| 30 | |
| 31 | WifiStaIface::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 | |
| 42 | std::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 | |
| 52 | void WifiStaIface::invalidate() { |
| 53 | legacy_hal_.reset(); |
| 54 | event_cb_handler_.invalidate(); |
| 55 | is_valid_ = false; |
| 56 | } |
| 57 | |
| 58 | void WifiStaIface::setWeakPtr(std::weak_ptr<WifiStaIface> ptr) { |
| 59 | weak_ptr_this_ = ptr; |
| 60 | } |
| 61 | |
| 62 | bool WifiStaIface::isValid() { |
| 63 | return is_valid_; |
| 64 | } |
| 65 | |
| 66 | std::string WifiStaIface::getName() { |
| 67 | return ifname_; |
| 68 | } |
| 69 | |
| 70 | std::set<std::shared_ptr<IWifiStaIfaceEventCallback>> WifiStaIface::getEventCallbacks() { |
| 71 | return event_cb_handler_.getCallbacks(); |
| 72 | } |
| 73 | |
| 74 | ndk::ScopedAStatus WifiStaIface::getName(std::string* _aidl_return) { |
| 75 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 76 | &WifiStaIface::getNameInternal, _aidl_return); |
| 77 | } |
| 78 | |
| 79 | ndk::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 Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 85 | ndk::ScopedAStatus WifiStaIface::getCapabilities(int32_t* _aidl_return) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 86 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 87 | &WifiStaIface::getCapabilitiesInternal, _aidl_return); |
| 88 | } |
| 89 | |
| 90 | ndk::ScopedAStatus WifiStaIface::getApfPacketFilterCapabilities( |
| 91 | StaApfPacketFilterCapabilities* _aidl_return) { |
| 92 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 93 | &WifiStaIface::getApfPacketFilterCapabilitiesInternal, _aidl_return); |
| 94 | } |
| 95 | |
| 96 | ndk::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 | |
| 101 | ndk::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 | |
| 106 | ndk::ScopedAStatus WifiStaIface::getBackgroundScanCapabilities( |
| 107 | StaBackgroundScanCapabilities* _aidl_return) { |
| 108 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 109 | &WifiStaIface::getBackgroundScanCapabilitiesInternal, _aidl_return); |
| 110 | } |
| 111 | |
| 112 | ndk::ScopedAStatus WifiStaIface::getValidFrequenciesForBand(WifiBand in_band, |
| 113 | std::vector<int32_t>* _aidl_return) { |
| 114 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 115 | &WifiStaIface::getValidFrequenciesForBandInternal, _aidl_return, |
| 116 | in_band); |
| 117 | } |
| 118 | |
| 119 | ndk::ScopedAStatus WifiStaIface::startBackgroundScan(int32_t in_cmdId, |
| 120 | const StaBackgroundScanParameters& in_params) { |
| 121 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 122 | &WifiStaIface::startBackgroundScanInternal, in_cmdId, in_params); |
| 123 | } |
| 124 | |
| 125 | ndk::ScopedAStatus WifiStaIface::stopBackgroundScan(int32_t in_cmdId) { |
| 126 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 127 | &WifiStaIface::stopBackgroundScanInternal, in_cmdId); |
| 128 | } |
| 129 | |
| 130 | ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollection(bool in_debug) { |
| 131 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 132 | &WifiStaIface::enableLinkLayerStatsCollectionInternal, in_debug); |
| 133 | } |
| 134 | |
| 135 | ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollection() { |
| 136 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 137 | &WifiStaIface::disableLinkLayerStatsCollectionInternal); |
| 138 | } |
| 139 | |
| 140 | ndk::ScopedAStatus WifiStaIface::getLinkLayerStats(StaLinkLayerStats* _aidl_return) { |
| 141 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 142 | &WifiStaIface::getLinkLayerStatsInternal, _aidl_return); |
| 143 | } |
| 144 | |
| 145 | ndk::ScopedAStatus WifiStaIface::startRssiMonitoring(int32_t in_cmdId, int32_t in_maxRssi, |
| 146 | int32_t in_minRssi) { |
| 147 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 148 | &WifiStaIface::startRssiMonitoringInternal, in_cmdId, in_maxRssi, |
| 149 | in_minRssi); |
| 150 | } |
| 151 | |
| 152 | ndk::ScopedAStatus WifiStaIface::stopRssiMonitoring(int32_t in_cmdId) { |
| 153 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 154 | &WifiStaIface::stopRssiMonitoringInternal, in_cmdId); |
| 155 | } |
| 156 | |
| 157 | ndk::ScopedAStatus WifiStaIface::getRoamingCapabilities(StaRoamingCapabilities* _aidl_return) { |
| 158 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 159 | &WifiStaIface::getRoamingCapabilitiesInternal, _aidl_return); |
| 160 | } |
| 161 | |
| 162 | ndk::ScopedAStatus WifiStaIface::configureRoaming(const StaRoamingConfig& in_config) { |
| 163 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 164 | &WifiStaIface::configureRoamingInternal, in_config); |
| 165 | } |
| 166 | |
| 167 | ndk::ScopedAStatus WifiStaIface::setRoamingState(StaRoamingState in_state) { |
| 168 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 169 | &WifiStaIface::setRoamingStateInternal, in_state); |
| 170 | } |
| 171 | |
| 172 | ndk::ScopedAStatus WifiStaIface::enableNdOffload(bool in_enable) { |
| 173 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 174 | &WifiStaIface::enableNdOffloadInternal, in_enable); |
| 175 | } |
| 176 | |
| 177 | ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePackets( |
| 178 | int32_t in_cmdId, const std::vector<uint8_t>& in_ipPacketData, char16_t in_etherType, |
| 179 | const std::array<uint8_t, 6>& in_srcAddress, const std::array<uint8_t, 6>& in_dstAddress, |
| 180 | int32_t in_periodInMs) { |
| 181 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 182 | &WifiStaIface::startSendingKeepAlivePacketsInternal, in_cmdId, |
| 183 | in_ipPacketData, in_etherType, in_srcAddress, in_dstAddress, |
| 184 | in_periodInMs); |
| 185 | } |
| 186 | |
| 187 | ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePackets(int32_t in_cmdId) { |
| 188 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 189 | &WifiStaIface::stopSendingKeepAlivePacketsInternal, in_cmdId); |
| 190 | } |
| 191 | |
| 192 | ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoring() { |
| 193 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 194 | &WifiStaIface::startDebugPacketFateMonitoringInternal); |
| 195 | } |
| 196 | |
| 197 | ndk::ScopedAStatus WifiStaIface::getDebugTxPacketFates( |
| 198 | std::vector<WifiDebugTxPacketFateReport>* _aidl_return) { |
| 199 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 200 | &WifiStaIface::getDebugTxPacketFatesInternal, _aidl_return); |
| 201 | } |
| 202 | |
| 203 | ndk::ScopedAStatus WifiStaIface::getDebugRxPacketFates( |
| 204 | std::vector<WifiDebugRxPacketFateReport>* _aidl_return) { |
| 205 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 206 | &WifiStaIface::getDebugRxPacketFatesInternal, _aidl_return); |
| 207 | } |
| 208 | |
| 209 | ndk::ScopedAStatus WifiStaIface::setMacAddress(const std::array<uint8_t, 6>& in_mac) { |
| 210 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 211 | &WifiStaIface::setMacAddressInternal, in_mac); |
| 212 | } |
| 213 | |
| 214 | ndk::ScopedAStatus WifiStaIface::getFactoryMacAddress(std::array<uint8_t, 6>* _aidl_return) { |
| 215 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 216 | &WifiStaIface::getFactoryMacAddressInternal, _aidl_return); |
| 217 | } |
| 218 | |
| 219 | ndk::ScopedAStatus WifiStaIface::setScanMode(bool in_enable) { |
| 220 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 221 | &WifiStaIface::setScanModeInternal, in_enable); |
| 222 | } |
| 223 | |
Kai Shi | 6d02d40 | 2022-11-17 16:34:05 -0800 | [diff] [blame] | 224 | ndk::ScopedAStatus WifiStaIface::setDtimMultiplier(int32_t in_multiplier) { |
| 225 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 226 | &WifiStaIface::setDtimMultiplierInternal, in_multiplier); |
| 227 | } |
| 228 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 229 | std::pair<std::string, ndk::ScopedAStatus> WifiStaIface::getNameInternal() { |
| 230 | return {ifname_, ndk::ScopedAStatus::ok()}; |
| 231 | } |
| 232 | |
| 233 | ndk::ScopedAStatus WifiStaIface::registerEventCallbackInternal( |
| 234 | const std::shared_ptr<IWifiStaIfaceEventCallback>& callback) { |
| 235 | if (!event_cb_handler_.addCallback(callback)) { |
| 236 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 237 | } |
| 238 | return ndk::ScopedAStatus::ok(); |
| 239 | } |
| 240 | |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 241 | std::pair<int32_t, ndk::ScopedAStatus> WifiStaIface::getCapabilitiesInternal() { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 242 | legacy_hal::wifi_error legacy_status; |
| 243 | uint64_t legacy_feature_set; |
| 244 | std::tie(legacy_status, legacy_feature_set) = |
| 245 | legacy_hal_.lock()->getSupportedFeatureSet(ifname_); |
| 246 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 247 | return {0, createWifiStatusFromLegacyError(legacy_status)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 248 | } |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 249 | uint32_t aidl_caps; |
Gabriel Biren | dd47e71 | 2023-02-15 23:50:07 +0000 | [diff] [blame] | 250 | if (!aidl_struct_util::convertLegacyFeaturesToAidlStaCapabilities(legacy_feature_set, |
| 251 | &aidl_caps)) { |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 252 | return {0, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 253 | } |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 254 | return {aidl_caps, ndk::ScopedAStatus::ok()}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | std::pair<StaApfPacketFilterCapabilities, ndk::ScopedAStatus> |
| 258 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
| 259 | legacy_hal::wifi_error legacy_status; |
| 260 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 261 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getPacketFilterCapabilities(ifname_); |
| 262 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 263 | return {StaApfPacketFilterCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; |
| 264 | } |
| 265 | StaApfPacketFilterCapabilities aidl_caps; |
| 266 | if (!aidl_struct_util::convertLegacyApfCapabilitiesToAidl(legacy_caps, &aidl_caps)) { |
| 267 | return {StaApfPacketFilterCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 268 | } |
| 269 | return {aidl_caps, ndk::ScopedAStatus::ok()}; |
| 270 | } |
| 271 | |
| 272 | ndk::ScopedAStatus WifiStaIface::installApfPacketFilterInternal( |
| 273 | const std::vector<uint8_t>& program) { |
| 274 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setPacketFilter(ifname_, program); |
| 275 | return createWifiStatusFromLegacyError(legacy_status); |
| 276 | } |
| 277 | |
| 278 | std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> |
| 279 | WifiStaIface::readApfPacketFilterDataInternal() { |
| 280 | const std::pair<legacy_hal::wifi_error, std::vector<uint8_t>> legacy_status_and_data = |
| 281 | legacy_hal_.lock()->readApfPacketFilterData(ifname_); |
| 282 | return {std::move(legacy_status_and_data.second), |
| 283 | createWifiStatusFromLegacyError(legacy_status_and_data.first)}; |
| 284 | } |
| 285 | |
| 286 | std::pair<StaBackgroundScanCapabilities, ndk::ScopedAStatus> |
| 287 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
| 288 | legacy_hal::wifi_error legacy_status; |
| 289 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 290 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getGscanCapabilities(ifname_); |
| 291 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 292 | return {StaBackgroundScanCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; |
| 293 | } |
| 294 | StaBackgroundScanCapabilities aidl_caps; |
| 295 | if (!aidl_struct_util::convertLegacyGscanCapabilitiesToAidl(legacy_caps, &aidl_caps)) { |
| 296 | return {StaBackgroundScanCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 297 | } |
| 298 | return {aidl_caps, ndk::ScopedAStatus::ok()}; |
| 299 | } |
| 300 | |
| 301 | std::pair<std::vector<int32_t>, ndk::ScopedAStatus> |
| 302 | WifiStaIface::getValidFrequenciesForBandInternal(WifiBand band) { |
| 303 | static_assert(sizeof(WifiChannelWidthInMhz) == sizeof(int32_t), "Size mismatch"); |
| 304 | legacy_hal::wifi_error legacy_status; |
| 305 | std::vector<uint32_t> valid_frequencies; |
| 306 | std::tie(legacy_status, valid_frequencies) = legacy_hal_.lock()->getValidFrequenciesForBand( |
| 307 | ifname_, aidl_struct_util::convertAidlWifiBandToLegacy(band)); |
| 308 | return {std::vector<int32_t>(valid_frequencies.begin(), valid_frequencies.end()), |
| 309 | createWifiStatusFromLegacyError(legacy_status)}; |
| 310 | } |
| 311 | |
| 312 | ndk::ScopedAStatus WifiStaIface::startBackgroundScanInternal( |
| 313 | int32_t cmd_id, const StaBackgroundScanParameters& params) { |
| 314 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 315 | if (!aidl_struct_util::convertAidlGscanParamsToLegacy(params, &legacy_params)) { |
| 316 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 317 | } |
| 318 | std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_; |
| 319 | const auto& on_failure_callback = [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 320 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 321 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 322 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 323 | return; |
| 324 | } |
| 325 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 326 | if (!callback->onBackgroundScanFailure(id).isOk()) { |
| 327 | LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; |
| 328 | } |
| 329 | } |
| 330 | }; |
| 331 | const auto& on_results_callback = |
| 332 | [weak_ptr_this](legacy_hal::wifi_request_id id, |
| 333 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 334 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 335 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 336 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 337 | return; |
| 338 | } |
| 339 | std::vector<StaScanData> aidl_scan_datas; |
| 340 | if (!aidl_struct_util::convertLegacyVectorOfCachedGscanResultsToAidl( |
| 341 | results, &aidl_scan_datas)) { |
| 342 | LOG(ERROR) << "Failed to convert scan results to AIDL structs"; |
| 343 | return; |
| 344 | } |
| 345 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 346 | if (!callback->onBackgroundScanResults(id, aidl_scan_datas).isOk()) { |
| 347 | LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; |
| 348 | } |
| 349 | } |
| 350 | }; |
| 351 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 352 | legacy_hal::wifi_request_id id, |
| 353 | const legacy_hal::wifi_scan_result* result, |
| 354 | uint32_t buckets_scanned) { |
| 355 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 356 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 357 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 358 | return; |
| 359 | } |
| 360 | StaScanResult aidl_scan_result; |
| 361 | if (!aidl_struct_util::convertLegacyGscanResultToAidl(*result, true, &aidl_scan_result)) { |
| 362 | LOG(ERROR) << "Failed to convert full scan results to AIDL structs"; |
| 363 | return; |
| 364 | } |
| 365 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 366 | if (!callback->onBackgroundFullScanResult(id, buckets_scanned, aidl_scan_result) |
| 367 | .isOk()) { |
| 368 | LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; |
| 369 | } |
| 370 | } |
| 371 | }; |
| 372 | legacy_hal::wifi_error legacy_status = |
| 373 | legacy_hal_.lock()->startGscan(ifname_, cmd_id, legacy_params, on_failure_callback, |
| 374 | on_results_callback, on_full_result_callback); |
| 375 | return createWifiStatusFromLegacyError(legacy_status); |
| 376 | } |
| 377 | |
| 378 | ndk::ScopedAStatus WifiStaIface::stopBackgroundScanInternal(int32_t cmd_id) { |
| 379 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(ifname_, cmd_id); |
| 380 | return createWifiStatusFromLegacyError(legacy_status); |
| 381 | } |
| 382 | |
| 383 | ndk::ScopedAStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 384 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableLinkLayerStats(ifname_, debug); |
| 385 | return createWifiStatusFromLegacyError(legacy_status); |
| 386 | } |
| 387 | |
| 388 | ndk::ScopedAStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
| 389 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableLinkLayerStats(ifname_); |
| 390 | return createWifiStatusFromLegacyError(legacy_status); |
| 391 | } |
| 392 | |
| 393 | std::pair<StaLinkLayerStats, ndk::ScopedAStatus> WifiStaIface::getLinkLayerStatsInternal() { |
| 394 | legacy_hal::wifi_error legacy_status; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 395 | legacy_hal::LinkLayerStats legacy_stats{}; |
| 396 | legacy_hal::LinkLayerMlStats legacy_ml_stats{}; |
| 397 | legacy_status = legacy_hal_.lock()->getLinkLayerStats(ifname_, legacy_stats, legacy_ml_stats); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 398 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 399 | return {StaLinkLayerStats{}, createWifiStatusFromLegacyError(legacy_status)}; |
| 400 | } |
| 401 | StaLinkLayerStats aidl_stats; |
Mahesh KKV | 5f30d33 | 2022-10-26 14:07:44 -0700 | [diff] [blame] | 402 | if (legacy_stats.valid) { |
| 403 | if (!aidl_struct_util::convertLegacyLinkLayerStatsToAidl(legacy_stats, &aidl_stats)) { |
| 404 | return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 405 | } |
| 406 | } else if (legacy_ml_stats.valid) { |
| 407 | if (!aidl_struct_util::convertLegacyLinkLayerMlStatsToAidl(legacy_ml_stats, &aidl_stats)) { |
| 408 | return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 409 | } |
| 410 | } else { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 411 | return {StaLinkLayerStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 412 | } |
| 413 | return {aidl_stats, ndk::ScopedAStatus::ok()}; |
| 414 | } |
| 415 | |
| 416 | ndk::ScopedAStatus WifiStaIface::startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi, |
| 417 | int32_t min_rssi) { |
| 418 | std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_; |
| 419 | const auto& on_threshold_breached_callback = |
| 420 | [weak_ptr_this](legacy_hal::wifi_request_id id, std::array<uint8_t, ETH_ALEN> bssid, |
| 421 | int8_t rssi) { |
| 422 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 423 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 424 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 425 | return; |
| 426 | } |
| 427 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 428 | if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { |
| 429 | LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; |
| 430 | } |
| 431 | } |
| 432 | }; |
| 433 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring( |
| 434 | ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 435 | return createWifiStatusFromLegacyError(legacy_status); |
| 436 | } |
| 437 | |
| 438 | ndk::ScopedAStatus WifiStaIface::stopRssiMonitoringInternal(int32_t cmd_id) { |
| 439 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id); |
| 440 | return createWifiStatusFromLegacyError(legacy_status); |
| 441 | } |
| 442 | |
| 443 | std::pair<StaRoamingCapabilities, ndk::ScopedAStatus> |
| 444 | WifiStaIface::getRoamingCapabilitiesInternal() { |
| 445 | legacy_hal::wifi_error legacy_status; |
| 446 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 447 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_); |
| 448 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 449 | return {StaRoamingCapabilities{}, createWifiStatusFromLegacyError(legacy_status)}; |
| 450 | } |
| 451 | StaRoamingCapabilities aidl_caps; |
| 452 | if (!aidl_struct_util::convertLegacyRoamingCapabilitiesToAidl(legacy_caps, &aidl_caps)) { |
| 453 | return {StaRoamingCapabilities{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 454 | } |
| 455 | return {aidl_caps, ndk::ScopedAStatus::ok()}; |
| 456 | } |
| 457 | |
| 458 | ndk::ScopedAStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) { |
| 459 | legacy_hal::wifi_roaming_config legacy_config; |
| 460 | if (!aidl_struct_util::convertAidlRoamingConfigToLegacy(config, &legacy_config)) { |
| 461 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 462 | } |
| 463 | legacy_hal::wifi_error legacy_status = |
| 464 | legacy_hal_.lock()->configureRoaming(ifname_, legacy_config); |
| 465 | return createWifiStatusFromLegacyError(legacy_status); |
| 466 | } |
| 467 | |
| 468 | ndk::ScopedAStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 469 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming( |
| 470 | ifname_, aidl_struct_util::convertAidlRoamingStateToLegacy(state)); |
| 471 | return createWifiStatusFromLegacyError(legacy_status); |
| 472 | } |
| 473 | |
| 474 | ndk::ScopedAStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 475 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable); |
| 476 | return createWifiStatusFromLegacyError(legacy_status); |
| 477 | } |
| 478 | |
| 479 | ndk::ScopedAStatus WifiStaIface::startSendingKeepAlivePacketsInternal( |
| 480 | int32_t cmd_id, const std::vector<uint8_t>& ip_packet_data, char16_t ether_type, |
| 481 | const std::array<uint8_t, 6>& src_address, const std::array<uint8_t, 6>& dst_address, |
| 482 | int32_t period_in_ms) { |
| 483 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket( |
| 484 | ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms); |
| 485 | return createWifiStatusFromLegacyError(legacy_status); |
| 486 | } |
| 487 | |
| 488 | ndk::ScopedAStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(int32_t cmd_id) { |
| 489 | legacy_hal::wifi_error legacy_status = |
| 490 | legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id); |
| 491 | return createWifiStatusFromLegacyError(legacy_status); |
| 492 | } |
| 493 | |
| 494 | ndk::ScopedAStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
| 495 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_); |
| 496 | return createWifiStatusFromLegacyError(legacy_status); |
| 497 | } |
| 498 | |
| 499 | std::pair<std::vector<WifiDebugTxPacketFateReport>, ndk::ScopedAStatus> |
| 500 | WifiStaIface::getDebugTxPacketFatesInternal() { |
| 501 | legacy_hal::wifi_error legacy_status; |
| 502 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 503 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_); |
| 504 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 505 | return {std::vector<WifiDebugTxPacketFateReport>(), |
| 506 | createWifiStatusFromLegacyError(legacy_status)}; |
| 507 | } |
| 508 | std::vector<WifiDebugTxPacketFateReport> aidl_fates; |
| 509 | if (!aidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToAidl(legacy_fates, |
| 510 | &aidl_fates)) { |
| 511 | return {std::vector<WifiDebugTxPacketFateReport>(), |
| 512 | createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 513 | } |
| 514 | return {aidl_fates, ndk::ScopedAStatus::ok()}; |
| 515 | } |
| 516 | |
| 517 | std::pair<std::vector<WifiDebugRxPacketFateReport>, ndk::ScopedAStatus> |
| 518 | WifiStaIface::getDebugRxPacketFatesInternal() { |
| 519 | legacy_hal::wifi_error legacy_status; |
| 520 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 521 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_); |
| 522 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 523 | return {std::vector<WifiDebugRxPacketFateReport>(), |
| 524 | createWifiStatusFromLegacyError(legacy_status)}; |
| 525 | } |
| 526 | std::vector<WifiDebugRxPacketFateReport> aidl_fates; |
| 527 | if (!aidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToAidl(legacy_fates, |
| 528 | &aidl_fates)) { |
| 529 | return {std::vector<WifiDebugRxPacketFateReport>(), |
| 530 | createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 531 | } |
| 532 | return {aidl_fates, ndk::ScopedAStatus::ok()}; |
| 533 | } |
| 534 | |
| 535 | ndk::ScopedAStatus WifiStaIface::setMacAddressInternal(const std::array<uint8_t, 6>& mac) { |
| 536 | bool status = iface_util_.lock()->setMacAddress(ifname_, mac); |
| 537 | if (!status) { |
| 538 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 539 | } |
| 540 | return ndk::ScopedAStatus::ok(); |
| 541 | } |
| 542 | |
| 543 | std::pair<std::array<uint8_t, 6>, ndk::ScopedAStatus> WifiStaIface::getFactoryMacAddressInternal() { |
| 544 | std::array<uint8_t, 6> mac = iface_util_.lock()->getFactoryMacAddress(ifname_); |
| 545 | if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) { |
| 546 | return {mac, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 547 | } |
| 548 | return {mac, ndk::ScopedAStatus::ok()}; |
| 549 | } |
| 550 | |
| 551 | ndk::ScopedAStatus WifiStaIface::setScanModeInternal(bool enable) { |
Ye Jiao | 50274f7 | 2023-01-17 14:53:22 +0800 | [diff] [blame] | 552 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setScanMode(ifname_, enable); |
| 553 | return createWifiStatusFromLegacyError(legacy_status); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Kai Shi | 6d02d40 | 2022-11-17 16:34:05 -0800 | [diff] [blame] | 556 | ndk::ScopedAStatus WifiStaIface::setDtimMultiplierInternal(const int multiplier) { |
| 557 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDtimConfig(ifname_, multiplier); |
| 558 | return createWifiStatusFromLegacyError(legacy_status); |
| 559 | } |
| 560 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 561 | } // namespace wifi |
| 562 | } // namespace hardware |
| 563 | } // namespace android |
| 564 | } // namespace aidl |