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 | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 189 | Return<void> WifiStaIface::startDebugPacketFateMonitoring( |
| 190 | startDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 191 | return validateAndCall(this, |
| 192 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 193 | &WifiStaIface::startDebugPacketFateMonitoringInternal, |
| 194 | hidl_status_cb); |
| 195 | } |
| 196 | |
| 197 | Return<void> WifiStaIface::stopDebugPacketFateMonitoring( |
| 198 | stopDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 199 | return validateAndCall(this, |
| 200 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 201 | &WifiStaIface::stopDebugPacketFateMonitoringInternal, |
| 202 | hidl_status_cb); |
| 203 | } |
| 204 | |
| 205 | Return<void> WifiStaIface::getDebugTxPacketFates( |
| 206 | getDebugTxPacketFates_cb hidl_status_cb) { |
| 207 | return validateAndCall(this, |
| 208 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 209 | &WifiStaIface::getDebugTxPacketFatesInternal, |
| 210 | hidl_status_cb); |
| 211 | } |
| 212 | |
| 213 | Return<void> WifiStaIface::getDebugRxPacketFates( |
| 214 | getDebugRxPacketFates_cb hidl_status_cb) { |
| 215 | return validateAndCall(this, |
| 216 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 217 | &WifiStaIface::getDebugRxPacketFatesInternal, |
| 218 | hidl_status_cb); |
| 219 | } |
| 220 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 221 | std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() { |
| 222 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
| 223 | } |
| 224 | |
| 225 | std::pair<WifiStatus, IfaceType> WifiStaIface::getTypeInternal() { |
| 226 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::STA}; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 229 | WifiStatus WifiStaIface::registerEventCallbackInternal( |
| 230 | const sp<IWifiStaIfaceEventCallback>& callback) { |
| 231 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 232 | event_callbacks_.emplace_back(callback); |
| 233 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 234 | } |
| 235 | |
| 236 | std::pair<WifiStatus, uint32_t> WifiStaIface::getCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 237 | legacy_hal::wifi_error legacy_status; |
| 238 | uint32_t legacy_feature_set; |
| 239 | std::tie(legacy_status, legacy_feature_set) = |
| 240 | legacy_hal_.lock()->getSupportedFeatureSet(); |
| 241 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 242 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 243 | } |
| 244 | uint32_t legacy_logger_feature_set; |
| 245 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 246 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 247 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 248 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 249 | } |
| 250 | uint32_t hidl_caps; |
| 251 | if (!hidl_struct_util::convertLegacyFeaturesToHidlStaCapabilities( |
| 252 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 253 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 254 | } |
| 255 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | std::pair<WifiStatus, StaApfPacketFilterCapabilities> |
| 259 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 260 | legacy_hal::wifi_error legacy_status; |
| 261 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 262 | std::tie(legacy_status, legacy_caps) = |
| 263 | legacy_hal_.lock()->getPacketFilterCapabilities(); |
| 264 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 265 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 266 | } |
| 267 | StaApfPacketFilterCapabilities hidl_caps; |
| 268 | if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, |
| 269 | &hidl_caps)) { |
| 270 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 271 | } |
| 272 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | WifiStatus WifiStaIface::installApfPacketFilterInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 276 | uint32_t /* cmd_id */, const std::vector<uint8_t>& program) { |
| 277 | legacy_hal::wifi_error legacy_status = |
| 278 | legacy_hal_.lock()->setPacketFilter(program); |
| 279 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | std::pair<WifiStatus, StaBackgroundScanCapabilities> |
| 283 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 284 | legacy_hal::wifi_error legacy_status; |
| 285 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 286 | std::tie(legacy_status, legacy_caps) = |
| 287 | legacy_hal_.lock()->getGscanCapabilities(); |
| 288 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 289 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 290 | } |
| 291 | StaBackgroundScanCapabilities hidl_caps; |
| 292 | if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, |
| 293 | &hidl_caps)) { |
| 294 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 295 | } |
| 296 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 300 | WifiStaIface::getValidFrequenciesForBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 301 | StaBackgroundScanBand band) { |
| 302 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); |
| 303 | legacy_hal::wifi_error legacy_status; |
| 304 | std::vector<uint32_t> valid_frequencies; |
| 305 | std::tie(legacy_status, valid_frequencies) = |
| 306 | legacy_hal_.lock()->getValidFrequenciesForGscan( |
| 307 | hidl_struct_util::convertHidlGscanBandToLegacy(band)); |
| 308 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | WifiStatus WifiStaIface::startBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 312 | uint32_t cmd_id, const StaBackgroundScanParameters& params) { |
| 313 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 314 | if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, |
| 315 | &legacy_params)) { |
| 316 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 317 | } |
| 318 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 319 | const auto& on_failure_callback = |
| 320 | [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 321 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 322 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 323 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 324 | return; |
| 325 | } |
| 326 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 327 | callback->onBackgroundScanFailure(id); |
| 328 | } |
| 329 | }; |
| 330 | const auto& on_results_callback = [weak_ptr_this]( |
| 331 | legacy_hal::wifi_request_id id, |
| 332 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 333 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 334 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 335 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 336 | return; |
| 337 | } |
| 338 | std::vector<StaScanData> hidl_scan_datas; |
| 339 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 340 | results, &hidl_scan_datas)) { |
| 341 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 342 | return; |
| 343 | } |
| 344 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 345 | callback->onBackgroundScanResults(id, hidl_scan_datas); |
| 346 | } |
| 347 | }; |
| 348 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 349 | legacy_hal::wifi_request_id id, |
| 350 | const legacy_hal::wifi_scan_result* result, |
| 351 | uint32_t /* buckets_scanned */) { |
| 352 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 353 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 354 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 355 | return; |
| 356 | } |
| 357 | StaScanResult hidl_scan_result; |
| 358 | if (!hidl_struct_util::convertLegacyGscanResultToHidl( |
| 359 | *result, true, &hidl_scan_result)) { |
| 360 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 361 | return; |
| 362 | } |
| 363 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 364 | callback->onBackgroundFullScanResult(id, hidl_scan_result); |
| 365 | } |
| 366 | }; |
| 367 | legacy_hal::wifi_error legacy_status = |
| 368 | legacy_hal_.lock()->startGscan(cmd_id, |
| 369 | legacy_params, |
| 370 | on_failure_callback, |
| 371 | on_results_callback, |
| 372 | on_full_result_callback); |
| 373 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 376 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 377 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(cmd_id); |
| 378 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 381 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 382 | legacy_hal::wifi_error legacy_status = |
| 383 | legacy_hal_.lock()->enableLinkLayerStats(debug); |
| 384 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 388 | legacy_hal::wifi_error legacy_status = |
| 389 | legacy_hal_.lock()->disableLinkLayerStats(); |
| 390 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | std::pair<WifiStatus, StaLinkLayerStats> |
| 394 | WifiStaIface::getLinkLayerStatsInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 395 | legacy_hal::wifi_error legacy_status; |
| 396 | legacy_hal::LinkLayerStats legacy_stats; |
| 397 | std::tie(legacy_status, legacy_stats) = |
| 398 | legacy_hal_.lock()->getLinkLayerStats(); |
| 399 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 400 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 401 | } |
| 402 | StaLinkLayerStats hidl_stats; |
| 403 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, |
| 404 | &hidl_stats)) { |
| 405 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 406 | } |
| 407 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 410 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, |
| 411 | int32_t max_rssi, |
| 412 | int32_t min_rssi) { |
| 413 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 414 | const auto& on_threshold_breached_callback = [weak_ptr_this]( |
| 415 | legacy_hal::wifi_request_id id, |
| 416 | std::array<uint8_t, 6> bssid, |
| 417 | int8_t rssi) { |
| 418 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 419 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 420 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 421 | return; |
| 422 | } |
| 423 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 424 | callback->onRssiThresholdBreached(id, bssid, rssi); |
| 425 | } |
| 426 | }; |
| 427 | legacy_hal::wifi_error legacy_status = |
| 428 | legacy_hal_.lock()->startRssiMonitoring( |
| 429 | cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 430 | return createWifiStatusFromLegacyError(legacy_status); |
| 431 | } |
| 432 | |
| 433 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 434 | legacy_hal::wifi_error legacy_status = |
| 435 | legacy_hal_.lock()->stopRssiMonitoring(cmd_id); |
| 436 | return createWifiStatusFromLegacyError(legacy_status); |
| 437 | } |
| 438 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 439 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 440 | legacy_hal::wifi_error legacy_status = |
| 441 | legacy_hal_.lock()->startPktFateMonitoring(); |
| 442 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | WifiStatus WifiStaIface::stopDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 446 | // There is no stop in legacy HAL implementation. |
| 447 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 451 | WifiStaIface::getDebugTxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 452 | legacy_hal::wifi_error legacy_status; |
| 453 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 454 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(); |
| 455 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 456 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 457 | } |
| 458 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 459 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 460 | legacy_fates, &hidl_fates)) { |
| 461 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 462 | } |
| 463 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 467 | WifiStaIface::getDebugRxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 468 | legacy_hal::wifi_error legacy_status; |
| 469 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 470 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(); |
| 471 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 472 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 473 | } |
| 474 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 475 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 476 | legacy_fates, &hidl_fates)) { |
| 477 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 478 | } |
| 479 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 482 | } // namespace implementation |
| 483 | } // namespace V1_0 |
| 484 | } // namespace wifi |
| 485 | } // namespace hardware |
| 486 | } // namespace android |