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