Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 17 | #include <android-base/logging.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 18 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 19 | #include "hidl_return_util.h" |
| 20 | #include "wifi.h" |
Roshan Pius | 503582e | 2016-10-11 08:25:30 -0700 | [diff] [blame] | 21 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 23 | namespace { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 24 | // Starting Chip ID, will be assigned to primary chip |
| 25 | static constexpr android::hardware::wifi::V1_0::ChipId kPrimaryChipId = 0; |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 26 | } // namespace |
| 27 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace wifi { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 31 | namespace V1_6 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 32 | namespace implementation { |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 33 | using hidl_return_util::validateAndCall; |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 34 | using hidl_return_util::validateAndCallWithLock; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 35 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 36 | Wifi::Wifi(const std::shared_ptr<wifi_system::InterfaceTool> iface_tool, |
| 37 | const std::shared_ptr<legacy_hal::WifiLegacyHalFactory> legacy_hal_factory, |
| 38 | const std::shared_ptr<mode_controller::WifiModeController> mode_controller, |
| 39 | const std::shared_ptr<feature_flags::WifiFeatureFlags> feature_flags) |
Roshan Pius | c885df0 | 2019-05-21 14:49:05 -0700 | [diff] [blame] | 40 | : iface_tool_(iface_tool), |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 41 | legacy_hal_factory_(legacy_hal_factory), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 42 | mode_controller_(mode_controller), |
| 43 | feature_flags_(feature_flags), |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 44 | run_state_(RunState::STOPPED) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 45 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 46 | bool Wifi::isValid() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 47 | // This object is always valid. |
| 48 | return true; |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 51 | Return<void> Wifi::registerEventCallback(const sp<V1_0::IWifiEventCallback>& event_callback, |
| 52 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 53 | return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 54 | &Wifi::registerEventCallbackInternal, hidl_status_cb, event_callback); |
| 55 | } |
| 56 | |
| 57 | Return<void> Wifi::registerEventCallback_1_5(const sp<V1_5::IWifiEventCallback>& event_callback, |
| 58 | registerEventCallback_1_5_cb hidl_status_cb) { |
| 59 | return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, |
| 60 | &Wifi::registerEventCallbackInternal_1_5, hidl_status_cb, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 61 | event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 64 | Return<bool> Wifi::isStarted() { |
| 65 | return run_state_ != RunState::STOPPED; |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 66 | } |
| 67 | |
Roshan Pius | 503582e | 2016-10-11 08:25:30 -0700 | [diff] [blame] | 68 | Return<void> Wifi::start(start_cb hidl_status_cb) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 69 | return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::startInternal, |
| 70 | hidl_status_cb); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | Return<void> Wifi::stop(stop_cb hidl_status_cb) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 74 | return validateAndCallWithLock(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::stopInternal, |
| 75 | hidl_status_cb); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | Return<void> Wifi::getChipIds(getChipIds_cb hidl_status_cb) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 79 | return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::getChipIdsInternal, |
| 80 | hidl_status_cb); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Return<void> Wifi::getChip(ChipId chip_id, getChip_cb hidl_status_cb) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 84 | return validateAndCall(this, WifiStatusCode::ERROR_UNKNOWN, &Wifi::getChipInternal, |
| 85 | hidl_status_cb, chip_id); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 88 | Return<void> Wifi::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 89 | LOG(INFO) << "-----------Debug is called----------------"; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 90 | if (chips_.size() == 0) { |
Roshan Pius | 7cf1df7 | 2018-01-24 19:13:09 -0800 | [diff] [blame] | 91 | return Void(); |
| 92 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 93 | |
| 94 | for (sp<WifiChip> chip : chips_) { |
| 95 | if (!chip.get()) continue; |
| 96 | |
| 97 | chip->debug(handle, {}); |
| 98 | } |
| 99 | return Void(); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 102 | WifiStatus Wifi::registerEventCallbackInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 103 | const sp<V1_0::IWifiEventCallback>& event_callback __unused) { |
chenpaul | b690fb8 | 2021-03-16 22:49:18 +0800 | [diff] [blame] | 104 | // Deprecated support for this callback. |
| 105 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
| 106 | } |
| 107 | |
| 108 | WifiStatus Wifi::registerEventCallbackInternal_1_5( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 109 | const sp<V1_5::IWifiEventCallback>& event_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 110 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 111 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 112 | } |
| 113 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | WifiStatus Wifi::startInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 117 | if (run_state_ == RunState::STARTED) { |
| 118 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 119 | } else if (run_state_ == RunState::STOPPING) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 120 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, "HAL is stopping"); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 121 | } |
Roshan Pius | 8fc6d17 | 2017-11-27 16:08:27 -0800 | [diff] [blame] | 122 | WifiStatus wifi_status = initializeModeControllerAndLegacyHal(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 123 | if (wifi_status.code == WifiStatusCode::SUCCESS) { |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 124 | // Register the callback for subsystem restart |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 125 | const auto& on_subsystem_restart_callback = [this](const std::string& error) { |
| 126 | WifiStatus wifi_status = createWifiStatus(WifiStatusCode::ERROR_UNKNOWN, error); |
| 127 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 128 | LOG(INFO) << "Attempting to invoke onSubsystemRestart " |
| 129 | "callback"; |
| 130 | if (!callback->onSubsystemRestart(wifi_status).isOk()) { |
| 131 | LOG(ERROR) << "Failed to invoke onSubsystemRestart callback"; |
| 132 | } else { |
| 133 | LOG(INFO) << "Succeeded to invoke onSubsystemRestart " |
chenpaul | 2fa7d52 | 2021-10-06 09:24:09 +0800 | [diff] [blame] | 134 | "callback"; |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 135 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 136 | } |
| 137 | }; |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 138 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 139 | // Create the chip instance once the HAL is started. |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 140 | android::hardware::wifi::V1_0::ChipId chipId = kPrimaryChipId; |
| 141 | for (auto& hal : legacy_hals_) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 142 | chips_.push_back( |
| 143 | new WifiChip(chipId, chipId == kPrimaryChipId, hal, mode_controller_, |
| 144 | std::make_shared<iface_util::WifiIfaceUtil>(iface_tool_, hal), |
| 145 | feature_flags_, on_subsystem_restart_callback)); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 146 | chipId++; |
| 147 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 148 | run_state_ = RunState::STARTED; |
| 149 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 150 | if (!callback->onStart().isOk()) { |
| 151 | LOG(ERROR) << "Failed to invoke onStart callback"; |
| 152 | }; |
| 153 | } |
| 154 | LOG(INFO) << "Wifi HAL started"; |
| 155 | } else { |
| 156 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 157 | if (!callback->onFailure(wifi_status).isOk()) { |
| 158 | LOG(ERROR) << "Failed to invoke onFailure callback"; |
| 159 | } |
| 160 | } |
| 161 | LOG(ERROR) << "Wifi HAL start failed"; |
Kyounghan Lee | f2e21c2 | 2020-01-29 14:56:15 +0900 | [diff] [blame] | 162 | // Clear the event callback objects since the HAL start failed. |
| 163 | event_cb_handler_.invalidate(); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 164 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 165 | return wifi_status; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 168 | WifiStatus Wifi::stopInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 169 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 170 | if (run_state_ == RunState::STOPPED) { |
| 171 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 172 | } else if (run_state_ == RunState::STOPPING) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 173 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE, "HAL is stopping"); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 174 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 175 | // Clear the chip object and its child objects since the HAL is now |
| 176 | // stopped. |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 177 | for (auto& chip : chips_) { |
| 178 | if (chip.get()) { |
| 179 | chip->invalidate(); |
| 180 | chip.clear(); |
| 181 | } |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 182 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 183 | chips_.clear(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 184 | WifiStatus wifi_status = stopLegacyHalAndDeinitializeModeController(lock); |
| 185 | if (wifi_status.code == WifiStatusCode::SUCCESS) { |
| 186 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 187 | if (!callback->onStop().isOk()) { |
| 188 | LOG(ERROR) << "Failed to invoke onStop callback"; |
| 189 | }; |
| 190 | } |
| 191 | LOG(INFO) << "Wifi HAL stopped"; |
| 192 | } else { |
| 193 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 194 | if (!callback->onFailure(wifi_status).isOk()) { |
| 195 | LOG(ERROR) << "Failed to invoke onFailure callback"; |
| 196 | } |
| 197 | } |
| 198 | LOG(ERROR) << "Wifi HAL stop failed"; |
| 199 | } |
Kyounghan Lee | f2e21c2 | 2020-01-29 14:56:15 +0900 | [diff] [blame] | 200 | // Clear the event callback objects since the HAL is now stopped. |
| 201 | event_cb_handler_.invalidate(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 202 | return wifi_status; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Roshan Pius | 5647665 | 2016-10-26 14:43:05 -0700 | [diff] [blame] | 205 | std::pair<WifiStatus, std::vector<ChipId>> Wifi::getChipIdsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 206 | std::vector<ChipId> chip_ids; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 207 | |
| 208 | for (auto& chip : chips_) { |
| 209 | ChipId chip_id = getChipIdFromWifiChip(chip); |
| 210 | if (chip_id != UINT32_MAX) chip_ids.emplace_back(chip_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 211 | } |
| 212 | return {createWifiStatus(WifiStatusCode::SUCCESS), std::move(chip_ids)}; |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 215 | std::pair<WifiStatus, sp<V1_4::IWifiChip>> Wifi::getChipInternal(ChipId chip_id) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 216 | for (auto& chip : chips_) { |
| 217 | ChipId cand_id = getChipIdFromWifiChip(chip); |
| 218 | if ((cand_id != UINT32_MAX) && (cand_id == chip_id)) |
| 219 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip}; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 220 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 221 | |
| 222 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 223 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 224 | |
Roshan Pius | 8fc6d17 | 2017-11-27 16:08:27 -0800 | [diff] [blame] | 225 | WifiStatus Wifi::initializeModeControllerAndLegacyHal() { |
| 226 | if (!mode_controller_->initialize()) { |
| 227 | LOG(ERROR) << "Failed to initialize firmware mode controller"; |
| 228 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 229 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 230 | |
| 231 | legacy_hals_ = legacy_hal_factory_->getHals(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 232 | if (legacy_hals_.empty()) return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 233 | int index = 0; // for failure log |
| 234 | for (auto& hal : legacy_hals_) { |
| 235 | legacy_hal::wifi_error legacy_status = hal->initialize(); |
| 236 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 237 | // Currently WifiLegacyHal::initialize does not allocate extra mem, |
| 238 | // only initializes the function table. If this changes, need to |
| 239 | // implement WifiLegacyHal::deinitialize and deinitalize the |
| 240 | // HALs already initialized |
| 241 | LOG(ERROR) << "Failed to initialize legacy HAL index: " << index |
| 242 | << " error: " << legacyErrorToString(legacy_status); |
| 243 | return createWifiStatusFromLegacyError(legacy_status); |
| 244 | } |
| 245 | index++; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 246 | } |
| 247 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Roshan Pius | 155344b | 2017-08-11 15:47:42 -0700 | [diff] [blame] | 250 | WifiStatus Wifi::stopLegacyHalAndDeinitializeModeController( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 251 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 252 | legacy_hal::wifi_error legacy_status = legacy_hal::WIFI_SUCCESS; |
| 253 | int index = 0; |
| 254 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 255 | run_state_ = RunState::STOPPING; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 256 | for (auto& hal : legacy_hals_) { |
| 257 | legacy_hal::wifi_error tmp = hal->stop(lock, [&]() {}); |
| 258 | if (tmp != legacy_hal::WIFI_SUCCESS) { |
| 259 | LOG(ERROR) << "Failed to stop legacy HAL index: " << index |
| 260 | << " error: " << legacyErrorToString(legacy_status); |
| 261 | legacy_status = tmp; |
| 262 | } |
| 263 | index++; |
| 264 | } |
| 265 | run_state_ = RunState::STOPPED; |
| 266 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 267 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 268 | LOG(ERROR) << "One or more legacy HALs failed to stop"; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 269 | return createWifiStatusFromLegacyError(legacy_status); |
| 270 | } |
| 271 | if (!mode_controller_->deinitialize()) { |
| 272 | LOG(ERROR) << "Failed to deinitialize firmware mode controller"; |
| 273 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 274 | } |
| 275 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 276 | } |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 277 | |
| 278 | ChipId Wifi::getChipIdFromWifiChip(sp<WifiChip>& chip) { |
| 279 | ChipId chip_id = UINT32_MAX; |
| 280 | if (chip.get()) { |
| 281 | chip->getId([&](WifiStatus status, uint32_t id) { |
| 282 | if (status.code == WifiStatusCode::SUCCESS) { |
| 283 | chip_id = id; |
| 284 | } |
| 285 | }); |
| 286 | } |
| 287 | |
| 288 | return chip_id; |
| 289 | } |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 290 | } // namespace implementation |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 291 | } // namespace V1_6 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 292 | } // namespace wifi |
| 293 | } // namespace hardware |
| 294 | } // namespace android |