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