Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -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 | |
| 17 | #include "wifi_chip.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 21 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 23 | namespace { |
| 24 | using android::sp; |
| 25 | using android::hardware::hidl_vec; |
| 26 | using android::hardware::hidl_string; |
| 27 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 28 | std::vector<hidl_string> createHidlVecOfIfaceNames(const std::string& ifname) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 29 | std::vector<hidl_string> ifnames; |
| 30 | if (!ifname.empty()) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 31 | ifnames.emplace_back(ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 32 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 33 | return ifnames; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | template <typename Iface> |
| 37 | void invalidateAndClear(sp<Iface>& iface) { |
| 38 | if (iface.get()) { |
| 39 | iface->invalidate(); |
| 40 | iface.clear(); |
| 41 | } |
| 42 | } |
| 43 | } // namepsace |
| 44 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 45 | namespace android { |
| 46 | namespace hardware { |
| 47 | namespace wifi { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 48 | namespace V1_0 { |
| 49 | namespace implementation { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 50 | |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 51 | WifiChip::WifiChip(ChipId chip_id, |
| 52 | const std::weak_ptr<WifiLegacyHal> legacy_hal) |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 53 | : chip_id_(chip_id), legacy_hal_(legacy_hal), is_valid_(true) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 54 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 55 | void WifiChip::invalidate() { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 56 | invalidateAndRemoveAllIfaces(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 57 | legacy_hal_.reset(); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 58 | event_callbacks_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 59 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 62 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
| 63 | if (!is_valid_) { |
| 64 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 65 | UINT32_MAX); |
| 66 | return Void(); |
| 67 | } |
| 68 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), chip_id_); |
| 69 | return Void(); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 72 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 73 | const sp<IWifiChipEventCallback>& event_callback, |
| 74 | registerEventCallback_cb hidl_status_cb) { |
| 75 | if (!is_valid_) { |
| 76 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID)); |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 77 | return Void(); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 78 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 79 | // TODO(b/31632518): remove the callback when the client is destroyed |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 80 | event_callbacks_.emplace_back(event_callback); |
| 81 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS)); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 82 | return Void(); |
| 83 | } |
| 84 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 85 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 86 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 87 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 88 | hidl_vec<ChipMode>()); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 89 | return Void(); |
| 90 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 91 | // TODO add implementation |
| 92 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), |
| 93 | hidl_vec<ChipMode>()); |
| 94 | return Void(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 97 | Return<void> WifiChip::configureChip(uint32_t /*mode_id*/, |
| 98 | configureChip_cb hidl_status_cb) { |
| 99 | if (!is_valid_) { |
| 100 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID)); |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 101 | return Void(); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 102 | } |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 103 | |
| 104 | invalidateAndRemoveAllIfaces(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 105 | // TODO add implementation |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 106 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS)); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 107 | return Void(); |
| 108 | } |
| 109 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 110 | Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) { |
| 111 | if (!is_valid_) { |
| 112 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 113 | UINT32_MAX); |
| 114 | return Void(); |
| 115 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 116 | // TODO add implementation |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 117 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), 0); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 118 | return Void(); |
| 119 | } |
| 120 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 121 | Return<void> WifiChip::requestChipDebugInfo( |
| 122 | requestChipDebugInfo_cb hidl_status_cb) { |
| 123 | if (!is_valid_) { |
| 124 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 125 | IWifiChip::ChipDebugInfo()); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 126 | return Void(); |
| 127 | } |
| 128 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 129 | IWifiChip::ChipDebugInfo result; |
| 130 | |
| 131 | wifi_error legacy_status; |
| 132 | std::string driver_desc; |
| 133 | std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(); |
| 134 | if (legacy_status != WIFI_SUCCESS) { |
| 135 | LOG(ERROR) << "Failed to get driver version: " |
| 136 | << legacyErrorToString(legacy_status); |
| 137 | WifiStatus status = createWifiStatusFromLegacyError( |
| 138 | legacy_status, "failed to get driver version"); |
| 139 | hidl_status_cb(status, result); |
| 140 | return Void(); |
| 141 | } |
| 142 | result.driverDescription = driver_desc.c_str(); |
| 143 | |
| 144 | std::string firmware_desc; |
| 145 | std::tie(legacy_status, firmware_desc) = |
| 146 | legacy_hal_.lock()->getFirmwareVersion(); |
| 147 | if (legacy_status != WIFI_SUCCESS) { |
| 148 | LOG(ERROR) << "Failed to get firmware version: " |
| 149 | << legacyErrorToString(legacy_status); |
| 150 | WifiStatus status = createWifiStatusFromLegacyError( |
| 151 | legacy_status, "failed to get firmware version"); |
| 152 | hidl_status_cb(status, result); |
| 153 | return Void(); |
| 154 | } |
| 155 | result.firmwareDescription = firmware_desc.c_str(); |
| 156 | |
| 157 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), result); |
| 158 | return Void(); |
| 159 | } |
| 160 | |
| 161 | Return<void> WifiChip::requestDriverDebugDump( |
| 162 | requestDriverDebugDump_cb hidl_status_cb) { |
| 163 | if (!is_valid_) { |
| 164 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 165 | hidl_vec<uint8_t>()); |
| 166 | return Void(); |
| 167 | } |
| 168 | |
| 169 | wifi_error legacy_status; |
| 170 | std::vector<char> driver_dump; |
| 171 | std::tie(legacy_status, driver_dump) = |
| 172 | legacy_hal_.lock()->requestDriverMemoryDump(); |
| 173 | if (legacy_status != WIFI_SUCCESS) { |
| 174 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 175 | << legacyErrorToString(legacy_status); |
| 176 | hidl_status_cb(createWifiStatusFromLegacyError(legacy_status), |
| 177 | hidl_vec<uint8_t>()); |
| 178 | return Void(); |
| 179 | } |
| 180 | |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 181 | hidl_vec<uint8_t> hidl_data; |
| 182 | hidl_data.setToExternal(reinterpret_cast<uint8_t*>(driver_dump.data()), |
| 183 | driver_dump.size()); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 184 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), hidl_data); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 185 | return Void(); |
| 186 | } |
| 187 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 188 | Return<void> WifiChip::requestFirmwareDebugDump( |
| 189 | requestFirmwareDebugDump_cb hidl_status_cb) { |
| 190 | if (!is_valid_) { |
| 191 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 192 | hidl_vec<uint8_t>()); |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 193 | return Void(); |
| 194 | } |
| 195 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 196 | wifi_error legacy_status; |
| 197 | std::vector<char> firmware_dump; |
| 198 | std::tie(legacy_status, firmware_dump) = |
| 199 | legacy_hal_.lock()->requestFirmwareMemoryDump(); |
| 200 | if (legacy_status != WIFI_SUCCESS) { |
| 201 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 202 | << legacyErrorToString(legacy_status); |
| 203 | hidl_status_cb(createWifiStatusFromLegacyError(legacy_status), |
| 204 | hidl_vec<uint8_t>()); |
| 205 | return Void(); |
| 206 | } |
| 207 | |
Roshan Pius | cdb77f3 | 2016-10-03 14:09:57 -0700 | [diff] [blame] | 208 | hidl_vec<uint8_t> hidl_data; |
| 209 | hidl_data.setToExternal(reinterpret_cast<uint8_t*>(firmware_dump.data()), |
| 210 | firmware_dump.size()); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 211 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), hidl_data); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 212 | return Void(); |
| 213 | } |
| 214 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 215 | Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 216 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 217 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 218 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 219 | return Void(); |
| 220 | } |
| 221 | |
| 222 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 223 | std::string ifname = legacy_hal_.lock()->getApIfaceName(); |
| 224 | ap_iface_ = new WifiApIface(ifname, legacy_hal_); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 225 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 226 | return Void(); |
| 227 | } |
| 228 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 229 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 230 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 231 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 232 | hidl_vec<hidl_string>()); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 233 | return Void(); |
| 234 | } |
| 235 | |
| 236 | std::string ifname; |
| 237 | if (ap_iface_.get()) { |
| 238 | ifname = legacy_hal_.lock()->getApIfaceName().c_str(); |
| 239 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 240 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), |
| 241 | createHidlVecOfIfaceNames(ifname)); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 242 | return Void(); |
| 243 | } |
| 244 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 245 | Return<void> WifiChip::getApIface(const hidl_string& ifname, |
| 246 | getApIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 247 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 248 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 249 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 250 | return Void(); |
| 251 | } |
| 252 | |
| 253 | if (ap_iface_.get() && |
| 254 | (ifname.c_str() == legacy_hal_.lock()->getApIfaceName())) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 255 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 256 | } else { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 257 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), |
| 258 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 259 | } |
| 260 | return Void(); |
| 261 | } |
| 262 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 263 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 264 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 265 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 266 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 267 | return Void(); |
| 268 | } |
| 269 | |
| 270 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 271 | std::string ifname = legacy_hal_.lock()->getNanIfaceName(); |
| 272 | nan_iface_ = new WifiNanIface(ifname, legacy_hal_); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 273 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 274 | return Void(); |
| 275 | } |
| 276 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 277 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 278 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 279 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 280 | hidl_vec<hidl_string>()); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 281 | return Void(); |
| 282 | } |
| 283 | |
| 284 | std::string ifname; |
| 285 | if (nan_iface_.get()) { |
| 286 | ifname = legacy_hal_.lock()->getNanIfaceName().c_str(); |
| 287 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 288 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), |
| 289 | createHidlVecOfIfaceNames(ifname)); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 290 | return Void(); |
| 291 | } |
| 292 | |
| 293 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 294 | getNanIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 295 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 296 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 297 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 298 | return Void(); |
| 299 | } |
| 300 | |
| 301 | if (nan_iface_.get() && |
| 302 | (ifname.c_str() == legacy_hal_.lock()->getNanIfaceName())) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 303 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 304 | } else { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 305 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), |
| 306 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 307 | } |
| 308 | return Void(); |
| 309 | } |
| 310 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 311 | Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 312 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 313 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 314 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 315 | return Void(); |
| 316 | } |
| 317 | |
| 318 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 319 | std::string ifname = legacy_hal_.lock()->getP2pIfaceName(); |
| 320 | p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 321 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 322 | return Void(); |
| 323 | } |
| 324 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 325 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 326 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 327 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 328 | hidl_vec<hidl_string>()); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 329 | return Void(); |
| 330 | } |
| 331 | |
| 332 | std::string ifname; |
| 333 | if (p2p_iface_.get()) { |
| 334 | ifname = legacy_hal_.lock()->getP2pIfaceName().c_str(); |
| 335 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 336 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), |
| 337 | createHidlVecOfIfaceNames(ifname)); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 338 | return Void(); |
| 339 | } |
| 340 | |
| 341 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 342 | getP2pIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 343 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 344 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 345 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 346 | return Void(); |
| 347 | } |
| 348 | |
| 349 | if (p2p_iface_.get() && |
| 350 | (ifname.c_str() == legacy_hal_.lock()->getP2pIfaceName())) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 351 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 352 | } else { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 353 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), |
| 354 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 355 | } |
| 356 | return Void(); |
| 357 | } |
| 358 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 359 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 360 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 361 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 362 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 363 | return Void(); |
| 364 | } |
| 365 | |
| 366 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 367 | std::string ifname = legacy_hal_.lock()->getStaIfaceName(); |
| 368 | sta_iface_ = new WifiStaIface(ifname, legacy_hal_); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 369 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 370 | return Void(); |
| 371 | } |
| 372 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 373 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 374 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 375 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 376 | hidl_vec<hidl_string>()); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 377 | return Void(); |
| 378 | } |
| 379 | |
| 380 | std::string ifname; |
| 381 | if (sta_iface_.get()) { |
| 382 | ifname = legacy_hal_.lock()->getStaIfaceName().c_str(); |
| 383 | } |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 384 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), |
| 385 | createHidlVecOfIfaceNames(ifname)); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 386 | return Void(); |
| 387 | } |
| 388 | |
| 389 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 390 | getStaIface_cb hidl_status_cb) { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 391 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 392 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 393 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 394 | return Void(); |
| 395 | } |
| 396 | |
| 397 | if (sta_iface_.get() && |
| 398 | (ifname.c_str() == legacy_hal_.lock()->getStaIfaceName())) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 399 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 400 | } else { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 401 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), |
| 402 | nullptr); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 403 | } |
| 404 | return Void(); |
| 405 | } |
| 406 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 407 | Return<void> WifiChip::createRttController( |
| 408 | const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) { |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 409 | if (!is_valid_) { |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 410 | hidl_status_cb(createWifiStatus(WifiStatusCode::ERROR_WIFI_CHIP_INVALID), |
| 411 | nullptr); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 412 | return Void(); |
| 413 | } |
| 414 | |
| 415 | sp<WifiRttController> rtt = new WifiRttController(bound_iface, legacy_hal_); |
| 416 | rtt_controllers_.emplace_back(rtt); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame^] | 417 | hidl_status_cb(createWifiStatus(WifiStatusCode::SUCCESS), rtt); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 418 | return Void(); |
| 419 | } |
| 420 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 421 | void WifiChip::invalidateAndRemoveAllIfaces() { |
| 422 | invalidateAndClear(ap_iface_); |
| 423 | invalidateAndClear(nan_iface_); |
| 424 | invalidateAndClear(p2p_iface_); |
| 425 | invalidateAndClear(sta_iface_); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 426 | // Since all the ifaces are invalid now, all RTT controller objects |
| 427 | // using those ifaces also need to be invalidated. |
| 428 | for (const auto& rtt : rtt_controllers_) { |
| 429 | rtt->invalidate(); |
| 430 | } |
| 431 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 434 | } // namespace implementation |
| 435 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 436 | } // namespace wifi |
| 437 | } // namespace hardware |
| 438 | } // namespace android |