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