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 | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 38 | event_cb_handler_.invalidate(); |
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 | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 46 | std::set<sp<IWifiStaIfaceEventCallback>> WifiStaIface::getEventCallbacks() { |
| 47 | return event_cb_handler_.getCallbacks(); |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 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) { |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 296 | if (!event_cb_handler_.addCallback(callback)) { |
| 297 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 298 | } |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 299 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 300 | } |
| 301 | |
| 302 | std::pair<WifiStatus, uint32_t> WifiStaIface::getCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 303 | legacy_hal::wifi_error legacy_status; |
| 304 | uint32_t legacy_feature_set; |
| 305 | std::tie(legacy_status, legacy_feature_set) = |
| 306 | legacy_hal_.lock()->getSupportedFeatureSet(); |
| 307 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 308 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 309 | } |
| 310 | uint32_t legacy_logger_feature_set; |
| 311 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 312 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 313 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 314 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 315 | } |
| 316 | uint32_t hidl_caps; |
| 317 | if (!hidl_struct_util::convertLegacyFeaturesToHidlStaCapabilities( |
| 318 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 319 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 320 | } |
| 321 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | std::pair<WifiStatus, StaApfPacketFilterCapabilities> |
| 325 | WifiStaIface::getApfPacketFilterCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 326 | legacy_hal::wifi_error legacy_status; |
| 327 | legacy_hal::PacketFilterCapabilities legacy_caps; |
| 328 | std::tie(legacy_status, legacy_caps) = |
| 329 | legacy_hal_.lock()->getPacketFilterCapabilities(); |
| 330 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 331 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 332 | } |
| 333 | StaApfPacketFilterCapabilities hidl_caps; |
| 334 | if (!hidl_struct_util::convertLegacyApfCapabilitiesToHidl(legacy_caps, |
| 335 | &hidl_caps)) { |
| 336 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 337 | } |
| 338 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | WifiStatus WifiStaIface::installApfPacketFilterInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 342 | uint32_t /* cmd_id */, const std::vector<uint8_t>& program) { |
| 343 | legacy_hal::wifi_error legacy_status = |
| 344 | legacy_hal_.lock()->setPacketFilter(program); |
| 345 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | std::pair<WifiStatus, StaBackgroundScanCapabilities> |
| 349 | WifiStaIface::getBackgroundScanCapabilitiesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 350 | legacy_hal::wifi_error legacy_status; |
| 351 | legacy_hal::wifi_gscan_capabilities legacy_caps; |
| 352 | std::tie(legacy_status, legacy_caps) = |
| 353 | legacy_hal_.lock()->getGscanCapabilities(); |
| 354 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 355 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 356 | } |
| 357 | StaBackgroundScanCapabilities hidl_caps; |
| 358 | if (!hidl_struct_util::convertLegacyGscanCapabilitiesToHidl(legacy_caps, |
| 359 | &hidl_caps)) { |
| 360 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 361 | } |
| 362 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | std::pair<WifiStatus, std::vector<WifiChannelInMhz>> |
| 366 | WifiStaIface::getValidFrequenciesForBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 367 | StaBackgroundScanBand band) { |
| 368 | static_assert(sizeof(WifiChannelInMhz) == sizeof(uint32_t), "Size mismatch"); |
| 369 | legacy_hal::wifi_error legacy_status; |
| 370 | std::vector<uint32_t> valid_frequencies; |
| 371 | std::tie(legacy_status, valid_frequencies) = |
| 372 | legacy_hal_.lock()->getValidFrequenciesForGscan( |
| 373 | hidl_struct_util::convertHidlGscanBandToLegacy(band)); |
| 374 | return {createWifiStatusFromLegacyError(legacy_status), valid_frequencies}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | WifiStatus WifiStaIface::startBackgroundScanInternal( |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 378 | uint32_t cmd_id, const StaBackgroundScanParameters& params) { |
| 379 | legacy_hal::wifi_scan_cmd_params legacy_params; |
| 380 | if (!hidl_struct_util::convertHidlGscanParamsToLegacy(params, |
| 381 | &legacy_params)) { |
| 382 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 383 | } |
| 384 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 385 | const auto& on_failure_callback = |
| 386 | [weak_ptr_this](legacy_hal::wifi_request_id id) { |
| 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 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 393 | if (!callback->onBackgroundScanFailure(id).isOk()) { |
| 394 | LOG(ERROR) << "Failed to invoke onBackgroundScanFailure callback"; |
| 395 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 396 | } |
| 397 | }; |
| 398 | const auto& on_results_callback = [weak_ptr_this]( |
| 399 | legacy_hal::wifi_request_id id, |
| 400 | const std::vector<legacy_hal::wifi_cached_scan_results>& results) { |
| 401 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 402 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 403 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 404 | return; |
| 405 | } |
| 406 | std::vector<StaScanData> hidl_scan_datas; |
| 407 | if (!hidl_struct_util::convertLegacyVectorOfCachedGscanResultsToHidl( |
| 408 | results, &hidl_scan_datas)) { |
| 409 | LOG(ERROR) << "Failed to convert scan results to HIDL structs"; |
| 410 | return; |
| 411 | } |
| 412 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 413 | if (!callback->onBackgroundScanResults(id, hidl_scan_datas).isOk()) { |
| 414 | LOG(ERROR) << "Failed to invoke onBackgroundScanResults callback"; |
| 415 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 416 | } |
| 417 | }; |
| 418 | const auto& on_full_result_callback = [weak_ptr_this]( |
| 419 | legacy_hal::wifi_request_id id, |
| 420 | const legacy_hal::wifi_scan_result* result, |
| 421 | uint32_t /* buckets_scanned */) { |
| 422 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 423 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 424 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 425 | return; |
| 426 | } |
| 427 | StaScanResult hidl_scan_result; |
| 428 | if (!hidl_struct_util::convertLegacyGscanResultToHidl( |
| 429 | *result, true, &hidl_scan_result)) { |
| 430 | LOG(ERROR) << "Failed to convert full scan results to HIDL structs"; |
| 431 | return; |
| 432 | } |
| 433 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 434 | if (!callback->onBackgroundFullScanResult(id, hidl_scan_result).isOk()) { |
| 435 | LOG(ERROR) << "Failed to invoke onBackgroundFullScanResult callback"; |
| 436 | } |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 437 | } |
| 438 | }; |
| 439 | legacy_hal::wifi_error legacy_status = |
| 440 | legacy_hal_.lock()->startGscan(cmd_id, |
| 441 | legacy_params, |
| 442 | on_failure_callback, |
| 443 | on_results_callback, |
| 444 | on_full_result_callback); |
| 445 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 448 | WifiStatus WifiStaIface::stopBackgroundScanInternal(uint32_t cmd_id) { |
| 449 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stopGscan(cmd_id); |
| 450 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 453 | WifiStatus WifiStaIface::enableLinkLayerStatsCollectionInternal(bool debug) { |
| 454 | legacy_hal::wifi_error legacy_status = |
| 455 | legacy_hal_.lock()->enableLinkLayerStats(debug); |
| 456 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | WifiStatus WifiStaIface::disableLinkLayerStatsCollectionInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 460 | legacy_hal::wifi_error legacy_status = |
| 461 | legacy_hal_.lock()->disableLinkLayerStats(); |
| 462 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | std::pair<WifiStatus, StaLinkLayerStats> |
| 466 | WifiStaIface::getLinkLayerStatsInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 467 | legacy_hal::wifi_error legacy_status; |
| 468 | legacy_hal::LinkLayerStats legacy_stats; |
| 469 | std::tie(legacy_status, legacy_stats) = |
| 470 | legacy_hal_.lock()->getLinkLayerStats(); |
| 471 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 472 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 473 | } |
| 474 | StaLinkLayerStats hidl_stats; |
| 475 | if (!hidl_struct_util::convertLegacyLinkLayerStatsToHidl(legacy_stats, |
| 476 | &hidl_stats)) { |
| 477 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 478 | } |
| 479 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 482 | WifiStatus WifiStaIface::startRssiMonitoringInternal(uint32_t cmd_id, |
| 483 | int32_t max_rssi, |
| 484 | int32_t min_rssi) { |
| 485 | android::wp<WifiStaIface> weak_ptr_this(this); |
| 486 | const auto& on_threshold_breached_callback = [weak_ptr_this]( |
| 487 | legacy_hal::wifi_request_id id, |
| 488 | std::array<uint8_t, 6> bssid, |
| 489 | int8_t rssi) { |
| 490 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 491 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 492 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 493 | return; |
| 494 | } |
| 495 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 496 | if (!callback->onRssiThresholdBreached(id, bssid, rssi).isOk()) { |
| 497 | LOG(ERROR) << "Failed to invoke onRssiThresholdBreached callback"; |
| 498 | } |
Roshan Pius | d476754 | 2016-12-06 10:04:05 -0800 | [diff] [blame] | 499 | } |
| 500 | }; |
| 501 | legacy_hal::wifi_error legacy_status = |
| 502 | legacy_hal_.lock()->startRssiMonitoring( |
| 503 | cmd_id, max_rssi, min_rssi, on_threshold_breached_callback); |
| 504 | return createWifiStatusFromLegacyError(legacy_status); |
| 505 | } |
| 506 | |
| 507 | WifiStatus WifiStaIface::stopRssiMonitoringInternal(uint32_t cmd_id) { |
| 508 | legacy_hal::wifi_error legacy_status = |
| 509 | legacy_hal_.lock()->stopRssiMonitoring(cmd_id); |
| 510 | return createWifiStatusFromLegacyError(legacy_status); |
| 511 | } |
| 512 | |
Roshan Pius | 26801cb | 2016-12-13 14:25:45 -0800 | [diff] [blame] | 513 | std::pair<WifiStatus, StaRoamingCapabilities> |
| 514 | WifiStaIface::getRoamingCapabilitiesInternal() { |
| 515 | legacy_hal::wifi_error legacy_status; |
| 516 | legacy_hal::wifi_roaming_capabilities legacy_caps; |
| 517 | std::tie(legacy_status, legacy_caps) = |
| 518 | legacy_hal_.lock()->getRoamingCapabilities(); |
| 519 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 520 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 521 | } |
| 522 | StaRoamingCapabilities hidl_caps; |
| 523 | if (!hidl_struct_util::convertLegacyRoamingCapabilitiesToHidl(legacy_caps, |
| 524 | &hidl_caps)) { |
| 525 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 526 | } |
| 527 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 528 | } |
| 529 | |
| 530 | WifiStatus WifiStaIface::configureRoamingInternal( |
| 531 | const StaRoamingConfig& config) { |
| 532 | legacy_hal::wifi_roaming_config legacy_config; |
| 533 | if (!hidl_struct_util::convertHidlRoamingConfigToLegacy(config, |
| 534 | &legacy_config)) { |
| 535 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 536 | } |
| 537 | legacy_hal::wifi_error legacy_status = |
| 538 | legacy_hal_.lock()->configureRoaming(legacy_config); |
| 539 | return createWifiStatusFromLegacyError(legacy_status); |
| 540 | } |
| 541 | |
| 542 | WifiStatus WifiStaIface::setRoamingStateInternal(StaRoamingState state) { |
| 543 | legacy_hal::wifi_error legacy_status = |
| 544 | legacy_hal_.lock()->enableFirmwareRoaming( |
| 545 | hidl_struct_util::convertHidlRoamingStateToLegacy(state)); |
| 546 | return createWifiStatusFromLegacyError(legacy_status); |
| 547 | } |
| 548 | |
Roshan Pius | af727c0 | 2017-01-11 15:37:25 -0800 | [diff] [blame] | 549 | WifiStatus WifiStaIface::enableNdOffloadInternal(bool enable) { |
| 550 | legacy_hal::wifi_error legacy_status = |
| 551 | legacy_hal_.lock()->configureNdOffload(enable); |
| 552 | return createWifiStatusFromLegacyError(legacy_status); |
| 553 | } |
| 554 | |
Roshan Pius | 9a9869a | 2017-01-11 16:42:16 -0800 | [diff] [blame] | 555 | WifiStatus WifiStaIface::startSendingKeepAlivePacketsInternal( |
| 556 | uint32_t cmd_id, |
| 557 | const std::vector<uint8_t>& ip_packet_data, |
| 558 | uint16_t /* ether_type */, |
| 559 | const std::array<uint8_t, 6>& src_address, |
| 560 | const std::array<uint8_t, 6>& dst_address, |
| 561 | uint32_t period_in_ms) { |
| 562 | legacy_hal::wifi_error legacy_status = |
| 563 | legacy_hal_.lock()->startSendingOffloadedPacket( |
| 564 | cmd_id, ip_packet_data, src_address, dst_address, period_in_ms); |
| 565 | return createWifiStatusFromLegacyError(legacy_status); |
| 566 | } |
| 567 | |
| 568 | WifiStatus WifiStaIface::stopSendingKeepAlivePacketsInternal(uint32_t cmd_id) { |
| 569 | legacy_hal::wifi_error legacy_status = |
| 570 | legacy_hal_.lock()->stopSendingOffloadedPacket(cmd_id); |
| 571 | return createWifiStatusFromLegacyError(legacy_status); |
| 572 | } |
| 573 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 574 | WifiStatus WifiStaIface::setScanningMacOuiInternal( |
| 575 | const std::array<uint8_t, 3>& oui) { |
Roshan Pius | 795bb81 | 2017-02-01 13:09:08 -0800 | [diff] [blame] | 576 | legacy_hal::wifi_error legacy_status = |
| 577 | legacy_hal_.lock()->setScanningMacOui(oui); |
| 578 | return createWifiStatusFromLegacyError(legacy_status); |
| 579 | } |
| 580 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 581 | WifiStatus WifiStaIface::startDebugPacketFateMonitoringInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 582 | legacy_hal::wifi_error legacy_status = |
| 583 | legacy_hal_.lock()->startPktFateMonitoring(); |
| 584 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 587 | std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>> |
| 588 | WifiStaIface::getDebugTxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 589 | legacy_hal::wifi_error legacy_status; |
| 590 | std::vector<legacy_hal::wifi_tx_report> legacy_fates; |
| 591 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getTxPktFates(); |
| 592 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 593 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 594 | } |
| 595 | std::vector<WifiDebugTxPacketFateReport> hidl_fates; |
| 596 | if (!hidl_struct_util::convertLegacyVectorOfDebugTxPacketFateToHidl( |
| 597 | legacy_fates, &hidl_fates)) { |
| 598 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 599 | } |
| 600 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>> |
| 604 | WifiStaIface::getDebugRxPacketFatesInternal() { |
Roshan Pius | 970f031 | 2016-12-05 15:25:51 -0800 | [diff] [blame] | 605 | legacy_hal::wifi_error legacy_status; |
| 606 | std::vector<legacy_hal::wifi_rx_report> legacy_fates; |
| 607 | std::tie(legacy_status, legacy_fates) = legacy_hal_.lock()->getRxPktFates(); |
| 608 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 609 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 610 | } |
| 611 | std::vector<WifiDebugRxPacketFateReport> hidl_fates; |
| 612 | if (!hidl_struct_util::convertLegacyVectorOfDebugRxPacketFateToHidl( |
| 613 | legacy_fates, &hidl_fates)) { |
| 614 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 615 | } |
| 616 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_fates}; |
Roshan Pius | a04ba3f | 2016-10-27 14:36:26 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 619 | } // namespace implementation |
| 620 | } // namespace V1_0 |
| 621 | } // namespace wifi |
| 622 | } // namespace hardware |
| 623 | } // namespace android |