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