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