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 kStaChipModeId = 0; |
| 34 | constexpr ChipModeId kApChipModeId = 1; |
| 35 | constexpr ChipModeId kInvalidModeId = UINT32_MAX; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 36 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 37 | template <typename Iface> |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 38 | void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) { |
| 39 | iface->invalidate(); |
| 40 | ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), |
| 41 | ifaces.end()); |
| 42 | } |
| 43 | |
| 44 | template <typename Iface> |
| 45 | void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) { |
| 46 | for (const auto& iface : ifaces) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 47 | iface->invalidate(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 48 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 49 | ifaces.clear(); |
| 50 | } |
| 51 | |
| 52 | template <typename Iface> |
| 53 | std::vector<hidl_string> getNames(std::vector<sp<Iface>>& ifaces) { |
| 54 | std::vector<hidl_string> names; |
| 55 | for (const auto& iface : ifaces) { |
| 56 | names.emplace_back(iface->getName()); |
| 57 | } |
| 58 | return names; |
| 59 | } |
| 60 | |
| 61 | template <typename Iface> |
| 62 | sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces, |
| 63 | const std::string& name) { |
| 64 | std::vector<hidl_string> names; |
| 65 | for (const auto& iface : ifaces) { |
| 66 | if (name == iface->getName()) { |
| 67 | return iface; |
| 68 | } |
| 69 | } |
| 70 | return nullptr; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 71 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 72 | |
| 73 | std::string getWlan0IfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 74 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 75 | property_get("wifi.interface", buffer.data(), "wlan0"); |
| 76 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** Not used yet. |
| 80 | std::string getWlan1IfaceName() { |
| 81 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 82 | property_get("wifi.concurrent.interface", buffer.data(), "wlan1"); |
| 83 | return buffer.data(); |
| 84 | } |
| 85 | */ |
| 86 | |
| 87 | std::string getP2pIfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 88 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 89 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 90 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 93 | } // namespace |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 94 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 95 | namespace android { |
| 96 | namespace hardware { |
| 97 | namespace wifi { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 98 | namespace V1_2 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 99 | namespace implementation { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 100 | using hidl_return_util::validateAndCall; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 101 | using hidl_return_util::validateAndCallWithLock; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 102 | |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 103 | WifiChip::WifiChip( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 104 | ChipId chip_id, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 105 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 106 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags) |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 107 | : chip_id_(chip_id), |
| 108 | legacy_hal_(legacy_hal), |
| 109 | mode_controller_(mode_controller), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 110 | feature_flags_(feature_flags), |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 111 | is_valid_(true), |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 112 | current_mode_id_(kInvalidModeId), |
| 113 | debug_ring_buffer_cb_registered_(false) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 114 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 115 | void WifiChip::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 116 | invalidateAndRemoveAllIfaces(); |
| 117 | legacy_hal_.reset(); |
| 118 | event_cb_handler_.invalidate(); |
| 119 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 122 | bool WifiChip::isValid() { return is_valid_; } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 123 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 124 | std::set<sp<IWifiChipEventCallback>> WifiChip::getEventCallbacks() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 125 | return event_cb_handler_.getCallbacks(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 128 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 129 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 130 | &WifiChip::getIdInternal, hidl_status_cb); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 133 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 134 | const sp<IWifiChipEventCallback>& event_callback, |
| 135 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 136 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 137 | &WifiChip::registerEventCallbackInternal, |
| 138 | hidl_status_cb, event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 141 | Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 142 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 143 | &WifiChip::getCapabilitiesInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 146 | Return<void> WifiChip::getAvailableModes(getAvailableModes_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::getAvailableModesInternal, |
| 149 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 152 | Return<void> WifiChip::configureChip(ChipModeId mode_id, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 153 | configureChip_cb hidl_status_cb) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 154 | return validateAndCallWithLock( |
| 155 | this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 156 | &WifiChip::configureChipInternal, hidl_status_cb, mode_id); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 159 | Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 160 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 161 | &WifiChip::getModeInternal, hidl_status_cb); |
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::requestChipDebugInfo( |
| 165 | requestChipDebugInfo_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 166 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 167 | &WifiChip::requestChipDebugInfoInternal, |
| 168 | hidl_status_cb); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | Return<void> WifiChip::requestDriverDebugDump( |
| 172 | requestDriverDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 173 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 174 | &WifiChip::requestDriverDebugDumpInternal, |
| 175 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 178 | Return<void> WifiChip::requestFirmwareDebugDump( |
| 179 | requestFirmwareDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 180 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 181 | &WifiChip::requestFirmwareDebugDumpInternal, |
| 182 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 185 | Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 186 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 187 | &WifiChip::createApIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 190 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_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::getApIfaceNamesInternal, 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::getApIface(const hidl_string& ifname, |
| 196 | getApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 197 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 198 | &WifiChip::getApIfaceInternal, hidl_status_cb, |
| 199 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 202 | Return<void> WifiChip::removeApIface(const hidl_string& ifname, |
| 203 | removeApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 204 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 205 | &WifiChip::removeApIfaceInternal, hidl_status_cb, |
| 206 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 209 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 210 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 211 | &WifiChip::createNanIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 214 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_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::getNanIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 220 | getNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 221 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 222 | &WifiChip::getNanIfaceInternal, hidl_status_cb, |
| 223 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 226 | Return<void> WifiChip::removeNanIface(const hidl_string& ifname, |
| 227 | removeNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 228 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 229 | &WifiChip::removeNanIfaceInternal, hidl_status_cb, |
| 230 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 233 | Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 234 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 235 | &WifiChip::createP2pIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 238 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_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::getP2pIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 244 | getP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 245 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 246 | &WifiChip::getP2pIfaceInternal, hidl_status_cb, |
| 247 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 250 | Return<void> WifiChip::removeP2pIface(const hidl_string& ifname, |
| 251 | removeP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 252 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 253 | &WifiChip::removeP2pIfaceInternal, hidl_status_cb, |
| 254 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 257 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 258 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 259 | &WifiChip::createStaIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 262 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_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::getStaIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 268 | getStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 269 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 270 | &WifiChip::getStaIfaceInternal, hidl_status_cb, |
| 271 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 274 | Return<void> WifiChip::removeStaIface(const hidl_string& ifname, |
| 275 | removeStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 276 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 277 | &WifiChip::removeStaIfaceInternal, hidl_status_cb, |
| 278 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 281 | Return<void> WifiChip::createRttController( |
| 282 | const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 283 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 284 | &WifiChip::createRttControllerInternal, |
| 285 | hidl_status_cb, bound_iface); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 288 | Return<void> WifiChip::getDebugRingBuffersStatus( |
| 289 | getDebugRingBuffersStatus_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 290 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 291 | &WifiChip::getDebugRingBuffersStatusInternal, |
| 292 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | Return<void> WifiChip::startLoggingToDebugRingBuffer( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 296 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 297 | 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] | 298 | startLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 299 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 300 | &WifiChip::startLoggingToDebugRingBufferInternal, |
| 301 | hidl_status_cb, ring_name, verbose_level, |
| 302 | max_interval_in_sec, min_data_size_in_bytes); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | Return<void> WifiChip::forceDumpToDebugRingBuffer( |
| 306 | const hidl_string& ring_name, |
| 307 | forceDumpToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 308 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 309 | &WifiChip::forceDumpToDebugRingBufferInternal, |
| 310 | hidl_status_cb, ring_name); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 313 | Return<void> WifiChip::stopLoggingToDebugRingBuffer( |
| 314 | stopLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 315 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 316 | &WifiChip::stopLoggingToDebugRingBufferInternal, |
| 317 | hidl_status_cb); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 320 | Return<void> WifiChip::getDebugHostWakeReasonStats( |
| 321 | getDebugHostWakeReasonStats_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 322 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 323 | &WifiChip::getDebugHostWakeReasonStatsInternal, |
| 324 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 327 | Return<void> WifiChip::enableDebugErrorAlerts( |
| 328 | bool enable, enableDebugErrorAlerts_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 329 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 330 | &WifiChip::enableDebugErrorAlertsInternal, |
| 331 | hidl_status_cb, enable); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 334 | Return<void> WifiChip::selectTxPowerScenario( |
| 335 | TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 336 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 337 | &WifiChip::selectTxPowerScenarioInternal, |
| 338 | hidl_status_cb, scenario); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 341 | Return<void> WifiChip::resetTxPowerScenario( |
| 342 | resetTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 343 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 344 | &WifiChip::resetTxPowerScenarioInternal, |
| 345 | hidl_status_cb); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 348 | void WifiChip::invalidateAndRemoveAllIfaces() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 349 | invalidateAndClearAll(ap_ifaces_); |
| 350 | invalidateAndClearAll(nan_ifaces_); |
| 351 | invalidateAndClearAll(p2p_ifaces_); |
| 352 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 353 | // Since all the ifaces are invalid now, all RTT controller objects |
| 354 | // using those ifaces also need to be invalidated. |
| 355 | for (const auto& rtt : rtt_controllers_) { |
| 356 | rtt->invalidate(); |
| 357 | } |
| 358 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 361 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 362 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | WifiStatus WifiChip::registerEventCallbackInternal( |
| 366 | const sp<IWifiChipEventCallback>& event_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 367 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 368 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 369 | } |
| 370 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 373 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 374 | legacy_hal::wifi_error legacy_status; |
| 375 | uint32_t legacy_feature_set; |
| 376 | uint32_t legacy_logger_feature_set; |
| 377 | std::tie(legacy_status, legacy_feature_set) = |
| 378 | legacy_hal_.lock()->getSupportedFeatureSet(getWlan0IfaceName()); |
| 379 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 380 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 381 | } |
| 382 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 383 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(getWlan0IfaceName()); |
| 384 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 385 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 386 | } |
| 387 | uint32_t hidl_caps; |
| 388 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 389 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 390 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 391 | } |
| 392 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 395 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 396 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 397 | // The chip combination supported for current devices is fixed for now with |
| 398 | // 2 separate modes of operation: |
| 399 | // Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN iface operations |
| 400 | // concurrently [NAN conditional on wifiHidlFeatureAware] |
| 401 | // Mode 2 (AP mode): Will support 1 AP iface operations. |
| 402 | // TODO (b/32997844): Read this from some device specific flags in the |
| 403 | // makefile. |
| 404 | // STA mode iface combinations. |
| 405 | const IWifiChip::ChipIfaceCombinationLimit |
| 406 | sta_chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 407 | IWifiChip::ChipIfaceCombinationLimit sta_chip_iface_combination_limit_2; |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 408 | if (feature_flags_.lock()->isAwareSupported()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 409 | sta_chip_iface_combination_limit_2 = {{IfaceType::P2P, IfaceType::NAN}, |
| 410 | 1}; |
| 411 | } else { |
| 412 | sta_chip_iface_combination_limit_2 = {{IfaceType::P2P}, 1}; |
| 413 | } |
| 414 | const IWifiChip::ChipIfaceCombination sta_chip_iface_combination = { |
| 415 | {sta_chip_iface_combination_limit_1, |
| 416 | sta_chip_iface_combination_limit_2}}; |
| 417 | const IWifiChip::ChipMode sta_chip_mode = {kStaChipModeId, |
| 418 | {sta_chip_iface_combination}}; |
| 419 | // AP mode iface combinations. |
| 420 | const IWifiChip::ChipIfaceCombinationLimit ap_chip_iface_combination_limit = |
| 421 | {{IfaceType::AP}, 1}; |
| 422 | const IWifiChip::ChipIfaceCombination ap_chip_iface_combination = { |
| 423 | {ap_chip_iface_combination_limit}}; |
| 424 | const IWifiChip::ChipMode ap_chip_mode = {kApChipModeId, |
| 425 | {ap_chip_iface_combination}}; |
| 426 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 427 | {sta_chip_mode, ap_chip_mode}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 430 | WifiStatus WifiChip::configureChipInternal( |
| 431 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 432 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 433 | if (mode_id != kStaChipModeId && mode_id != kApChipModeId) { |
| 434 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 435 | } |
| 436 | if (mode_id == current_mode_id_) { |
| 437 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 438 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 439 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 440 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 441 | if (status.code != WifiStatusCode::SUCCESS) { |
| 442 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 443 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
| 444 | LOG(ERROR) |
| 445 | << "Failed to invoke onChipReconfigureFailure callback"; |
| 446 | } |
| 447 | } |
| 448 | return status; |
| 449 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 450 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 451 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 452 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 453 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 454 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 455 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 456 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 457 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 461 | if (current_mode_id_ == kInvalidModeId) { |
| 462 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 463 | current_mode_id_}; |
| 464 | } |
| 465 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 469 | WifiChip::requestChipDebugInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 470 | IWifiChip::ChipDebugInfo result; |
| 471 | legacy_hal::wifi_error legacy_status; |
| 472 | std::string driver_desc; |
| 473 | std::tie(legacy_status, driver_desc) = |
| 474 | legacy_hal_.lock()->getDriverVersion(getWlan0IfaceName()); |
| 475 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 476 | LOG(ERROR) << "Failed to get driver version: " |
| 477 | << legacyErrorToString(legacy_status); |
| 478 | WifiStatus status = createWifiStatusFromLegacyError( |
| 479 | legacy_status, "failed to get driver version"); |
| 480 | return {status, result}; |
| 481 | } |
| 482 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 483 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 484 | std::string firmware_desc; |
| 485 | std::tie(legacy_status, firmware_desc) = |
| 486 | legacy_hal_.lock()->getFirmwareVersion(getWlan0IfaceName()); |
| 487 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 488 | LOG(ERROR) << "Failed to get firmware version: " |
| 489 | << legacyErrorToString(legacy_status); |
| 490 | WifiStatus status = createWifiStatusFromLegacyError( |
| 491 | legacy_status, "failed to get firmware version"); |
| 492 | return {status, result}; |
| 493 | } |
| 494 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 495 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 496 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 500 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 501 | legacy_hal::wifi_error legacy_status; |
| 502 | std::vector<uint8_t> driver_dump; |
| 503 | std::tie(legacy_status, driver_dump) = |
| 504 | legacy_hal_.lock()->requestDriverMemoryDump(getWlan0IfaceName()); |
| 505 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 506 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 507 | << legacyErrorToString(legacy_status); |
| 508 | return {createWifiStatusFromLegacyError(legacy_status), |
| 509 | std::vector<uint8_t>()}; |
| 510 | } |
| 511 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 515 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 516 | legacy_hal::wifi_error legacy_status; |
| 517 | std::vector<uint8_t> firmware_dump; |
| 518 | std::tie(legacy_status, firmware_dump) = |
| 519 | legacy_hal_.lock()->requestFirmwareMemoryDump(getWlan0IfaceName()); |
| 520 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 521 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 522 | << legacyErrorToString(legacy_status); |
| 523 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 524 | } |
| 525 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 529 | if (current_mode_id_ != kApChipModeId || !ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 530 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 531 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 532 | std::string ifname = getWlan0IfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 533 | sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_); |
| 534 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 535 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 536 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 537 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 538 | } |
| 539 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 540 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 544 | WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 545 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 546 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 547 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 548 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 552 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 553 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 554 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 555 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 556 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 557 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 560 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 561 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 562 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 563 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 564 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 565 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 566 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 567 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 568 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 569 | } |
| 570 | } |
| 571 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 574 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 575 | // Only 1 of NAN or P2P iface can be active at a time. |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 576 | if (feature_flags_.lock()->isAwareSupported()) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 577 | if (current_mode_id_ != kStaChipModeId || !nan_ifaces_.empty() || |
| 578 | !p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 579 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 580 | } |
| 581 | std::string ifname = getWlan0IfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 582 | sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_); |
| 583 | nan_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 584 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 585 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 586 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 587 | } |
| 588 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 589 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 590 | } else { |
| 591 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 592 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 596 | WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 597 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 598 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 599 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 600 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 604 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 605 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 606 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 607 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 608 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 609 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 612 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 613 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 614 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 615 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 616 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 617 | invalidateAndClear(nan_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 618 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 619 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 620 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 621 | } |
| 622 | } |
| 623 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 626 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 627 | // Only 1 of NAN or P2P iface can be active at a time. |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 628 | if (current_mode_id_ != kStaChipModeId || !p2p_ifaces_.empty() || |
| 629 | !nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 630 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 631 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 632 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 633 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 634 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 635 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 636 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 637 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 638 | } |
| 639 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 640 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 644 | WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 645 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 646 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 647 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 648 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 652 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 653 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 654 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 655 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 656 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 657 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 660 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 661 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 662 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 663 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 664 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 665 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 666 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 667 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 668 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 669 | } |
| 670 | } |
| 671 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 674 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 675 | if (current_mode_id_ != kStaChipModeId || !sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 676 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 677 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 678 | std::string ifname = getWlan0IfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 679 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_); |
| 680 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 681 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 682 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 683 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 684 | } |
| 685 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 686 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 690 | WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 691 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 692 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 693 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 694 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 698 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 699 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 700 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 701 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 702 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 703 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 706 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 707 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 708 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 709 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 710 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 711 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 712 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 713 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 714 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 715 | } |
| 716 | } |
| 717 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 718 | } |
| 719 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 720 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 721 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 722 | sp<WifiRttController> rtt = |
| 723 | new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_); |
| 724 | rtt_controllers_.emplace_back(rtt); |
| 725 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 726 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 727 | |
| 728 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 729 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 730 | legacy_hal::wifi_error legacy_status; |
| 731 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 732 | legacy_ring_buffer_status_vec; |
| 733 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 734 | legacy_hal_.lock()->getRingBuffersStatus(getWlan0IfaceName()); |
| 735 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 736 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 737 | } |
| 738 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 739 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 740 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 741 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 742 | } |
| 743 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 744 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 748 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 749 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 750 | WifiStatus status = registerDebugRingBufferCallback(); |
| 751 | if (status.code != WifiStatusCode::SUCCESS) { |
| 752 | return status; |
| 753 | } |
| 754 | legacy_hal::wifi_error legacy_status = |
| 755 | legacy_hal_.lock()->startRingBufferLogging( |
| 756 | getWlan0IfaceName(), ring_name, |
| 757 | static_cast< |
| 758 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 759 | verbose_level), |
| 760 | max_interval_in_sec, min_data_size_in_bytes); |
| 761 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 765 | const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 766 | WifiStatus status = registerDebugRingBufferCallback(); |
| 767 | if (status.code != WifiStatusCode::SUCCESS) { |
| 768 | return status; |
| 769 | } |
| 770 | legacy_hal::wifi_error legacy_status = |
| 771 | legacy_hal_.lock()->getRingBufferData(getWlan0IfaceName(), ring_name); |
| 772 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 775 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 776 | legacy_hal::wifi_error legacy_status = |
| 777 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler( |
| 778 | getWlan0IfaceName()); |
| 779 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 780 | } |
| 781 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 782 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 783 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 784 | legacy_hal::wifi_error legacy_status; |
| 785 | legacy_hal::WakeReasonStats legacy_stats; |
| 786 | std::tie(legacy_status, legacy_stats) = |
| 787 | legacy_hal_.lock()->getWakeReasonStats(getWlan0IfaceName()); |
| 788 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 789 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 790 | } |
| 791 | WifiDebugHostWakeReasonStats hidl_stats; |
| 792 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 793 | &hidl_stats)) { |
| 794 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 795 | } |
| 796 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 799 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 800 | legacy_hal::wifi_error legacy_status; |
| 801 | if (enable) { |
| 802 | android::wp<WifiChip> weak_ptr_this(this); |
| 803 | const auto& on_alert_callback = [weak_ptr_this]( |
| 804 | int32_t error_code, |
| 805 | std::vector<uint8_t> debug_data) { |
| 806 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 807 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 808 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 809 | return; |
| 810 | } |
| 811 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 812 | if (!callback->onDebugErrorAlert(error_code, debug_data) |
| 813 | .isOk()) { |
| 814 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 815 | } |
| 816 | } |
| 817 | }; |
| 818 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 819 | getWlan0IfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 820 | } else { |
| 821 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 822 | getWlan0IfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 823 | } |
| 824 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 825 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 826 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 827 | WifiStatus WifiChip::selectTxPowerScenarioInternal(TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 828 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 829 | getWlan0IfaceName(), |
| 830 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
| 831 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 832 | } |
| 833 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 834 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 835 | auto legacy_status = |
| 836 | legacy_hal_.lock()->resetTxPowerScenario(getWlan0IfaceName()); |
| 837 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 840 | WifiStatus WifiChip::handleChipConfiguration( |
| 841 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 842 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 843 | // If the chip is already configured in a different mode, stop |
| 844 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 845 | if (current_mode_id_ != kInvalidModeId) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 846 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ |
| 847 | << " to mode " << mode_id; |
| 848 | invalidateAndRemoveAllIfaces(); |
| 849 | legacy_hal::wifi_error legacy_status = |
| 850 | legacy_hal_.lock()->stop(lock, []() {}); |
| 851 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 852 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 853 | << legacyErrorToString(legacy_status); |
| 854 | return createWifiStatusFromLegacyError(legacy_status); |
| 855 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 856 | } |
| 857 | bool success; |
| 858 | if (mode_id == kStaChipModeId) { |
| 859 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
| 860 | } else { |
| 861 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 862 | } |
| 863 | if (!success) { |
| 864 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 865 | } |
| 866 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 867 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 868 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 869 | << legacyErrorToString(legacy_status); |
| 870 | return createWifiStatusFromLegacyError(legacy_status); |
| 871 | } |
| 872 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 873 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 874 | |
| 875 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 876 | if (debug_ring_buffer_cb_registered_) { |
| 877 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 878 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 879 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 880 | android::wp<WifiChip> weak_ptr_this(this); |
| 881 | const auto& on_ring_buffer_data_callback = |
| 882 | [weak_ptr_this](const std::string& /* name */, |
| 883 | const std::vector<uint8_t>& data, |
| 884 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 885 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 886 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 887 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 888 | return; |
| 889 | } |
| 890 | WifiDebugRingBufferStatus hidl_status; |
| 891 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 892 | status, &hidl_status)) { |
| 893 | LOG(ERROR) << "Error converting ring buffer status"; |
| 894 | return; |
| 895 | } |
| 896 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 897 | if (!callback->onDebugRingBufferDataAvailable(hidl_status, data) |
| 898 | .isOk()) { |
| 899 | LOG(ERROR) |
| 900 | << "Failed to invoke onDebugRingBufferDataAvailable" |
| 901 | << " callback on: " << toString(callback); |
| 902 | } |
| 903 | } |
| 904 | }; |
| 905 | legacy_hal::wifi_error legacy_status = |
| 906 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 907 | getWlan0IfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 908 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 909 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 910 | debug_ring_buffer_cb_registered_ = true; |
| 911 | } |
| 912 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 913 | } |
| 914 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 915 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 916 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 917 | } // namespace wifi |
| 918 | } // namespace hardware |
| 919 | } // namespace android |