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 | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 224 | Return<void> WifiStaIface::startSendingKeepAlivePackets( |
| 225 | uint32_t cmd_id, |
| 226 | const hidl_vec<uint8_t>& ip_packet_data, |
| 227 | uint16_t ether_type, |
| 228 | const hidl_array<uint8_t, 6>& src_address, |
| 229 | const hidl_array<uint8_t, 6>& dst_address, |
| 230 | uint32_t period_in_ms, |
| 231 | startSendingKeepAlivePackets_cb hidl_status_cb) { |
| 232 | return validateAndCall(this, |
| 233 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 234 | &WifiStaIface::startSendingKeepAlivePacketsInternal, |
| 235 | hidl_status_cb, |
| 236 | cmd_id, |
| 237 | ip_packet_data, |
| 238 | ether_type, |
| 239 | src_address, |
| 240 | dst_address, |
| 241 | period_in_ms); |
| 242 | } |
| 243 | |
| 244 | Return<void> WifiStaIface::stopSendingKeepAlivePackets( |
| 245 | uint32_t cmd_id, stopSendingKeepAlivePackets_cb hidl_status_cb) { |
| 246 | return validateAndCall(this, |
| 247 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 248 | &WifiStaIface::stopSendingKeepAlivePacketsInternal, |
| 249 | hidl_status_cb, |
| 250 | cmd_id); |
| 251 | } |
| 252 | |
Roshan Pius | 795bb81 | 2017-02-01 13:09:08 -0800 | [diff] [blame] | 253 | Return<void> WifiStaIface::setScanningMacOui( |
| 254 | const hidl_array<uint8_t, 3>& oui, setScanningMacOui_cb hidl_status_cb) { |
| 255 | return validateAndCall(this, |
| 256 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 257 | &WifiStaIface::setScanningMacOuiInternal, |
| 258 | hidl_status_cb, |
| 259 | oui); |
| 260 | } |
| 261 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 262 | Return<void> WifiStaIface::startDebugPacketFateMonitoring( |
| 263 | startDebugPacketFateMonitoring_cb hidl_status_cb) { |
| 264 | return validateAndCall(this, |
| 265 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 266 | &WifiStaIface::startDebugPacketFateMonitoringInternal, |
| 267 | hidl_status_cb); |
| 268 | } |
| 269 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 270 | Return<void> WifiStaIface::getDebugTxPacketFates( |
| 271 | getDebugTxPacketFates_cb hidl_status_cb) { |
| 272 | return validateAndCall(this, |
| 273 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 274 | &WifiStaIface::getDebugTxPacketFatesInternal, |
| 275 | hidl_status_cb); |
| 276 | } |
| 277 | |
| 278 | Return<void> WifiStaIface::getDebugRxPacketFates( |
| 279 | getDebugRxPacketFates_cb hidl_status_cb) { |
| 280 | return validateAndCall(this, |
| 281 | WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 282 | &WifiStaIface::getDebugRxPacketFatesInternal, |
| 283 | hidl_status_cb); |
| 284 | } |
| 285 | |
Roshan Pius | 907d4a2 | 2016-10-27 12:48:12 -0700 | [diff] [blame] | 286 | std::pair<WifiStatus, std::string> WifiStaIface::getNameInternal() { |
| 287 | return {createWifiStatus(WifiStatusCode::SUCCESS), ifname_}; |
| 288 | } |
| 289 | |
| 290 | std::pair<WifiStatus, IfaceType> WifiStaIface::getTypeInternal() { |
| 291 | return {createWifiStatus(WifiStatusCode::SUCCESS), IfaceType::STA}; |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 294 | WifiStatus WifiStaIface::registerEventCallbackInternal( |
| 295 | const sp<IWifiStaIfaceEventCallback>& callback) { |
| 296 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 297 | event_callbacks_.emplace_back(callback); |
| 298 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 299 | } |
| 300 | |
| 301 | std::pair<WifiStatus, uint32_t> WifiStaIface::getCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 302 | legacy_hal::wifi_error legacy_status; |
| 303 | uint32_t legacy_feature_set; |
| 304 | std::tie(legacy_status, legacy_feature_set) = |
| 305 | legacy_hal_.lock()->getSupportedFeatureSet(); |
| 306 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 307 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 308 | } |
| 309 | uint32_t legacy_logger_feature_set; |
| 310 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 311 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 312 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 313 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 314 | } |
| 315 | uint32_t hidl_caps; |
| 316 | if (!hidl_struct_util::convertLegacyFeaturesToHidlStaCapabilities( |
| 317 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 318 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 319 | } |
| 320 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | std::pair<WifiStatus, StaApfPacketFilterCapabilities> |
| 324 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 325 | legacy_hal::wifi_error legacy_status; |
| 326 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 327 | std::tie(legacy_status, legacy_caps) = |
| 328 | legacy_hal_.lock()->getPacketFilterCapabilities(); |
| 329 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 330 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 331 | } |
| 332 | StaApfPacketFilterCapabilities hidl_caps; |
| 333 | if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, |
| 334 | &hidl_caps)) { |
| 335 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 336 | } |
| 337 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | WifiStatus WifiStaIface::installApfPacketFilterInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 341 | uint32_t /* cmd_id */, const std::vector<uint8_t>& program) { |
| 342 | legacy_hal::wifi_error legacy_status = |
| 343 | legacy_hal_.lock()->setPacketFilter(program); |
| 344 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | std::pair<WifiStatus, StaBackgroundScanCapabilities> |
| 348 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 349 | legacy_hal::wifi_error legacy_status; |
| 350 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 351 | std::tie(legacy_status, legacy_caps) = |
| 352 | legacy_hal_.lock()->getGscanCapabilities(); |
| 353 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 354 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 355 | } |
| 356 | StaBackgroundScanCapabilities hidl_caps; |
| 357 | if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, |
| 358 | &hidl_caps)) { |
| 359 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 360 | } |
| 361 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 365 | WifiStaIface::getValidFrequenciesForBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 366 | StaBackgroundScanBand band) { |
| 367 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); |
| 368 | legacy_hal::wifi_error legacy_status; |
| 369 | std::vector<uint32_t> valid_frequencies; |
| 370 | std::tie(legacy_status, valid_frequencies) = |
| 371 | legacy_hal_.lock()->getValidFrequenciesForGscan( |
| 372 | hidl_struct_util::convertHidlGscanBandToLegacy(band)); |
| 373 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | WifiStatus WifiStaIface::startBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 377 | uint32_t cmd_id, const StaBackgroundScanParameters& params) { |
| 378 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 379 | if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, |
| 380 | &legacy_params)) { |
| 381 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 382 | } |
| 383 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 384 | const auto& on_failure_callback = |
| 385 | [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 386 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 387 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 388 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 389 | return; |
| 390 | } |
| 391 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 392 | callback->onBackgroundScanFailure(id); |
| 393 | } |
| 394 | }; |
| 395 | const auto& on_results_callback = [weak_ptr_this]( |
| 396 | legacy_hal::wifi_request_id id, |
| 397 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 398 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 399 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 400 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 401 | return; |
| 402 | } |
| 403 | std::vector<StaScanData> hidl_scan_datas; |
| 404 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 405 | results, &hidl_scan_datas)) { |
| 406 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 407 | return; |
| 408 | } |
| 409 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 410 | callback->onBackgroundScanResults(id, hidl_scan_datas); |
| 411 | } |
| 412 | }; |
| 413 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 414 | legacy_hal::wifi_request_id id, |
| 415 | const legacy_hal::wifi_scan_result* result, |
| 416 | uint32_t /* buckets_scanned */) { |
| 417 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 418 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 419 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 420 | return; |
| 421 | } |
| 422 | StaScanResult hidl_scan_result; |
| 423 | if (!hidl_struct_util::convertLegacyGscanResultToHidl( |
| 424 | *result, true, &hidl_scan_result)) { |
| 425 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 426 | return; |
| 427 | } |
| 428 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 429 | callback->onBackgroundFullScanResult(id, hidl_scan_result); |
| 430 | } |
| 431 | }; |
| 432 | legacy_hal::wifi_error legacy_status = |
| 433 | legacy_hal_.lock()->startGscan(cmd_id, |
| 434 | legacy_params, |
| 435 | on_failure_callback, |
| 436 | on_results_callback, |
| 437 | on_full_result_callback); |
| 438 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 441 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 442 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(cmd_id); |
| 443 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 446 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 447 | legacy_hal::wifi_error legacy_status = |
| 448 | legacy_hal_.lock()->enableLinkLayerStats(debug); |
| 449 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 453 | legacy_hal::wifi_error legacy_status = |
| 454 | legacy_hal_.lock()->disableLinkLayerStats(); |
| 455 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | std::pair<WifiStatus, StaLinkLayerStats> |
| 459 | WifiStaIface::getLinkLayerStatsInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 460 | legacy_hal::wifi_error legacy_status; |
| 461 | legacy_hal::LinkLayerStats legacy_stats; |
| 462 | std::tie(legacy_status, legacy_stats) = |
| 463 | legacy_hal_.lock()->getLinkLayerStats(); |
| 464 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 465 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 466 | } |
| 467 | StaLinkLayerStats hidl_stats; |
| 468 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, |
| 469 | &hidl_stats)) { |
| 470 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 471 | } |
| 472 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 475 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, |
| 476 | int32_t max_rssi, |
| 477 | int32_t min_rssi) { |
| 478 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 479 | const auto& on_threshold_breached_callback = [weak_ptr_this]( |
| 480 | legacy_hal::wifi_request_id id, |
| 481 | std::array<uint8_t, 6> bssid, |
| 482 | int8_t rssi) { |
| 483 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 484 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 485 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 486 | return; |
| 487 | } |
| 488 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 489 | callback->onRssiThresholdBreached(id, bssid, rssi); |
| 490 | } |
| 491 | }; |
| 492 | legacy_hal::wifi_error legacy_status = |
| 493 | legacy_hal_.lock()->startRssiMonitoring( |
| 494 | cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 495 | return createWifiStatusFromLegacyError(legacy_status); |
| 496 | } |
| 497 | |
| 498 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 499 | legacy_hal::wifi_error legacy_status = |
| 500 | legacy_hal_.lock()->stopRssiMonitoring(cmd_id); |
| 501 | return createWifiStatusFromLegacyError(legacy_status); |
| 502 | } |
| 503 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 504 | std::pair<WifiStatus, StaRoamingCapabilities> |
| 505 | WifiStaIface::getRoamingCapabilitiesInternal() { |
| 506 | legacy_hal::wifi_error legacy_status; |
| 507 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 508 | std::tie(legacy_status, legacy_caps) = |
| 509 | legacy_hal_.lock()->getRoamingCapabilities(); |
| 510 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 511 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 512 | } |
| 513 | StaRoamingCapabilities hidl_caps; |
| 514 | if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, |
| 515 | &hidl_caps)) { |
| 516 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 517 | } |
| 518 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 519 | } |
| 520 | |
| 521 | WifiStatus WifiStaIface::configureRoamingInternal( |
| 522 | const StaRoamingConfig& config) { |
| 523 | legacy_hal::wifi_roaming_config legacy_config; |
| 524 | if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, |
| 525 | &legacy_config)) { |
| 526 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 527 | } |
| 528 | legacy_hal::wifi_error legacy_status = |
| 529 | legacy_hal_.lock()->configureRoaming(legacy_config); |
| 530 | return createWifiStatusFromLegacyError(legacy_status); |
| 531 | } |
| 532 | |
| 533 | WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 534 | legacy_hal::wifi_error legacy_status = |
| 535 | legacy_hal_.lock()->enableFirmwareRoaming( |
| 536 | hidl_struct_util::convertHidlRoamingStateToLegacy(state)); |
| 537 | return createWifiStatusFromLegacyError(legacy_status); |
| 538 | } |
| 539 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 540 | WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 541 | legacy_hal::wifi_error legacy_status = |
| 542 | legacy_hal_.lock()->configureNdOffload(enable); |
| 543 | return createWifiStatusFromLegacyError(legacy_status); |
| 544 | } |
| 545 | |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 546 | WifiStatus WifiStaIface::startSendingKeepAlivePacketsInternal( |
| 547 | uint32_t cmd_id, |
| 548 | const std::vector<uint8_t>& ip_packet_data, |
| 549 | uint16_t /* ether_type */, |
| 550 | const std::array<uint8_t, 6>& src_address, |
| 551 | const std::array<uint8_t, 6>& dst_address, |
| 552 | uint32_t period_in_ms) { |
| 553 | legacy_hal::wifi_error legacy_status = |
| 554 | legacy_hal_.lock()->startSendingOffloadedPacket( |
| 555 | cmd_id, ip_packet_data, src_address, dst_address, period_in_ms); |
| 556 | return createWifiStatusFromLegacyError(legacy_status); |
| 557 | } |
| 558 | |
| 559 | WifiStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(uint32_t cmd_id) { |
| 560 | legacy_hal::wifi_error legacy_status = |
| 561 | legacy_hal_.lock()->stopSendingOffloadedPacket(cmd_id); |
| 562 | return createWifiStatusFromLegacyError(legacy_status); |
| 563 | } |
| 564 | |
Roshan Pius | 795bb81 | 2017-02-01 13:09:08 -0800 | [diff] [blame] | 565 | WifiStatus WifiStaIface::setScanningMacOuiInternal(const std::array<uint8_t, 3>& oui) { |
| 566 | legacy_hal::wifi_error legacy_status = |
| 567 | legacy_hal_.lock()->setScanningMacOui(oui); |
| 568 | return createWifiStatusFromLegacyError(legacy_status); |
| 569 | } |
| 570 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 571 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 572 | legacy_hal::wifi_error legacy_status = |
| 573 | legacy_hal_.lock()->startPktFateMonitoring(); |
| 574 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 577 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 578 | WifiStaIface::getDebugTxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 579 | legacy_hal::wifi_error legacy_status; |
| 580 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 581 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(); |
| 582 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 583 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 584 | } |
| 585 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 586 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 587 | legacy_fates, &hidl_fates)) { |
| 588 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 589 | } |
| 590 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 594 | WifiStaIface::getDebugRxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 595 | legacy_hal::wifi_error legacy_status; |
| 596 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 597 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(); |
| 598 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 599 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 600 | } |
| 601 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 602 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 603 | legacy_fates, &hidl_fates)) { |
| 604 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 605 | } |
| 606 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 609 | } // namespace implementation |
| 610 | } // namespace V1_0 |
| 611 | } // namespace wifi |
| 612 | } // namespace hardware |
| 613 | } // namespace android |