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