Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <android-base/logging.h> |
| 18 | |
| 19 | #include "hidl_return_util.h" |
| 20 | #include "hidl_struct_util.h" |
| 21 | #include "wifi_sta_iface.h" |
| 22 | #include "wifi_status_util.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
| 27 | namespace V1_6 { |
| 28 | namespace implementation { |
| 29 | using hidl_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 | void WifiStaIface::invalidate() { |
| 43 | legacy_hal_.reset(); |
| 44 | event_cb_handler_.invalidate(); |
| 45 | is_valid_ = false; |
| 46 | } |
| 47 | |
| 48 | bool WifiStaIface::isValid() { |
| 49 | return is_valid_; |
| 50 | } |
| 51 | |
| 52 | std::string WifiStaIface::getName() { |
| 53 | return ifname_; |
| 54 | } |
| 55 | |
| 56 | std::set<sp<IWifiStaIfaceEventCallback>> WifiStaIface::getEventCallbacks() { |
| 57 | return event_cb_handler_.getCallbacks(); |
| 58 | } |
| 59 | |
| 60 | Return<void> WifiStaIface::getName(getName_cb hidl_status_cb) { |
| 61 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 62 | &WifiStaIface::getNameInternal, hidl_status_cb); |
| 63 | } |
| 64 | |
| 65 | Return<void> WifiStaIface::getType(getType_cb hidl_status_cb) { |
| 66 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 67 | &WifiStaIface::getTypeInternal, hidl_status_cb); |
| 68 | } |
| 69 | |
| 70 | Return<void> WifiStaIface::registerEventCallback(const sp<IWifiStaIfaceEventCallback>& callback, |
| 71 | registerEventCallback_cb hidl_status_cb) { |
| 72 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 73 | &WifiStaIface::registerEventCallbackInternal, hidl_status_cb, callback); |
| 74 | } |
| 75 | |
| 76 | Return<void> WifiStaIface::getCapabilities(getCapabilities_cb hidl_status_cb) { |
| 77 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 78 | &WifiStaIface::getCapabilitiesInternal, hidl_status_cb); |
| 79 | } |
| 80 | |
| 81 | Return<void> WifiStaIface::getApfPacketFilterCapabilities( |
| 82 | getApfPacketFilterCapabilities_cb hidl_status_cb) { |
| 83 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 84 | &WifiStaIface::getApfPacketFilterCapabilitiesInternal, hidl_status_cb); |
| 85 | } |
| 86 | |
| 87 | Return<void> WifiStaIface::installApfPacketFilter(uint32_t cmd_id, const hidl_vec<uint8_t>& program, |
| 88 | installApfPacketFilter_cb hidl_status_cb) { |
| 89 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 90 | &WifiStaIface::installApfPacketFilterInternal, hidl_status_cb, cmd_id, |
| 91 | program); |
| 92 | } |
| 93 | |
| 94 | Return<void> WifiStaIface::readApfPacketFilterData(readApfPacketFilterData_cb hidl_status_cb) { |
| 95 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 96 | &WifiStaIface::readApfPacketFilterDataInternal, hidl_status_cb); |
| 97 | } |
| 98 | |
| 99 | Return<void> WifiStaIface::getBackgroundScanCapabilities( |
| 100 | getBackgroundScanCapabilities_cb hidl_status_cb) { |
| 101 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 102 | &WifiStaIface::getBackgroundScanCapabilitiesInternal, hidl_status_cb); |
| 103 | } |
| 104 | |
| 105 | Return<void> WifiStaIface::getValidFrequenciesForBand( |
| 106 | V1_0::WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) { |
| 107 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 108 | &WifiStaIface::getValidFrequenciesForBandInternal, hidl_status_cb, band); |
| 109 | } |
| 110 | |
| 111 | Return<void> WifiStaIface::startBackgroundScan(uint32_t cmd_id, |
| 112 | const StaBackgroundScanParameters& params, |
| 113 | startBackgroundScan_cb hidl_status_cb) { |
| 114 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 115 | &WifiStaIface::startBackgroundScanInternal, hidl_status_cb, cmd_id, |
| 116 | params); |
| 117 | } |
| 118 | |
| 119 | Return<void> WifiStaIface::stopBackgroundScan(uint32_t cmd_id, |
| 120 | stopBackgroundScan_cb hidl_status_cb) { |
| 121 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 122 | &WifiStaIface::stopBackgroundScanInternal, hidl_status_cb, cmd_id); |
| 123 | } |
| 124 | |
| 125 | Return<void> WifiStaIface::enableLinkLayerStatsCollection( |
| 126 | bool debug, enableLinkLayerStatsCollection_cb hidl_status_cb) { |
| 127 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 128 | &WifiStaIface::enableLinkLayerStatsCollectionInternal, hidl_status_cb, |
| 129 | debug); |
| 130 | } |
| 131 | |
| 132 | Return<void> WifiStaIface::disableLinkLayerStatsCollection( |
| 133 | disableLinkLayerStatsCollection_cb hidl_status_cb) { |
| 134 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 135 | &WifiStaIface::disableLinkLayerStatsCollectionInternal, hidl_status_cb); |
| 136 | } |
| 137 | |
| 138 | Return<void> WifiStaIface::getLinkLayerStats(getLinkLayerStats_cb hidl_status_cb) { |
| 139 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 140 | &WifiStaIface::getLinkLayerStatsInternal, hidl_status_cb); |
| 141 | } |
| 142 | |
| 143 | Return<void> WifiStaIface::getLinkLayerStats_1_3(getLinkLayerStats_1_3_cb hidl_status_cb) { |
| 144 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 145 | &WifiStaIface::getLinkLayerStatsInternal_1_3, hidl_status_cb); |
| 146 | } |
| 147 | |
| 148 | Return<void> WifiStaIface::getLinkLayerStats_1_5(getLinkLayerStats_1_5_cb hidl_status_cb) { |
| 149 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 150 | &WifiStaIface::getLinkLayerStatsInternal_1_5, hidl_status_cb); |
| 151 | } |
| 152 | |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame^] | 153 | Return<void> WifiStaIface::getLinkLayerStats_1_6(getLinkLayerStats_1_6_cb hidl_status_cb) { |
| 154 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 155 | &WifiStaIface::getLinkLayerStatsInternal_1_6, hidl_status_cb); |
| 156 | } |
| 157 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 158 | Return<void> WifiStaIface::startRssiMonitoring(uint32_t cmd_id, int32_t max_rssi, int32_t min_rssi, |
| 159 | startRssiMonitoring_cb hidl_status_cb) { |
| 160 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 161 | &WifiStaIface::startRssiMonitoringInternal, hidl_status_cb, cmd_id, |
| 162 | max_rssi, min_rssi); |
| 163 | } |
| 164 | |
| 165 | Return<void> WifiStaIface::stopRssiMonitoring(uint32_t cmd_id, |
| 166 | stopRssiMonitoring_cb hidl_status_cb) { |
| 167 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 168 | &WifiStaIface::stopRssiMonitoringInternal, hidl_status_cb, cmd_id); |
| 169 | } |
| 170 | |
| 171 | Return<void> WifiStaIface::getRoamingCapabilities(getRoamingCapabilities_cb hidl_status_cb) { |
| 172 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 173 | &WifiStaIface::getRoamingCapabilitiesInternal, hidl_status_cb); |
| 174 | } |
| 175 | |
| 176 | Return<void> WifiStaIface::configureRoaming(const StaRoamingConfig& config, |
| 177 | configureRoaming_cb hidl_status_cb) { |
| 178 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 179 | &WifiStaIface::configureRoamingInternal, hidl_status_cb, config); |
| 180 | } |
| 181 | |
| 182 | Return<void> WifiStaIface::setRoamingState(StaRoamingState state, |
| 183 | setRoamingState_cb hidl_status_cb) { |
| 184 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 185 | &WifiStaIface::setRoamingStateInternal, hidl_status_cb, state); |
| 186 | } |
| 187 | |
| 188 | Return<void> WifiStaIface::enableNdOffload(bool enable, enableNdOffload_cb hidl_status_cb) { |
| 189 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 190 | &WifiStaIface::enableNdOffloadInternal, hidl_status_cb, enable); |
| 191 | } |
| 192 | |
| 193 | Return<void> WifiStaIface::startSendingKeepAlivePackets( |
| 194 | uint32_t cmd_id, const hidl_vec<uint8_t>& ip_packet_data, uint16_t ether_type, |
| 195 | const hidl_array<uint8_t, 6>& src_address, const hidl_array<uint8_t, 6>& dst_address, |
| 196 | uint32_t period_in_ms, startSendingKeepAlivePackets_cb hidl_status_cb) { |
| 197 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 198 | &WifiStaIface::startSendingKeepAlivePacketsInternal, hidl_status_cb, |
| 199 | cmd_id, ip_packet_data, ether_type, src_address, dst_address, |
| 200 | period_in_ms); |
| 201 | } |
| 202 | |
| 203 | Return<void> WifiStaIface::stopSendingKeepAlivePackets( |
| 204 | uint32_t cmd_id, stopSendingKeepAlivePackets_cb hidl_status_cb) { |
| 205 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 206 | &WifiStaIface::stopSendingKeepAlivePacketsInternal, hidl_status_cb, |
| 207 | cmd_id); |
| 208 | } |
| 209 | |
| 210 | Return<void> WifiStaIface::setScanningMacOui(const hidl_array<uint8_t, 3>& oui, |
| 211 | setScanningMacOui_cb hidl_status_cb) { |
| 212 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 213 | &WifiStaIface::setScanningMacOuiInternal, hidl_status_cb, oui); |
| 214 | } |
| 215 | |
| 216 | Return<void> WifiStaIface::startDebugPacketFateMonitoring( |
| 217 | startDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 218 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 219 | &WifiStaIface::startDebugPacketFateMonitoringInternal, hidl_status_cb); |
| 220 | } |
| 221 | |
| 222 | Return<void> WifiStaIface::getDebugTxPacketFates(getDebugTxPacketFates_cb hidl_status_cb) { |
| 223 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 224 | &WifiStaIface::getDebugTxPacketFatesInternal, hidl_status_cb); |
| 225 | } |
| 226 | |
| 227 | Return<void> WifiStaIface::getDebugRxPacketFates(getDebugRxPacketFates_cb hidl_status_cb) { |
| 228 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 229 | &WifiStaIface::getDebugRxPacketFatesInternal, hidl_status_cb); |
| 230 | } |
| 231 | |
| 232 | Return<void> WifiStaIface::setMacAddress(const hidl_array<uint8_t, 6>& mac, |
| 233 | setMacAddress_cb hidl_status_cb) { |
| 234 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 235 | &WifiStaIface::setMacAddressInternal, hidl_status_cb, mac); |
| 236 | } |
| 237 | |
| 238 | Return<void> WifiStaIface::getFactoryMacAddress(getFactoryMacAddress_cb hidl_status_cb) { |
| 239 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 240 | &WifiStaIface::getFactoryMacAddressInternal, hidl_status_cb); |
| 241 | } |
| 242 | |
| 243 | Return<void> WifiStaIface::setScanMode(bool enable, setScanMode_cb hidl_status_cb) { |
| 244 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 245 | &WifiStaIface::setScanModeInternal, hidl_status_cb, enable); |
| 246 | } |
| 247 | |
| 248 | std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() { |
| 249 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
| 250 | } |
| 251 | |
| 252 | std::pair<WifiStatus, IfaceType> WifiStaIface::getTypeInternal() { |
| 253 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::STA}; |
| 254 | } |
| 255 | |
| 256 | WifiStatus WifiStaIface::registerEventCallbackInternal( |
| 257 | const sp<IWifiStaIfaceEventCallback>& callback) { |
| 258 | if (!event_cb_handler_.addCallback(callback)) { |
| 259 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 260 | } |
| 261 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 262 | } |
| 263 | |
| 264 | std::pair<WifiStatus, uint32_t> WifiStaIface::getCapabilitiesInternal() { |
| 265 | legacy_hal::wifi_error legacy_status; |
| 266 | uint64_t legacy_feature_set; |
| 267 | std::tie(legacy_status, legacy_feature_set) = |
| 268 | legacy_hal_.lock()->getSupportedFeatureSet(ifname_); |
| 269 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 270 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 271 | } |
| 272 | uint32_t legacy_logger_feature_set; |
| 273 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 274 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname_); |
| 275 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 276 | // some devices don't support querying logger feature set |
| 277 | legacy_logger_feature_set = 0; |
| 278 | } |
| 279 | uint32_t hidl_caps; |
| 280 | if (!hidl_struct_util::convertLegacyFeaturesToHidlStaCapabilities( |
| 281 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 282 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 283 | } |
| 284 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 285 | } |
| 286 | |
| 287 | std::pair<WifiStatus, StaApfPacketFilterCapabilities> |
| 288 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
| 289 | legacy_hal::wifi_error legacy_status; |
| 290 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 291 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getPacketFilterCapabilities(ifname_); |
| 292 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 293 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 294 | } |
| 295 | StaApfPacketFilterCapabilities hidl_caps; |
| 296 | if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, &hidl_caps)) { |
| 297 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 298 | } |
| 299 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 300 | } |
| 301 | |
| 302 | WifiStatus WifiStaIface::installApfPacketFilterInternal(uint32_t /* cmd_id */, |
| 303 | const std::vector<uint8_t>& program) { |
| 304 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setPacketFilter(ifname_, program); |
| 305 | return createWifiStatusFromLegacyError(legacy_status); |
| 306 | } |
| 307 | |
| 308 | std::pair<WifiStatus, std::vector<uint8_t>> WifiStaIface::readApfPacketFilterDataInternal() { |
| 309 | const std::pair<legacy_hal::wifi_error, std::vector<uint8_t>> legacy_status_and_data = |
| 310 | legacy_hal_.lock()->readApfPacketFilterData(ifname_); |
| 311 | return {createWifiStatusFromLegacyError(legacy_status_and_data.first), |
| 312 | std::move(legacy_status_and_data.second)}; |
| 313 | } |
| 314 | |
| 315 | std::pair<WifiStatus, StaBackgroundScanCapabilities> |
| 316 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
| 317 | legacy_hal::wifi_error legacy_status; |
| 318 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 319 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getGscanCapabilities(ifname_); |
| 320 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 321 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 322 | } |
| 323 | StaBackgroundScanCapabilities hidl_caps; |
| 324 | if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, &hidl_caps)) { |
| 325 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 326 | } |
| 327 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 328 | } |
| 329 | |
| 330 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 331 | WifiStaIface::getValidFrequenciesForBandInternal(V1_0::WifiBand band) { |
| 332 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); |
| 333 | legacy_hal::wifi_error legacy_status; |
| 334 | std::vector<uint32_t> valid_frequencies; |
| 335 | std::tie(legacy_status, valid_frequencies) = legacy_hal_.lock()->getValidFrequenciesForBand( |
| 336 | ifname_, hidl_struct_util::convertHidlWifiBandToLegacy(band)); |
| 337 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
| 338 | } |
| 339 | |
| 340 | WifiStatus WifiStaIface::startBackgroundScanInternal(uint32_t cmd_id, |
| 341 | const StaBackgroundScanParameters& params) { |
| 342 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 343 | if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, &legacy_params)) { |
| 344 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 345 | } |
| 346 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 347 | const auto& on_failure_callback = [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 348 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 349 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 350 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 351 | return; |
| 352 | } |
| 353 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 354 | if (!callback->onBackgroundScanFailure(id).isOk()) { |
| 355 | LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; |
| 356 | } |
| 357 | } |
| 358 | }; |
| 359 | const auto& on_results_callback = |
| 360 | [weak_ptr_this](legacy_hal::wifi_request_id id, |
| 361 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 362 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 363 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 364 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 365 | return; |
| 366 | } |
| 367 | std::vector<StaScanData> hidl_scan_datas; |
| 368 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 369 | results, &hidl_scan_datas)) { |
| 370 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 371 | return; |
| 372 | } |
| 373 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 374 | if (!callback->onBackgroundScanResults(id, hidl_scan_datas).isOk()) { |
| 375 | LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; |
| 376 | } |
| 377 | } |
| 378 | }; |
| 379 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 380 | legacy_hal::wifi_request_id id, |
| 381 | const legacy_hal::wifi_scan_result* result, |
| 382 | uint32_t buckets_scanned) { |
| 383 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 384 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 385 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 386 | return; |
| 387 | } |
| 388 | StaScanResult hidl_scan_result; |
| 389 | if (!hidl_struct_util::convertLegacyGscanResultToHidl(*result, true, &hidl_scan_result)) { |
| 390 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 391 | return; |
| 392 | } |
| 393 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 394 | if (!callback->onBackgroundFullScanResult(id, buckets_scanned, hidl_scan_result) |
| 395 | .isOk()) { |
| 396 | LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; |
| 397 | } |
| 398 | } |
| 399 | }; |
| 400 | legacy_hal::wifi_error legacy_status = |
| 401 | legacy_hal_.lock()->startGscan(ifname_, cmd_id, legacy_params, on_failure_callback, |
| 402 | on_results_callback, on_full_result_callback); |
| 403 | return createWifiStatusFromLegacyError(legacy_status); |
| 404 | } |
| 405 | |
| 406 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 407 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(ifname_, cmd_id); |
| 408 | return createWifiStatusFromLegacyError(legacy_status); |
| 409 | } |
| 410 | |
| 411 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 412 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableLinkLayerStats(ifname_, debug); |
| 413 | return createWifiStatusFromLegacyError(legacy_status); |
| 414 | } |
| 415 | |
| 416 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
| 417 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->disableLinkLayerStats(ifname_); |
| 418 | return createWifiStatusFromLegacyError(legacy_status); |
| 419 | } |
| 420 | |
| 421 | std::pair<WifiStatus, V1_0::StaLinkLayerStats> WifiStaIface::getLinkLayerStatsInternal() { |
| 422 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
| 423 | } |
| 424 | |
| 425 | std::pair<WifiStatus, V1_3::StaLinkLayerStats> WifiStaIface::getLinkLayerStatsInternal_1_3() { |
| 426 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
| 427 | } |
| 428 | |
| 429 | std::pair<WifiStatus, V1_5::StaLinkLayerStats> WifiStaIface::getLinkLayerStatsInternal_1_5() { |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame^] | 430 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
| 431 | } |
| 432 | |
| 433 | std::pair<WifiStatus, V1_6::StaLinkLayerStats> WifiStaIface::getLinkLayerStatsInternal_1_6() { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 434 | legacy_hal::wifi_error legacy_status; |
| 435 | legacy_hal::LinkLayerStats legacy_stats; |
| 436 | std::tie(legacy_status, legacy_stats) = legacy_hal_.lock()->getLinkLayerStats(ifname_); |
| 437 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 438 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 439 | } |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame^] | 440 | V1_6::StaLinkLayerStats hidl_stats; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 441 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, &hidl_stats)) { |
| 442 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 443 | } |
| 444 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
| 445 | } |
| 446 | |
| 447 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, int32_t max_rssi, |
| 448 | int32_t min_rssi) { |
| 449 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 450 | const auto& on_threshold_breached_callback = [weak_ptr_this](legacy_hal::wifi_request_id id, |
| 451 | std::array<uint8_t, 6> bssid, |
| 452 | int8_t rssi) { |
| 453 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 454 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 455 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 456 | return; |
| 457 | } |
| 458 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 459 | if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { |
| 460 | LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; |
| 461 | } |
| 462 | } |
| 463 | }; |
| 464 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRssiMonitoring( |
| 465 | ifname_, cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 466 | return createWifiStatusFromLegacyError(legacy_status); |
| 467 | } |
| 468 | |
| 469 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 470 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopRssiMonitoring(ifname_, cmd_id); |
| 471 | return createWifiStatusFromLegacyError(legacy_status); |
| 472 | } |
| 473 | |
| 474 | std::pair<WifiStatus, StaRoamingCapabilities> WifiStaIface::getRoamingCapabilitiesInternal() { |
| 475 | legacy_hal::wifi_error legacy_status; |
| 476 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 477 | std::tie(legacy_status, legacy_caps) = legacy_hal_.lock()->getRoamingCapabilities(ifname_); |
| 478 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 479 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 480 | } |
| 481 | StaRoamingCapabilities hidl_caps; |
| 482 | if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, &hidl_caps)) { |
| 483 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 484 | } |
| 485 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 486 | } |
| 487 | |
| 488 | WifiStatus WifiStaIface::configureRoamingInternal(const StaRoamingConfig& config) { |
| 489 | legacy_hal::wifi_roaming_config legacy_config; |
| 490 | if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, &legacy_config)) { |
| 491 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 492 | } |
| 493 | legacy_hal::wifi_error legacy_status = |
| 494 | legacy_hal_.lock()->configureRoaming(ifname_, legacy_config); |
| 495 | return createWifiStatusFromLegacyError(legacy_status); |
| 496 | } |
| 497 | |
| 498 | WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 499 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->enableFirmwareRoaming( |
| 500 | ifname_, hidl_struct_util::convertHidlRoamingStateToLegacy(state)); |
| 501 | return createWifiStatusFromLegacyError(legacy_status); |
| 502 | } |
| 503 | |
| 504 | WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 505 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->configureNdOffload(ifname_, enable); |
| 506 | return createWifiStatusFromLegacyError(legacy_status); |
| 507 | } |
| 508 | |
| 509 | WifiStatus WifiStaIface::startSendingKeepAlivePacketsInternal( |
| 510 | uint32_t cmd_id, const std::vector<uint8_t>& ip_packet_data, uint16_t ether_type, |
| 511 | const std::array<uint8_t, 6>& src_address, const std::array<uint8_t, 6>& dst_address, |
| 512 | uint32_t period_in_ms) { |
| 513 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startSendingOffloadedPacket( |
| 514 | ifname_, cmd_id, ether_type, ip_packet_data, src_address, dst_address, period_in_ms); |
| 515 | return createWifiStatusFromLegacyError(legacy_status); |
| 516 | } |
| 517 | |
| 518 | WifiStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(uint32_t cmd_id) { |
| 519 | legacy_hal::wifi_error legacy_status = |
| 520 | legacy_hal_.lock()->stopSendingOffloadedPacket(ifname_, cmd_id); |
| 521 | return createWifiStatusFromLegacyError(legacy_status); |
| 522 | } |
| 523 | |
| 524 | WifiStatus WifiStaIface::setScanningMacOuiInternal(const std::array<uint8_t, 3>& /* oui */) { |
| 525 | // deprecated. |
| 526 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
| 527 | } |
| 528 | |
| 529 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
| 530 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startPktFateMonitoring(ifname_); |
| 531 | return createWifiStatusFromLegacyError(legacy_status); |
| 532 | } |
| 533 | |
| 534 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 535 | WifiStaIface::getDebugTxPacketFatesInternal() { |
| 536 | legacy_hal::wifi_error legacy_status; |
| 537 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 538 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(ifname_); |
| 539 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 540 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 541 | } |
| 542 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 543 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl(legacy_fates, |
| 544 | &hidl_fates)) { |
| 545 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 546 | } |
| 547 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
| 548 | } |
| 549 | |
| 550 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 551 | WifiStaIface::getDebugRxPacketFatesInternal() { |
| 552 | legacy_hal::wifi_error legacy_status; |
| 553 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 554 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(ifname_); |
| 555 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 556 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 557 | } |
| 558 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 559 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl(legacy_fates, |
| 560 | &hidl_fates)) { |
| 561 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 562 | } |
| 563 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
| 564 | } |
| 565 | |
| 566 | WifiStatus WifiStaIface::setMacAddressInternal(const std::array<uint8_t, 6>& mac) { |
| 567 | bool status = iface_util_.lock()->setMacAddress(ifname_, mac); |
| 568 | if (!status) { |
| 569 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 570 | } |
| 571 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 572 | } |
| 573 | |
| 574 | std::pair<WifiStatus, std::array<uint8_t, 6>> WifiStaIface::getFactoryMacAddressInternal() { |
| 575 | std::array<uint8_t, 6> mac = iface_util_.lock()->getFactoryMacAddress(ifname_); |
| 576 | if (mac[0] == 0 && mac[1] == 0 && mac[2] == 0 && mac[3] == 0 && mac[4] == 0 && mac[5] == 0) { |
| 577 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), mac}; |
| 578 | } |
| 579 | return {createWifiStatus(WifiStatusCode::SUCCESS), mac}; |
| 580 | } |
| 581 | |
| 582 | WifiStatus WifiStaIface::setScanModeInternal(bool enable) { |
| 583 | // OEM's need to implement this on their devices if needed. |
| 584 | LOG(WARNING) << "setScanModeInternal(" << enable << ") not supported"; |
| 585 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
| 586 | } |
| 587 | |
| 588 | } // namespace implementation |
| 589 | } // namespace V1_6 |
| 590 | } // namespace wifi |
| 591 | } // namespace hardware |
| 592 | } // namespace android |