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) = |
| 415 | legacy_hal_.lock()->getSupportedFeatureSet(); |
| 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) = |
| 420 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 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; |
| 506 | std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 507 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 508 | LOG(ERROR) << "Failed to get driver version: " |
| 509 | << legacyErrorToString(legacy_status); |
| 510 | WifiStatus status = createWifiStatusFromLegacyError( |
| 511 | legacy_status, "failed to get driver version"); |
| 512 | return {status, result}; |
| 513 | } |
| 514 | result.driverDescription = driver_desc.c_str(); |
| 515 | |
| 516 | std::string firmware_desc; |
| 517 | std::tie(legacy_status, firmware_desc) = |
| 518 | legacy_hal_.lock()->getFirmwareVersion(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 519 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 520 | LOG(ERROR) << "Failed to get firmware version: " |
| 521 | << legacyErrorToString(legacy_status); |
| 522 | WifiStatus status = createWifiStatusFromLegacyError( |
| 523 | legacy_status, "failed to get firmware version"); |
| 524 | return {status, result}; |
| 525 | } |
| 526 | result.firmwareDescription = firmware_desc.c_str(); |
| 527 | |
| 528 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
| 529 | } |
| 530 | |
| 531 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 532 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 533 | legacy_hal::wifi_error legacy_status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 534 | std::vector<uint8_t> driver_dump; |
| 535 | std::tie(legacy_status, driver_dump) = |
| 536 | legacy_hal_.lock()->requestDriverMemoryDump(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 537 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 538 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 539 | << legacyErrorToString(legacy_status); |
| 540 | return {createWifiStatusFromLegacyError(legacy_status), |
| 541 | std::vector<uint8_t>()}; |
| 542 | } |
| 543 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
| 544 | } |
| 545 | |
| 546 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 547 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 548 | legacy_hal::wifi_error legacy_status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 549 | std::vector<uint8_t> firmware_dump; |
| 550 | std::tie(legacy_status, firmware_dump) = |
| 551 | legacy_hal_.lock()->requestFirmwareMemoryDump(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 552 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 553 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 554 | << legacyErrorToString(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 555 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 556 | } |
| 557 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
| 558 | } |
| 559 | |
| 560 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | 073d5b9 | 2016-12-08 19:10:06 -0800 | [diff] [blame] | 561 | if (current_mode_id_ != kApChipModeId || ap_iface_.get()) { |
| 562 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 563 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 564 | std::string ifname = getWlan0IfaceName(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 565 | ap_iface_ = new WifiApIface(ifname, legacy_hal_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 566 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 567 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 568 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 569 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 570 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 571 | return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; |
| 572 | } |
| 573 | |
| 574 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 575 | WifiChip::getApIfaceNamesInternal() { |
| 576 | if (!ap_iface_.get()) { |
| 577 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 578 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 579 | return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 583 | const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 584 | if (!ap_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 585 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 586 | } |
| 587 | return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; |
| 588 | } |
| 589 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 590 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 591 | if (!ap_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 592 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 593 | } |
| 594 | invalidateAndClear(ap_iface_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 595 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 596 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 597 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 598 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 599 | } |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 600 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 601 | } |
| 602 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 603 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | 073d5b9 | 2016-12-08 19:10:06 -0800 | [diff] [blame] | 604 | // 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] | 605 | if (WifiFeatureFlags::wifiHidlFeatureAware) { |
| 606 | if (current_mode_id_ != kStaChipModeId || nan_iface_.get() || |
| 607 | p2p_iface_.get()) { |
| 608 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 609 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 610 | std::string ifname = getWlan0IfaceName(); |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 611 | nan_iface_ = new WifiNanIface(ifname, legacy_hal_); |
| 612 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 613 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 614 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 615 | } |
| 616 | } |
| 617 | return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; |
| 618 | } else { |
Roshan Pius | 073d5b9 | 2016-12-08 19:10:06 -0800 | [diff] [blame] | 619 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 620 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 624 | WifiChip::getNanIfaceNamesInternal() { |
| 625 | if (!nan_iface_.get()) { |
| 626 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 627 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 628 | return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 632 | const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 633 | if (!nan_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 634 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 635 | } |
| 636 | return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; |
| 637 | } |
| 638 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 639 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 640 | if (!nan_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 641 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 642 | } |
| 643 | invalidateAndClear(nan_iface_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 644 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 645 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 646 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 647 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 648 | } |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 649 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 650 | } |
| 651 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 652 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | 073d5b9 | 2016-12-08 19:10:06 -0800 | [diff] [blame] | 653 | // Only 1 of NAN or P2P iface can be active at a time. |
| 654 | if (current_mode_id_ != kStaChipModeId || p2p_iface_.get() || |
| 655 | nan_iface_.get()) { |
| 656 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 657 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 658 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 659 | p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 660 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 661 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 662 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 663 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 664 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 665 | return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; |
| 666 | } |
| 667 | |
| 668 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 669 | WifiChip::getP2pIfaceNamesInternal() { |
| 670 | if (!p2p_iface_.get()) { |
| 671 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 672 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 673 | return {createWifiStatus(WifiStatusCode::SUCCESS), {getP2pIfaceName()}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 677 | const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 678 | if (!p2p_iface_.get() || (ifname != getP2pIfaceName())) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 679 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 680 | } |
| 681 | return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; |
| 682 | } |
| 683 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 684 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 685 | if (!p2p_iface_.get() || (ifname != getP2pIfaceName())) { |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 686 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 687 | } |
| 688 | invalidateAndClear(p2p_iface_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 689 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 690 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 691 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 692 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 693 | } |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 694 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 695 | } |
| 696 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 697 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Roshan Pius | 073d5b9 | 2016-12-08 19:10:06 -0800 | [diff] [blame] | 698 | if (current_mode_id_ != kStaChipModeId || sta_iface_.get()) { |
| 699 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 700 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 701 | std::string ifname = getWlan0IfaceName(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 702 | sta_iface_ = new WifiStaIface(ifname, legacy_hal_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 703 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 704 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 705 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 706 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 707 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 708 | return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; |
| 709 | } |
| 710 | |
| 711 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 712 | WifiChip::getStaIfaceNamesInternal() { |
| 713 | if (!sta_iface_.get()) { |
| 714 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 715 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 716 | return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 720 | const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 721 | if (!sta_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 722 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 723 | } |
| 724 | return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; |
| 725 | } |
| 726 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 727 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 728 | if (!sta_iface_.get() || (ifname != getWlan0IfaceName())) { |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 729 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 730 | } |
| 731 | invalidateAndClear(sta_iface_); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 732 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 733 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 734 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 735 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 736 | } |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 737 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 738 | } |
| 739 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 740 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 741 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame^] | 742 | sp<WifiRttController> rtt = |
| 743 | new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 744 | rtt_controllers_.emplace_back(rtt); |
| 745 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
| 746 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 747 | |
| 748 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 749 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 750 | legacy_hal::wifi_error legacy_status; |
| 751 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 752 | legacy_ring_buffer_status_vec; |
| 753 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 754 | legacy_hal_.lock()->getRingBuffersStatus(); |
| 755 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 756 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 757 | } |
| 758 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 759 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 760 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 761 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 762 | } |
| 763 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 764 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 768 | const hidl_string& ring_name, |
| 769 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 770 | uint32_t max_interval_in_sec, |
| 771 | uint32_t min_data_size_in_bytes) { |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 772 | WifiStatus status = registerDebugRingBufferCallback(); |
| 773 | if (status.code != WifiStatusCode::SUCCESS) { |
| 774 | return status; |
| 775 | } |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 776 | legacy_hal::wifi_error legacy_status = |
| 777 | legacy_hal_.lock()->startRingBufferLogging( |
| 778 | ring_name, |
| 779 | static_cast< |
| 780 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 781 | verbose_level), |
| 782 | max_interval_in_sec, |
| 783 | min_data_size_in_bytes); |
| 784 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 788 | const hidl_string& ring_name) { |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 789 | WifiStatus status = registerDebugRingBufferCallback(); |
| 790 | if (status.code != WifiStatusCode::SUCCESS) { |
| 791 | return status; |
| 792 | } |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 793 | legacy_hal::wifi_error legacy_status = |
| 794 | legacy_hal_.lock()->getRingBufferData(ring_name); |
| 795 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 798 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
| 799 | legacy_hal::wifi_error legacy_status = |
| 800 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler(); |
| 801 | return createWifiStatusFromLegacyError(legacy_status); |
| 802 | } |
| 803 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 804 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 805 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 806 | legacy_hal::wifi_error legacy_status; |
| 807 | legacy_hal::WakeReasonStats legacy_stats; |
| 808 | std::tie(legacy_status, legacy_stats) = |
| 809 | legacy_hal_.lock()->getWakeReasonStats(); |
| 810 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 811 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 812 | } |
| 813 | WifiDebugHostWakeReasonStats hidl_stats; |
| 814 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 815 | &hidl_stats)) { |
| 816 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 817 | } |
| 818 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 821 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
| 822 | legacy_hal::wifi_error legacy_status; |
| 823 | if (enable) { |
| 824 | android::wp<WifiChip> weak_ptr_this(this); |
| 825 | const auto& on_alert_callback = [weak_ptr_this]( |
| 826 | int32_t error_code, std::vector<uint8_t> debug_data) { |
| 827 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 828 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 829 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 830 | return; |
| 831 | } |
| 832 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 833 | if (!callback->onDebugErrorAlert(error_code, debug_data).isOk()) { |
| 834 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 835 | } |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 836 | } |
| 837 | }; |
| 838 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
| 839 | on_alert_callback); |
| 840 | } else { |
| 841 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(); |
| 842 | } |
| 843 | return createWifiStatusFromLegacyError(legacy_status); |
| 844 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 845 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 846 | WifiStatus WifiChip::selectTxPowerScenarioInternal(TxPowerScenario scenario) { |
| 847 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 848 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 849 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 852 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
| 853 | auto legacy_status = legacy_hal_.lock()->resetTxPowerScenario(); |
Roshan Pius | 8184d21 | 2017-07-11 08:59:29 -0700 | [diff] [blame] | 854 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 857 | WifiStatus WifiChip::handleChipConfiguration(ChipModeId mode_id) { |
| 858 | // If the chip is already configured in a different mode, stop |
| 859 | // the legacy HAL and then start it after firmware mode change. |
Ningyuan Wang | b1ad3a7 | 2017-04-18 14:20:41 -0700 | [diff] [blame] | 860 | // Currently the underlying implementation has a deadlock issue. |
| 861 | // We should return ERROR_NOT_SUPPORTED if chip is already configured in |
| 862 | // a different mode. |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 863 | if (current_mode_id_ != kInvalidModeId) { |
Ningyuan Wang | b1ad3a7 | 2017-04-18 14:20:41 -0700 | [diff] [blame] | 864 | // TODO(b/37446050): Fix the deadlock. |
| 865 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 866 | } |
| 867 | bool success; |
| 868 | if (mode_id == kStaChipModeId) { |
| 869 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
| 870 | } else { |
| 871 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 872 | } |
| 873 | if (!success) { |
| 874 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 875 | } |
| 876 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 877 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 878 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 879 | << legacyErrorToString(legacy_status); |
| 880 | return createWifiStatusFromLegacyError(legacy_status); |
| 881 | } |
| 882 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 883 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 884 | |
| 885 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
| 886 | if (debug_ring_buffer_cb_registered_) { |
| 887 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 888 | } |
| 889 | |
| 890 | android::wp<WifiChip> weak_ptr_this(this); |
| 891 | const auto& on_ring_buffer_data_callback = [weak_ptr_this]( |
| 892 | const std::string& /* name */, |
| 893 | const std::vector<uint8_t>& data, |
| 894 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 895 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 896 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 897 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 898 | return; |
| 899 | } |
| 900 | WifiDebugRingBufferStatus hidl_status; |
| 901 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 902 | status, &hidl_status)) { |
| 903 | LOG(ERROR) << "Error converting ring buffer status"; |
| 904 | return; |
| 905 | } |
| 906 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 907 | if (!callback->onDebugRingBufferDataAvailable(hidl_status, data).isOk()) { |
| 908 | LOG(ERROR) << "Failed to invoke onDebugRingBufferDataAvailable" |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 909 | << " callback on: " << toString(callback); |
| 910 | |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 911 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 912 | } |
| 913 | }; |
| 914 | legacy_hal::wifi_error legacy_status = |
| 915 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 916 | on_ring_buffer_data_callback); |
| 917 | |
| 918 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 919 | debug_ring_buffer_cb_registered_ = true; |
| 920 | } |
| 921 | return createWifiStatusFromLegacyError(legacy_status); |
| 922 | } |
| 923 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 924 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 925 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 926 | } // namespace wifi |
| 927 | } // namespace hardware |
| 928 | } // namespace android |