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 | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 18 | #include <cutils/properties.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 19 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 20 | #include "hidl_return_util.h" |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 21 | #include "hidl_struct_util.h" |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 22 | #include "wifi_chip.h" |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 23 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 25 | namespace { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 26 | using android::hardware::hidl_string; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 27 | using android::hardware::hidl_vec; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 28 | using android::hardware::wifi::V1_0::ChipModeId; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 29 | using android::hardware::wifi::V1_0::IfaceType; |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 30 | using android::hardware::wifi::V1_0::IWifiChip; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 31 | using android::sp; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 32 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 33 | constexpr ChipModeId kInvalidModeId = UINT32_MAX; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 34 | // These mode ID's should be unique (even across combo versions). Refer to |
| 35 | // handleChipConfiguration() for it's usage. |
| 36 | // Mode ID's for V1 |
| 37 | constexpr ChipModeId kV1StaChipModeId = 0; |
| 38 | constexpr ChipModeId kV1ApChipModeId = 1; |
| 39 | // Mode ID for V2 |
| 40 | constexpr ChipModeId kV2ChipModeId = 2; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 41 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 42 | template <typename Iface> |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 43 | void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) { |
| 44 | iface->invalidate(); |
| 45 | ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), |
| 46 | ifaces.end()); |
| 47 | } |
| 48 | |
| 49 | template <typename Iface> |
| 50 | void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) { |
| 51 | for (const auto& iface : ifaces) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 52 | iface->invalidate(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 53 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 54 | ifaces.clear(); |
| 55 | } |
| 56 | |
| 57 | template <typename Iface> |
| 58 | std::vector<hidl_string> getNames(std::vector<sp<Iface>>& ifaces) { |
| 59 | std::vector<hidl_string> names; |
| 60 | for (const auto& iface : ifaces) { |
| 61 | names.emplace_back(iface->getName()); |
| 62 | } |
| 63 | return names; |
| 64 | } |
| 65 | |
| 66 | template <typename Iface> |
| 67 | sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces, |
| 68 | const std::string& name) { |
| 69 | std::vector<hidl_string> names; |
| 70 | for (const auto& iface : ifaces) { |
| 71 | if (name == iface->getName()) { |
| 72 | return iface; |
| 73 | } |
| 74 | } |
| 75 | return nullptr; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 76 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 77 | |
| 78 | std::string getWlan0IfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 79 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 80 | property_get("wifi.interface", buffer.data(), "wlan0"); |
| 81 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 84 | std::string getWlan1IfaceName() { |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame^] | 85 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 86 | property_get("wifi.concurrent.interface", buffer.data(), "wlan1"); |
| 87 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 88 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 89 | |
| 90 | std::string getP2pIfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 91 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 92 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 93 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 96 | } // namespace |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 97 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 98 | namespace android { |
| 99 | namespace hardware { |
| 100 | namespace wifi { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 101 | namespace V1_2 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 102 | namespace implementation { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 103 | using hidl_return_util::validateAndCall; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 104 | using hidl_return_util::validateAndCallWithLock; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 105 | |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 106 | WifiChip::WifiChip( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 107 | ChipId chip_id, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 108 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 109 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags) |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 110 | : chip_id_(chip_id), |
| 111 | legacy_hal_(legacy_hal), |
| 112 | mode_controller_(mode_controller), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 113 | feature_flags_(feature_flags), |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 114 | is_valid_(true), |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 115 | current_mode_id_(kInvalidModeId), |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 116 | debug_ring_buffer_cb_registered_(false) { |
| 117 | populateModes(); |
| 118 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 119 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 120 | void WifiChip::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 121 | invalidateAndRemoveAllIfaces(); |
| 122 | legacy_hal_.reset(); |
| 123 | event_cb_handler_.invalidate(); |
| 124 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 127 | bool WifiChip::isValid() { return is_valid_; } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 128 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 129 | std::set<sp<IWifiChipEventCallback>> WifiChip::getEventCallbacks() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 130 | return event_cb_handler_.getCallbacks(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 133 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 134 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 135 | &WifiChip::getIdInternal, hidl_status_cb); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 138 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 139 | const sp<IWifiChipEventCallback>& event_callback, |
| 140 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 141 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 142 | &WifiChip::registerEventCallbackInternal, |
| 143 | hidl_status_cb, event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 146 | Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 147 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 148 | &WifiChip::getCapabilitiesInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 151 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 152 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 153 | &WifiChip::getAvailableModesInternal, |
| 154 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 157 | Return<void> WifiChip::configureChip(ChipModeId mode_id, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 158 | configureChip_cb hidl_status_cb) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 159 | return validateAndCallWithLock( |
| 160 | this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 161 | &WifiChip::configureChipInternal, hidl_status_cb, mode_id); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 164 | Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 165 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 166 | &WifiChip::getModeInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 169 | Return<void> WifiChip::requestChipDebugInfo( |
| 170 | requestChipDebugInfo_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 171 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 172 | &WifiChip::requestChipDebugInfoInternal, |
| 173 | hidl_status_cb); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | Return<void> WifiChip::requestDriverDebugDump( |
| 177 | requestDriverDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 178 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 179 | &WifiChip::requestDriverDebugDumpInternal, |
| 180 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 183 | Return<void> WifiChip::requestFirmwareDebugDump( |
| 184 | requestFirmwareDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 185 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 186 | &WifiChip::requestFirmwareDebugDumpInternal, |
| 187 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 190 | Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 191 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 192 | &WifiChip::createApIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 195 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 196 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 197 | &WifiChip::getApIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 200 | Return<void> WifiChip::getApIface(const hidl_string& ifname, |
| 201 | getApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 202 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 203 | &WifiChip::getApIfaceInternal, hidl_status_cb, |
| 204 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 207 | Return<void> WifiChip::removeApIface(const hidl_string& ifname, |
| 208 | removeApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 209 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 210 | &WifiChip::removeApIfaceInternal, hidl_status_cb, |
| 211 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 214 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 215 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 216 | &WifiChip::createNanIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 219 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 220 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 221 | &WifiChip::getNanIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 225 | getNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 226 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 227 | &WifiChip::getNanIfaceInternal, hidl_status_cb, |
| 228 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 231 | Return<void> WifiChip::removeNanIface(const hidl_string& ifname, |
| 232 | removeNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 233 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 234 | &WifiChip::removeNanIfaceInternal, hidl_status_cb, |
| 235 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 238 | Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 239 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 240 | &WifiChip::createP2pIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 243 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 244 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 245 | &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 249 | getP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 250 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 251 | &WifiChip::getP2pIfaceInternal, hidl_status_cb, |
| 252 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 255 | Return<void> WifiChip::removeP2pIface(const hidl_string& ifname, |
| 256 | removeP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 257 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 258 | &WifiChip::removeP2pIfaceInternal, hidl_status_cb, |
| 259 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 262 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 263 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 264 | &WifiChip::createStaIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 267 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 268 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 269 | &WifiChip::getStaIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 273 | getStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 274 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 275 | &WifiChip::getStaIfaceInternal, hidl_status_cb, |
| 276 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 279 | Return<void> WifiChip::removeStaIface(const hidl_string& ifname, |
| 280 | removeStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 281 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 282 | &WifiChip::removeStaIfaceInternal, hidl_status_cb, |
| 283 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 286 | Return<void> WifiChip::createRttController( |
| 287 | const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 288 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 289 | &WifiChip::createRttControllerInternal, |
| 290 | hidl_status_cb, bound_iface); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 293 | Return<void> WifiChip::getDebugRingBuffersStatus( |
| 294 | getDebugRingBuffersStatus_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 295 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 296 | &WifiChip::getDebugRingBuffersStatusInternal, |
| 297 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | Return<void> WifiChip::startLoggingToDebugRingBuffer( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 301 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 302 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes, |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 303 | startLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 304 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 305 | &WifiChip::startLoggingToDebugRingBufferInternal, |
| 306 | hidl_status_cb, ring_name, verbose_level, |
| 307 | max_interval_in_sec, min_data_size_in_bytes); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | Return<void> WifiChip::forceDumpToDebugRingBuffer( |
| 311 | const hidl_string& ring_name, |
| 312 | forceDumpToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 313 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 314 | &WifiChip::forceDumpToDebugRingBufferInternal, |
| 315 | hidl_status_cb, ring_name); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 318 | Return<void> WifiChip::stopLoggingToDebugRingBuffer( |
| 319 | stopLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 320 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 321 | &WifiChip::stopLoggingToDebugRingBufferInternal, |
| 322 | hidl_status_cb); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 325 | Return<void> WifiChip::getDebugHostWakeReasonStats( |
| 326 | getDebugHostWakeReasonStats_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 327 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 328 | &WifiChip::getDebugHostWakeReasonStatsInternal, |
| 329 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 332 | Return<void> WifiChip::enableDebugErrorAlerts( |
| 333 | bool enable, enableDebugErrorAlerts_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 334 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 335 | &WifiChip::enableDebugErrorAlertsInternal, |
| 336 | hidl_status_cb, enable); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 339 | Return<void> WifiChip::selectTxPowerScenario( |
| 340 | TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 341 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 342 | &WifiChip::selectTxPowerScenarioInternal, |
| 343 | hidl_status_cb, scenario); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 346 | Return<void> WifiChip::resetTxPowerScenario( |
| 347 | resetTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 348 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 349 | &WifiChip::resetTxPowerScenarioInternal, |
| 350 | hidl_status_cb); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 353 | void WifiChip::invalidateAndRemoveAllIfaces() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 354 | invalidateAndClearAll(ap_ifaces_); |
| 355 | invalidateAndClearAll(nan_ifaces_); |
| 356 | invalidateAndClearAll(p2p_ifaces_); |
| 357 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 358 | // Since all the ifaces are invalid now, all RTT controller objects |
| 359 | // using those ifaces also need to be invalidated. |
| 360 | for (const auto& rtt : rtt_controllers_) { |
| 361 | rtt->invalidate(); |
| 362 | } |
| 363 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 366 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 367 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | WifiStatus WifiChip::registerEventCallbackInternal( |
| 371 | const sp<IWifiChipEventCallback>& event_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 372 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 373 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 374 | } |
| 375 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 378 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 379 | legacy_hal::wifi_error legacy_status; |
| 380 | uint32_t legacy_feature_set; |
| 381 | uint32_t legacy_logger_feature_set; |
| 382 | std::tie(legacy_status, legacy_feature_set) = |
| 383 | legacy_hal_.lock()->getSupportedFeatureSet(getWlan0IfaceName()); |
| 384 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 385 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 386 | } |
| 387 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 388 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(getWlan0IfaceName()); |
| 389 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 390 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 391 | } |
| 392 | uint32_t hidl_caps; |
| 393 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 394 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 395 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 396 | } |
| 397 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 400 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 401 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 402 | return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 405 | WifiStatus WifiChip::configureChipInternal( |
| 406 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 407 | ChipModeId mode_id) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 408 | if (!isValidModeId(mode_id)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 409 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 410 | } |
| 411 | if (mode_id == current_mode_id_) { |
| 412 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 413 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 414 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 415 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 416 | if (status.code != WifiStatusCode::SUCCESS) { |
| 417 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 418 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
| 419 | LOG(ERROR) |
| 420 | << "Failed to invoke onChipReconfigureFailure callback"; |
| 421 | } |
| 422 | } |
| 423 | return status; |
| 424 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 425 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 426 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 427 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 428 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 429 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 430 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 431 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 432 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 436 | if (!isValidModeId(current_mode_id_)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 437 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 438 | current_mode_id_}; |
| 439 | } |
| 440 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 444 | WifiChip::requestChipDebugInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 445 | IWifiChip::ChipDebugInfo result; |
| 446 | legacy_hal::wifi_error legacy_status; |
| 447 | std::string driver_desc; |
| 448 | std::tie(legacy_status, driver_desc) = |
| 449 | legacy_hal_.lock()->getDriverVersion(getWlan0IfaceName()); |
| 450 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 451 | LOG(ERROR) << "Failed to get driver version: " |
| 452 | << legacyErrorToString(legacy_status); |
| 453 | WifiStatus status = createWifiStatusFromLegacyError( |
| 454 | legacy_status, "failed to get driver version"); |
| 455 | return {status, result}; |
| 456 | } |
| 457 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 458 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 459 | std::string firmware_desc; |
| 460 | std::tie(legacy_status, firmware_desc) = |
| 461 | legacy_hal_.lock()->getFirmwareVersion(getWlan0IfaceName()); |
| 462 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 463 | LOG(ERROR) << "Failed to get firmware version: " |
| 464 | << legacyErrorToString(legacy_status); |
| 465 | WifiStatus status = createWifiStatusFromLegacyError( |
| 466 | legacy_status, "failed to get firmware version"); |
| 467 | return {status, result}; |
| 468 | } |
| 469 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 470 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 471 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 475 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 476 | legacy_hal::wifi_error legacy_status; |
| 477 | std::vector<uint8_t> driver_dump; |
| 478 | std::tie(legacy_status, driver_dump) = |
| 479 | legacy_hal_.lock()->requestDriverMemoryDump(getWlan0IfaceName()); |
| 480 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 481 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 482 | << legacyErrorToString(legacy_status); |
| 483 | return {createWifiStatusFromLegacyError(legacy_status), |
| 484 | std::vector<uint8_t>()}; |
| 485 | } |
| 486 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 490 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 491 | legacy_hal::wifi_error legacy_status; |
| 492 | std::vector<uint8_t> firmware_dump; |
| 493 | std::tie(legacy_status, firmware_dump) = |
| 494 | legacy_hal_.lock()->requestFirmwareMemoryDump(getWlan0IfaceName()); |
| 495 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 496 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 497 | << legacyErrorToString(legacy_status); |
| 498 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 499 | } |
| 500 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 504 | if (!canCurrentModeSupportIfaceOfType(IfaceType::AP)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 505 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 506 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame^] | 507 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 508 | sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_); |
| 509 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 510 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 511 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 512 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 513 | } |
| 514 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 515 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 519 | WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 520 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 521 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 522 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 523 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 527 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 528 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 529 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 530 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 531 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 532 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 535 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 536 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 537 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 538 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 539 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 540 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 541 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 542 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 543 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 544 | } |
| 545 | } |
| 546 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 549 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 550 | if (!canCurrentModeSupportIfaceOfType(IfaceType::NAN)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 551 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 552 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame^] | 553 | // These are still assumed to be based on wlan0. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 554 | std::string ifname = getWlan0IfaceName(); |
| 555 | sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_); |
| 556 | nan_ifaces_.push_back(iface); |
| 557 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 558 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 559 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 560 | } |
| 561 | } |
| 562 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 566 | WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 567 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 568 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 569 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 570 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 574 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 575 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 576 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 577 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 578 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 579 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 582 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 583 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 584 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 585 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 586 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 587 | invalidateAndClear(nan_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 588 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 589 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 590 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 591 | } |
| 592 | } |
| 593 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 596 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 597 | if (!canCurrentModeSupportIfaceOfType(IfaceType::P2P)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 598 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 599 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 600 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 601 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 602 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 603 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 604 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 605 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 606 | } |
| 607 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 608 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 612 | WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 613 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 614 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 615 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 616 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 620 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 621 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 622 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 623 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 624 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 625 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 628 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 629 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 630 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 631 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 632 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 633 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 634 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 635 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 636 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 637 | } |
| 638 | } |
| 639 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 642 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 643 | if (!canCurrentModeSupportIfaceOfType(IfaceType::STA)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 644 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 645 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame^] | 646 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 647 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_); |
| 648 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 649 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 650 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 651 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 652 | } |
| 653 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 654 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 658 | WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 659 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 660 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 661 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 662 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 666 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 667 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 668 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 669 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 670 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 671 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 674 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 675 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 676 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 677 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 678 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 679 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 680 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 681 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 682 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 683 | } |
| 684 | } |
| 685 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 686 | } |
| 687 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 688 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 689 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 690 | sp<WifiRttController> rtt = |
| 691 | new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_); |
| 692 | rtt_controllers_.emplace_back(rtt); |
| 693 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 694 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 695 | |
| 696 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 697 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 698 | legacy_hal::wifi_error legacy_status; |
| 699 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 700 | legacy_ring_buffer_status_vec; |
| 701 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 702 | legacy_hal_.lock()->getRingBuffersStatus(getWlan0IfaceName()); |
| 703 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 704 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 705 | } |
| 706 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 707 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 708 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 709 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 710 | } |
| 711 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 712 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 716 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 717 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 718 | WifiStatus status = registerDebugRingBufferCallback(); |
| 719 | if (status.code != WifiStatusCode::SUCCESS) { |
| 720 | return status; |
| 721 | } |
| 722 | legacy_hal::wifi_error legacy_status = |
| 723 | legacy_hal_.lock()->startRingBufferLogging( |
| 724 | getWlan0IfaceName(), ring_name, |
| 725 | static_cast< |
| 726 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 727 | verbose_level), |
| 728 | max_interval_in_sec, min_data_size_in_bytes); |
| 729 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 733 | const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 734 | WifiStatus status = registerDebugRingBufferCallback(); |
| 735 | if (status.code != WifiStatusCode::SUCCESS) { |
| 736 | return status; |
| 737 | } |
| 738 | legacy_hal::wifi_error legacy_status = |
| 739 | legacy_hal_.lock()->getRingBufferData(getWlan0IfaceName(), ring_name); |
| 740 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 743 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 744 | legacy_hal::wifi_error legacy_status = |
| 745 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler( |
| 746 | getWlan0IfaceName()); |
| 747 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 750 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 751 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 752 | legacy_hal::wifi_error legacy_status; |
| 753 | legacy_hal::WakeReasonStats legacy_stats; |
| 754 | std::tie(legacy_status, legacy_stats) = |
| 755 | legacy_hal_.lock()->getWakeReasonStats(getWlan0IfaceName()); |
| 756 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 757 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 758 | } |
| 759 | WifiDebugHostWakeReasonStats hidl_stats; |
| 760 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 761 | &hidl_stats)) { |
| 762 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 763 | } |
| 764 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 767 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 768 | legacy_hal::wifi_error legacy_status; |
| 769 | if (enable) { |
| 770 | android::wp<WifiChip> weak_ptr_this(this); |
| 771 | const auto& on_alert_callback = [weak_ptr_this]( |
| 772 | int32_t error_code, |
| 773 | std::vector<uint8_t> debug_data) { |
| 774 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 775 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 776 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 777 | return; |
| 778 | } |
| 779 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 780 | if (!callback->onDebugErrorAlert(error_code, debug_data) |
| 781 | .isOk()) { |
| 782 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 783 | } |
| 784 | } |
| 785 | }; |
| 786 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 787 | getWlan0IfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 788 | } else { |
| 789 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 790 | getWlan0IfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 791 | } |
| 792 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 793 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 794 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 795 | WifiStatus WifiChip::selectTxPowerScenarioInternal(TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 796 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 797 | getWlan0IfaceName(), |
| 798 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
| 799 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 802 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 803 | auto legacy_status = |
| 804 | legacy_hal_.lock()->resetTxPowerScenario(getWlan0IfaceName()); |
| 805 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 808 | WifiStatus WifiChip::handleChipConfiguration( |
| 809 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 810 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 811 | // If the chip is already configured in a different mode, stop |
| 812 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 813 | if (isValidModeId(current_mode_id_)) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 814 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ |
| 815 | << " to mode " << mode_id; |
| 816 | invalidateAndRemoveAllIfaces(); |
| 817 | legacy_hal::wifi_error legacy_status = |
| 818 | legacy_hal_.lock()->stop(lock, []() {}); |
| 819 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 820 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 821 | << legacyErrorToString(legacy_status); |
| 822 | return createWifiStatusFromLegacyError(legacy_status); |
| 823 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 824 | } |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 825 | // Firmware mode change not needed for V2 devices. |
| 826 | bool success = true; |
| 827 | if (mode_id == kV1StaChipModeId) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 828 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 829 | } else if (mode_id == kV1ApChipModeId) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 830 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 831 | } |
| 832 | if (!success) { |
| 833 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 834 | } |
| 835 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 836 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 837 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 838 | << legacyErrorToString(legacy_status); |
| 839 | return createWifiStatusFromLegacyError(legacy_status); |
| 840 | } |
| 841 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 842 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 843 | |
| 844 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 845 | if (debug_ring_buffer_cb_registered_) { |
| 846 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 847 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 848 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 849 | android::wp<WifiChip> weak_ptr_this(this); |
| 850 | const auto& on_ring_buffer_data_callback = |
| 851 | [weak_ptr_this](const std::string& /* name */, |
| 852 | const std::vector<uint8_t>& data, |
| 853 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 854 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 855 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 856 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 857 | return; |
| 858 | } |
| 859 | WifiDebugRingBufferStatus hidl_status; |
| 860 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 861 | status, &hidl_status)) { |
| 862 | LOG(ERROR) << "Error converting ring buffer status"; |
| 863 | return; |
| 864 | } |
| 865 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 866 | if (!callback->onDebugRingBufferDataAvailable(hidl_status, data) |
| 867 | .isOk()) { |
| 868 | LOG(ERROR) |
| 869 | << "Failed to invoke onDebugRingBufferDataAvailable" |
| 870 | << " callback on: " << toString(callback); |
| 871 | } |
| 872 | } |
| 873 | }; |
| 874 | legacy_hal::wifi_error legacy_status = |
| 875 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 876 | getWlan0IfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 877 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 878 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 879 | debug_ring_buffer_cb_registered_ = true; |
| 880 | } |
| 881 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 882 | } |
| 883 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 884 | void WifiChip::populateModes() { |
| 885 | // The chip combination supported for current devices is fixed. |
| 886 | // They can be one of the following based on device features: |
| 887 | // a) 2 separate modes of operation with 1 interface combination each: |
| 888 | // Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN(optional) |
| 889 | // concurrent iface operations. |
| 890 | // Mode 2 (AP mode): Will support 1 AP iface operation. |
| 891 | // |
| 892 | // b) 1 mode of operation with 2 interface combinations |
| 893 | // (conditional on isDualInterfaceSupported()): |
| 894 | // Interface Combination 1: Will support 1 STA and 1 P2P or NAN(optional) |
| 895 | // concurrent iface operations. |
| 896 | // Interface Combination 2: Will support 1 STA and 1 STA or AP concurrent |
| 897 | // iface operations. |
| 898 | // If Aware is enabled (conditional on isAwareSupported()), the iface |
| 899 | // combination will be modified to support either P2P or NAN in place of |
| 900 | // just P2P. |
| 901 | if (feature_flags_.lock()->isDualInterfaceSupported()) { |
| 902 | // V2 Iface combinations for Mode Id = 2. |
| 903 | const IWifiChip::ChipIfaceCombinationLimit |
| 904 | chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 905 | const IWifiChip::ChipIfaceCombinationLimit |
| 906 | chip_iface_combination_limit_2 = {{IfaceType::STA, IfaceType::AP}, |
| 907 | 1}; |
| 908 | IWifiChip::ChipIfaceCombinationLimit chip_iface_combination_limit_3; |
| 909 | if (feature_flags_.lock()->isAwareSupported()) { |
| 910 | chip_iface_combination_limit_3 = {{IfaceType::P2P, IfaceType::NAN}, |
| 911 | 1}; |
| 912 | } else { |
| 913 | chip_iface_combination_limit_3 = {{IfaceType::P2P}, 1}; |
| 914 | } |
| 915 | const IWifiChip::ChipIfaceCombination chip_iface_combination_1 = { |
| 916 | {chip_iface_combination_limit_1, chip_iface_combination_limit_2}}; |
| 917 | const IWifiChip::ChipIfaceCombination chip_iface_combination_2 = { |
| 918 | {chip_iface_combination_limit_1, chip_iface_combination_limit_3}}; |
| 919 | const IWifiChip::ChipMode chip_mode = { |
| 920 | kV2ChipModeId, |
| 921 | {chip_iface_combination_1, chip_iface_combination_2}}; |
| 922 | modes_ = {chip_mode}; |
| 923 | } else { |
| 924 | // V1 Iface combinations for Mode Id = 0. (STA Mode) |
| 925 | const IWifiChip::ChipIfaceCombinationLimit |
| 926 | sta_chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 927 | IWifiChip::ChipIfaceCombinationLimit sta_chip_iface_combination_limit_2; |
| 928 | if (feature_flags_.lock()->isAwareSupported()) { |
| 929 | sta_chip_iface_combination_limit_2 = { |
| 930 | {IfaceType::P2P, IfaceType::NAN}, 1}; |
| 931 | } else { |
| 932 | sta_chip_iface_combination_limit_2 = {{IfaceType::P2P}, 1}; |
| 933 | } |
| 934 | const IWifiChip::ChipIfaceCombination sta_chip_iface_combination = { |
| 935 | {sta_chip_iface_combination_limit_1, |
| 936 | sta_chip_iface_combination_limit_2}}; |
| 937 | const IWifiChip::ChipMode sta_chip_mode = { |
| 938 | kV1StaChipModeId, {sta_chip_iface_combination}}; |
| 939 | // Iface combinations for Mode Id = 1. (AP Mode) |
| 940 | const IWifiChip::ChipIfaceCombinationLimit |
| 941 | ap_chip_iface_combination_limit = {{IfaceType::AP}, 1}; |
| 942 | const IWifiChip::ChipIfaceCombination ap_chip_iface_combination = { |
| 943 | {ap_chip_iface_combination_limit}}; |
| 944 | const IWifiChip::ChipMode ap_chip_mode = {kV1ApChipModeId, |
| 945 | {ap_chip_iface_combination}}; |
| 946 | modes_ = {sta_chip_mode, ap_chip_mode}; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | std::vector<IWifiChip::ChipIfaceCombination> |
| 951 | WifiChip::getCurrentModeIfaceCombinations() { |
| 952 | if (!isValidModeId(current_mode_id_)) { |
| 953 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 954 | return {}; |
| 955 | } |
| 956 | for (const auto& mode : modes_) { |
| 957 | if (mode.id == current_mode_id_) { |
| 958 | return mode.availableCombinations; |
| 959 | } |
| 960 | } |
| 961 | CHECK(0) << "Expected to find iface combinations for current mode!"; |
| 962 | return {}; |
| 963 | } |
| 964 | |
| 965 | // Returns a map indexed by IfaceType with the number of ifaces currently |
| 966 | // created of the corresponding type. |
| 967 | std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() { |
| 968 | std::map<IfaceType, size_t> iface_counts; |
| 969 | iface_counts[IfaceType::AP] = ap_ifaces_.size(); |
| 970 | iface_counts[IfaceType::NAN] = nan_ifaces_.size(); |
| 971 | iface_counts[IfaceType::P2P] = p2p_ifaces_.size(); |
| 972 | iface_counts[IfaceType::STA] = sta_ifaces_.size(); |
| 973 | return iface_counts; |
| 974 | } |
| 975 | |
| 976 | // This expands the provided iface combinations to a more parseable |
| 977 | // form. Returns a vector of available combinations possible with the number |
| 978 | // of ifaces of each type in the combination. |
| 979 | // This method is a port of HalDeviceManager.expandIfaceCombos() from framework. |
| 980 | std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations( |
| 981 | const IWifiChip::ChipIfaceCombination& combination) { |
| 982 | uint32_t num_expanded_combos = 1; |
| 983 | for (const auto& limit : combination.limits) { |
| 984 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 985 | num_expanded_combos *= limit.types.size(); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | // Allocate the vector of expanded combos and reset all iface counts to 0 |
| 990 | // in each combo. |
| 991 | std::vector<std::map<IfaceType, size_t>> expanded_combos; |
| 992 | expanded_combos.resize(num_expanded_combos); |
| 993 | for (auto& expanded_combo : expanded_combos) { |
| 994 | for (const auto type : |
| 995 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 996 | expanded_combo[type] = 0; |
| 997 | } |
| 998 | } |
| 999 | uint32_t span = num_expanded_combos; |
| 1000 | for (const auto& limit : combination.limits) { |
| 1001 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1002 | span /= limit.types.size(); |
| 1003 | for (uint32_t k = 0; k < num_expanded_combos; ++k) { |
| 1004 | const auto iface_type = |
| 1005 | limit.types[(k / span) % limit.types.size()]; |
| 1006 | expanded_combos[k][iface_type]++; |
| 1007 | } |
| 1008 | } |
| 1009 | } |
| 1010 | return expanded_combos; |
| 1011 | } |
| 1012 | |
| 1013 | bool WifiChip::canExpandedIfaceCombinationSupportIfaceOfType( |
| 1014 | const std::map<IfaceType, size_t>& combo, IfaceType requested_type) { |
| 1015 | const auto current_combo = getCurrentIfaceCombination(); |
| 1016 | |
| 1017 | // Check if we have space for 1 more iface of |type| in this combo |
| 1018 | for (const auto type : |
| 1019 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1020 | size_t num_ifaces_needed = current_combo.at(type); |
| 1021 | if (type == requested_type) { |
| 1022 | num_ifaces_needed++; |
| 1023 | } |
| 1024 | size_t num_ifaces_allowed = combo.at(type); |
| 1025 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1026 | return false; |
| 1027 | } |
| 1028 | } |
| 1029 | return true; |
| 1030 | } |
| 1031 | |
| 1032 | // This method does the following: |
| 1033 | // a) Enumerate all possible iface combos by expanding the current |
| 1034 | // ChipIfaceCombination. |
| 1035 | // b) Check if the requested iface type can be added to the current mode. |
| 1036 | bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType type) { |
| 1037 | if (!isValidModeId(current_mode_id_)) { |
| 1038 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1039 | return false; |
| 1040 | } |
| 1041 | const auto combinations = getCurrentModeIfaceCombinations(); |
| 1042 | for (const auto& combination : combinations) { |
| 1043 | const auto expanded_combos = expandIfaceCombinations(combination); |
| 1044 | for (const auto& expanded_combo : expanded_combos) { |
| 1045 | if (canExpandedIfaceCombinationSupportIfaceOfType(expanded_combo, |
| 1046 | type)) { |
| 1047 | return true; |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | return false; |
| 1052 | } |
| 1053 | |
| 1054 | bool WifiChip::isValidModeId(ChipModeId mode_id) { |
| 1055 | for (const auto& mode : modes_) { |
| 1056 | if (mode.id == mode_id) { |
| 1057 | return true; |
| 1058 | } |
| 1059 | } |
| 1060 | return false; |
| 1061 | } |
| 1062 | |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame^] | 1063 | // Return "wlan0", if "wlan0" is not already in use, else return "wlan1". |
| 1064 | // This is based on the assumption that we'll have a max of 2 concurrent |
| 1065 | // AP/STA ifaces. |
| 1066 | std::string WifiChip::allocateApOrStaIfaceName() { |
| 1067 | auto ap_iface = findUsingName(ap_ifaces_, getWlan0IfaceName()); |
| 1068 | auto sta_iface = findUsingName(sta_ifaces_, getWlan0IfaceName()); |
| 1069 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1070 | return getWlan0IfaceName(); |
| 1071 | } |
| 1072 | ap_iface = findUsingName(ap_ifaces_, getWlan1IfaceName()); |
| 1073 | sta_iface = findUsingName(sta_ifaces_, getWlan1IfaceName()); |
| 1074 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1075 | return getWlan1IfaceName(); |
| 1076 | } |
| 1077 | // This should never happen. We screwed up somewhere if it did. |
| 1078 | CHECK(0) << "wlan0 and wlan1 in use already!"; |
| 1079 | return {}; |
| 1080 | } |
| 1081 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 1082 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 1083 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1084 | } // namespace wifi |
| 1085 | } // namespace hardware |
| 1086 | } // namespace android |