Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [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 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
| 18 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 19 | #include "hidl_return_util.h" |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 20 | #include "hidl_struct_util.h" |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 21 | #include "wifi_sta_iface.h" |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 22 | #include "wifi_status_util.h" |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
| 27 | namespace V1_0 { |
| 28 | namespace implementation { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 29 | using hidl_return_util::validateAndCall; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 30 | |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 31 | WifiStaIface::WifiStaIface( |
| 32 | const std::string& ifname, |
| 33 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal) |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 34 | : ifname_(ifname), legacy_hal_(legacy_hal), is_valid_(true) {} |
| 35 | |
| 36 | void WifiStaIface::invalidate() { |
| 37 | legacy_hal_.reset(); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 38 | event_callbacks_.clear(); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 39 | is_valid_ = false; |
| 40 | } |
| 41 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 42 | bool WifiStaIface::isValid() { |
| 43 | return is_valid_; |
| 44 | } |
| 45 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 46 | std::vector<sp<IWifiStaIfaceEventCallback>> WifiStaIface::getEventCallbacks() { |
| 47 | return event_callbacks_; |
| 48 | } |
| 49 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 50 | Return<void> WifiStaIface::getName(getName_cb hidl_status_cb) { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 51 | return validateAndCall(this, |
| 52 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 53 | &WifiStaIface::getNameInternal, |
| 54 | hidl_status_cb); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Roshan Pius | 734fea0 | 2016-10-11 08:30:28 -0700 | [diff] [blame] | 57 | Return<void> WifiStaIface::getType(getType_cb hidl_status_cb) { |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 58 | return validateAndCall(this, |
| 59 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 60 | &WifiStaIface::getTypeInternal, |
| 61 | hidl_status_cb); |
| 62 | } |
| 63 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 64 | Return<void> WifiStaIface::registerEventCallback( |
| 65 | const sp<IWifiStaIfaceEventCallback>& callback, |
| 66 | registerEventCallback_cb hidl_status_cb) { |
| 67 | return validateAndCall(this, |
| 68 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 69 | &WifiStaIface::registerEventCallbackInternal, |
| 70 | hidl_status_cb, |
| 71 | callback); |
| 72 | } |
| 73 | |
| 74 | Return<void> WifiStaIface::getCapabilities(getCapabilities_cb hidl_status_cb) { |
| 75 | return validateAndCall(this, |
| 76 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 77 | &WifiStaIface::getCapabilitiesInternal, |
| 78 | hidl_status_cb); |
| 79 | } |
| 80 | |
| 81 | Return<void> WifiStaIface::getApfPacketFilterCapabilities( |
| 82 | getApfPacketFilterCapabilities_cb hidl_status_cb) { |
| 83 | return validateAndCall(this, |
| 84 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 85 | &WifiStaIface::getApfPacketFilterCapabilitiesInternal, |
| 86 | hidl_status_cb); |
| 87 | } |
| 88 | |
| 89 | Return<void> WifiStaIface::installApfPacketFilter( |
| 90 | uint32_t cmd_id, |
| 91 | const hidl_vec<uint8_t>& program, |
| 92 | installApfPacketFilter_cb hidl_status_cb) { |
| 93 | return validateAndCall(this, |
| 94 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 95 | &WifiStaIface::installApfPacketFilterInternal, |
| 96 | hidl_status_cb, |
| 97 | cmd_id, |
| 98 | program); |
| 99 | } |
| 100 | |
| 101 | Return<void> WifiStaIface::getBackgroundScanCapabilities( |
| 102 | getBackgroundScanCapabilities_cb hidl_status_cb) { |
| 103 | return validateAndCall(this, |
| 104 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 105 | &WifiStaIface::getBackgroundScanCapabilitiesInternal, |
| 106 | hidl_status_cb); |
| 107 | } |
| 108 | |
| 109 | Return<void> WifiStaIface::getValidFrequenciesForBackgroundScan( |
| 110 | StaBackgroundScanBand band, |
| 111 | getValidFrequenciesForBackgroundScan_cb hidl_status_cb) { |
| 112 | return validateAndCall( |
| 113 | this, |
| 114 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 115 | &WifiStaIface::getValidFrequenciesForBackgroundScanInternal, |
| 116 | hidl_status_cb, |
| 117 | band); |
| 118 | } |
| 119 | |
| 120 | Return<void> WifiStaIface::startBackgroundScan( |
| 121 | uint32_t cmd_id, |
| 122 | const StaBackgroundScanParameters& params, |
| 123 | startBackgroundScan_cb hidl_status_cb) { |
| 124 | return validateAndCall(this, |
| 125 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 126 | &WifiStaIface::startBackgroundScanInternal, |
| 127 | hidl_status_cb, |
| 128 | cmd_id, |
| 129 | params); |
| 130 | } |
| 131 | |
| 132 | Return<void> WifiStaIface::stopBackgroundScan( |
| 133 | uint32_t cmd_id, stopBackgroundScan_cb hidl_status_cb) { |
| 134 | return validateAndCall(this, |
| 135 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 136 | &WifiStaIface::stopBackgroundScanInternal, |
| 137 | hidl_status_cb, |
| 138 | cmd_id); |
| 139 | } |
| 140 | |
| 141 | Return<void> WifiStaIface::enableLinkLayerStatsCollection( |
| 142 | bool debug, enableLinkLayerStatsCollection_cb hidl_status_cb) { |
| 143 | return validateAndCall(this, |
| 144 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 145 | &WifiStaIface::enableLinkLayerStatsCollectionInternal, |
| 146 | hidl_status_cb, |
| 147 | debug); |
| 148 | } |
| 149 | |
| 150 | Return<void> WifiStaIface::disableLinkLayerStatsCollection( |
| 151 | disableLinkLayerStatsCollection_cb hidl_status_cb) { |
| 152 | return validateAndCall(this, |
| 153 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 154 | &WifiStaIface::disableLinkLayerStatsCollectionInternal, |
| 155 | hidl_status_cb); |
| 156 | } |
| 157 | |
| 158 | Return<void> WifiStaIface::getLinkLayerStats( |
| 159 | getLinkLayerStats_cb hidl_status_cb) { |
| 160 | return validateAndCall(this, |
| 161 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 162 | &WifiStaIface::getLinkLayerStatsInternal, |
| 163 | hidl_status_cb); |
| 164 | } |
| 165 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 166 | Return<void> WifiStaIface::startRssiMonitoring( |
| 167 | uint32_t cmd_id, |
| 168 | int32_t max_rssi, |
| 169 | int32_t min_rssi, |
| 170 | startRssiMonitoring_cb hidl_status_cb) { |
| 171 | return validateAndCall(this, |
| 172 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 173 | &WifiStaIface::startRssiMonitoringInternal, |
| 174 | hidl_status_cb, |
| 175 | cmd_id, |
| 176 | max_rssi, |
| 177 | min_rssi); |
| 178 | } |
| 179 | |
| 180 | Return<void> WifiStaIface::stopRssiMonitoring( |
| 181 | uint32_t cmd_id, stopRssiMonitoring_cb hidl_status_cb) { |
| 182 | return validateAndCall(this, |
| 183 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 184 | &WifiStaIface::stopRssiMonitoringInternal, |
| 185 | hidl_status_cb, |
| 186 | cmd_id); |
| 187 | } |
| 188 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 189 | Return<void> WifiStaIface::getRoamingCapabilities( |
| 190 | getRoamingCapabilities_cb hidl_status_cb) { |
| 191 | return validateAndCall(this, |
| 192 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 193 | &WifiStaIface::getRoamingCapabilitiesInternal, |
| 194 | hidl_status_cb); |
| 195 | } |
| 196 | |
| 197 | Return<void> WifiStaIface::configureRoaming( |
| 198 | const StaRoamingConfig& config, configureRoaming_cb hidl_status_cb) { |
| 199 | return validateAndCall(this, |
| 200 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 201 | &WifiStaIface::configureRoamingInternal, |
| 202 | hidl_status_cb, |
| 203 | config); |
| 204 | } |
| 205 | |
| 206 | Return<void> WifiStaIface::setRoamingState(StaRoamingState state, |
| 207 | setRoamingState_cb hidl_status_cb) { |
| 208 | return validateAndCall(this, |
| 209 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 210 | &WifiStaIface::setRoamingStateInternal, |
| 211 | hidl_status_cb, |
| 212 | state); |
| 213 | } |
| 214 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame^] | 215 | Return<void> WifiStaIface::enableNdOffload(bool enable, |
| 216 | enableNdOffload_cb hidl_status_cb) { |
| 217 | return validateAndCall(this, |
| 218 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 219 | &WifiStaIface::enableNdOffloadInternal, |
| 220 | hidl_status_cb, |
| 221 | enable); |
| 222 | } |
| 223 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 224 | Return<void> WifiStaIface::startDebugPacketFateMonitoring( |
| 225 | startDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 226 | return validateAndCall(this, |
| 227 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 228 | &WifiStaIface::startDebugPacketFateMonitoringInternal, |
| 229 | hidl_status_cb); |
| 230 | } |
| 231 | |
| 232 | Return<void> WifiStaIface::stopDebugPacketFateMonitoring( |
| 233 | stopDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 234 | return validateAndCall(this, |
| 235 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 236 | &WifiStaIface::stopDebugPacketFateMonitoringInternal, |
| 237 | hidl_status_cb); |
| 238 | } |
| 239 | |
| 240 | Return<void> WifiStaIface::getDebugTxPacketFates( |
| 241 | getDebugTxPacketFates_cb hidl_status_cb) { |
| 242 | return validateAndCall(this, |
| 243 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 244 | &WifiStaIface::getDebugTxPacketFatesInternal, |
| 245 | hidl_status_cb); |
| 246 | } |
| 247 | |
| 248 | Return<void> WifiStaIface::getDebugRxPacketFates( |
| 249 | getDebugRxPacketFates_cb hidl_status_cb) { |
| 250 | return validateAndCall(this, |
| 251 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 252 | &WifiStaIface::getDebugRxPacketFatesInternal, |
| 253 | hidl_status_cb); |
| 254 | } |
| 255 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 256 | std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() { |
| 257 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
| 258 | } |
| 259 | |
| 260 | std::pair<WifiStatus, IfaceType> WifiStaIface::getTypeInternal() { |
| 261 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::STA}; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 264 | WifiStatus WifiStaIface::registerEventCallbackInternal( |
| 265 | const sp<IWifiStaIfaceEventCallback>& callback) { |
| 266 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 267 | event_callbacks_.emplace_back(callback); |
| 268 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 269 | } |
| 270 | |
| 271 | std::pair<WifiStatus, uint32_t> WifiStaIface::getCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 272 | legacy_hal::wifi_error legacy_status; |
| 273 | uint32_t legacy_feature_set; |
| 274 | std::tie(legacy_status, legacy_feature_set) = |
| 275 | legacy_hal_.lock()->getSupportedFeatureSet(); |
| 276 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 277 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 278 | } |
| 279 | uint32_t legacy_logger_feature_set; |
| 280 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 281 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 282 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 283 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 284 | } |
| 285 | uint32_t hidl_caps; |
| 286 | if (!hidl_struct_util::convertLegacyFeaturesToHidlStaCapabilities( |
| 287 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 288 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 289 | } |
| 290 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | std::pair<WifiStatus, StaApfPacketFilterCapabilities> |
| 294 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 295 | legacy_hal::wifi_error legacy_status; |
| 296 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 297 | std::tie(legacy_status, legacy_caps) = |
| 298 | legacy_hal_.lock()->getPacketFilterCapabilities(); |
| 299 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 300 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 301 | } |
| 302 | StaApfPacketFilterCapabilities hidl_caps; |
| 303 | if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, |
| 304 | &hidl_caps)) { |
| 305 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 306 | } |
| 307 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | WifiStatus WifiStaIface::installApfPacketFilterInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 311 | uint32_t /* cmd_id */, const std::vector<uint8_t>& program) { |
| 312 | legacy_hal::wifi_error legacy_status = |
| 313 | legacy_hal_.lock()->setPacketFilter(program); |
| 314 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | std::pair<WifiStatus, StaBackgroundScanCapabilities> |
| 318 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 319 | legacy_hal::wifi_error legacy_status; |
| 320 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 321 | std::tie(legacy_status, legacy_caps) = |
| 322 | legacy_hal_.lock()->getGscanCapabilities(); |
| 323 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 324 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 325 | } |
| 326 | StaBackgroundScanCapabilities hidl_caps; |
| 327 | if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, |
| 328 | &hidl_caps)) { |
| 329 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 330 | } |
| 331 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 335 | WifiStaIface::getValidFrequenciesForBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 336 | StaBackgroundScanBand band) { |
| 337 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); |
| 338 | legacy_hal::wifi_error legacy_status; |
| 339 | std::vector<uint32_t> valid_frequencies; |
| 340 | std::tie(legacy_status, valid_frequencies) = |
| 341 | legacy_hal_.lock()->getValidFrequenciesForGscan( |
| 342 | hidl_struct_util::convertHidlGscanBandToLegacy(band)); |
| 343 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | WifiStatus WifiStaIface::startBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 347 | uint32_t cmd_id, const StaBackgroundScanParameters& params) { |
| 348 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 349 | if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, |
| 350 | &legacy_params)) { |
| 351 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 352 | } |
| 353 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 354 | const auto& on_failure_callback = |
| 355 | [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 356 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 357 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 358 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 359 | return; |
| 360 | } |
| 361 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 362 | callback->onBackgroundScanFailure(id); |
| 363 | } |
| 364 | }; |
| 365 | const auto& on_results_callback = [weak_ptr_this]( |
| 366 | legacy_hal::wifi_request_id id, |
| 367 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 368 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 369 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 370 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 371 | return; |
| 372 | } |
| 373 | std::vector<StaScanData> hidl_scan_datas; |
| 374 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 375 | results, &hidl_scan_datas)) { |
| 376 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 377 | return; |
| 378 | } |
| 379 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 380 | callback->onBackgroundScanResults(id, hidl_scan_datas); |
| 381 | } |
| 382 | }; |
| 383 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 384 | legacy_hal::wifi_request_id id, |
| 385 | const legacy_hal::wifi_scan_result* result, |
| 386 | uint32_t /* buckets_scanned */) { |
| 387 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 388 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 389 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 390 | return; |
| 391 | } |
| 392 | StaScanResult hidl_scan_result; |
| 393 | if (!hidl_struct_util::convertLegacyGscanResultToHidl( |
| 394 | *result, true, &hidl_scan_result)) { |
| 395 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 396 | return; |
| 397 | } |
| 398 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 399 | callback->onBackgroundFullScanResult(id, hidl_scan_result); |
| 400 | } |
| 401 | }; |
| 402 | legacy_hal::wifi_error legacy_status = |
| 403 | legacy_hal_.lock()->startGscan(cmd_id, |
| 404 | legacy_params, |
| 405 | on_failure_callback, |
| 406 | on_results_callback, |
| 407 | on_full_result_callback); |
| 408 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 411 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 412 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(cmd_id); |
| 413 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 416 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 417 | legacy_hal::wifi_error legacy_status = |
| 418 | legacy_hal_.lock()->enableLinkLayerStats(debug); |
| 419 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 423 | legacy_hal::wifi_error legacy_status = |
| 424 | legacy_hal_.lock()->disableLinkLayerStats(); |
| 425 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | std::pair<WifiStatus, StaLinkLayerStats> |
| 429 | WifiStaIface::getLinkLayerStatsInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 430 | legacy_hal::wifi_error legacy_status; |
| 431 | legacy_hal::LinkLayerStats legacy_stats; |
| 432 | std::tie(legacy_status, legacy_stats) = |
| 433 | legacy_hal_.lock()->getLinkLayerStats(); |
| 434 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 435 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 436 | } |
| 437 | StaLinkLayerStats hidl_stats; |
| 438 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, |
| 439 | &hidl_stats)) { |
| 440 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 441 | } |
| 442 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 445 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, |
| 446 | int32_t max_rssi, |
| 447 | int32_t min_rssi) { |
| 448 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 449 | const auto& on_threshold_breached_callback = [weak_ptr_this]( |
| 450 | 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 | callback->onRssiThresholdBreached(id, bssid, rssi); |
| 460 | } |
| 461 | }; |
| 462 | legacy_hal::wifi_error legacy_status = |
| 463 | legacy_hal_.lock()->startRssiMonitoring( |
| 464 | cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 465 | return createWifiStatusFromLegacyError(legacy_status); |
| 466 | } |
| 467 | |
| 468 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 469 | legacy_hal::wifi_error legacy_status = |
| 470 | legacy_hal_.lock()->stopRssiMonitoring(cmd_id); |
| 471 | return createWifiStatusFromLegacyError(legacy_status); |
| 472 | } |
| 473 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 474 | std::pair<WifiStatus, StaRoamingCapabilities> |
| 475 | WifiStaIface::getRoamingCapabilitiesInternal() { |
| 476 | legacy_hal::wifi_error legacy_status; |
| 477 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 478 | std::tie(legacy_status, legacy_caps) = |
| 479 | legacy_hal_.lock()->getRoamingCapabilities(); |
| 480 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 481 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 482 | } |
| 483 | StaRoamingCapabilities hidl_caps; |
| 484 | if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, |
| 485 | &hidl_caps)) { |
| 486 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 487 | } |
| 488 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 489 | } |
| 490 | |
| 491 | WifiStatus WifiStaIface::configureRoamingInternal( |
| 492 | const StaRoamingConfig& config) { |
| 493 | legacy_hal::wifi_roaming_config legacy_config; |
| 494 | if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, |
| 495 | &legacy_config)) { |
| 496 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 497 | } |
| 498 | legacy_hal::wifi_error legacy_status = |
| 499 | legacy_hal_.lock()->configureRoaming(legacy_config); |
| 500 | return createWifiStatusFromLegacyError(legacy_status); |
| 501 | } |
| 502 | |
| 503 | WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 504 | legacy_hal::wifi_error legacy_status = |
| 505 | legacy_hal_.lock()->enableFirmwareRoaming( |
| 506 | hidl_struct_util::convertHidlRoamingStateToLegacy(state)); |
| 507 | return createWifiStatusFromLegacyError(legacy_status); |
| 508 | } |
| 509 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame^] | 510 | WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 511 | legacy_hal::wifi_error legacy_status = |
| 512 | legacy_hal_.lock()->configureNdOffload(enable); |
| 513 | return createWifiStatusFromLegacyError(legacy_status); |
| 514 | } |
| 515 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 516 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 517 | legacy_hal::wifi_error legacy_status = |
| 518 | legacy_hal_.lock()->startPktFateMonitoring(); |
| 519 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | WifiStatus WifiStaIface::stopDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 523 | // There is no stop in legacy HAL implementation. |
| 524 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 528 | WifiStaIface::getDebugTxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 529 | legacy_hal::wifi_error legacy_status; |
| 530 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 531 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(); |
| 532 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 533 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 534 | } |
| 535 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 536 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 537 | legacy_fates, &hidl_fates)) { |
| 538 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 539 | } |
| 540 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 544 | WifiStaIface::getDebugRxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 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(); |
| 548 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 549 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 550 | } |
| 551 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 552 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 553 | legacy_fates, &hidl_fates)) { |
| 554 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 555 | } |
| 556 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 559 | } // namespace implementation |
| 560 | } // namespace V1_0 |
| 561 | } // namespace wifi |
| 562 | } // namespace hardware |
| 563 | } // namespace android |