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()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame^] | 392 | if (!callback->onBackgroundScanFailure(id).isOk()) { |
| 393 | LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; |
| 394 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 395 | } |
| 396 | }; |
| 397 | const auto& on_results_callback = [weak_ptr_this]( |
| 398 | legacy_hal::wifi_request_id id, |
| 399 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 400 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 401 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 402 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 403 | return; |
| 404 | } |
| 405 | std::vector<StaScanData> hidl_scan_datas; |
| 406 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 407 | results, &hidl_scan_datas)) { |
| 408 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 409 | return; |
| 410 | } |
| 411 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame^] | 412 | if (!callback->onBackgroundScanResults(id, hidl_scan_datas).isOk()) { |
| 413 | LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; |
| 414 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 415 | } |
| 416 | }; |
| 417 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 418 | legacy_hal::wifi_request_id id, |
| 419 | const legacy_hal::wifi_scan_result* result, |
| 420 | uint32_t /* buckets_scanned */) { |
| 421 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 422 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 423 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 424 | return; |
| 425 | } |
| 426 | StaScanResult hidl_scan_result; |
| 427 | if (!hidl_struct_util::convertLegacyGscanResultToHidl( |
| 428 | *result, true, &hidl_scan_result)) { |
| 429 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 430 | return; |
| 431 | } |
| 432 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame^] | 433 | if (!callback->onBackgroundFullScanResult(id, hidl_scan_result).isOk()) { |
| 434 | LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; |
| 435 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 436 | } |
| 437 | }; |
| 438 | legacy_hal::wifi_error legacy_status = |
| 439 | legacy_hal_.lock()->startGscan(cmd_id, |
| 440 | legacy_params, |
| 441 | on_failure_callback, |
| 442 | on_results_callback, |
| 443 | on_full_result_callback); |
| 444 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 447 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 448 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(cmd_id); |
| 449 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 452 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 453 | legacy_hal::wifi_error legacy_status = |
| 454 | legacy_hal_.lock()->enableLinkLayerStats(debug); |
| 455 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 459 | legacy_hal::wifi_error legacy_status = |
| 460 | legacy_hal_.lock()->disableLinkLayerStats(); |
| 461 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | std::pair<WifiStatus, StaLinkLayerStats> |
| 465 | WifiStaIface::getLinkLayerStatsInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 466 | legacy_hal::wifi_error legacy_status; |
| 467 | legacy_hal::LinkLayerStats legacy_stats; |
| 468 | std::tie(legacy_status, legacy_stats) = |
| 469 | legacy_hal_.lock()->getLinkLayerStats(); |
| 470 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 471 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 472 | } |
| 473 | StaLinkLayerStats hidl_stats; |
| 474 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, |
| 475 | &hidl_stats)) { |
| 476 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 477 | } |
| 478 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 481 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, |
| 482 | int32_t max_rssi, |
| 483 | int32_t min_rssi) { |
| 484 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 485 | const auto& on_threshold_breached_callback = [weak_ptr_this]( |
| 486 | legacy_hal::wifi_request_id id, |
| 487 | std::array<uint8_t, 6> bssid, |
| 488 | int8_t rssi) { |
| 489 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 490 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 491 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 492 | return; |
| 493 | } |
| 494 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame^] | 495 | if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { |
| 496 | LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; |
| 497 | } |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 498 | } |
| 499 | }; |
| 500 | legacy_hal::wifi_error legacy_status = |
| 501 | legacy_hal_.lock()->startRssiMonitoring( |
| 502 | cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 503 | return createWifiStatusFromLegacyError(legacy_status); |
| 504 | } |
| 505 | |
| 506 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 507 | legacy_hal::wifi_error legacy_status = |
| 508 | legacy_hal_.lock()->stopRssiMonitoring(cmd_id); |
| 509 | return createWifiStatusFromLegacyError(legacy_status); |
| 510 | } |
| 511 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 512 | std::pair<WifiStatus, StaRoamingCapabilities> |
| 513 | WifiStaIface::getRoamingCapabilitiesInternal() { |
| 514 | legacy_hal::wifi_error legacy_status; |
| 515 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 516 | std::tie(legacy_status, legacy_caps) = |
| 517 | legacy_hal_.lock()->getRoamingCapabilities(); |
| 518 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 519 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 520 | } |
| 521 | StaRoamingCapabilities hidl_caps; |
| 522 | if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, |
| 523 | &hidl_caps)) { |
| 524 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 525 | } |
| 526 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 527 | } |
| 528 | |
| 529 | WifiStatus WifiStaIface::configureRoamingInternal( |
| 530 | const StaRoamingConfig& config) { |
| 531 | legacy_hal::wifi_roaming_config legacy_config; |
| 532 | if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, |
| 533 | &legacy_config)) { |
| 534 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 535 | } |
| 536 | legacy_hal::wifi_error legacy_status = |
| 537 | legacy_hal_.lock()->configureRoaming(legacy_config); |
| 538 | return createWifiStatusFromLegacyError(legacy_status); |
| 539 | } |
| 540 | |
| 541 | WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 542 | legacy_hal::wifi_error legacy_status = |
| 543 | legacy_hal_.lock()->enableFirmwareRoaming( |
| 544 | hidl_struct_util::convertHidlRoamingStateToLegacy(state)); |
| 545 | return createWifiStatusFromLegacyError(legacy_status); |
| 546 | } |
| 547 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 548 | WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 549 | legacy_hal::wifi_error legacy_status = |
| 550 | legacy_hal_.lock()->configureNdOffload(enable); |
| 551 | return createWifiStatusFromLegacyError(legacy_status); |
| 552 | } |
| 553 | |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 554 | WifiStatus WifiStaIface::startSendingKeepAlivePacketsInternal( |
| 555 | uint32_t cmd_id, |
| 556 | const std::vector<uint8_t>& ip_packet_data, |
| 557 | uint16_t /* ether_type */, |
| 558 | const std::array<uint8_t, 6>& src_address, |
| 559 | const std::array<uint8_t, 6>& dst_address, |
| 560 | uint32_t period_in_ms) { |
| 561 | legacy_hal::wifi_error legacy_status = |
| 562 | legacy_hal_.lock()->startSendingOffloadedPacket( |
| 563 | cmd_id, ip_packet_data, src_address, dst_address, period_in_ms); |
| 564 | return createWifiStatusFromLegacyError(legacy_status); |
| 565 | } |
| 566 | |
| 567 | WifiStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(uint32_t cmd_id) { |
| 568 | legacy_hal::wifi_error legacy_status = |
| 569 | legacy_hal_.lock()->stopSendingOffloadedPacket(cmd_id); |
| 570 | return createWifiStatusFromLegacyError(legacy_status); |
| 571 | } |
| 572 | |
Roshan Pius | 795bb81 | 2017-02-01 13:09:08 -0800 | [diff] [blame] | 573 | WifiStatus WifiStaIface::setScanningMacOuiInternal(const std::array<uint8_t, 3>& oui) { |
| 574 | legacy_hal::wifi_error legacy_status = |
| 575 | legacy_hal_.lock()->setScanningMacOui(oui); |
| 576 | return createWifiStatusFromLegacyError(legacy_status); |
| 577 | } |
| 578 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 579 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 580 | legacy_hal::wifi_error legacy_status = |
| 581 | legacy_hal_.lock()->startPktFateMonitoring(); |
| 582 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 585 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 586 | WifiStaIface::getDebugTxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 587 | legacy_hal::wifi_error legacy_status; |
| 588 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 589 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(); |
| 590 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 591 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 592 | } |
| 593 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 594 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 595 | legacy_fates, &hidl_fates)) { |
| 596 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 597 | } |
| 598 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 602 | WifiStaIface::getDebugRxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 603 | legacy_hal::wifi_error legacy_status; |
| 604 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 605 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(); |
| 606 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 607 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 608 | } |
| 609 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 610 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 611 | legacy_fates, &hidl_fates)) { |
| 612 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 613 | } |
| 614 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 617 | } // namespace implementation |
| 618 | } // namespace V1_0 |
| 619 | } // namespace wifi |
| 620 | } // namespace hardware |
| 621 | } // namespace android |