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