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