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