Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include <android-base/unique_fd.h> |
| 21 | #include <cutils/properties.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <net/if.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/sysmacros.h> |
| 26 | |
| 27 | #include "aidl_return_util.h" |
| 28 | #include "aidl_struct_util.h" |
maheshkkv | a8aba17 | 2023-02-13 12:33:26 -0800 | [diff] [blame] | 29 | #include "wifi_legacy_hal.h" |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 30 | #include "wifi_status_util.h" |
| 31 | |
| 32 | #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" |
| 33 | |
| 34 | namespace { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 35 | using android::base::unique_fd; |
| 36 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 37 | constexpr size_t kMaxBufferSizeBytes = 1024 * 1024 * 3; |
| 38 | constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60 * 10; |
| 39 | constexpr uint32_t kMaxRingBufferFileNum = 20; |
| 40 | constexpr char kTombstoneFolderPath[] = "/data/vendor/tombstones/wifi/"; |
| 41 | constexpr char kActiveWlanIfaceNameProperty[] = "wifi.active.interface"; |
| 42 | constexpr char kNoActiveWlanIfaceNamePropertyValue[] = ""; |
| 43 | constexpr unsigned kMaxWlanIfaces = 5; |
| 44 | constexpr char kApBridgeIfacePrefix[] = "ap_br_"; |
| 45 | |
| 46 | template <typename Iface> |
| 47 | void invalidateAndClear(std::vector<std::shared_ptr<Iface>>& ifaces, std::shared_ptr<Iface> iface) { |
| 48 | iface->invalidate(); |
| 49 | ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), ifaces.end()); |
| 50 | } |
| 51 | |
| 52 | template <typename Iface> |
| 53 | void invalidateAndClearAll(std::vector<std::shared_ptr<Iface>>& ifaces) { |
| 54 | for (const auto& iface : ifaces) { |
| 55 | iface->invalidate(); |
| 56 | } |
| 57 | ifaces.clear(); |
| 58 | } |
| 59 | |
| 60 | template <typename Iface> |
| 61 | std::vector<std::string> getNames(std::vector<std::shared_ptr<Iface>>& ifaces) { |
| 62 | std::vector<std::string> names; |
| 63 | for (const auto& iface : ifaces) { |
| 64 | names.emplace_back(iface->getName()); |
| 65 | } |
| 66 | return names; |
| 67 | } |
| 68 | |
| 69 | template <typename Iface> |
| 70 | std::shared_ptr<Iface> findUsingName(std::vector<std::shared_ptr<Iface>>& ifaces, |
| 71 | const std::string& name) { |
| 72 | std::vector<std::string> names; |
| 73 | for (const auto& iface : ifaces) { |
| 74 | if (name == iface->getName()) { |
| 75 | return iface; |
| 76 | } |
| 77 | } |
| 78 | return nullptr; |
| 79 | } |
| 80 | |
| 81 | std::string getWlanIfaceName(unsigned idx) { |
| 82 | if (idx >= kMaxWlanIfaces) { |
| 83 | CHECK(false) << "Requested interface beyond wlan" << kMaxWlanIfaces; |
| 84 | return {}; |
| 85 | } |
| 86 | |
| 87 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 88 | if (idx == 0 || idx == 1) { |
| 89 | const char* altPropName = (idx == 0) ? "wifi.interface" : "wifi.concurrent.interface"; |
| 90 | auto res = property_get(altPropName, buffer.data(), nullptr); |
| 91 | if (res > 0) return buffer.data(); |
| 92 | } |
| 93 | std::string propName = "wifi.interface." + std::to_string(idx); |
| 94 | auto res = property_get(propName.c_str(), buffer.data(), nullptr); |
| 95 | if (res > 0) return buffer.data(); |
| 96 | |
| 97 | return "wlan" + std::to_string(idx); |
| 98 | } |
| 99 | |
| 100 | // Returns the dedicated iface name if defined. |
| 101 | // Returns two ifaces in bridged mode. |
| 102 | std::vector<std::string> getPredefinedApIfaceNames(bool is_bridged) { |
| 103 | std::vector<std::string> ifnames; |
| 104 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 105 | buffer.fill(0); |
| 106 | if (property_get("ro.vendor.wifi.sap.interface", buffer.data(), nullptr) == 0) { |
| 107 | return ifnames; |
| 108 | } |
| 109 | ifnames.push_back(buffer.data()); |
| 110 | if (is_bridged) { |
| 111 | buffer.fill(0); |
| 112 | if (property_get("ro.vendor.wifi.sap.concurrent.iface", buffer.data(), nullptr) == 0) { |
| 113 | return ifnames; |
| 114 | } |
| 115 | ifnames.push_back(buffer.data()); |
| 116 | } |
| 117 | return ifnames; |
| 118 | } |
| 119 | |
| 120 | std::string getPredefinedP2pIfaceName() { |
| 121 | std::array<char, PROPERTY_VALUE_MAX> primaryIfaceName; |
| 122 | char p2pParentIfname[100]; |
| 123 | std::string p2pDevIfName = ""; |
| 124 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 125 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 126 | if (strncmp(buffer.data(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
| 127 | /* Get the p2p parent interface name from p2p device interface name set |
| 128 | * in property */ |
| 129 | strlcpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX), |
| 130 | strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX)); |
| 131 | if (property_get(kActiveWlanIfaceNameProperty, primaryIfaceName.data(), nullptr) == 0) { |
| 132 | return buffer.data(); |
| 133 | } |
| 134 | /* Check if the parent interface derived from p2p device interface name |
| 135 | * is active */ |
| 136 | if (strncmp(p2pParentIfname, primaryIfaceName.data(), |
| 137 | strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX)) != 0) { |
| 138 | /* |
| 139 | * Update the predefined p2p device interface parent interface name |
| 140 | * with current active wlan interface |
| 141 | */ |
| 142 | p2pDevIfName += P2P_MGMT_DEVICE_PREFIX; |
| 143 | p2pDevIfName += primaryIfaceName.data(); |
| 144 | LOG(INFO) << "update the p2p device interface name to " << p2pDevIfName.c_str(); |
| 145 | return p2pDevIfName; |
| 146 | } |
| 147 | } |
| 148 | return buffer.data(); |
| 149 | } |
| 150 | |
| 151 | // Returns the dedicated iface name if one is defined. |
| 152 | std::string getPredefinedNanIfaceName() { |
| 153 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 154 | if (property_get("wifi.aware.interface", buffer.data(), nullptr) == 0) { |
| 155 | return {}; |
| 156 | } |
| 157 | return buffer.data(); |
| 158 | } |
| 159 | |
| 160 | void setActiveWlanIfaceNameProperty(const std::string& ifname) { |
| 161 | auto res = property_set(kActiveWlanIfaceNameProperty, ifname.data()); |
| 162 | if (res != 0) { |
| 163 | PLOG(ERROR) << "Failed to set active wlan iface name property"; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Delete files that meet either condition: |
| 168 | // 1. Older than a predefined time in the wifi tombstone dir. |
| 169 | // 2. Files in excess to a predefined amount, starting from the oldest ones |
| 170 | bool removeOldFilesInternal() { |
| 171 | time_t now = time(0); |
| 172 | const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds; |
| 173 | std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(kTombstoneFolderPath), closedir); |
| 174 | if (!dir_dump) { |
| 175 | PLOG(ERROR) << "Failed to open directory"; |
| 176 | return false; |
| 177 | } |
| 178 | struct dirent* dp; |
| 179 | bool success = true; |
| 180 | std::list<std::pair<const time_t, std::string>> valid_files; |
| 181 | while ((dp = readdir(dir_dump.get()))) { |
| 182 | if (dp->d_type != DT_REG) { |
| 183 | continue; |
| 184 | } |
| 185 | std::string cur_file_name(dp->d_name); |
| 186 | struct stat cur_file_stat; |
| 187 | std::string cur_file_path = kTombstoneFolderPath + cur_file_name; |
| 188 | if (stat(cur_file_path.c_str(), &cur_file_stat) == -1) { |
| 189 | PLOG(ERROR) << "Failed to get file stat for " << cur_file_path; |
| 190 | success = false; |
| 191 | continue; |
| 192 | } |
| 193 | const time_t cur_file_time = cur_file_stat.st_mtime; |
| 194 | valid_files.push_back(std::pair<const time_t, std::string>(cur_file_time, cur_file_path)); |
| 195 | } |
| 196 | valid_files.sort(); // sort the list of files by last modified time from |
| 197 | // small to big. |
| 198 | uint32_t cur_file_count = valid_files.size(); |
| 199 | for (auto cur_file : valid_files) { |
| 200 | if (cur_file_count > kMaxRingBufferFileNum || cur_file.first < delete_files_before) { |
| 201 | if (unlink(cur_file.second.c_str()) != 0) { |
| 202 | PLOG(ERROR) << "Error deleting file"; |
| 203 | success = false; |
| 204 | } |
| 205 | cur_file_count--; |
| 206 | } else { |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | return success; |
| 211 | } |
| 212 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 213 | // Helper function to create a non-const char*. |
| 214 | std::vector<char> makeCharVec(const std::string& str) { |
| 215 | std::vector<char> vec(str.size() + 1); |
| 216 | vec.assign(str.begin(), str.end()); |
| 217 | vec.push_back('\0'); |
| 218 | return vec; |
| 219 | } |
| 220 | |
| 221 | } // namespace |
| 222 | |
| 223 | namespace aidl { |
| 224 | namespace android { |
| 225 | namespace hardware { |
| 226 | namespace wifi { |
| 227 | using aidl_return_util::validateAndCall; |
| 228 | using aidl_return_util::validateAndCallWithLock; |
| 229 | |
| 230 | WifiChip::WifiChip(int32_t chip_id, bool is_primary, |
| 231 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 232 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 233 | const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util, |
| 234 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags, |
Gabriel Biren | 989c78a | 2023-06-14 22:42:07 +0000 | [diff] [blame] | 235 | const std::function<void(const std::string&)>& handler, |
| 236 | bool using_dynamic_iface_combination) |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 237 | : chip_id_(chip_id), |
| 238 | legacy_hal_(legacy_hal), |
| 239 | mode_controller_(mode_controller), |
| 240 | iface_util_(iface_util), |
| 241 | is_valid_(true), |
| 242 | current_mode_id_(feature_flags::chip_mode_ids::kInvalid), |
| 243 | modes_(feature_flags.lock()->getChipModes(is_primary)), |
| 244 | debug_ring_buffer_cb_registered_(false), |
Gabriel Biren | 989c78a | 2023-06-14 22:42:07 +0000 | [diff] [blame] | 245 | using_dynamic_iface_combination_(using_dynamic_iface_combination), |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 246 | subsystemCallbackHandler_(handler) { |
| 247 | setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue); |
Sunil Ravi | 2be1f26 | 2023-02-15 20:56:56 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void WifiChip::retrieveDynamicIfaceCombination() { |
| 251 | if (using_dynamic_iface_combination_) return; |
| 252 | |
| 253 | legacy_hal::wifi_iface_concurrency_matrix legacy_matrix; |
| 254 | legacy_hal::wifi_error legacy_status; |
| 255 | |
| 256 | std::tie(legacy_status, legacy_matrix) = |
| 257 | legacy_hal_.lock()->getSupportedIfaceConcurrencyMatrix(); |
| 258 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 259 | LOG(ERROR) << "Failed to get SupportedIfaceCombinations matrix from legacy HAL: " |
| 260 | << legacyErrorToString(legacy_status); |
| 261 | return; |
| 262 | } |
| 263 | |
| 264 | IWifiChip::ChipMode aidl_chip_mode; |
| 265 | if (!aidl_struct_util::convertLegacyIfaceCombinationsMatrixToChipMode(legacy_matrix, |
| 266 | &aidl_chip_mode)) { |
| 267 | LOG(ERROR) << "Failed convertLegacyIfaceCombinationsMatrixToChipMode() "; |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | LOG(INFO) << "Reloading iface concurrency combination from driver"; |
| 272 | aidl_chip_mode.id = feature_flags::chip_mode_ids::kV3; |
| 273 | modes_.clear(); |
| 274 | modes_.push_back(aidl_chip_mode); |
| 275 | using_dynamic_iface_combination_ = true; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | std::shared_ptr<WifiChip> WifiChip::create( |
| 279 | int32_t chip_id, bool is_primary, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 280 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 281 | const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util, |
| 282 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags, |
Gabriel Biren | 989c78a | 2023-06-14 22:42:07 +0000 | [diff] [blame] | 283 | const std::function<void(const std::string&)>& handler, |
| 284 | bool using_dynamic_iface_combination) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 285 | std::shared_ptr<WifiChip> ptr = ndk::SharedRefBase::make<WifiChip>( |
Gabriel Biren | 989c78a | 2023-06-14 22:42:07 +0000 | [diff] [blame] | 286 | chip_id, is_primary, legacy_hal, mode_controller, iface_util, feature_flags, handler, |
| 287 | using_dynamic_iface_combination); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 288 | std::weak_ptr<WifiChip> weak_ptr_this(ptr); |
| 289 | ptr->setWeakPtr(weak_ptr_this); |
| 290 | return ptr; |
| 291 | } |
| 292 | |
| 293 | void WifiChip::invalidate() { |
| 294 | if (!writeRingbufferFilesInternal()) { |
| 295 | LOG(ERROR) << "Error writing files to flash"; |
| 296 | } |
| 297 | invalidateAndRemoveAllIfaces(); |
| 298 | setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue); |
| 299 | legacy_hal_.reset(); |
| 300 | event_cb_handler_.invalidate(); |
| 301 | is_valid_ = false; |
| 302 | } |
| 303 | |
| 304 | void WifiChip::setWeakPtr(std::weak_ptr<WifiChip> ptr) { |
| 305 | weak_ptr_this_ = ptr; |
| 306 | } |
| 307 | |
| 308 | bool WifiChip::isValid() { |
| 309 | return is_valid_; |
| 310 | } |
| 311 | |
| 312 | std::set<std::shared_ptr<IWifiChipEventCallback>> WifiChip::getEventCallbacks() { |
| 313 | return event_cb_handler_.getCallbacks(); |
| 314 | } |
| 315 | |
| 316 | ndk::ScopedAStatus WifiChip::getId(int32_t* _aidl_return) { |
| 317 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, &WifiChip::getIdInternal, |
| 318 | _aidl_return); |
| 319 | } |
| 320 | |
| 321 | ndk::ScopedAStatus WifiChip::registerEventCallback( |
| 322 | const std::shared_ptr<IWifiChipEventCallback>& event_callback) { |
| 323 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 324 | &WifiChip::registerEventCallbackInternal, event_callback); |
| 325 | } |
| 326 | |
Gabriel Biren | 2f86249 | 2023-03-09 19:13:07 +0000 | [diff] [blame] | 327 | ndk::ScopedAStatus WifiChip::getFeatureSet(int32_t* _aidl_return) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 328 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Gabriel Biren | 2f86249 | 2023-03-09 19:13:07 +0000 | [diff] [blame] | 329 | &WifiChip::getFeatureSetInternal, _aidl_return); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | ndk::ScopedAStatus WifiChip::getAvailableModes(std::vector<IWifiChip::ChipMode>* _aidl_return) { |
| 333 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 334 | &WifiChip::getAvailableModesInternal, _aidl_return); |
| 335 | } |
| 336 | |
| 337 | ndk::ScopedAStatus WifiChip::configureChip(int32_t in_modeId) { |
| 338 | return validateAndCallWithLock(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 339 | &WifiChip::configureChipInternal, in_modeId); |
| 340 | } |
| 341 | |
| 342 | ndk::ScopedAStatus WifiChip::getMode(int32_t* _aidl_return) { |
| 343 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 344 | &WifiChip::getModeInternal, _aidl_return); |
| 345 | } |
| 346 | |
| 347 | ndk::ScopedAStatus WifiChip::requestChipDebugInfo(IWifiChip::ChipDebugInfo* _aidl_return) { |
| 348 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 349 | &WifiChip::requestChipDebugInfoInternal, _aidl_return); |
| 350 | } |
| 351 | |
| 352 | ndk::ScopedAStatus WifiChip::requestDriverDebugDump(std::vector<uint8_t>* _aidl_return) { |
| 353 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 354 | &WifiChip::requestDriverDebugDumpInternal, _aidl_return); |
| 355 | } |
| 356 | |
| 357 | ndk::ScopedAStatus WifiChip::requestFirmwareDebugDump(std::vector<uint8_t>* _aidl_return) { |
| 358 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 359 | &WifiChip::requestFirmwareDebugDumpInternal, _aidl_return); |
| 360 | } |
| 361 | |
| 362 | ndk::ScopedAStatus WifiChip::createApIface(std::shared_ptr<IWifiApIface>* _aidl_return) { |
| 363 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 364 | &WifiChip::createApIfaceInternal, _aidl_return); |
| 365 | } |
| 366 | |
| 367 | ndk::ScopedAStatus WifiChip::createBridgedApIface(std::shared_ptr<IWifiApIface>* _aidl_return) { |
| 368 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 369 | &WifiChip::createBridgedApIfaceInternal, _aidl_return); |
| 370 | } |
| 371 | |
Gabriel Biren | aa9bd83 | 2023-11-10 00:43:08 +0000 | [diff] [blame] | 372 | ndk::ScopedAStatus WifiChip::createApOrBridgedApIface( |
| 373 | IfaceConcurrencyType in_ifaceType, const std::vector<common::OuiKeyedData>& in_vendorData, |
| 374 | std::shared_ptr<IWifiApIface>* _aidl_return) { |
| 375 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 376 | &WifiChip::createApOrBridgedApIfaceInternal, _aidl_return, in_ifaceType, |
| 377 | in_vendorData); |
| 378 | } |
| 379 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 380 | ndk::ScopedAStatus WifiChip::getApIfaceNames(std::vector<std::string>* _aidl_return) { |
| 381 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 382 | &WifiChip::getApIfaceNamesInternal, _aidl_return); |
| 383 | } |
| 384 | |
| 385 | ndk::ScopedAStatus WifiChip::getApIface(const std::string& in_ifname, |
| 386 | std::shared_ptr<IWifiApIface>* _aidl_return) { |
| 387 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 388 | &WifiChip::getApIfaceInternal, _aidl_return, in_ifname); |
| 389 | } |
| 390 | |
| 391 | ndk::ScopedAStatus WifiChip::removeApIface(const std::string& in_ifname) { |
| 392 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 393 | &WifiChip::removeApIfaceInternal, in_ifname); |
| 394 | } |
| 395 | |
| 396 | ndk::ScopedAStatus WifiChip::removeIfaceInstanceFromBridgedApIface( |
| 397 | const std::string& in_brIfaceName, const std::string& in_ifaceInstanceName) { |
| 398 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 399 | &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal, in_brIfaceName, |
| 400 | in_ifaceInstanceName); |
| 401 | } |
| 402 | |
| 403 | ndk::ScopedAStatus WifiChip::createNanIface(std::shared_ptr<IWifiNanIface>* _aidl_return) { |
| 404 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 405 | &WifiChip::createNanIfaceInternal, _aidl_return); |
| 406 | } |
| 407 | |
| 408 | ndk::ScopedAStatus WifiChip::getNanIfaceNames(std::vector<std::string>* _aidl_return) { |
| 409 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 410 | &WifiChip::getNanIfaceNamesInternal, _aidl_return); |
| 411 | } |
| 412 | |
| 413 | ndk::ScopedAStatus WifiChip::getNanIface(const std::string& in_ifname, |
| 414 | std::shared_ptr<IWifiNanIface>* _aidl_return) { |
| 415 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 416 | &WifiChip::getNanIfaceInternal, _aidl_return, in_ifname); |
| 417 | } |
| 418 | |
| 419 | ndk::ScopedAStatus WifiChip::removeNanIface(const std::string& in_ifname) { |
| 420 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 421 | &WifiChip::removeNanIfaceInternal, in_ifname); |
| 422 | } |
| 423 | |
| 424 | ndk::ScopedAStatus WifiChip::createP2pIface(std::shared_ptr<IWifiP2pIface>* _aidl_return) { |
| 425 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 426 | &WifiChip::createP2pIfaceInternal, _aidl_return); |
| 427 | } |
| 428 | |
| 429 | ndk::ScopedAStatus WifiChip::getP2pIfaceNames(std::vector<std::string>* _aidl_return) { |
| 430 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 431 | &WifiChip::getP2pIfaceNamesInternal, _aidl_return); |
| 432 | } |
| 433 | |
| 434 | ndk::ScopedAStatus WifiChip::getP2pIface(const std::string& in_ifname, |
| 435 | std::shared_ptr<IWifiP2pIface>* _aidl_return) { |
| 436 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 437 | &WifiChip::getP2pIfaceInternal, _aidl_return, in_ifname); |
| 438 | } |
| 439 | |
| 440 | ndk::ScopedAStatus WifiChip::removeP2pIface(const std::string& in_ifname) { |
| 441 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 442 | &WifiChip::removeP2pIfaceInternal, in_ifname); |
| 443 | } |
| 444 | |
| 445 | ndk::ScopedAStatus WifiChip::createStaIface(std::shared_ptr<IWifiStaIface>* _aidl_return) { |
| 446 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 447 | &WifiChip::createStaIfaceInternal, _aidl_return); |
| 448 | } |
| 449 | |
| 450 | ndk::ScopedAStatus WifiChip::getStaIfaceNames(std::vector<std::string>* _aidl_return) { |
| 451 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 452 | &WifiChip::getStaIfaceNamesInternal, _aidl_return); |
| 453 | } |
| 454 | |
| 455 | ndk::ScopedAStatus WifiChip::getStaIface(const std::string& in_ifname, |
| 456 | std::shared_ptr<IWifiStaIface>* _aidl_return) { |
| 457 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 458 | &WifiChip::getStaIfaceInternal, _aidl_return, in_ifname); |
| 459 | } |
| 460 | |
| 461 | ndk::ScopedAStatus WifiChip::removeStaIface(const std::string& in_ifname) { |
| 462 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 463 | &WifiChip::removeStaIfaceInternal, in_ifname); |
| 464 | } |
| 465 | |
| 466 | ndk::ScopedAStatus WifiChip::createRttController( |
| 467 | const std::shared_ptr<IWifiStaIface>& in_boundIface, |
| 468 | std::shared_ptr<IWifiRttController>* _aidl_return) { |
| 469 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 470 | &WifiChip::createRttControllerInternal, _aidl_return, in_boundIface); |
| 471 | } |
| 472 | |
| 473 | ndk::ScopedAStatus WifiChip::getDebugRingBuffersStatus( |
| 474 | std::vector<WifiDebugRingBufferStatus>* _aidl_return) { |
| 475 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 476 | &WifiChip::getDebugRingBuffersStatusInternal, _aidl_return); |
| 477 | } |
| 478 | |
| 479 | ndk::ScopedAStatus WifiChip::startLoggingToDebugRingBuffer( |
| 480 | const std::string& in_ringName, WifiDebugRingBufferVerboseLevel in_verboseLevel, |
| 481 | int32_t in_maxIntervalInSec, int32_t in_minDataSizeInBytes) { |
| 482 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 483 | &WifiChip::startLoggingToDebugRingBufferInternal, in_ringName, |
| 484 | in_verboseLevel, in_maxIntervalInSec, in_minDataSizeInBytes); |
| 485 | } |
| 486 | |
| 487 | ndk::ScopedAStatus WifiChip::forceDumpToDebugRingBuffer(const std::string& in_ringName) { |
| 488 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 489 | &WifiChip::forceDumpToDebugRingBufferInternal, in_ringName); |
| 490 | } |
| 491 | |
| 492 | ndk::ScopedAStatus WifiChip::flushRingBufferToFile() { |
| 493 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 494 | &WifiChip::flushRingBufferToFileInternal); |
| 495 | } |
| 496 | |
| 497 | ndk::ScopedAStatus WifiChip::stopLoggingToDebugRingBuffer() { |
| 498 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 499 | &WifiChip::stopLoggingToDebugRingBufferInternal); |
| 500 | } |
| 501 | |
| 502 | ndk::ScopedAStatus WifiChip::getDebugHostWakeReasonStats( |
| 503 | WifiDebugHostWakeReasonStats* _aidl_return) { |
| 504 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 505 | &WifiChip::getDebugHostWakeReasonStatsInternal, _aidl_return); |
| 506 | } |
| 507 | |
| 508 | ndk::ScopedAStatus WifiChip::enableDebugErrorAlerts(bool in_enable) { |
| 509 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 510 | &WifiChip::enableDebugErrorAlertsInternal, in_enable); |
| 511 | } |
| 512 | |
| 513 | ndk::ScopedAStatus WifiChip::selectTxPowerScenario(IWifiChip::TxPowerScenario in_scenario) { |
| 514 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 515 | &WifiChip::selectTxPowerScenarioInternal, in_scenario); |
| 516 | } |
| 517 | |
| 518 | ndk::ScopedAStatus WifiChip::resetTxPowerScenario() { |
| 519 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 520 | &WifiChip::resetTxPowerScenarioInternal); |
| 521 | } |
| 522 | |
| 523 | ndk::ScopedAStatus WifiChip::setLatencyMode(IWifiChip::LatencyMode in_mode) { |
| 524 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 525 | &WifiChip::setLatencyModeInternal, in_mode); |
| 526 | } |
| 527 | |
Hsiu-Chang Chen | 802828f | 2023-10-21 03:16:10 +0800 | [diff] [blame] | 528 | binder_status_t WifiChip::dump(int fd __unused, const char**, uint32_t) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 529 | { |
| 530 | std::unique_lock<std::mutex> lk(lock_t); |
| 531 | for (const auto& item : ringbuffer_map_) { |
| 532 | forceDumpToDebugRingBufferInternal(item.first); |
| 533 | } |
| 534 | // unique_lock unlocked here |
| 535 | } |
| 536 | usleep(100 * 1000); // sleep for 100 milliseconds to wait for |
| 537 | // ringbuffer updates. |
| 538 | if (!writeRingbufferFilesInternal()) { |
| 539 | LOG(ERROR) << "Error writing files to flash"; |
| 540 | } |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 541 | return STATUS_OK; |
| 542 | } |
| 543 | |
| 544 | ndk::ScopedAStatus WifiChip::setMultiStaPrimaryConnection(const std::string& in_ifName) { |
| 545 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 546 | &WifiChip::setMultiStaPrimaryConnectionInternal, in_ifName); |
| 547 | } |
| 548 | |
| 549 | ndk::ScopedAStatus WifiChip::setMultiStaUseCase(IWifiChip::MultiStaUseCase in_useCase) { |
| 550 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 551 | &WifiChip::setMultiStaUseCaseInternal, in_useCase); |
| 552 | } |
| 553 | |
| 554 | ndk::ScopedAStatus WifiChip::setCoexUnsafeChannels( |
| 555 | const std::vector<IWifiChip::CoexUnsafeChannel>& in_unsafeChannels, |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 556 | int32_t in_restrictions) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 557 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 558 | &WifiChip::setCoexUnsafeChannelsInternal, in_unsafeChannels, |
| 559 | in_restrictions); |
| 560 | } |
| 561 | |
| 562 | ndk::ScopedAStatus WifiChip::setCountryCode(const std::array<uint8_t, 2>& in_code) { |
| 563 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
| 564 | &WifiChip::setCountryCodeInternal, in_code); |
| 565 | } |
| 566 | |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 567 | ndk::ScopedAStatus WifiChip::getUsableChannels(WifiBand in_band, int32_t in_ifaceModeMask, |
| 568 | int32_t in_filterMask, |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 569 | std::vector<WifiUsableChannel>* _aidl_return) { |
| 570 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 571 | &WifiChip::getUsableChannelsInternal, _aidl_return, in_band, |
| 572 | in_ifaceModeMask, in_filterMask); |
| 573 | } |
| 574 | |
Oscar Shu | ab8313c | 2022-12-13 00:55:11 +0000 | [diff] [blame] | 575 | ndk::ScopedAStatus WifiChip::setAfcChannelAllowance( |
Oscar Shu | 4275c87 | 2023-03-08 22:48:09 +0000 | [diff] [blame] | 576 | const AfcChannelAllowance& afcChannelAllowance) { |
Oscar Shu | ab8313c | 2022-12-13 00:55:11 +0000 | [diff] [blame] | 577 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Oscar Shu | 4275c87 | 2023-03-08 22:48:09 +0000 | [diff] [blame] | 578 | &WifiChip::setAfcChannelAllowanceInternal, afcChannelAllowance); |
Oscar Shu | ab8313c | 2022-12-13 00:55:11 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 581 | ndk::ScopedAStatus WifiChip::triggerSubsystemRestart() { |
| 582 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 583 | &WifiChip::triggerSubsystemRestartInternal); |
| 584 | } |
| 585 | |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 586 | ndk::ScopedAStatus WifiChip::getSupportedRadioCombinations( |
| 587 | std::vector<WifiRadioCombination>* _aidl_return) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 588 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 589 | &WifiChip::getSupportedRadioCombinationsInternal, _aidl_return); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Mahesh KKV | c84d377 | 2022-12-02 16:53:28 -0800 | [diff] [blame] | 592 | ndk::ScopedAStatus WifiChip::getWifiChipCapabilities(WifiChipCapabilities* _aidl_return) { |
| 593 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 594 | &WifiChip::getWifiChipCapabilitiesInternal, _aidl_return); |
| 595 | } |
| 596 | |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 597 | ndk::ScopedAStatus WifiChip::enableStaChannelForPeerNetwork(int32_t in_channelCategoryEnableFlag) { |
Shuibing Dai | e5fbcab | 2022-12-19 15:37:19 -0800 | [diff] [blame] | 598 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 599 | &WifiChip::enableStaChannelForPeerNetworkInternal, |
| 600 | in_channelCategoryEnableFlag); |
| 601 | } |
| 602 | |
maheshkkv | a8aba17 | 2023-02-13 12:33:26 -0800 | [diff] [blame] | 603 | ndk::ScopedAStatus WifiChip::setMloMode(const ChipMloMode in_mode) { |
| 604 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 605 | &WifiChip::setMloModeInternal, in_mode); |
| 606 | } |
| 607 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 608 | void WifiChip::invalidateAndRemoveAllIfaces() { |
| 609 | invalidateAndClearBridgedApAll(); |
| 610 | invalidateAndClearAll(ap_ifaces_); |
| 611 | invalidateAndClearAll(nan_ifaces_); |
| 612 | invalidateAndClearAll(p2p_ifaces_); |
| 613 | invalidateAndClearAll(sta_ifaces_); |
| 614 | // Since all the ifaces are invalid now, all RTT controller objects |
| 615 | // using those ifaces also need to be invalidated. |
| 616 | for (const auto& rtt : rtt_controllers_) { |
| 617 | rtt->invalidate(); |
| 618 | } |
| 619 | rtt_controllers_.clear(); |
| 620 | } |
| 621 | |
| 622 | void WifiChip::invalidateAndRemoveDependencies(const std::string& removed_iface_name) { |
| 623 | for (auto it = nan_ifaces_.begin(); it != nan_ifaces_.end();) { |
| 624 | auto nan_iface = *it; |
| 625 | if (nan_iface->getName() == removed_iface_name) { |
| 626 | nan_iface->invalidate(); |
| 627 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 628 | if (!callback->onIfaceRemoved(IfaceType::NAN_IFACE, removed_iface_name).isOk()) { |
| 629 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 630 | } |
| 631 | } |
| 632 | it = nan_ifaces_.erase(it); |
| 633 | } else { |
| 634 | ++it; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | for (auto it = rtt_controllers_.begin(); it != rtt_controllers_.end();) { |
| 639 | auto rtt = *it; |
| 640 | if (rtt->getIfaceName() == removed_iface_name) { |
| 641 | rtt->invalidate(); |
| 642 | it = rtt_controllers_.erase(it); |
| 643 | } else { |
| 644 | ++it; |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | std::pair<int32_t, ndk::ScopedAStatus> WifiChip::getIdInternal() { |
| 650 | return {chip_id_, ndk::ScopedAStatus::ok()}; |
| 651 | } |
| 652 | |
| 653 | ndk::ScopedAStatus WifiChip::registerEventCallbackInternal( |
| 654 | const std::shared_ptr<IWifiChipEventCallback>& event_callback) { |
| 655 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 656 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 657 | } |
| 658 | return ndk::ScopedAStatus::ok(); |
| 659 | } |
| 660 | |
Gabriel Biren | 2f86249 | 2023-03-09 19:13:07 +0000 | [diff] [blame] | 661 | std::pair<int32_t, ndk::ScopedAStatus> WifiChip::getFeatureSetInternal() { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 662 | legacy_hal::wifi_error legacy_status; |
| 663 | uint64_t legacy_feature_set; |
| 664 | uint32_t legacy_logger_feature_set; |
| 665 | const auto ifname = getFirstActiveWlanIfaceName(); |
| 666 | std::tie(legacy_status, legacy_feature_set) = |
| 667 | legacy_hal_.lock()->getSupportedFeatureSet(ifname); |
| 668 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 669 | return {0, createWifiStatusFromLegacyError(legacy_status)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 670 | } |
| 671 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 672 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname); |
| 673 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 674 | // some devices don't support querying logger feature set |
| 675 | legacy_logger_feature_set = 0; |
| 676 | } |
Gabriel Biren | 2f86249 | 2023-03-09 19:13:07 +0000 | [diff] [blame] | 677 | uint32_t aidl_feature_set; |
| 678 | if (!aidl_struct_util::convertLegacyChipFeaturesToAidl(legacy_feature_set, &aidl_feature_set)) { |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 679 | return {0, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 680 | } |
Gabriel Biren | 2f86249 | 2023-03-09 19:13:07 +0000 | [diff] [blame] | 681 | return {aidl_feature_set, ndk::ScopedAStatus::ok()}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | std::pair<std::vector<IWifiChip::ChipMode>, ndk::ScopedAStatus> |
| 685 | WifiChip::getAvailableModesInternal() { |
| 686 | return {modes_, ndk::ScopedAStatus::ok()}; |
| 687 | } |
| 688 | |
| 689 | ndk::ScopedAStatus WifiChip::configureChipInternal( |
| 690 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, int32_t mode_id) { |
| 691 | if (!isValidModeId(mode_id)) { |
| 692 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 693 | } |
| 694 | if (mode_id == current_mode_id_) { |
| 695 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 696 | return ndk::ScopedAStatus::ok(); |
| 697 | } |
| 698 | ndk::ScopedAStatus status = handleChipConfiguration(lock, mode_id); |
| 699 | if (!status.isOk()) { |
| 700 | WifiStatusCode errorCode = static_cast<WifiStatusCode>(status.getServiceSpecificError()); |
| 701 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 702 | if (!callback->onChipReconfigureFailure(errorCode).isOk()) { |
| 703 | LOG(ERROR) << "Failed to invoke onChipReconfigureFailure callback"; |
| 704 | } |
| 705 | } |
| 706 | return status; |
| 707 | } |
| 708 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 709 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 710 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 711 | } |
| 712 | } |
| 713 | current_mode_id_ = mode_id; |
| 714 | LOG(INFO) << "Configured chip in mode " << mode_id; |
| 715 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 716 | |
| 717 | legacy_hal_.lock()->registerSubsystemRestartCallbackHandler(subsystemCallbackHandler_); |
| 718 | |
| 719 | return status; |
| 720 | } |
| 721 | |
| 722 | std::pair<int32_t, ndk::ScopedAStatus> WifiChip::getModeInternal() { |
| 723 | if (!isValidModeId(current_mode_id_)) { |
| 724 | return {current_mode_id_, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 725 | } |
| 726 | return {current_mode_id_, ndk::ScopedAStatus::ok()}; |
| 727 | } |
| 728 | |
| 729 | std::pair<IWifiChip::ChipDebugInfo, ndk::ScopedAStatus> WifiChip::requestChipDebugInfoInternal() { |
| 730 | IWifiChip::ChipDebugInfo result; |
| 731 | legacy_hal::wifi_error legacy_status; |
| 732 | std::string driver_desc; |
| 733 | const auto ifname = getFirstActiveWlanIfaceName(); |
| 734 | std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(ifname); |
| 735 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 736 | LOG(ERROR) << "Failed to get driver version: " << legacyErrorToString(legacy_status); |
| 737 | ndk::ScopedAStatus status = |
| 738 | createWifiStatusFromLegacyError(legacy_status, "failed to get driver version"); |
| 739 | return {std::move(result), std::move(status)}; |
| 740 | } |
| 741 | result.driverDescription = driver_desc.c_str(); |
| 742 | |
| 743 | std::string firmware_desc; |
| 744 | std::tie(legacy_status, firmware_desc) = legacy_hal_.lock()->getFirmwareVersion(ifname); |
| 745 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 746 | LOG(ERROR) << "Failed to get firmware version: " << legacyErrorToString(legacy_status); |
| 747 | ndk::ScopedAStatus status = |
| 748 | createWifiStatusFromLegacyError(legacy_status, "failed to get firmware version"); |
| 749 | return {std::move(result), std::move(status)}; |
| 750 | } |
| 751 | result.firmwareDescription = firmware_desc.c_str(); |
| 752 | |
| 753 | return {std::move(result), ndk::ScopedAStatus::ok()}; |
| 754 | } |
| 755 | |
| 756 | std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> WifiChip::requestDriverDebugDumpInternal() { |
| 757 | legacy_hal::wifi_error legacy_status; |
| 758 | std::vector<uint8_t> driver_dump; |
| 759 | std::tie(legacy_status, driver_dump) = |
| 760 | legacy_hal_.lock()->requestDriverMemoryDump(getFirstActiveWlanIfaceName()); |
| 761 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 762 | LOG(ERROR) << "Failed to get driver debug dump: " << legacyErrorToString(legacy_status); |
| 763 | return {std::vector<uint8_t>(), createWifiStatusFromLegacyError(legacy_status)}; |
| 764 | } |
| 765 | return {driver_dump, ndk::ScopedAStatus::ok()}; |
| 766 | } |
| 767 | |
| 768 | std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> WifiChip::requestFirmwareDebugDumpInternal() { |
| 769 | legacy_hal::wifi_error legacy_status; |
| 770 | std::vector<uint8_t> firmware_dump; |
| 771 | std::tie(legacy_status, firmware_dump) = |
| 772 | legacy_hal_.lock()->requestFirmwareMemoryDump(getFirstActiveWlanIfaceName()); |
| 773 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 774 | LOG(ERROR) << "Failed to get firmware debug dump: " << legacyErrorToString(legacy_status); |
| 775 | return {std::vector<uint8_t>(), createWifiStatusFromLegacyError(legacy_status)}; |
| 776 | } |
| 777 | return {firmware_dump, ndk::ScopedAStatus::ok()}; |
| 778 | } |
| 779 | |
| 780 | ndk::ScopedAStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) { |
| 781 | legacy_hal::wifi_error legacy_status; |
| 782 | legacy_status = legacy_hal_.lock()->createVirtualInterface( |
| 783 | apVirtIf, aidl_struct_util::convertAidlIfaceTypeToLegacy(IfaceType::AP)); |
| 784 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 785 | LOG(ERROR) << "Failed to add interface: " << apVirtIf << " " |
| 786 | << legacyErrorToString(legacy_status); |
| 787 | return createWifiStatusFromLegacyError(legacy_status); |
| 788 | } |
| 789 | return ndk::ScopedAStatus::ok(); |
| 790 | } |
| 791 | |
| 792 | std::shared_ptr<WifiApIface> WifiChip::newWifiApIface(std::string& ifname) { |
| 793 | std::vector<std::string> ap_instances; |
| 794 | for (auto const& it : br_ifaces_ap_instances_) { |
| 795 | if (it.first == ifname) { |
| 796 | ap_instances = it.second; |
| 797 | } |
| 798 | } |
| 799 | std::shared_ptr<WifiApIface> iface = |
| 800 | ndk::SharedRefBase::make<WifiApIface>(ifname, ap_instances, legacy_hal_, iface_util_); |
| 801 | ap_ifaces_.push_back(iface); |
| 802 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 803 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 804 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 805 | } |
| 806 | } |
| 807 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 808 | return iface; |
| 809 | } |
| 810 | |
| 811 | std::pair<std::shared_ptr<IWifiApIface>, ndk::ScopedAStatus> WifiChip::createApIfaceInternal() { |
| 812 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP)) { |
| 813 | return {std::shared_ptr<WifiApIface>(), |
| 814 | createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 815 | } |
| 816 | std::string ifname = allocateApIfaceName(); |
| 817 | ndk::ScopedAStatus status = createVirtualApInterface(ifname); |
| 818 | if (!status.isOk()) { |
| 819 | return {std::shared_ptr<WifiApIface>(), std::move(status)}; |
| 820 | } |
| 821 | std::shared_ptr<WifiApIface> iface = newWifiApIface(ifname); |
| 822 | return {iface, ndk::ScopedAStatus::ok()}; |
| 823 | } |
| 824 | |
| 825 | std::pair<std::shared_ptr<IWifiApIface>, ndk::ScopedAStatus> |
| 826 | WifiChip::createBridgedApIfaceInternal() { |
| 827 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP_BRIDGED)) { |
| 828 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 829 | } |
| 830 | std::vector<std::string> ap_instances = allocateBridgedApInstanceNames(); |
| 831 | if (ap_instances.size() < 2) { |
| 832 | LOG(ERROR) << "Fail to allocate two instances"; |
| 833 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 834 | } |
| 835 | std::string br_ifname = kApBridgeIfacePrefix + ap_instances[0]; |
| 836 | for (int i = 0; i < 2; i++) { |
| 837 | ndk::ScopedAStatus status = createVirtualApInterface(ap_instances[i]); |
| 838 | if (!status.isOk()) { |
| 839 | if (i != 0) { // The failure happened when creating second virtual |
| 840 | // iface. |
| 841 | legacy_hal_.lock()->deleteVirtualInterface( |
| 842 | ap_instances.front()); // Remove the first virtual iface. |
| 843 | } |
| 844 | return {nullptr, std::move(status)}; |
| 845 | } |
| 846 | } |
| 847 | br_ifaces_ap_instances_[br_ifname] = ap_instances; |
| 848 | if (!iface_util_->createBridge(br_ifname)) { |
| 849 | LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str(); |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 850 | deleteApIface(br_ifname); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 851 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 852 | } |
| 853 | for (auto const& instance : ap_instances) { |
| 854 | // Bind ap instance interface to AP bridge |
| 855 | if (!iface_util_->addIfaceToBridge(br_ifname, instance)) { |
| 856 | LOG(ERROR) << "Failed add if to Bridge - if_name=" << instance.c_str(); |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 857 | deleteApIface(br_ifname); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 858 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 859 | } |
| 860 | } |
| 861 | std::shared_ptr<WifiApIface> iface = newWifiApIface(br_ifname); |
| 862 | return {iface, ndk::ScopedAStatus::ok()}; |
| 863 | } |
| 864 | |
Gabriel Biren | aa9bd83 | 2023-11-10 00:43:08 +0000 | [diff] [blame] | 865 | std::pair<std::shared_ptr<IWifiApIface>, ndk::ScopedAStatus> |
| 866 | WifiChip::createApOrBridgedApIfaceInternal( |
| 867 | IfaceConcurrencyType ifaceType, const std::vector<common::OuiKeyedData>& /* vendorData */) { |
| 868 | if (ifaceType == IfaceConcurrencyType::AP) { |
| 869 | return createApIfaceInternal(); |
| 870 | } else if (ifaceType == IfaceConcurrencyType::AP_BRIDGED) { |
| 871 | return createBridgedApIfaceInternal(); |
| 872 | } else { |
| 873 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 874 | } |
| 875 | } |
| 876 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 877 | std::pair<std::vector<std::string>, ndk::ScopedAStatus> WifiChip::getApIfaceNamesInternal() { |
| 878 | if (ap_ifaces_.empty()) { |
| 879 | return {std::vector<std::string>(), ndk::ScopedAStatus::ok()}; |
| 880 | } |
| 881 | return {getNames(ap_ifaces_), ndk::ScopedAStatus::ok()}; |
| 882 | } |
| 883 | |
| 884 | std::pair<std::shared_ptr<IWifiApIface>, ndk::ScopedAStatus> WifiChip::getApIfaceInternal( |
| 885 | const std::string& ifname) { |
| 886 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 887 | if (!iface.get()) { |
| 888 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 889 | } |
| 890 | return {iface, ndk::ScopedAStatus::ok()}; |
| 891 | } |
| 892 | |
| 893 | ndk::ScopedAStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
| 894 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 895 | if (!iface.get()) { |
| 896 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 897 | } |
| 898 | // Invalidate & remove any dependent objects first. |
| 899 | // Note: This is probably not required because we never create |
| 900 | // nan/rtt objects over AP iface. But, there is no harm to do it |
| 901 | // here and not make that assumption all over the place. |
| 902 | invalidateAndRemoveDependencies(ifname); |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 903 | deleteApIface(ifname); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 904 | invalidateAndClear(ap_ifaces_, iface); |
| 905 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 906 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 907 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 908 | } |
| 909 | } |
| 910 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 911 | return ndk::ScopedAStatus::ok(); |
| 912 | } |
| 913 | |
| 914 | ndk::ScopedAStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal( |
| 915 | const std::string& ifname, const std::string& ifInstanceName) { |
| 916 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 917 | if (!iface.get() || ifInstanceName.empty()) { |
| 918 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 919 | } |
| 920 | // Requires to remove one of the instance in bridge mode |
| 921 | for (auto const& it : br_ifaces_ap_instances_) { |
| 922 | if (it.first == ifname) { |
| 923 | std::vector<std::string> ap_instances = it.second; |
| 924 | for (auto const& iface : ap_instances) { |
| 925 | if (iface == ifInstanceName) { |
| 926 | if (!iface_util_->removeIfaceFromBridge(it.first, iface)) { |
| 927 | LOG(ERROR) << "Failed to remove interface: " << ifInstanceName << " from " |
| 928 | << ifname; |
| 929 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE); |
| 930 | } |
| 931 | legacy_hal::wifi_error legacy_status = |
| 932 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
| 933 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 934 | LOG(ERROR) << "Failed to del interface: " << iface << " " |
| 935 | << legacyErrorToString(legacy_status); |
| 936 | return createWifiStatusFromLegacyError(legacy_status); |
| 937 | } |
| 938 | ap_instances.erase( |
| 939 | std::remove(ap_instances.begin(), ap_instances.end(), ifInstanceName), |
| 940 | ap_instances.end()); |
| 941 | br_ifaces_ap_instances_[ifname] = ap_instances; |
| 942 | break; |
| 943 | } |
| 944 | } |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | iface->removeInstance(ifInstanceName); |
| 949 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 950 | |
| 951 | return ndk::ScopedAStatus::ok(); |
| 952 | } |
| 953 | |
| 954 | std::pair<std::shared_ptr<IWifiNanIface>, ndk::ScopedAStatus> WifiChip::createNanIfaceInternal() { |
| 955 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::NAN_IFACE)) { |
| 956 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 957 | } |
| 958 | bool is_dedicated_iface = true; |
| 959 | std::string ifname = getPredefinedNanIfaceName(); |
| 960 | if (ifname.empty() || !iface_util_->ifNameToIndex(ifname)) { |
| 961 | // Use the first shared STA iface (wlan0) if a dedicated aware iface is |
| 962 | // not defined. |
| 963 | ifname = getFirstActiveWlanIfaceName(); |
| 964 | is_dedicated_iface = false; |
| 965 | } |
| 966 | std::shared_ptr<WifiNanIface> iface = |
| 967 | WifiNanIface::create(ifname, is_dedicated_iface, legacy_hal_, iface_util_); |
| 968 | nan_ifaces_.push_back(iface); |
| 969 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 970 | if (!callback->onIfaceAdded(IfaceType::NAN_IFACE, ifname).isOk()) { |
| 971 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 972 | } |
| 973 | } |
| 974 | return {iface, ndk::ScopedAStatus::ok()}; |
| 975 | } |
| 976 | |
| 977 | std::pair<std::vector<std::string>, ndk::ScopedAStatus> WifiChip::getNanIfaceNamesInternal() { |
| 978 | if (nan_ifaces_.empty()) { |
| 979 | return {std::vector<std::string>(), ndk::ScopedAStatus::ok()}; |
| 980 | } |
| 981 | return {getNames(nan_ifaces_), ndk::ScopedAStatus::ok()}; |
| 982 | } |
| 983 | |
| 984 | std::pair<std::shared_ptr<IWifiNanIface>, ndk::ScopedAStatus> WifiChip::getNanIfaceInternal( |
| 985 | const std::string& ifname) { |
| 986 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 987 | if (!iface.get()) { |
| 988 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 989 | } |
| 990 | return {iface, ndk::ScopedAStatus::ok()}; |
| 991 | } |
| 992 | |
| 993 | ndk::ScopedAStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
| 994 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 995 | if (!iface.get()) { |
| 996 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 997 | } |
| 998 | invalidateAndClear(nan_ifaces_, iface); |
| 999 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1000 | if (!callback->onIfaceRemoved(IfaceType::NAN_IFACE, ifname).isOk()) { |
| 1001 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1002 | } |
| 1003 | } |
| 1004 | return ndk::ScopedAStatus::ok(); |
| 1005 | } |
| 1006 | |
| 1007 | std::pair<std::shared_ptr<IWifiP2pIface>, ndk::ScopedAStatus> WifiChip::createP2pIfaceInternal() { |
| 1008 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::P2P)) { |
| 1009 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 1010 | } |
| 1011 | std::string ifname = getPredefinedP2pIfaceName(); |
| 1012 | std::shared_ptr<WifiP2pIface> iface = |
| 1013 | ndk::SharedRefBase::make<WifiP2pIface>(ifname, legacy_hal_); |
| 1014 | p2p_ifaces_.push_back(iface); |
| 1015 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1016 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 1017 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1018 | } |
| 1019 | } |
| 1020 | return {iface, ndk::ScopedAStatus::ok()}; |
| 1021 | } |
| 1022 | |
| 1023 | std::pair<std::vector<std::string>, ndk::ScopedAStatus> WifiChip::getP2pIfaceNamesInternal() { |
| 1024 | if (p2p_ifaces_.empty()) { |
| 1025 | return {std::vector<std::string>(), ndk::ScopedAStatus::ok()}; |
| 1026 | } |
| 1027 | return {getNames(p2p_ifaces_), ndk::ScopedAStatus::ok()}; |
| 1028 | } |
| 1029 | |
| 1030 | std::pair<std::shared_ptr<IWifiP2pIface>, ndk::ScopedAStatus> WifiChip::getP2pIfaceInternal( |
| 1031 | const std::string& ifname) { |
| 1032 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 1033 | if (!iface.get()) { |
| 1034 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 1035 | } |
| 1036 | return {iface, ndk::ScopedAStatus::ok()}; |
| 1037 | } |
| 1038 | |
| 1039 | ndk::ScopedAStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
| 1040 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 1041 | if (!iface.get()) { |
| 1042 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1043 | } |
| 1044 | invalidateAndClear(p2p_ifaces_, iface); |
| 1045 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1046 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 1047 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 1048 | } |
| 1049 | } |
| 1050 | return ndk::ScopedAStatus::ok(); |
| 1051 | } |
| 1052 | |
| 1053 | std::pair<std::shared_ptr<IWifiStaIface>, ndk::ScopedAStatus> WifiChip::createStaIfaceInternal() { |
| 1054 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { |
| 1055 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 1056 | } |
| 1057 | std::string ifname = allocateStaIfaceName(); |
| 1058 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->createVirtualInterface( |
| 1059 | ifname, aidl_struct_util::convertAidlIfaceTypeToLegacy(IfaceType::STA)); |
| 1060 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1061 | LOG(ERROR) << "Failed to add interface: " << ifname << " " |
| 1062 | << legacyErrorToString(legacy_status); |
| 1063 | return {nullptr, createWifiStatusFromLegacyError(legacy_status)}; |
| 1064 | } |
Gabriel Biren | 2f7bec81 | 2023-01-31 01:07:38 +0000 | [diff] [blame] | 1065 | std::shared_ptr<WifiStaIface> iface = WifiStaIface::create(ifname, legacy_hal_, iface_util_); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1066 | sta_ifaces_.push_back(iface); |
| 1067 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1068 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 1069 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1070 | } |
| 1071 | } |
| 1072 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 1073 | return {iface, ndk::ScopedAStatus::ok()}; |
| 1074 | } |
| 1075 | |
| 1076 | std::pair<std::vector<std::string>, ndk::ScopedAStatus> WifiChip::getStaIfaceNamesInternal() { |
| 1077 | if (sta_ifaces_.empty()) { |
| 1078 | return {std::vector<std::string>(), ndk::ScopedAStatus::ok()}; |
| 1079 | } |
| 1080 | return {getNames(sta_ifaces_), ndk::ScopedAStatus::ok()}; |
| 1081 | } |
| 1082 | |
| 1083 | std::pair<std::shared_ptr<IWifiStaIface>, ndk::ScopedAStatus> WifiChip::getStaIfaceInternal( |
| 1084 | const std::string& ifname) { |
| 1085 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 1086 | if (!iface.get()) { |
| 1087 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 1088 | } |
| 1089 | return {iface, ndk::ScopedAStatus::ok()}; |
| 1090 | } |
| 1091 | |
| 1092 | ndk::ScopedAStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
| 1093 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 1094 | if (!iface.get()) { |
| 1095 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1096 | } |
| 1097 | // Invalidate & remove any dependent objects first. |
| 1098 | invalidateAndRemoveDependencies(ifname); |
| 1099 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(ifname); |
| 1100 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1101 | LOG(ERROR) << "Failed to remove interface: " << ifname << " " |
| 1102 | << legacyErrorToString(legacy_status); |
| 1103 | } |
| 1104 | invalidateAndClear(sta_ifaces_, iface); |
| 1105 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1106 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 1107 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 1108 | } |
| 1109 | } |
| 1110 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 1111 | return ndk::ScopedAStatus::ok(); |
| 1112 | } |
| 1113 | |
| 1114 | std::pair<std::shared_ptr<IWifiRttController>, ndk::ScopedAStatus> |
| 1115 | WifiChip::createRttControllerInternal(const std::shared_ptr<IWifiStaIface>& bound_iface) { |
| 1116 | if (sta_ifaces_.size() == 0 && |
| 1117 | !canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { |
| 1118 | LOG(ERROR) << "createRttControllerInternal: Chip cannot support STAs " |
| 1119 | "(and RTT by extension)"; |
| 1120 | return {nullptr, createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE)}; |
| 1121 | } |
| 1122 | std::shared_ptr<WifiRttController> rtt = |
| 1123 | WifiRttController::create(getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); |
| 1124 | rtt_controllers_.emplace_back(rtt); |
| 1125 | return {rtt, ndk::ScopedAStatus::ok()}; |
| 1126 | } |
| 1127 | |
| 1128 | std::pair<std::vector<WifiDebugRingBufferStatus>, ndk::ScopedAStatus> |
| 1129 | WifiChip::getDebugRingBuffersStatusInternal() { |
| 1130 | legacy_hal::wifi_error legacy_status; |
| 1131 | std::vector<legacy_hal::wifi_ring_buffer_status> legacy_ring_buffer_status_vec; |
| 1132 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 1133 | legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName()); |
| 1134 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1135 | return {std::vector<WifiDebugRingBufferStatus>(), |
| 1136 | createWifiStatusFromLegacyError(legacy_status)}; |
| 1137 | } |
| 1138 | std::vector<WifiDebugRingBufferStatus> aidl_ring_buffer_status_vec; |
| 1139 | if (!aidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToAidl( |
| 1140 | legacy_ring_buffer_status_vec, &aidl_ring_buffer_status_vec)) { |
| 1141 | return {std::vector<WifiDebugRingBufferStatus>(), |
| 1142 | createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 1143 | } |
| 1144 | return {aidl_ring_buffer_status_vec, ndk::ScopedAStatus::ok()}; |
| 1145 | } |
| 1146 | |
| 1147 | ndk::ScopedAStatus WifiChip::startLoggingToDebugRingBufferInternal( |
| 1148 | const std::string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 1149 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 1150 | ndk::ScopedAStatus status = registerDebugRingBufferCallback(); |
| 1151 | if (!status.isOk()) { |
| 1152 | return status; |
| 1153 | } |
| 1154 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRingBufferLogging( |
| 1155 | getFirstActiveWlanIfaceName(), ring_name, |
| 1156 | static_cast<std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(verbose_level), |
| 1157 | max_interval_in_sec, min_data_size_in_bytes); |
| 1158 | ringbuffer_map_.insert( |
| 1159 | std::pair<std::string, Ringbuffer>(ring_name, Ringbuffer(kMaxBufferSizeBytes))); |
| 1160 | // if verbose logging enabled, turn up HAL daemon logging as well. |
| 1161 | if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) { |
| 1162 | ::android::base::SetMinimumLogSeverity(::android::base::DEBUG); |
| 1163 | } else { |
| 1164 | ::android::base::SetMinimumLogSeverity(::android::base::VERBOSE); |
| 1165 | } |
| 1166 | return createWifiStatusFromLegacyError(legacy_status); |
| 1167 | } |
| 1168 | |
| 1169 | ndk::ScopedAStatus WifiChip::forceDumpToDebugRingBufferInternal(const std::string& ring_name) { |
| 1170 | ndk::ScopedAStatus status = registerDebugRingBufferCallback(); |
| 1171 | if (!status.isOk()) { |
| 1172 | return status; |
| 1173 | } |
| 1174 | legacy_hal::wifi_error legacy_status = |
| 1175 | legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(), ring_name); |
| 1176 | |
| 1177 | return createWifiStatusFromLegacyError(legacy_status); |
| 1178 | } |
| 1179 | |
| 1180 | ndk::ScopedAStatus WifiChip::flushRingBufferToFileInternal() { |
| 1181 | if (!writeRingbufferFilesInternal()) { |
| 1182 | LOG(ERROR) << "Error writing files to flash"; |
| 1183 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1184 | } |
| 1185 | return ndk::ScopedAStatus::ok(); |
| 1186 | } |
| 1187 | |
| 1188 | ndk::ScopedAStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
| 1189 | legacy_hal::wifi_error legacy_status = |
| 1190 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler(getFirstActiveWlanIfaceName()); |
| 1191 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1192 | debug_ring_buffer_cb_registered_ = false; |
| 1193 | } |
| 1194 | return createWifiStatusFromLegacyError(legacy_status); |
| 1195 | } |
| 1196 | |
| 1197 | std::pair<WifiDebugHostWakeReasonStats, ndk::ScopedAStatus> |
| 1198 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
| 1199 | legacy_hal::wifi_error legacy_status; |
| 1200 | legacy_hal::WakeReasonStats legacy_stats; |
| 1201 | std::tie(legacy_status, legacy_stats) = |
| 1202 | legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName()); |
| 1203 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1204 | return {WifiDebugHostWakeReasonStats{}, createWifiStatusFromLegacyError(legacy_status)}; |
| 1205 | } |
| 1206 | WifiDebugHostWakeReasonStats aidl_stats; |
| 1207 | if (!aidl_struct_util::convertLegacyWakeReasonStatsToAidl(legacy_stats, &aidl_stats)) { |
| 1208 | return {WifiDebugHostWakeReasonStats{}, createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 1209 | } |
| 1210 | return {aidl_stats, ndk::ScopedAStatus::ok()}; |
| 1211 | } |
| 1212 | |
| 1213 | ndk::ScopedAStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
| 1214 | legacy_hal::wifi_error legacy_status; |
| 1215 | if (enable) { |
| 1216 | std::weak_ptr<WifiChip> weak_ptr_this = weak_ptr_this_; |
| 1217 | const auto& on_alert_callback = [weak_ptr_this](int32_t error_code, |
| 1218 | std::vector<uint8_t> debug_data) { |
| 1219 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 1220 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1221 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1222 | return; |
| 1223 | } |
| 1224 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1225 | if (!callback->onDebugErrorAlert(error_code, debug_data).isOk()) { |
| 1226 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 1227 | } |
| 1228 | } |
| 1229 | }; |
| 1230 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
| 1231 | getFirstActiveWlanIfaceName(), on_alert_callback); |
| 1232 | } else { |
| 1233 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
| 1234 | getFirstActiveWlanIfaceName()); |
| 1235 | } |
| 1236 | return createWifiStatusFromLegacyError(legacy_status); |
| 1237 | } |
| 1238 | |
| 1239 | ndk::ScopedAStatus WifiChip::selectTxPowerScenarioInternal(IWifiChip::TxPowerScenario scenario) { |
| 1240 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 1241 | getFirstActiveWlanIfaceName(), |
| 1242 | aidl_struct_util::convertAidlTxPowerScenarioToLegacy(scenario)); |
| 1243 | return createWifiStatusFromLegacyError(legacy_status); |
| 1244 | } |
| 1245 | |
| 1246 | ndk::ScopedAStatus WifiChip::resetTxPowerScenarioInternal() { |
| 1247 | auto legacy_status = legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName()); |
| 1248 | return createWifiStatusFromLegacyError(legacy_status); |
| 1249 | } |
| 1250 | |
| 1251 | ndk::ScopedAStatus WifiChip::setLatencyModeInternal(IWifiChip::LatencyMode mode) { |
| 1252 | auto legacy_status = legacy_hal_.lock()->setLatencyMode( |
| 1253 | getFirstActiveWlanIfaceName(), aidl_struct_util::convertAidlLatencyModeToLegacy(mode)); |
| 1254 | return createWifiStatusFromLegacyError(legacy_status); |
| 1255 | } |
| 1256 | |
| 1257 | ndk::ScopedAStatus WifiChip::setMultiStaPrimaryConnectionInternal(const std::string& ifname) { |
| 1258 | auto legacy_status = legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname); |
| 1259 | return createWifiStatusFromLegacyError(legacy_status); |
| 1260 | } |
| 1261 | |
| 1262 | ndk::ScopedAStatus WifiChip::setMultiStaUseCaseInternal(IWifiChip::MultiStaUseCase use_case) { |
| 1263 | auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase( |
| 1264 | aidl_struct_util::convertAidlMultiStaUseCaseToLegacy(use_case)); |
| 1265 | return createWifiStatusFromLegacyError(legacy_status); |
| 1266 | } |
| 1267 | |
| 1268 | ndk::ScopedAStatus WifiChip::setCoexUnsafeChannelsInternal( |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 1269 | std::vector<IWifiChip::CoexUnsafeChannel> unsafe_channels, int32_t aidl_restrictions) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1270 | std::vector<legacy_hal::wifi_coex_unsafe_channel> legacy_unsafe_channels; |
| 1271 | if (!aidl_struct_util::convertAidlVectorOfCoexUnsafeChannelToLegacy(unsafe_channels, |
| 1272 | &legacy_unsafe_channels)) { |
| 1273 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1274 | } |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1275 | uint32_t legacy_restrictions = 0; |
| 1276 | if (aidl_restrictions & static_cast<uint32_t>(CoexRestriction::WIFI_DIRECT)) { |
| 1277 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_DIRECT; |
| 1278 | } |
| 1279 | if (aidl_restrictions & static_cast<uint32_t>(CoexRestriction::SOFTAP)) { |
| 1280 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::SOFTAP; |
| 1281 | } |
| 1282 | if (aidl_restrictions & static_cast<uint32_t>(CoexRestriction::WIFI_AWARE)) { |
| 1283 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_AWARE; |
| 1284 | } |
| 1285 | auto legacy_status = |
| 1286 | legacy_hal_.lock()->setCoexUnsafeChannels(legacy_unsafe_channels, legacy_restrictions); |
| 1287 | return createWifiStatusFromLegacyError(legacy_status); |
| 1288 | } |
| 1289 | |
| 1290 | ndk::ScopedAStatus WifiChip::setCountryCodeInternal(const std::array<uint8_t, 2>& code) { |
| 1291 | auto legacy_status = legacy_hal_.lock()->setCountryCode(getFirstActiveWlanIfaceName(), code); |
| 1292 | return createWifiStatusFromLegacyError(legacy_status); |
| 1293 | } |
| 1294 | |
| 1295 | std::pair<std::vector<WifiUsableChannel>, ndk::ScopedAStatus> WifiChip::getUsableChannelsInternal( |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 1296 | WifiBand band, int32_t ifaceModeMask, int32_t filterMask) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1297 | legacy_hal::wifi_error legacy_status; |
| 1298 | std::vector<legacy_hal::wifi_usable_channel> legacy_usable_channels; |
| 1299 | std::tie(legacy_status, legacy_usable_channels) = legacy_hal_.lock()->getUsableChannels( |
| 1300 | aidl_struct_util::convertAidlWifiBandToLegacyMacBand(band), |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 1301 | aidl_struct_util::convertAidlWifiIfaceModeToLegacy(ifaceModeMask), |
| 1302 | aidl_struct_util::convertAidlUsableChannelFilterToLegacy(filterMask)); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1303 | |
| 1304 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1305 | return {std::vector<WifiUsableChannel>(), createWifiStatusFromLegacyError(legacy_status)}; |
| 1306 | } |
| 1307 | std::vector<WifiUsableChannel> aidl_usable_channels; |
| 1308 | if (!aidl_struct_util::convertLegacyWifiUsableChannelsToAidl(legacy_usable_channels, |
| 1309 | &aidl_usable_channels)) { |
| 1310 | return {std::vector<WifiUsableChannel>(), createWifiStatus(WifiStatusCode::ERROR_UNKNOWN)}; |
| 1311 | } |
| 1312 | return {aidl_usable_channels, ndk::ScopedAStatus::ok()}; |
| 1313 | } |
| 1314 | |
Oscar Shu | ab8313c | 2022-12-13 00:55:11 +0000 | [diff] [blame] | 1315 | ndk::ScopedAStatus WifiChip::setAfcChannelAllowanceInternal( |
Oscar Shu | 4275c87 | 2023-03-08 22:48:09 +0000 | [diff] [blame] | 1316 | const AfcChannelAllowance& afcChannelAllowance) { |
| 1317 | LOG(INFO) << "setAfcChannelAllowance is not yet supported. availableAfcFrequencyInfos size=" |
| 1318 | << afcChannelAllowance.availableAfcFrequencyInfos.size() |
| 1319 | << " availableAfcChannelInfos size=" |
| 1320 | << afcChannelAllowance.availableAfcChannelInfos.size() |
| 1321 | << " availabilityExpireTimeMs=" << afcChannelAllowance.availabilityExpireTimeMs; |
Oscar Shu | ab8313c | 2022-12-13 00:55:11 +0000 | [diff] [blame] | 1322 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
| 1323 | } |
| 1324 | |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1325 | std::pair<std::vector<WifiRadioCombination>, ndk::ScopedAStatus> |
| 1326 | WifiChip::getSupportedRadioCombinationsInternal() { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1327 | legacy_hal::wifi_error legacy_status; |
| 1328 | legacy_hal::wifi_radio_combination_matrix* legacy_matrix; |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1329 | std::vector<WifiRadioCombination> aidl_combinations; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1330 | |
| 1331 | std::tie(legacy_status, legacy_matrix) = |
| 1332 | legacy_hal_.lock()->getSupportedRadioCombinationsMatrix(); |
| 1333 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1334 | LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: " |
| 1335 | << legacyErrorToString(legacy_status); |
Ye Jiao | 8431076 | 2023-06-16 17:21:01 +0800 | [diff] [blame] | 1336 | if (legacy_matrix != nullptr) { |
| 1337 | free(legacy_matrix); |
| 1338 | } |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1339 | return {aidl_combinations, createWifiStatusFromLegacyError(legacy_status)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1342 | if (!aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix, |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1343 | &aidl_combinations)) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1344 | LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToAidl() "; |
Ye Jiao | 8431076 | 2023-06-16 17:21:01 +0800 | [diff] [blame] | 1345 | if (legacy_matrix != nullptr) { |
| 1346 | free(legacy_matrix); |
| 1347 | } |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1348 | return {aidl_combinations, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1349 | } |
Ye Jiao | 8431076 | 2023-06-16 17:21:01 +0800 | [diff] [blame] | 1350 | |
| 1351 | if (legacy_matrix != nullptr) { |
| 1352 | free(legacy_matrix); |
| 1353 | } |
Gabriel Biren | 263db45 | 2023-02-24 21:07:38 +0000 | [diff] [blame] | 1354 | return {aidl_combinations, ndk::ScopedAStatus::ok()}; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
Mahesh KKV | c84d377 | 2022-12-02 16:53:28 -0800 | [diff] [blame] | 1357 | std::pair<WifiChipCapabilities, ndk::ScopedAStatus> WifiChip::getWifiChipCapabilitiesInternal() { |
| 1358 | legacy_hal::wifi_error legacy_status; |
| 1359 | legacy_hal::wifi_chip_capabilities legacy_chip_capabilities; |
| 1360 | std::tie(legacy_status, legacy_chip_capabilities) = |
| 1361 | legacy_hal_.lock()->getWifiChipCapabilities(); |
| 1362 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1363 | LOG(ERROR) << "Failed to get chip capabilities from legacy HAL: " |
| 1364 | << legacyErrorToString(legacy_status); |
| 1365 | return {WifiChipCapabilities(), createWifiStatusFromLegacyError(legacy_status)}; |
| 1366 | } |
| 1367 | WifiChipCapabilities aidl_chip_capabilities; |
| 1368 | if (!aidl_struct_util::convertLegacyWifiChipCapabilitiesToAidl(legacy_chip_capabilities, |
| 1369 | aidl_chip_capabilities)) { |
| 1370 | LOG(ERROR) << "Failed convertLegacyWifiChipCapabilitiesToAidl() "; |
| 1371 | return {WifiChipCapabilities(), createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; |
| 1372 | } |
| 1373 | |
| 1374 | return {aidl_chip_capabilities, ndk::ScopedAStatus::ok()}; |
| 1375 | } |
| 1376 | |
Shuibing Dai | e5fbcab | 2022-12-19 15:37:19 -0800 | [diff] [blame] | 1377 | ndk::ScopedAStatus WifiChip::enableStaChannelForPeerNetworkInternal( |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 1378 | int32_t channelCategoryEnableFlag) { |
Shuibing Dai | e5fbcab | 2022-12-19 15:37:19 -0800 | [diff] [blame] | 1379 | auto legacy_status = legacy_hal_.lock()->enableStaChannelForPeerNetwork( |
Gabriel Biren | 3b86a78 | 2023-02-04 00:42:53 +0000 | [diff] [blame] | 1380 | aidl_struct_util::convertAidlChannelCategoryToLegacy(channelCategoryEnableFlag)); |
Shuibing Dai | e5fbcab | 2022-12-19 15:37:19 -0800 | [diff] [blame] | 1381 | return createWifiStatusFromLegacyError(legacy_status); |
| 1382 | } |
| 1383 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1384 | ndk::ScopedAStatus WifiChip::triggerSubsystemRestartInternal() { |
| 1385 | auto legacy_status = legacy_hal_.lock()->triggerSubsystemRestart(); |
| 1386 | return createWifiStatusFromLegacyError(legacy_status); |
| 1387 | } |
| 1388 | |
| 1389 | ndk::ScopedAStatus WifiChip::handleChipConfiguration( |
| 1390 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, int32_t mode_id) { |
| 1391 | // If the chip is already configured in a different mode, stop |
| 1392 | // the legacy HAL and then start it after firmware mode change. |
| 1393 | if (isValidModeId(current_mode_id_)) { |
| 1394 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ << " to mode " << mode_id; |
| 1395 | invalidateAndRemoveAllIfaces(); |
| 1396 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop(lock, []() {}); |
| 1397 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1398 | LOG(ERROR) << "Failed to stop legacy HAL: " << legacyErrorToString(legacy_status); |
| 1399 | return createWifiStatusFromLegacyError(legacy_status); |
| 1400 | } |
| 1401 | } |
| 1402 | // Firmware mode change not needed for V2 devices. |
| 1403 | bool success = true; |
| 1404 | if (mode_id == feature_flags::chip_mode_ids::kV1Sta) { |
| 1405 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
| 1406 | } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) { |
| 1407 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 1408 | } |
| 1409 | if (!success) { |
| 1410 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1411 | } |
| 1412 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 1413 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1414 | LOG(ERROR) << "Failed to start legacy HAL: " << legacyErrorToString(legacy_status); |
| 1415 | return createWifiStatusFromLegacyError(legacy_status); |
| 1416 | } |
| 1417 | // Every time the HAL is restarted, we need to register the |
| 1418 | // radio mode change callback. |
| 1419 | ndk::ScopedAStatus status = registerRadioModeChangeCallback(); |
| 1420 | if (!status.isOk()) { |
| 1421 | // This is probably not a critical failure? |
| 1422 | LOG(ERROR) << "Failed to register radio mode change callback"; |
| 1423 | } |
| 1424 | // Extract and save the version information into property. |
| 1425 | std::pair<IWifiChip::ChipDebugInfo, ndk::ScopedAStatus> version_info; |
| 1426 | version_info = WifiChip::requestChipDebugInfoInternal(); |
| 1427 | if (version_info.second.isOk()) { |
| 1428 | property_set("vendor.wlan.firmware.version", |
| 1429 | version_info.first.firmwareDescription.c_str()); |
| 1430 | property_set("vendor.wlan.driver.version", version_info.first.driverDescription.c_str()); |
| 1431 | } |
Sunil Ravi | 2be1f26 | 2023-02-15 20:56:56 +0000 | [diff] [blame] | 1432 | // Get the driver supported interface combination. |
| 1433 | retrieveDynamicIfaceCombination(); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1434 | |
| 1435 | return ndk::ScopedAStatus::ok(); |
| 1436 | } |
| 1437 | |
| 1438 | ndk::ScopedAStatus WifiChip::registerDebugRingBufferCallback() { |
| 1439 | if (debug_ring_buffer_cb_registered_) { |
| 1440 | return ndk::ScopedAStatus::ok(); |
| 1441 | } |
| 1442 | |
| 1443 | std::weak_ptr<WifiChip> weak_ptr_this = weak_ptr_this_; |
| 1444 | const auto& on_ring_buffer_data_callback = |
| 1445 | [weak_ptr_this](const std::string& name, const std::vector<uint8_t>& data, |
| 1446 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 1447 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 1448 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1449 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1450 | return; |
| 1451 | } |
| 1452 | WifiDebugRingBufferStatus aidl_status; |
| 1453 | Ringbuffer::AppendStatus appendstatus; |
| 1454 | if (!aidl_struct_util::convertLegacyDebugRingBufferStatusToAidl(status, |
| 1455 | &aidl_status)) { |
| 1456 | LOG(ERROR) << "Error converting ring buffer status"; |
| 1457 | return; |
| 1458 | } |
| 1459 | { |
| 1460 | std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t); |
| 1461 | const auto& target = shared_ptr_this->ringbuffer_map_.find(name); |
| 1462 | if (target != shared_ptr_this->ringbuffer_map_.end()) { |
| 1463 | Ringbuffer& cur_buffer = target->second; |
| 1464 | appendstatus = cur_buffer.append(data); |
| 1465 | } else { |
| 1466 | LOG(ERROR) << "Ringname " << name << " not found"; |
| 1467 | return; |
| 1468 | } |
| 1469 | // unique_lock unlocked here |
| 1470 | } |
| 1471 | if (appendstatus == Ringbuffer::AppendStatus::FAIL_RING_BUFFER_CORRUPTED) { |
| 1472 | LOG(ERROR) << "Ringname " << name << " is corrupted. Clear the ring buffer"; |
| 1473 | shared_ptr_this->writeRingbufferFilesInternal(); |
| 1474 | return; |
| 1475 | } |
| 1476 | }; |
| 1477 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 1478 | getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback); |
| 1479 | |
| 1480 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1481 | debug_ring_buffer_cb_registered_ = true; |
| 1482 | } |
| 1483 | return createWifiStatusFromLegacyError(legacy_status); |
| 1484 | } |
| 1485 | |
| 1486 | ndk::ScopedAStatus WifiChip::registerRadioModeChangeCallback() { |
| 1487 | std::weak_ptr<WifiChip> weak_ptr_this = weak_ptr_this_; |
| 1488 | const auto& on_radio_mode_change_callback = |
| 1489 | [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) { |
| 1490 | const auto shared_ptr_this = weak_ptr_this.lock(); |
| 1491 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1492 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1493 | return; |
| 1494 | } |
| 1495 | std::vector<IWifiChipEventCallback::RadioModeInfo> aidl_radio_mode_infos; |
| 1496 | if (!aidl_struct_util::convertLegacyWifiMacInfosToAidl(mac_infos, |
| 1497 | &aidl_radio_mode_infos)) { |
| 1498 | LOG(ERROR) << "Error converting wifi mac info"; |
| 1499 | return; |
| 1500 | } |
| 1501 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1502 | if (!callback->onRadioModeChange(aidl_radio_mode_infos).isOk()) { |
| 1503 | LOG(ERROR) << "Failed to invoke onRadioModeChange callback"; |
| 1504 | } |
| 1505 | } |
| 1506 | }; |
| 1507 | legacy_hal::wifi_error legacy_status = |
| 1508 | legacy_hal_.lock()->registerRadioModeChangeCallbackHandler( |
| 1509 | getFirstActiveWlanIfaceName(), on_radio_mode_change_callback); |
| 1510 | return createWifiStatusFromLegacyError(legacy_status); |
| 1511 | } |
| 1512 | |
| 1513 | std::vector<IWifiChip::ChipConcurrencyCombination> |
| 1514 | WifiChip::getCurrentModeConcurrencyCombinations() { |
| 1515 | if (!isValidModeId(current_mode_id_)) { |
| 1516 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1517 | return std::vector<IWifiChip::ChipConcurrencyCombination>(); |
| 1518 | } |
| 1519 | for (const auto& mode : modes_) { |
| 1520 | if (mode.id == current_mode_id_) { |
| 1521 | return mode.availableCombinations; |
| 1522 | } |
| 1523 | } |
| 1524 | CHECK(0) << "Expected to find concurrency combinations for current mode!"; |
| 1525 | return std::vector<IWifiChip::ChipConcurrencyCombination>(); |
| 1526 | } |
| 1527 | |
| 1528 | // Returns a map indexed by IfaceConcurrencyType with the number of ifaces currently |
| 1529 | // created of the corresponding concurrency type. |
| 1530 | std::map<IfaceConcurrencyType, size_t> WifiChip::getCurrentConcurrencyCombination() { |
| 1531 | std::map<IfaceConcurrencyType, size_t> iface_counts; |
| 1532 | uint32_t num_ap = 0; |
| 1533 | uint32_t num_ap_bridged = 0; |
| 1534 | for (const auto& ap_iface : ap_ifaces_) { |
| 1535 | std::string ap_iface_name = ap_iface->getName(); |
| 1536 | if (br_ifaces_ap_instances_.count(ap_iface_name) > 0 && |
| 1537 | br_ifaces_ap_instances_[ap_iface_name].size() > 1) { |
| 1538 | num_ap_bridged++; |
| 1539 | } else { |
| 1540 | num_ap++; |
| 1541 | } |
| 1542 | } |
| 1543 | iface_counts[IfaceConcurrencyType::AP] = num_ap; |
| 1544 | iface_counts[IfaceConcurrencyType::AP_BRIDGED] = num_ap_bridged; |
| 1545 | iface_counts[IfaceConcurrencyType::NAN_IFACE] = nan_ifaces_.size(); |
| 1546 | iface_counts[IfaceConcurrencyType::P2P] = p2p_ifaces_.size(); |
| 1547 | iface_counts[IfaceConcurrencyType::STA] = sta_ifaces_.size(); |
| 1548 | return iface_counts; |
| 1549 | } |
| 1550 | |
| 1551 | // This expands the provided concurrency combinations to a more parseable |
| 1552 | // form. Returns a vector of available combinations possible with the number |
| 1553 | // of each concurrency type in the combination. |
| 1554 | // This method is a port of HalDeviceManager.expandConcurrencyCombos() from framework. |
| 1555 | std::vector<std::map<IfaceConcurrencyType, size_t>> WifiChip::expandConcurrencyCombinations( |
| 1556 | const IWifiChip::ChipConcurrencyCombination& combination) { |
| 1557 | int32_t num_expanded_combos = 1; |
| 1558 | for (const auto& limit : combination.limits) { |
| 1559 | for (int32_t i = 0; i < limit.maxIfaces; i++) { |
| 1560 | num_expanded_combos *= limit.types.size(); |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | // Allocate the vector of expanded combos and reset all concurrency type counts to 0 |
| 1565 | // in each combo. |
| 1566 | std::vector<std::map<IfaceConcurrencyType, size_t>> expanded_combos; |
| 1567 | expanded_combos.resize(num_expanded_combos); |
| 1568 | for (auto& expanded_combo : expanded_combos) { |
| 1569 | for (const auto type : {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, |
| 1570 | IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, |
| 1571 | IfaceConcurrencyType::STA}) { |
| 1572 | expanded_combo[type] = 0; |
| 1573 | } |
| 1574 | } |
| 1575 | int32_t span = num_expanded_combos; |
| 1576 | for (const auto& limit : combination.limits) { |
| 1577 | for (int32_t i = 0; i < limit.maxIfaces; i++) { |
| 1578 | span /= limit.types.size(); |
| 1579 | for (int32_t k = 0; k < num_expanded_combos; ++k) { |
| 1580 | const auto iface_type = limit.types[(k / span) % limit.types.size()]; |
| 1581 | expanded_combos[k][iface_type]++; |
| 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | return expanded_combos; |
| 1586 | } |
| 1587 | |
| 1588 | bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes( |
| 1589 | const std::map<IfaceConcurrencyType, size_t>& expanded_combo, |
| 1590 | IfaceConcurrencyType requested_type) { |
| 1591 | const auto current_combo = getCurrentConcurrencyCombination(); |
| 1592 | |
| 1593 | // Check if we have space for 1 more iface of |type| in this combo |
| 1594 | for (const auto type : |
| 1595 | {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, |
| 1596 | IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { |
| 1597 | size_t num_ifaces_needed = current_combo.at(type); |
| 1598 | if (type == requested_type) { |
| 1599 | num_ifaces_needed++; |
| 1600 | } |
| 1601 | size_t num_ifaces_allowed = expanded_combo.at(type); |
| 1602 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1603 | return false; |
| 1604 | } |
| 1605 | } |
| 1606 | return true; |
| 1607 | } |
| 1608 | |
| 1609 | // This method does the following: |
| 1610 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1611 | // ChipConcurrencyCombination. |
| 1612 | // b) Check if the requested concurrency type can be added to the current mode |
| 1613 | // with the concurrency combination that is already active. |
| 1614 | bool WifiChip::canCurrentModeSupportConcurrencyTypeWithCurrentTypes( |
| 1615 | IfaceConcurrencyType requested_type) { |
| 1616 | if (!isValidModeId(current_mode_id_)) { |
| 1617 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1618 | return false; |
| 1619 | } |
| 1620 | const auto combinations = getCurrentModeConcurrencyCombinations(); |
| 1621 | for (const auto& combination : combinations) { |
| 1622 | const auto expanded_combos = expandConcurrencyCombinations(combination); |
| 1623 | for (const auto& expanded_combo : expanded_combos) { |
| 1624 | if (canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes(expanded_combo, |
| 1625 | requested_type)) { |
| 1626 | return true; |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | return false; |
| 1631 | } |
| 1632 | |
| 1633 | // Note: This does not consider concurrency types already active. It only checks if the |
| 1634 | // provided expanded concurrency combination can support the requested combo. |
| 1635 | bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyCombo( |
| 1636 | const std::map<IfaceConcurrencyType, size_t>& expanded_combo, |
| 1637 | const std::map<IfaceConcurrencyType, size_t>& req_combo) { |
| 1638 | // Check if we have space for 1 more |type| in this combo |
| 1639 | for (const auto type : |
| 1640 | {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, |
| 1641 | IfaceConcurrencyType::NAN_IFACE, IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { |
| 1642 | if (req_combo.count(type) == 0) { |
| 1643 | // Concurrency type not in the req_combo. |
| 1644 | continue; |
| 1645 | } |
| 1646 | size_t num_ifaces_needed = req_combo.at(type); |
| 1647 | size_t num_ifaces_allowed = expanded_combo.at(type); |
| 1648 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1649 | return false; |
| 1650 | } |
| 1651 | } |
| 1652 | return true; |
| 1653 | } |
| 1654 | |
| 1655 | // This method does the following: |
| 1656 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1657 | // ChipConcurrencyCombination. |
| 1658 | // b) Check if the requested concurrency combo can be added to the current mode. |
| 1659 | // Note: This does not consider concurrency types already active. It only checks if the |
| 1660 | // current mode can support the requested combo. |
| 1661 | bool WifiChip::canCurrentModeSupportConcurrencyCombo( |
| 1662 | const std::map<IfaceConcurrencyType, size_t>& req_combo) { |
| 1663 | if (!isValidModeId(current_mode_id_)) { |
| 1664 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1665 | return false; |
| 1666 | } |
| 1667 | const auto combinations = getCurrentModeConcurrencyCombinations(); |
| 1668 | for (const auto& combination : combinations) { |
| 1669 | const auto expanded_combos = expandConcurrencyCombinations(combination); |
| 1670 | for (const auto& expanded_combo : expanded_combos) { |
| 1671 | if (canExpandedConcurrencyComboSupportConcurrencyCombo(expanded_combo, req_combo)) { |
| 1672 | return true; |
| 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | return false; |
| 1677 | } |
| 1678 | |
| 1679 | // This method does the following: |
| 1680 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1681 | // ChipConcurrencyCombination. |
| 1682 | // b) Check if the requested concurrency type can be added to the current mode. |
| 1683 | bool WifiChip::canCurrentModeSupportConcurrencyType(IfaceConcurrencyType requested_type) { |
| 1684 | // Check if we can support at least 1 of the requested concurrency type. |
| 1685 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
| 1686 | req_iface_combo[requested_type] = 1; |
| 1687 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
| 1688 | } |
| 1689 | |
| 1690 | bool WifiChip::isValidModeId(int32_t mode_id) { |
| 1691 | for (const auto& mode : modes_) { |
| 1692 | if (mode.id == mode_id) { |
| 1693 | return true; |
| 1694 | } |
| 1695 | } |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
| 1699 | bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() { |
| 1700 | // Check if we can support at least 1 STA & 1 AP concurrently. |
| 1701 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
| 1702 | req_iface_combo[IfaceConcurrencyType::STA] = 1; |
| 1703 | req_iface_combo[IfaceConcurrencyType::AP] = 1; |
| 1704 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
| 1705 | } |
| 1706 | |
| 1707 | bool WifiChip::isDualStaConcurrencyAllowedInCurrentMode() { |
| 1708 | // Check if we can support at least 2 STA concurrently. |
| 1709 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
| 1710 | req_iface_combo[IfaceConcurrencyType::STA] = 2; |
| 1711 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
| 1712 | } |
| 1713 | |
| 1714 | std::string WifiChip::getFirstActiveWlanIfaceName() { |
| 1715 | if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName(); |
| 1716 | if (ap_ifaces_.size() > 0) { |
| 1717 | // If the first active wlan iface is bridged iface. |
| 1718 | // Return first instance name. |
| 1719 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1720 | if (it.first == ap_ifaces_[0]->getName()) { |
| 1721 | return it.second[0]; |
| 1722 | } |
| 1723 | } |
| 1724 | return ap_ifaces_[0]->getName(); |
| 1725 | } |
| 1726 | // This could happen if the chip call is made before any STA/AP |
| 1727 | // iface is created. Default to wlan0 for such cases. |
| 1728 | LOG(WARNING) << "No active wlan interfaces in use! Using default"; |
| 1729 | return getWlanIfaceNameWithType(IfaceType::STA, 0); |
| 1730 | } |
| 1731 | |
| 1732 | // Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx| |
| 1733 | // not already in use. |
| 1734 | // Note: This doesn't check the actual presence of these interfaces. |
| 1735 | std::string WifiChip::allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx) { |
| 1736 | for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) { |
| 1737 | const auto ifname = getWlanIfaceNameWithType(type, idx); |
| 1738 | if (findUsingNameFromBridgedApInstances(ifname)) continue; |
| 1739 | if (findUsingName(ap_ifaces_, ifname)) continue; |
| 1740 | if (findUsingName(sta_ifaces_, ifname)) continue; |
| 1741 | return ifname; |
| 1742 | } |
| 1743 | // This should never happen. We screwed up somewhere if it did. |
| 1744 | CHECK(false) << "All wlan interfaces in use already!"; |
| 1745 | return {}; |
| 1746 | } |
| 1747 | |
| 1748 | uint32_t WifiChip::startIdxOfApIface() { |
| 1749 | if (isDualStaConcurrencyAllowedInCurrentMode()) { |
| 1750 | // When the HAL support dual STAs, AP should start with idx 2. |
| 1751 | return 2; |
| 1752 | } else if (isStaApConcurrencyAllowedInCurrentMode()) { |
| 1753 | // When the HAL support STA + AP but it doesn't support dual STAs. |
| 1754 | // AP should start with idx 1. |
| 1755 | return 1; |
| 1756 | } |
| 1757 | // No concurrency support. |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
| 1761 | // AP iface names start with idx 1 for modes supporting |
| 1762 | // concurrent STA and not dual AP, else start with idx 0. |
| 1763 | std::string WifiChip::allocateApIfaceName() { |
| 1764 | // Check if we have a dedicated iface for AP. |
| 1765 | std::vector<std::string> ifnames = getPredefinedApIfaceNames(true); |
| 1766 | for (auto const& ifname : ifnames) { |
| 1767 | if (findUsingName(ap_ifaces_, ifname)) continue; |
| 1768 | return ifname; |
| 1769 | } |
| 1770 | return allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface()); |
| 1771 | } |
| 1772 | |
| 1773 | std::vector<std::string> WifiChip::allocateBridgedApInstanceNames() { |
| 1774 | // Check if we have a dedicated iface for AP. |
| 1775 | std::vector<std::string> instances = getPredefinedApIfaceNames(true); |
| 1776 | if (instances.size() == 2) { |
| 1777 | return instances; |
| 1778 | } else { |
| 1779 | int num_ifaces_need_to_allocate = 2 - instances.size(); |
| 1780 | for (int i = 0; i < num_ifaces_need_to_allocate; i++) { |
| 1781 | std::string instance_name = |
| 1782 | allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface() + i); |
| 1783 | if (!instance_name.empty()) { |
| 1784 | instances.push_back(instance_name); |
| 1785 | } |
| 1786 | } |
| 1787 | } |
| 1788 | return instances; |
| 1789 | } |
| 1790 | |
| 1791 | // STA iface names start with idx 0. |
| 1792 | // Primary STA iface will always be 0. |
| 1793 | std::string WifiChip::allocateStaIfaceName() { |
| 1794 | return allocateApOrStaIfaceName(IfaceType::STA, 0); |
| 1795 | } |
| 1796 | |
| 1797 | bool WifiChip::writeRingbufferFilesInternal() { |
| 1798 | if (!removeOldFilesInternal()) { |
| 1799 | LOG(ERROR) << "Error occurred while deleting old tombstone files"; |
| 1800 | return false; |
| 1801 | } |
| 1802 | // write ringbuffers to file |
| 1803 | { |
| 1804 | std::unique_lock<std::mutex> lk(lock_t); |
| 1805 | for (auto& item : ringbuffer_map_) { |
| 1806 | Ringbuffer& cur_buffer = item.second; |
| 1807 | if (cur_buffer.getData().empty()) { |
| 1808 | continue; |
| 1809 | } |
| 1810 | const std::string file_path_raw = kTombstoneFolderPath + item.first + "XXXXXXXXXX"; |
| 1811 | const int dump_fd = mkstemp(makeCharVec(file_path_raw).data()); |
| 1812 | if (dump_fd == -1) { |
| 1813 | PLOG(ERROR) << "create file failed"; |
| 1814 | return false; |
| 1815 | } |
| 1816 | unique_fd file_auto_closer(dump_fd); |
| 1817 | for (const auto& cur_block : cur_buffer.getData()) { |
| 1818 | if (cur_block.size() <= 0 || cur_block.size() > kMaxBufferSizeBytes) { |
| 1819 | PLOG(ERROR) << "Ring buffer: " << item.first |
| 1820 | << " is corrupted. Invalid block size: " << cur_block.size(); |
| 1821 | break; |
| 1822 | } |
| 1823 | if (write(dump_fd, cur_block.data(), sizeof(cur_block[0]) * cur_block.size()) == |
| 1824 | -1) { |
| 1825 | PLOG(ERROR) << "Error writing to file"; |
| 1826 | } |
| 1827 | } |
| 1828 | cur_buffer.clear(); |
| 1829 | } |
| 1830 | // unique_lock unlocked here |
| 1831 | } |
| 1832 | return true; |
| 1833 | } |
| 1834 | |
| 1835 | std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) { |
| 1836 | std::string ifname; |
| 1837 | |
| 1838 | // let the legacy hal override the interface name |
| 1839 | legacy_hal::wifi_error err = legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname); |
| 1840 | if (err == legacy_hal::WIFI_SUCCESS) return ifname; |
| 1841 | |
| 1842 | return getWlanIfaceName(idx); |
| 1843 | } |
| 1844 | |
| 1845 | void WifiChip::invalidateAndClearBridgedApAll() { |
| 1846 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1847 | for (auto const& iface : it.second) { |
| 1848 | iface_util_->removeIfaceFromBridge(it.first, iface); |
| 1849 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
| 1850 | } |
| 1851 | iface_util_->deleteBridge(it.first); |
| 1852 | } |
| 1853 | br_ifaces_ap_instances_.clear(); |
| 1854 | } |
| 1855 | |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 1856 | void WifiChip::deleteApIface(const std::string& if_name) { |
| 1857 | if (if_name.empty()) return; |
| 1858 | // delete bridged interfaces if any |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1859 | for (auto const& it : br_ifaces_ap_instances_) { |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 1860 | if (it.first == if_name) { |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1861 | for (auto const& iface : it.second) { |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 1862 | iface_util_->removeIfaceFromBridge(if_name, iface); |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1863 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
| 1864 | } |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 1865 | iface_util_->deleteBridge(if_name); |
| 1866 | br_ifaces_ap_instances_.erase(if_name); |
| 1867 | // ifname is bridged AP, return here. |
| 1868 | return; |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1869 | } |
| 1870 | } |
Sunil Ravi | 780bef0 | 2023-06-01 21:43:04 +0000 | [diff] [blame] | 1871 | |
| 1872 | // No bridged AP case, delete AP iface |
| 1873 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(if_name); |
| 1874 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1875 | LOG(ERROR) << "Failed to remove interface: " << if_name << " " |
| 1876 | << legacyErrorToString(legacy_status); |
| 1877 | } |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) { |
| 1881 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1882 | if (it.first == name) { |
| 1883 | return true; |
| 1884 | } |
| 1885 | for (auto const& iface : it.second) { |
| 1886 | if (iface == name) { |
| 1887 | return true; |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | return false; |
| 1892 | } |
| 1893 | |
maheshkkv | a8aba17 | 2023-02-13 12:33:26 -0800 | [diff] [blame] | 1894 | ndk::ScopedAStatus WifiChip::setMloModeInternal(const WifiChip::ChipMloMode in_mode) { |
| 1895 | legacy_hal::wifi_mlo_mode mode; |
| 1896 | switch (in_mode) { |
| 1897 | case WifiChip::ChipMloMode::DEFAULT: |
| 1898 | mode = legacy_hal::wifi_mlo_mode::WIFI_MLO_MODE_DEFAULT; |
| 1899 | break; |
| 1900 | case WifiChip::ChipMloMode::LOW_LATENCY: |
| 1901 | mode = legacy_hal::wifi_mlo_mode::WIFI_MLO_MODE_LOW_LATENCY; |
| 1902 | break; |
| 1903 | case WifiChip::ChipMloMode::HIGH_THROUGHPUT: |
| 1904 | mode = legacy_hal::wifi_mlo_mode::WIFI_MLO_MODE_HIGH_THROUGHPUT; |
| 1905 | break; |
| 1906 | case WifiChip::ChipMloMode::LOW_POWER: |
| 1907 | mode = legacy_hal::wifi_mlo_mode::WIFI_MLO_MODE_LOW_POWER; |
| 1908 | break; |
| 1909 | default: |
| 1910 | PLOG(ERROR) << "Error: invalid mode: " << toString(in_mode); |
| 1911 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1912 | } |
| 1913 | return createWifiStatusFromLegacyError(legacy_hal_.lock()->setMloMode(mode)); |
| 1914 | } |
| 1915 | |
Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1916 | } // namespace wifi |
| 1917 | } // namespace hardware |
| 1918 | } // namespace android |
| 1919 | } // namespace aidl |