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