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 | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 28 | using android::hardware::wifi::V1_0::IWifiChip; |
| 29 | using android::hardware::wifi::V1_0::IfaceType; |
| 30 | |
| 31 | constexpr uint32_t kStaChipModeId = 0; |
| 32 | constexpr uint32_t kApChipModeId = 1; |
| 33 | constexpr uint32_t kInvalidModeId = UINT32_MAX; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 34 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 35 | template <typename Iface> |
| 36 | void invalidateAndClear(sp<Iface>& iface) { |
| 37 | if (iface.get()) { |
| 38 | iface->invalidate(); |
| 39 | iface.clear(); |
| 40 | } |
| 41 | } |
| 42 | } // namepsace |
| 43 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 44 | namespace android { |
| 45 | namespace hardware { |
| 46 | namespace wifi { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 47 | namespace V1_0 { |
| 48 | namespace implementation { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 49 | using hidl_return_util::validateAndCall; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 50 | |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 51 | WifiChip::WifiChip( |
| 52 | ChipId chip_id, |
| 53 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 54 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller) |
| 55 | : chip_id_(chip_id), |
| 56 | legacy_hal_(legacy_hal), |
| 57 | mode_controller_(mode_controller), |
| 58 | is_valid_(true), |
| 59 | current_mode_id_(kInvalidModeId) {} |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 60 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 61 | void WifiChip::invalidate() { |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 62 | invalidateAndRemoveAllIfaces(); |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 63 | legacy_hal_.reset(); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 64 | event_callbacks_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 65 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 68 | bool WifiChip::isValid() { |
| 69 | return is_valid_; |
| 70 | } |
| 71 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 72 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 73 | return validateAndCall(this, |
| 74 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 75 | &WifiChip::getIdInternal, |
| 76 | hidl_status_cb); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 79 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 80 | const sp<IWifiChipEventCallback>& event_callback, |
| 81 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 82 | return validateAndCall(this, |
| 83 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 84 | &WifiChip::registerEventCallbackInternal, |
| 85 | hidl_status_cb, |
| 86 | event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 89 | Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { |
| 90 | return validateAndCall(this, |
| 91 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 92 | &WifiChip::getCapabilitiesInternal, |
| 93 | hidl_status_cb); |
| 94 | } |
| 95 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 96 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 97 | return validateAndCall(this, |
| 98 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 99 | &WifiChip::getAvailableModesInternal, |
| 100 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 103 | Return<void> WifiChip::configureChip(uint32_t mode_id, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 104 | configureChip_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 105 | return validateAndCall(this, |
| 106 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 107 | &WifiChip::configureChipInternal, |
| 108 | hidl_status_cb, |
| 109 | mode_id); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 112 | Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 113 | return validateAndCall(this, |
| 114 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 115 | &WifiChip::getModeInternal, |
| 116 | hidl_status_cb); |
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::requestChipDebugInfo( |
| 120 | requestChipDebugInfo_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 121 | return validateAndCall(this, |
| 122 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 123 | &WifiChip::requestChipDebugInfoInternal, |
| 124 | hidl_status_cb); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | Return<void> WifiChip::requestDriverDebugDump( |
| 128 | requestDriverDebugDump_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 129 | return validateAndCall(this, |
| 130 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 131 | &WifiChip::requestDriverDebugDumpInternal, |
| 132 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 135 | Return<void> WifiChip::requestFirmwareDebugDump( |
| 136 | requestFirmwareDebugDump_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 137 | return validateAndCall(this, |
| 138 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 139 | &WifiChip::requestFirmwareDebugDumpInternal, |
| 140 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 143 | Return<void> WifiChip::createApIface(createApIface_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::createApIfaceInternal, |
| 147 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 150 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_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::getApIfaceNamesInternal, |
| 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::getApIface(const hidl_string& ifname, |
| 158 | getApIface_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 159 | return validateAndCall(this, |
| 160 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 161 | &WifiChip::getApIfaceInternal, |
| 162 | hidl_status_cb, |
| 163 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 166 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 167 | return validateAndCall(this, |
| 168 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 169 | &WifiChip::createNanIfaceInternal, |
| 170 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 173 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 174 | return validateAndCall(this, |
| 175 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 176 | &WifiChip::getNanIfaceNamesInternal, |
| 177 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 181 | getNanIface_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::getNanIfaceInternal, |
| 185 | hidl_status_cb, |
| 186 | ifname); |
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::createP2pIface(createP2pIface_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::createP2pIfaceInternal, |
| 193 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 196 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_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::getP2pIfaceNamesInternal, |
| 200 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 204 | getP2pIface_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 205 | return validateAndCall(this, |
| 206 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 207 | &WifiChip::getP2pIfaceInternal, |
| 208 | hidl_status_cb, |
| 209 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 212 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 213 | return validateAndCall(this, |
| 214 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 215 | &WifiChip::createStaIfaceInternal, |
| 216 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 219 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 220 | return validateAndCall(this, |
| 221 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 222 | &WifiChip::getStaIfaceNamesInternal, |
| 223 | hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 227 | getStaIface_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 228 | return validateAndCall(this, |
| 229 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 230 | &WifiChip::getStaIfaceInternal, |
| 231 | hidl_status_cb, |
| 232 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 235 | Return<void> WifiChip::createRttController( |
| 236 | const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 237 | return validateAndCall(this, |
| 238 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 239 | &WifiChip::createRttControllerInternal, |
| 240 | hidl_status_cb, |
| 241 | bound_iface); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 244 | Return<void> WifiChip::getDebugRingBuffersStatus( |
| 245 | getDebugRingBuffersStatus_cb hidl_status_cb) { |
| 246 | return validateAndCall(this, |
| 247 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 248 | &WifiChip::getDebugRingBuffersStatusInternal, |
| 249 | hidl_status_cb); |
| 250 | } |
| 251 | |
| 252 | Return<void> WifiChip::startLoggingToDebugRingBuffer( |
| 253 | const hidl_string& ring_name, |
| 254 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 255 | uint32_t max_interval_in_sec, |
| 256 | uint32_t min_data_size_in_bytes, |
| 257 | startLoggingToDebugRingBuffer_cb hidl_status_cb) { |
| 258 | return validateAndCall(this, |
| 259 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 260 | &WifiChip::startLoggingToDebugRingBufferInternal, |
| 261 | hidl_status_cb, |
| 262 | ring_name, |
| 263 | verbose_level, |
| 264 | max_interval_in_sec, |
| 265 | min_data_size_in_bytes); |
| 266 | } |
| 267 | |
| 268 | Return<void> WifiChip::forceDumpToDebugRingBuffer( |
| 269 | const hidl_string& ring_name, |
| 270 | forceDumpToDebugRingBuffer_cb hidl_status_cb) { |
| 271 | return validateAndCall(this, |
| 272 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 273 | &WifiChip::forceDumpToDebugRingBufferInternal, |
| 274 | hidl_status_cb, |
| 275 | ring_name); |
| 276 | } |
| 277 | |
| 278 | Return<void> WifiChip::getDebugHostWakeReasonStats( |
| 279 | getDebugHostWakeReasonStats_cb hidl_status_cb) { |
| 280 | return validateAndCall(this, |
| 281 | WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 282 | &WifiChip::getDebugHostWakeReasonStatsInternal, |
| 283 | hidl_status_cb); |
| 284 | } |
| 285 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 286 | void WifiChip::invalidateAndRemoveAllIfaces() { |
| 287 | invalidateAndClear(ap_iface_); |
| 288 | invalidateAndClear(nan_iface_); |
| 289 | invalidateAndClear(p2p_iface_); |
| 290 | invalidateAndClear(sta_iface_); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 291 | // Since all the ifaces are invalid now, all RTT controller objects |
| 292 | // using those ifaces also need to be invalidated. |
| 293 | for (const auto& rtt : rtt_controllers_) { |
| 294 | rtt->invalidate(); |
| 295 | } |
| 296 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 299 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
| 300 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
| 301 | } |
| 302 | |
| 303 | WifiStatus WifiChip::registerEventCallbackInternal( |
| 304 | const sp<IWifiChipEventCallback>& event_callback) { |
| 305 | // TODO(b/31632518): remove the callback when the client is destroyed |
| 306 | event_callbacks_.emplace_back(event_callback); |
| 307 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 308 | } |
| 309 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 310 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame^] | 311 | legacy_hal::wifi_error legacy_status; |
| 312 | uint32_t legacy_logger_feature_set; |
| 313 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 314 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(); |
| 315 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 316 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 317 | } |
| 318 | uint32_t hidl_caps; |
| 319 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 320 | legacy_logger_feature_set, &hidl_caps)) { |
| 321 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 322 | } |
| 323 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 326 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 327 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 328 | // The chip combination supported for current devices is fixed for now with |
| 329 | // 2 separate modes of operation: |
| 330 | // Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN iface operations |
| 331 | // concurrently. |
| 332 | // Mode 2 (AP mode): Will support 1 AP iface operations. |
| 333 | // TODO (b/32997844): Read this from some device specific flags in the |
| 334 | // makefile. |
| 335 | // STA mode iface combinations. |
| 336 | const IWifiChip::ChipIfaceCombinationLimit |
| 337 | sta_chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 338 | const IWifiChip::ChipIfaceCombinationLimit |
| 339 | sta_chip_iface_combination_limit_2 = {{IfaceType::P2P, IfaceType::NAN}, |
| 340 | 1}; |
| 341 | const IWifiChip::ChipIfaceCombination sta_chip_iface_combination = { |
| 342 | {sta_chip_iface_combination_limit_1, sta_chip_iface_combination_limit_2}}; |
| 343 | const IWifiChip::ChipMode sta_chip_mode = {kStaChipModeId, |
| 344 | {sta_chip_iface_combination}}; |
| 345 | // AP mode iface combinations. |
| 346 | const IWifiChip::ChipIfaceCombinationLimit ap_chip_iface_combination_limit = { |
| 347 | {IfaceType::AP}, 1}; |
| 348 | const IWifiChip::ChipIfaceCombination ap_chip_iface_combination = { |
| 349 | {ap_chip_iface_combination_limit}}; |
| 350 | const IWifiChip::ChipMode ap_chip_mode = {kApChipModeId, |
| 351 | {ap_chip_iface_combination}}; |
| 352 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 353 | {sta_chip_mode, ap_chip_mode}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 356 | WifiStatus WifiChip::configureChipInternal(uint32_t mode_id) { |
| 357 | if (mode_id != kStaChipModeId && mode_id != kApChipModeId) { |
| 358 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 359 | } |
| 360 | if (mode_id == current_mode_id_) { |
| 361 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 362 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 363 | } |
| 364 | // If the chip is already configured in a different mode, stop |
| 365 | // the legacy HAL and then start it after firmware mode change. |
| 366 | if (current_mode_id_ != kInvalidModeId) { |
| 367 | invalidateAndRemoveAllIfaces(); |
| 368 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop([]() {}); |
| 369 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 370 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 371 | << legacyErrorToString(legacy_status); |
| 372 | // TODO(b/33038823): Need to invoke onChipReconfigureFailure() |
| 373 | return createWifiStatusFromLegacyError(legacy_status); |
| 374 | } |
| 375 | } |
| 376 | bool success; |
| 377 | if (mode_id == kStaChipModeId) { |
| 378 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
| 379 | } else { |
| 380 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 381 | } |
| 382 | if (!success) { |
| 383 | // TODO(b/33038823): Need to invoke onChipReconfigureFailure() |
| 384 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 385 | } |
| 386 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 387 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 388 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 389 | << legacyErrorToString(legacy_status); |
| 390 | // TODO(b/33038823): Need to invoke onChipReconfigureFailure() |
| 391 | return createWifiStatusFromLegacyError(legacy_status); |
| 392 | } |
| 393 | for (const auto& callback : event_callbacks_) { |
| 394 | callback->onChipReconfigured(mode_id); |
| 395 | } |
| 396 | current_mode_id_ = mode_id; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 397 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 398 | } |
| 399 | |
| 400 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 401 | if (current_mode_id_ == kInvalidModeId) { |
| 402 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 403 | current_mode_id_}; |
| 404 | } |
| 405 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 409 | WifiChip::requestChipDebugInfoInternal() { |
| 410 | IWifiChip::ChipDebugInfo result; |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 411 | legacy_hal::wifi_error legacy_status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 412 | std::string driver_desc; |
| 413 | std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 414 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 415 | LOG(ERROR) << "Failed to get driver version: " |
| 416 | << legacyErrorToString(legacy_status); |
| 417 | WifiStatus status = createWifiStatusFromLegacyError( |
| 418 | legacy_status, "failed to get driver version"); |
| 419 | return {status, result}; |
| 420 | } |
| 421 | result.driverDescription = driver_desc.c_str(); |
| 422 | |
| 423 | std::string firmware_desc; |
| 424 | std::tie(legacy_status, firmware_desc) = |
| 425 | legacy_hal_.lock()->getFirmwareVersion(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 426 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 427 | LOG(ERROR) << "Failed to get firmware version: " |
| 428 | << legacyErrorToString(legacy_status); |
| 429 | WifiStatus status = createWifiStatusFromLegacyError( |
| 430 | legacy_status, "failed to get firmware version"); |
| 431 | return {status, result}; |
| 432 | } |
| 433 | result.firmwareDescription = firmware_desc.c_str(); |
| 434 | |
| 435 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
| 436 | } |
| 437 | |
| 438 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 439 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 440 | legacy_hal::wifi_error legacy_status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 441 | std::vector<uint8_t> driver_dump; |
| 442 | std::tie(legacy_status, driver_dump) = |
| 443 | legacy_hal_.lock()->requestDriverMemoryDump(); |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 444 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 445 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 446 | << legacyErrorToString(legacy_status); |
| 447 | return {createWifiStatusFromLegacyError(legacy_status), |
| 448 | std::vector<uint8_t>()}; |
| 449 | } |
| 450 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
| 451 | } |
| 452 | |
| 453 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 454 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | a4854ff | 2016-12-01 13:47:41 -0800 | [diff] [blame] | 455 | legacy_hal::wifi_error legacy_status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 456 | std::vector<uint8_t> firmware_dump; |
| 457 | std::tie(legacy_status, firmware_dump) = |
| 458 | legacy_hal_.lock()->requestFirmwareMemoryDump(); |
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 debug dump: " |
| 461 | << legacyErrorToString(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 462 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 463 | } |
| 464 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
| 465 | } |
| 466 | |
| 467 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
| 468 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 469 | std::string ifname = legacy_hal_.lock()->getApIfaceName(); |
| 470 | ap_iface_ = new WifiApIface(ifname, legacy_hal_); |
| 471 | return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; |
| 472 | } |
| 473 | |
| 474 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 475 | WifiChip::getApIfaceNamesInternal() { |
| 476 | if (!ap_iface_.get()) { |
| 477 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 478 | } |
| 479 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 480 | {legacy_hal_.lock()->getApIfaceName()}}; |
| 481 | } |
| 482 | |
| 483 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
| 484 | const hidl_string& ifname) { |
| 485 | if (!ap_iface_.get() || |
| 486 | (ifname.c_str() != legacy_hal_.lock()->getApIfaceName())) { |
| 487 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 488 | } |
| 489 | return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_}; |
| 490 | } |
| 491 | |
| 492 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
| 493 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 494 | std::string ifname = legacy_hal_.lock()->getNanIfaceName(); |
| 495 | nan_iface_ = new WifiNanIface(ifname, legacy_hal_); |
| 496 | return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; |
| 497 | } |
| 498 | |
| 499 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 500 | WifiChip::getNanIfaceNamesInternal() { |
| 501 | if (!nan_iface_.get()) { |
| 502 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 503 | } |
| 504 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 505 | {legacy_hal_.lock()->getNanIfaceName()}}; |
| 506 | } |
| 507 | |
| 508 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
| 509 | const hidl_string& ifname) { |
| 510 | if (!nan_iface_.get() || |
| 511 | (ifname.c_str() != legacy_hal_.lock()->getNanIfaceName())) { |
| 512 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 513 | } |
| 514 | return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_}; |
| 515 | } |
| 516 | |
| 517 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
| 518 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 519 | std::string ifname = legacy_hal_.lock()->getP2pIfaceName(); |
| 520 | p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_); |
| 521 | return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; |
| 522 | } |
| 523 | |
| 524 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 525 | WifiChip::getP2pIfaceNamesInternal() { |
| 526 | if (!p2p_iface_.get()) { |
| 527 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 528 | } |
| 529 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 530 | {legacy_hal_.lock()->getP2pIfaceName()}}; |
| 531 | } |
| 532 | |
| 533 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
| 534 | const hidl_string& ifname) { |
| 535 | if (!p2p_iface_.get() || |
| 536 | (ifname.c_str() != legacy_hal_.lock()->getP2pIfaceName())) { |
| 537 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 538 | } |
| 539 | return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_}; |
| 540 | } |
| 541 | |
| 542 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
| 543 | // TODO(b/31997422): Disallow this based on the chip combination. |
| 544 | std::string ifname = legacy_hal_.lock()->getStaIfaceName(); |
| 545 | sta_iface_ = new WifiStaIface(ifname, legacy_hal_); |
| 546 | return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; |
| 547 | } |
| 548 | |
| 549 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 550 | WifiChip::getStaIfaceNamesInternal() { |
| 551 | if (!sta_iface_.get()) { |
| 552 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 553 | } |
| 554 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 555 | {legacy_hal_.lock()->getStaIfaceName()}}; |
| 556 | } |
| 557 | |
| 558 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
| 559 | const hidl_string& ifname) { |
| 560 | if (!sta_iface_.get() || |
| 561 | (ifname.c_str() != legacy_hal_.lock()->getStaIfaceName())) { |
| 562 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 563 | } |
| 564 | return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_}; |
| 565 | } |
| 566 | |
| 567 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 568 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
| 569 | sp<WifiRttController> rtt = new WifiRttController(bound_iface, legacy_hal_); |
| 570 | rtt_controllers_.emplace_back(rtt); |
| 571 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
| 572 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 573 | |
| 574 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 575 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame^] | 576 | legacy_hal::wifi_error legacy_status; |
| 577 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 578 | legacy_ring_buffer_status_vec; |
| 579 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 580 | legacy_hal_.lock()->getRingBuffersStatus(); |
| 581 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 582 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 583 | } |
| 584 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 585 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 586 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 587 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 588 | } |
| 589 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 590 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame^] | 594 | const hidl_string& ring_name, |
| 595 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 596 | uint32_t max_interval_in_sec, |
| 597 | uint32_t min_data_size_in_bytes) { |
| 598 | legacy_hal::wifi_error legacy_status = |
| 599 | legacy_hal_.lock()->startRingBufferLogging( |
| 600 | ring_name, |
| 601 | static_cast< |
| 602 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 603 | verbose_level), |
| 604 | max_interval_in_sec, |
| 605 | min_data_size_in_bytes); |
| 606 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame^] | 610 | const hidl_string& ring_name) { |
| 611 | legacy_hal::wifi_error legacy_status = |
| 612 | legacy_hal_.lock()->getRingBufferData(ring_name); |
| 613 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 617 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame^] | 618 | legacy_hal::wifi_error legacy_status; |
| 619 | legacy_hal::WakeReasonStats legacy_stats; |
| 620 | std::tie(legacy_status, legacy_stats) = |
| 621 | legacy_hal_.lock()->getWakeReasonStats(); |
| 622 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 623 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 624 | } |
| 625 | WifiDebugHostWakeReasonStats hidl_stats; |
| 626 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 627 | &hidl_stats)) { |
| 628 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 629 | } |
| 630 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 633 | } // namespace implementation |
| 634 | } // namespace V1_0 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 635 | } // namespace wifi |
| 636 | } // namespace hardware |
| 637 | } // namespace android |