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 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 17 | #include <fcntl.h> |
| 18 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 19 | #include <android-base/logging.h> |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 20 | #include <android-base/unique_fd.h> |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 21 | #include <cutils/properties.h> |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 22 | #include <sys/stat.h> |
| 23 | #include <sys/sysmacros.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 25 | #include "hidl_return_util.h" |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 26 | #include "hidl_struct_util.h" |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 27 | #include "wifi_chip.h" |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 28 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 29 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 30 | namespace { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 31 | using android::base::unique_fd; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 32 | using android::hardware::hidl_string; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 33 | using android::hardware::hidl_vec; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 34 | using android::hardware::wifi::V1_0::ChipModeId; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 35 | using android::hardware::wifi::V1_0::IfaceType; |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 36 | using android::hardware::wifi::V1_0::IWifiChip; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 37 | using android::sp; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 38 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 39 | constexpr ChipModeId kInvalidModeId = UINT32_MAX; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 40 | // These mode ID's should be unique (even across combo versions). Refer to |
| 41 | // handleChipConfiguration() for it's usage. |
| 42 | // Mode ID's for V1 |
| 43 | constexpr ChipModeId kV1StaChipModeId = 0; |
| 44 | constexpr ChipModeId kV1ApChipModeId = 1; |
| 45 | // Mode ID for V2 |
| 46 | constexpr ChipModeId kV2ChipModeId = 2; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 47 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 48 | constexpr char kCpioMagic[] = "070701"; |
| 49 | constexpr size_t kMaxBufferSizeBytes = 1024 * 1024; |
| 50 | constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60; |
| 51 | constexpr char kTombstoneFolderPath[] = "/data/vendor/tombstones/wifi/"; |
| 52 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 53 | template <typename Iface> |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 54 | void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) { |
| 55 | iface->invalidate(); |
| 56 | ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), |
| 57 | ifaces.end()); |
| 58 | } |
| 59 | |
| 60 | template <typename Iface> |
| 61 | void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) { |
| 62 | for (const auto& iface : ifaces) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 63 | iface->invalidate(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 64 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 65 | ifaces.clear(); |
| 66 | } |
| 67 | |
| 68 | template <typename Iface> |
| 69 | std::vector<hidl_string> getNames(std::vector<sp<Iface>>& ifaces) { |
| 70 | std::vector<hidl_string> names; |
| 71 | for (const auto& iface : ifaces) { |
| 72 | names.emplace_back(iface->getName()); |
| 73 | } |
| 74 | return names; |
| 75 | } |
| 76 | |
| 77 | template <typename Iface> |
| 78 | sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces, |
| 79 | const std::string& name) { |
| 80 | std::vector<hidl_string> names; |
| 81 | for (const auto& iface : ifaces) { |
| 82 | if (name == iface->getName()) { |
| 83 | return iface; |
| 84 | } |
| 85 | } |
| 86 | return nullptr; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 87 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 88 | |
| 89 | std::string getWlan0IfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 90 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 91 | property_get("wifi.interface", buffer.data(), "wlan0"); |
| 92 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 95 | std::string getWlan1IfaceName() { |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 96 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 97 | property_get("wifi.concurrent.interface", buffer.data(), "wlan1"); |
| 98 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 99 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 100 | |
| 101 | std::string getP2pIfaceName() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 102 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 103 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
| 104 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 105 | } |
| 106 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 107 | // delete files older than a predefined time in the wifi tombstone dir |
| 108 | bool removeOldFilesInternal() { |
| 109 | time_t now = time(0); |
| 110 | const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds; |
| 111 | DIR* dir_dump = opendir(kTombstoneFolderPath); |
| 112 | if (!dir_dump) { |
| 113 | LOG(ERROR) << "Failed to open directory: " << strerror(errno); |
| 114 | return false; |
| 115 | } |
| 116 | unique_fd dir_auto_closer(dirfd(dir_dump)); |
| 117 | struct dirent* dp; |
| 118 | bool success = true; |
| 119 | while ((dp = readdir(dir_dump))) { |
| 120 | if (dp->d_type != DT_REG) { |
| 121 | continue; |
| 122 | } |
| 123 | std::string cur_file_name(dp->d_name); |
| 124 | struct stat cur_file_stat; |
| 125 | std::string cur_file_path = kTombstoneFolderPath + cur_file_name; |
| 126 | if (stat(cur_file_path.c_str(), &cur_file_stat) != -1) { |
| 127 | if (cur_file_stat.st_mtime < delete_files_before) { |
| 128 | if (unlink(cur_file_path.c_str()) != 0) { |
| 129 | LOG(ERROR) << "Error deleting file " << strerror(errno); |
| 130 | success = false; |
| 131 | } |
| 132 | } |
| 133 | } else { |
| 134 | LOG(ERROR) << "Failed to get file stat for " << cur_file_path |
| 135 | << ": " << strerror(errno); |
| 136 | success = false; |
| 137 | } |
| 138 | } |
| 139 | return success; |
| 140 | } |
| 141 | |
| 142 | // Archives all files in |input_dir| and writes result into |out_fd| |
| 143 | // Logic obtained from //external/toybox/toys/posix/cpio.c "Output cpio archive" |
| 144 | // portion |
| 145 | size_t cpioFilesInDir(int out_fd, const char* input_dir) { |
| 146 | struct dirent* dp; |
| 147 | size_t n_error = 0; |
| 148 | char read_buf[32 * 1024]; |
| 149 | DIR* dir_dump = opendir(input_dir); |
| 150 | if (!dir_dump) { |
| 151 | LOG(ERROR) << "Failed to open directory: " << strerror(errno); |
| 152 | n_error++; |
| 153 | return n_error; |
| 154 | } |
| 155 | unique_fd dir_auto_closer(dirfd(dir_dump)); |
| 156 | while ((dp = readdir(dir_dump))) { |
| 157 | if (dp->d_type != DT_REG) { |
| 158 | continue; |
| 159 | } |
| 160 | std::string cur_file_name(dp->d_name); |
| 161 | const size_t file_name_len = |
| 162 | cur_file_name.size() + 1; // string.size() does not include the |
| 163 | // null terminator. The cpio FreeBSD file |
| 164 | // header expects the null character to |
| 165 | // be included in the length. |
| 166 | struct stat st; |
| 167 | ssize_t llen; |
| 168 | const std::string cur_file_path = kTombstoneFolderPath + cur_file_name; |
| 169 | if (stat(cur_file_path.c_str(), &st) != -1) { |
| 170 | const int fd_read = open(cur_file_path.c_str(), O_RDONLY); |
| 171 | unique_fd file_auto_closer(fd_read); |
| 172 | if (fd_read == -1) { |
| 173 | LOG(ERROR) << "Failed to read file " << cur_file_path << " " |
| 174 | << strerror(errno); |
| 175 | n_error++; |
| 176 | continue; |
| 177 | } |
| 178 | llen = sprintf( |
| 179 | read_buf, |
| 180 | "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X", |
| 181 | kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid, |
| 182 | st.st_gid, static_cast<int>(st.st_nlink), |
| 183 | static_cast<int>(st.st_mtime), static_cast<int>(st.st_size), |
| 184 | major(st.st_dev), minor(st.st_dev), major(st.st_rdev), |
| 185 | minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0); |
| 186 | if (write(out_fd, read_buf, llen) == -1) { |
| 187 | LOG(ERROR) << "Error writing cpio header to file " |
| 188 | << cur_file_path << " " << strerror(errno); |
| 189 | n_error++; |
| 190 | return n_error; |
| 191 | } |
| 192 | if (write(out_fd, cur_file_name.c_str(), file_name_len) == -1) { |
| 193 | LOG(ERROR) << "Error writing filename to file " << cur_file_path |
| 194 | << " " << strerror(errno); |
| 195 | n_error++; |
| 196 | return n_error; |
| 197 | } |
| 198 | |
| 199 | // NUL Pad header up to 4 multiple bytes. |
| 200 | llen = (llen + file_name_len) % 4; |
| 201 | if (llen != 0) { |
| 202 | const uint32_t zero = 0; |
| 203 | if (write(out_fd, &zero, 4 - llen) == -1) { |
| 204 | LOG(ERROR) << "Error padding 0s to file " << cur_file_path |
| 205 | << " " << strerror(errno); |
| 206 | n_error++; |
| 207 | return n_error; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // writing content of file |
| 212 | llen = st.st_size; |
| 213 | while (llen > 0) { |
| 214 | ssize_t bytes_read = read(fd_read, read_buf, sizeof(read_buf)); |
| 215 | if (bytes_read == -1) { |
| 216 | LOG(ERROR) << "Error reading file " << cur_file_path << " " |
| 217 | << strerror(errno); |
| 218 | n_error++; |
| 219 | return n_error; |
| 220 | } |
| 221 | llen -= bytes_read; |
| 222 | if (write(out_fd, read_buf, bytes_read) == -1) { |
| 223 | LOG(ERROR) << "Error writing data to file " << cur_file_path |
| 224 | << " " << strerror(errno); |
| 225 | n_error++; |
| 226 | return n_error; |
| 227 | } |
| 228 | if (bytes_read == |
| 229 | 0) { // this should never happen, but just in case |
| 230 | // to unstuck from while loop |
| 231 | LOG(ERROR) << "Unexpected file size for " << cur_file_path |
| 232 | << " " << strerror(errno); |
| 233 | n_error++; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | llen = st.st_size % 4; |
| 238 | if (llen != 0) { |
| 239 | const uint32_t zero = 0; |
| 240 | write(out_fd, &zero, 4 - llen); |
| 241 | } |
| 242 | } else { |
| 243 | LOG(ERROR) << "Failed to get file stat for " << cur_file_path |
| 244 | << ": " << strerror(errno); |
| 245 | n_error++; |
| 246 | } |
| 247 | } |
| 248 | memset(read_buf, 0, sizeof(read_buf)); |
| 249 | if (write(out_fd, read_buf, |
| 250 | sprintf(read_buf, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0) + |
| 251 | 4) == -1) { |
| 252 | LOG(ERROR) << "Error writing trailing bytes " << strerror(errno); |
| 253 | n_error++; |
| 254 | } |
| 255 | return n_error; |
| 256 | } |
| 257 | |
| 258 | // Helper function to create a non-const char*. |
| 259 | std::vector<char> makeCharVec(const std::string& str) { |
| 260 | std::vector<char> vec(str.size() + 1); |
| 261 | vec.assign(str.begin(), str.end()); |
| 262 | vec.push_back('\0'); |
| 263 | return vec; |
| 264 | } |
| 265 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 266 | } // namespace |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 267 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 268 | namespace android { |
| 269 | namespace hardware { |
| 270 | namespace wifi { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 271 | namespace V1_2 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 272 | namespace implementation { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 273 | using hidl_return_util::validateAndCall; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 274 | using hidl_return_util::validateAndCallWithLock; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 275 | |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 276 | WifiChip::WifiChip( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 277 | ChipId chip_id, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 278 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 279 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags) |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 280 | : chip_id_(chip_id), |
| 281 | legacy_hal_(legacy_hal), |
| 282 | mode_controller_(mode_controller), |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 283 | feature_flags_(feature_flags), |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 284 | is_valid_(true), |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 285 | current_mode_id_(kInvalidModeId), |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 286 | debug_ring_buffer_cb_registered_(false) { |
| 287 | populateModes(); |
| 288 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 289 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 290 | void WifiChip::invalidate() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 291 | invalidateAndRemoveAllIfaces(); |
| 292 | legacy_hal_.reset(); |
| 293 | event_cb_handler_.invalidate(); |
| 294 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 297 | bool WifiChip::isValid() { return is_valid_; } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 298 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 299 | std::set<sp<IWifiChipEventCallback>> WifiChip::getEventCallbacks() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 300 | return event_cb_handler_.getCallbacks(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 303 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 304 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 305 | &WifiChip::getIdInternal, hidl_status_cb); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 308 | Return<void> WifiChip::registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 309 | const sp<IWifiChipEventCallback>& event_callback, |
| 310 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 311 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 312 | &WifiChip::registerEventCallbackInternal, |
| 313 | hidl_status_cb, event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 316 | Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 317 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 318 | &WifiChip::getCapabilitiesInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 321 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 322 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 323 | &WifiChip::getAvailableModesInternal, |
| 324 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 327 | Return<void> WifiChip::configureChip(ChipModeId mode_id, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 328 | configureChip_cb hidl_status_cb) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 329 | return validateAndCallWithLock( |
| 330 | this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 331 | &WifiChip::configureChipInternal, hidl_status_cb, mode_id); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 334 | Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 335 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 336 | &WifiChip::getModeInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 339 | Return<void> WifiChip::requestChipDebugInfo( |
| 340 | requestChipDebugInfo_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 341 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 342 | &WifiChip::requestChipDebugInfoInternal, |
| 343 | hidl_status_cb); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | Return<void> WifiChip::requestDriverDebugDump( |
| 347 | requestDriverDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 348 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 349 | &WifiChip::requestDriverDebugDumpInternal, |
| 350 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 353 | Return<void> WifiChip::requestFirmwareDebugDump( |
| 354 | requestFirmwareDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 355 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 356 | &WifiChip::requestFirmwareDebugDumpInternal, |
| 357 | hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 360 | Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 361 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 362 | &WifiChip::createApIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 365 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 366 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 367 | &WifiChip::getApIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 370 | Return<void> WifiChip::getApIface(const hidl_string& ifname, |
| 371 | getApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 372 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 373 | &WifiChip::getApIfaceInternal, hidl_status_cb, |
| 374 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 377 | Return<void> WifiChip::removeApIface(const hidl_string& ifname, |
| 378 | removeApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 379 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 380 | &WifiChip::removeApIfaceInternal, hidl_status_cb, |
| 381 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 384 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 385 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 386 | &WifiChip::createNanIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 389 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 390 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 391 | &WifiChip::getNanIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 395 | getNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 396 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 397 | &WifiChip::getNanIfaceInternal, hidl_status_cb, |
| 398 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 401 | Return<void> WifiChip::removeNanIface(const hidl_string& ifname, |
| 402 | removeNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 403 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 404 | &WifiChip::removeNanIfaceInternal, hidl_status_cb, |
| 405 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 408 | Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 409 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 410 | &WifiChip::createP2pIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 413 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 414 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 415 | &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 419 | getP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 420 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 421 | &WifiChip::getP2pIfaceInternal, hidl_status_cb, |
| 422 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 425 | Return<void> WifiChip::removeP2pIface(const hidl_string& ifname, |
| 426 | removeP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 427 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 428 | &WifiChip::removeP2pIfaceInternal, hidl_status_cb, |
| 429 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 432 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 433 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 434 | &WifiChip::createStaIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 437 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 438 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 439 | &WifiChip::getStaIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 443 | getStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 444 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 445 | &WifiChip::getStaIfaceInternal, hidl_status_cb, |
| 446 | ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 449 | Return<void> WifiChip::removeStaIface(const hidl_string& ifname, |
| 450 | removeStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 451 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 452 | &WifiChip::removeStaIfaceInternal, hidl_status_cb, |
| 453 | ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 456 | Return<void> WifiChip::createRttController( |
| 457 | const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 458 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 459 | &WifiChip::createRttControllerInternal, |
| 460 | hidl_status_cb, bound_iface); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 463 | Return<void> WifiChip::getDebugRingBuffersStatus( |
| 464 | getDebugRingBuffersStatus_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 465 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 466 | &WifiChip::getDebugRingBuffersStatusInternal, |
| 467 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | Return<void> WifiChip::startLoggingToDebugRingBuffer( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 471 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 472 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes, |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 473 | startLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 474 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 475 | &WifiChip::startLoggingToDebugRingBufferInternal, |
| 476 | hidl_status_cb, ring_name, verbose_level, |
| 477 | max_interval_in_sec, min_data_size_in_bytes); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | Return<void> WifiChip::forceDumpToDebugRingBuffer( |
| 481 | const hidl_string& ring_name, |
| 482 | forceDumpToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 483 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 484 | &WifiChip::forceDumpToDebugRingBufferInternal, |
| 485 | hidl_status_cb, ring_name); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 488 | Return<void> WifiChip::stopLoggingToDebugRingBuffer( |
| 489 | stopLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 490 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 491 | &WifiChip::stopLoggingToDebugRingBufferInternal, |
| 492 | hidl_status_cb); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 495 | Return<void> WifiChip::getDebugHostWakeReasonStats( |
| 496 | getDebugHostWakeReasonStats_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 497 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 498 | &WifiChip::getDebugHostWakeReasonStatsInternal, |
| 499 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 502 | Return<void> WifiChip::enableDebugErrorAlerts( |
| 503 | bool enable, enableDebugErrorAlerts_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 504 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 505 | &WifiChip::enableDebugErrorAlertsInternal, |
| 506 | hidl_status_cb, enable); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 509 | Return<void> WifiChip::selectTxPowerScenario( |
| 510 | TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 511 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 512 | &WifiChip::selectTxPowerScenarioInternal, |
| 513 | hidl_status_cb, scenario); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 516 | Return<void> WifiChip::resetTxPowerScenario( |
| 517 | resetTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 518 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 519 | &WifiChip::resetTxPowerScenarioInternal, |
| 520 | hidl_status_cb); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 521 | } |
| 522 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 523 | Return<void> WifiChip::debug(const hidl_handle& handle, |
| 524 | const hidl_vec<hidl_string>&) { |
| 525 | if (handle != nullptr && handle->numFds >= 1) { |
| 526 | int fd = handle->data[0]; |
| 527 | if (!writeRingbufferFilesInternal()) { |
| 528 | LOG(ERROR) << "Error writing files to flash"; |
| 529 | } |
| 530 | uint32_t n_error = cpioFilesInDir(fd, kTombstoneFolderPath); |
| 531 | if (n_error != 0) { |
| 532 | LOG(ERROR) << n_error << " errors occured in cpio function"; |
| 533 | } |
| 534 | fsync(fd); |
| 535 | } else { |
| 536 | LOG(ERROR) << "File handle error"; |
| 537 | } |
| 538 | return Void(); |
| 539 | } |
| 540 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 541 | void WifiChip::invalidateAndRemoveAllIfaces() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 542 | invalidateAndClearAll(ap_ifaces_); |
| 543 | invalidateAndClearAll(nan_ifaces_); |
| 544 | invalidateAndClearAll(p2p_ifaces_); |
| 545 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 546 | // Since all the ifaces are invalid now, all RTT controller objects |
| 547 | // using those ifaces also need to be invalidated. |
| 548 | for (const auto& rtt : rtt_controllers_) { |
| 549 | rtt->invalidate(); |
| 550 | } |
| 551 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 554 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 555 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | WifiStatus WifiChip::registerEventCallbackInternal( |
| 559 | const sp<IWifiChipEventCallback>& event_callback) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 560 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 561 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 562 | } |
| 563 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 566 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 567 | legacy_hal::wifi_error legacy_status; |
| 568 | uint32_t legacy_feature_set; |
| 569 | uint32_t legacy_logger_feature_set; |
| 570 | std::tie(legacy_status, legacy_feature_set) = |
| 571 | legacy_hal_.lock()->getSupportedFeatureSet(getWlan0IfaceName()); |
| 572 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 573 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 574 | } |
| 575 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 576 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(getWlan0IfaceName()); |
| 577 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 876220f | 2017-12-28 16:19:06 -0800 | [diff] [blame] | 578 | // some devices don't support querying logger feature set |
| 579 | legacy_logger_feature_set = 0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 580 | } |
| 581 | uint32_t hidl_caps; |
| 582 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 583 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 584 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 585 | } |
| 586 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 589 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 590 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 591 | return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 594 | WifiStatus WifiChip::configureChipInternal( |
| 595 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 596 | ChipModeId mode_id) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 597 | if (!isValidModeId(mode_id)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 598 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 599 | } |
| 600 | if (mode_id == current_mode_id_) { |
| 601 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 602 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 603 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 604 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 605 | if (status.code != WifiStatusCode::SUCCESS) { |
| 606 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 607 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
| 608 | LOG(ERROR) |
| 609 | << "Failed to invoke onChipReconfigureFailure callback"; |
| 610 | } |
| 611 | } |
| 612 | return status; |
| 613 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 614 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 615 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 616 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 617 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 618 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 619 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 620 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 621 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 625 | if (!isValidModeId(current_mode_id_)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 626 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 627 | current_mode_id_}; |
| 628 | } |
| 629 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 633 | WifiChip::requestChipDebugInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 634 | IWifiChip::ChipDebugInfo result; |
| 635 | legacy_hal::wifi_error legacy_status; |
| 636 | std::string driver_desc; |
| 637 | std::tie(legacy_status, driver_desc) = |
| 638 | legacy_hal_.lock()->getDriverVersion(getWlan0IfaceName()); |
| 639 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 640 | LOG(ERROR) << "Failed to get driver version: " |
| 641 | << legacyErrorToString(legacy_status); |
| 642 | WifiStatus status = createWifiStatusFromLegacyError( |
| 643 | legacy_status, "failed to get driver version"); |
| 644 | return {status, result}; |
| 645 | } |
| 646 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 647 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 648 | std::string firmware_desc; |
| 649 | std::tie(legacy_status, firmware_desc) = |
| 650 | legacy_hal_.lock()->getFirmwareVersion(getWlan0IfaceName()); |
| 651 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 652 | LOG(ERROR) << "Failed to get firmware version: " |
| 653 | << legacyErrorToString(legacy_status); |
| 654 | WifiStatus status = createWifiStatusFromLegacyError( |
| 655 | legacy_status, "failed to get firmware version"); |
| 656 | return {status, result}; |
| 657 | } |
| 658 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 659 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 660 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 664 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 665 | legacy_hal::wifi_error legacy_status; |
| 666 | std::vector<uint8_t> driver_dump; |
| 667 | std::tie(legacy_status, driver_dump) = |
| 668 | legacy_hal_.lock()->requestDriverMemoryDump(getWlan0IfaceName()); |
| 669 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 670 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 671 | << legacyErrorToString(legacy_status); |
| 672 | return {createWifiStatusFromLegacyError(legacy_status), |
| 673 | std::vector<uint8_t>()}; |
| 674 | } |
| 675 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 679 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 680 | legacy_hal::wifi_error legacy_status; |
| 681 | std::vector<uint8_t> firmware_dump; |
| 682 | std::tie(legacy_status, firmware_dump) = |
| 683 | legacy_hal_.lock()->requestFirmwareMemoryDump(getWlan0IfaceName()); |
| 684 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 685 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 686 | << legacyErrorToString(legacy_status); |
| 687 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 688 | } |
| 689 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 693 | if (!canCurrentModeSupportIfaceOfType(IfaceType::AP)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 694 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 695 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 696 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 697 | sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_); |
| 698 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 699 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 700 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 701 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 702 | } |
| 703 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 704 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 708 | WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 709 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 710 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 711 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 712 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 716 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 717 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 718 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 719 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 720 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 721 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 724 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 725 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 726 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 727 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 728 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 729 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 730 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 731 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 732 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 733 | } |
| 734 | } |
| 735 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 738 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 739 | if (!canCurrentModeSupportIfaceOfType(IfaceType::NAN)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 740 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 741 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 742 | // These are still assumed to be based on wlan0. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 743 | std::string ifname = getWlan0IfaceName(); |
| 744 | sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_); |
| 745 | nan_ifaces_.push_back(iface); |
| 746 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 747 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 748 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 749 | } |
| 750 | } |
| 751 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 755 | WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 756 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 757 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 758 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 759 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 763 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 764 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 765 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 766 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 767 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 768 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 771 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 772 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 773 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 774 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 775 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 776 | invalidateAndClear(nan_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 777 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 778 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 779 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 780 | } |
| 781 | } |
| 782 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 785 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 786 | if (!canCurrentModeSupportIfaceOfType(IfaceType::P2P)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 787 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 788 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 789 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 790 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 791 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 792 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 793 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 794 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 795 | } |
| 796 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 797 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 801 | WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 802 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 803 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 804 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 805 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 809 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 810 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 811 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 812 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 813 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 814 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 817 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 818 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 819 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 820 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 821 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 822 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 823 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 824 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 825 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 826 | } |
| 827 | } |
| 828 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 829 | } |
| 830 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 831 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 832 | if (!canCurrentModeSupportIfaceOfType(IfaceType::STA)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 833 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 834 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 835 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 836 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_); |
| 837 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 838 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 839 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 840 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 841 | } |
| 842 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 843 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 847 | WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 848 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 849 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 850 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 851 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 855 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 856 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 857 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 858 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 859 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 860 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 863 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 864 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 865 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 866 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 867 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 868 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 869 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 870 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 871 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 872 | } |
| 873 | } |
| 874 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 877 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 878 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 879 | sp<WifiRttController> rtt = |
| 880 | new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_); |
| 881 | rtt_controllers_.emplace_back(rtt); |
| 882 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 883 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 884 | |
| 885 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 886 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 887 | legacy_hal::wifi_error legacy_status; |
| 888 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 889 | legacy_ring_buffer_status_vec; |
| 890 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 891 | legacy_hal_.lock()->getRingBuffersStatus(getWlan0IfaceName()); |
| 892 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 893 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 894 | } |
| 895 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 896 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 897 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 898 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 899 | } |
| 900 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 901 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 905 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 906 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 907 | WifiStatus status = registerDebugRingBufferCallback(); |
| 908 | if (status.code != WifiStatusCode::SUCCESS) { |
| 909 | return status; |
| 910 | } |
| 911 | legacy_hal::wifi_error legacy_status = |
| 912 | legacy_hal_.lock()->startRingBufferLogging( |
| 913 | getWlan0IfaceName(), ring_name, |
| 914 | static_cast< |
| 915 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 916 | verbose_level), |
| 917 | max_interval_in_sec, min_data_size_in_bytes); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 918 | ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>( |
| 919 | ring_name, Ringbuffer(kMaxBufferSizeBytes))); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 920 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 924 | const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 925 | WifiStatus status = registerDebugRingBufferCallback(); |
| 926 | if (status.code != WifiStatusCode::SUCCESS) { |
| 927 | return status; |
| 928 | } |
| 929 | legacy_hal::wifi_error legacy_status = |
| 930 | legacy_hal_.lock()->getRingBufferData(getWlan0IfaceName(), ring_name); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 931 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 932 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 935 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 936 | legacy_hal::wifi_error legacy_status = |
| 937 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler( |
| 938 | getWlan0IfaceName()); |
| 939 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 940 | } |
| 941 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 942 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 943 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 944 | legacy_hal::wifi_error legacy_status; |
| 945 | legacy_hal::WakeReasonStats legacy_stats; |
| 946 | std::tie(legacy_status, legacy_stats) = |
| 947 | legacy_hal_.lock()->getWakeReasonStats(getWlan0IfaceName()); |
| 948 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 949 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 950 | } |
| 951 | WifiDebugHostWakeReasonStats hidl_stats; |
| 952 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 953 | &hidl_stats)) { |
| 954 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 955 | } |
| 956 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 959 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 960 | legacy_hal::wifi_error legacy_status; |
| 961 | if (enable) { |
| 962 | android::wp<WifiChip> weak_ptr_this(this); |
| 963 | const auto& on_alert_callback = [weak_ptr_this]( |
| 964 | int32_t error_code, |
| 965 | std::vector<uint8_t> debug_data) { |
| 966 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 967 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 968 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 969 | return; |
| 970 | } |
| 971 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 972 | if (!callback->onDebugErrorAlert(error_code, debug_data) |
| 973 | .isOk()) { |
| 974 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 975 | } |
| 976 | } |
| 977 | }; |
| 978 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 979 | getWlan0IfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 980 | } else { |
| 981 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 982 | getWlan0IfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 983 | } |
| 984 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 985 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 986 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 987 | WifiStatus WifiChip::selectTxPowerScenarioInternal(TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 988 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 989 | getWlan0IfaceName(), |
| 990 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
| 991 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 994 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 995 | auto legacy_status = |
| 996 | legacy_hal_.lock()->resetTxPowerScenario(getWlan0IfaceName()); |
| 997 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1000 | WifiStatus WifiChip::handleChipConfiguration( |
| 1001 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 1002 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1003 | // If the chip is already configured in a different mode, stop |
| 1004 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1005 | if (isValidModeId(current_mode_id_)) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1006 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ |
| 1007 | << " to mode " << mode_id; |
| 1008 | invalidateAndRemoveAllIfaces(); |
| 1009 | legacy_hal::wifi_error legacy_status = |
| 1010 | legacy_hal_.lock()->stop(lock, []() {}); |
| 1011 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1012 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 1013 | << legacyErrorToString(legacy_status); |
| 1014 | return createWifiStatusFromLegacyError(legacy_status); |
| 1015 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1016 | } |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1017 | // Firmware mode change not needed for V2 devices. |
| 1018 | bool success = true; |
| 1019 | if (mode_id == kV1StaChipModeId) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1020 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1021 | } else if (mode_id == kV1ApChipModeId) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1022 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 1023 | } |
| 1024 | if (!success) { |
| 1025 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1026 | } |
| 1027 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 1028 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1029 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 1030 | << legacyErrorToString(legacy_status); |
| 1031 | return createWifiStatusFromLegacyError(legacy_status); |
| 1032 | } |
| 1033 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1034 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1035 | |
| 1036 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1037 | if (debug_ring_buffer_cb_registered_) { |
| 1038 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1039 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 1040 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1041 | android::wp<WifiChip> weak_ptr_this(this); |
| 1042 | const auto& on_ring_buffer_data_callback = |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1043 | [weak_ptr_this](const std::string& name, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1044 | const std::vector<uint8_t>& data, |
| 1045 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 1046 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1047 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1048 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1049 | return; |
| 1050 | } |
| 1051 | WifiDebugRingBufferStatus hidl_status; |
| 1052 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 1053 | status, &hidl_status)) { |
| 1054 | LOG(ERROR) << "Error converting ring buffer status"; |
| 1055 | return; |
| 1056 | } |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1057 | const auto& target = shared_ptr_this->ringbuffer_map_.find(name); |
| 1058 | if (target != shared_ptr_this->ringbuffer_map_.end()) { |
| 1059 | Ringbuffer& cur_buffer = target->second; |
| 1060 | cur_buffer.append(data); |
| 1061 | } else { |
| 1062 | LOG(ERROR) << "Ringname " << name << " not found"; |
| 1063 | return; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1064 | } |
| 1065 | }; |
| 1066 | legacy_hal::wifi_error legacy_status = |
| 1067 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 1068 | getWlan0IfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1069 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1070 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1071 | debug_ring_buffer_cb_registered_ = true; |
| 1072 | } |
| 1073 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1074 | } |
| 1075 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1076 | void WifiChip::populateModes() { |
| 1077 | // The chip combination supported for current devices is fixed. |
| 1078 | // They can be one of the following based on device features: |
| 1079 | // a) 2 separate modes of operation with 1 interface combination each: |
| 1080 | // Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN(optional) |
| 1081 | // concurrent iface operations. |
| 1082 | // Mode 2 (AP mode): Will support 1 AP iface operation. |
| 1083 | // |
| 1084 | // b) 1 mode of operation with 2 interface combinations |
| 1085 | // (conditional on isDualInterfaceSupported()): |
| 1086 | // Interface Combination 1: Will support 1 STA and 1 P2P or NAN(optional) |
| 1087 | // concurrent iface operations. |
| 1088 | // Interface Combination 2: Will support 1 STA and 1 STA or AP concurrent |
| 1089 | // iface operations. |
| 1090 | // If Aware is enabled (conditional on isAwareSupported()), the iface |
| 1091 | // combination will be modified to support either P2P or NAN in place of |
| 1092 | // just P2P. |
| 1093 | if (feature_flags_.lock()->isDualInterfaceSupported()) { |
| 1094 | // V2 Iface combinations for Mode Id = 2. |
| 1095 | const IWifiChip::ChipIfaceCombinationLimit |
| 1096 | chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 1097 | const IWifiChip::ChipIfaceCombinationLimit |
| 1098 | chip_iface_combination_limit_2 = {{IfaceType::STA, IfaceType::AP}, |
| 1099 | 1}; |
| 1100 | IWifiChip::ChipIfaceCombinationLimit chip_iface_combination_limit_3; |
| 1101 | if (feature_flags_.lock()->isAwareSupported()) { |
| 1102 | chip_iface_combination_limit_3 = {{IfaceType::P2P, IfaceType::NAN}, |
| 1103 | 1}; |
| 1104 | } else { |
| 1105 | chip_iface_combination_limit_3 = {{IfaceType::P2P}, 1}; |
| 1106 | } |
| 1107 | const IWifiChip::ChipIfaceCombination chip_iface_combination_1 = { |
| 1108 | {chip_iface_combination_limit_1, chip_iface_combination_limit_2}}; |
| 1109 | const IWifiChip::ChipIfaceCombination chip_iface_combination_2 = { |
| 1110 | {chip_iface_combination_limit_1, chip_iface_combination_limit_3}}; |
| 1111 | const IWifiChip::ChipMode chip_mode = { |
| 1112 | kV2ChipModeId, |
| 1113 | {chip_iface_combination_1, chip_iface_combination_2}}; |
| 1114 | modes_ = {chip_mode}; |
| 1115 | } else { |
| 1116 | // V1 Iface combinations for Mode Id = 0. (STA Mode) |
| 1117 | const IWifiChip::ChipIfaceCombinationLimit |
| 1118 | sta_chip_iface_combination_limit_1 = {{IfaceType::STA}, 1}; |
| 1119 | IWifiChip::ChipIfaceCombinationLimit sta_chip_iface_combination_limit_2; |
| 1120 | if (feature_flags_.lock()->isAwareSupported()) { |
| 1121 | sta_chip_iface_combination_limit_2 = { |
| 1122 | {IfaceType::P2P, IfaceType::NAN}, 1}; |
| 1123 | } else { |
| 1124 | sta_chip_iface_combination_limit_2 = {{IfaceType::P2P}, 1}; |
| 1125 | } |
| 1126 | const IWifiChip::ChipIfaceCombination sta_chip_iface_combination = { |
| 1127 | {sta_chip_iface_combination_limit_1, |
| 1128 | sta_chip_iface_combination_limit_2}}; |
| 1129 | const IWifiChip::ChipMode sta_chip_mode = { |
| 1130 | kV1StaChipModeId, {sta_chip_iface_combination}}; |
| 1131 | // Iface combinations for Mode Id = 1. (AP Mode) |
| 1132 | const IWifiChip::ChipIfaceCombinationLimit |
| 1133 | ap_chip_iface_combination_limit = {{IfaceType::AP}, 1}; |
| 1134 | const IWifiChip::ChipIfaceCombination ap_chip_iface_combination = { |
| 1135 | {ap_chip_iface_combination_limit}}; |
| 1136 | const IWifiChip::ChipMode ap_chip_mode = {kV1ApChipModeId, |
| 1137 | {ap_chip_iface_combination}}; |
| 1138 | modes_ = {sta_chip_mode, ap_chip_mode}; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | std::vector<IWifiChip::ChipIfaceCombination> |
| 1143 | WifiChip::getCurrentModeIfaceCombinations() { |
| 1144 | if (!isValidModeId(current_mode_id_)) { |
| 1145 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1146 | return {}; |
| 1147 | } |
| 1148 | for (const auto& mode : modes_) { |
| 1149 | if (mode.id == current_mode_id_) { |
| 1150 | return mode.availableCombinations; |
| 1151 | } |
| 1152 | } |
| 1153 | CHECK(0) << "Expected to find iface combinations for current mode!"; |
| 1154 | return {}; |
| 1155 | } |
| 1156 | |
| 1157 | // Returns a map indexed by IfaceType with the number of ifaces currently |
| 1158 | // created of the corresponding type. |
| 1159 | std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() { |
| 1160 | std::map<IfaceType, size_t> iface_counts; |
| 1161 | iface_counts[IfaceType::AP] = ap_ifaces_.size(); |
| 1162 | iface_counts[IfaceType::NAN] = nan_ifaces_.size(); |
| 1163 | iface_counts[IfaceType::P2P] = p2p_ifaces_.size(); |
| 1164 | iface_counts[IfaceType::STA] = sta_ifaces_.size(); |
| 1165 | return iface_counts; |
| 1166 | } |
| 1167 | |
| 1168 | // This expands the provided iface combinations to a more parseable |
| 1169 | // form. Returns a vector of available combinations possible with the number |
| 1170 | // of ifaces of each type in the combination. |
| 1171 | // This method is a port of HalDeviceManager.expandIfaceCombos() from framework. |
| 1172 | std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations( |
| 1173 | const IWifiChip::ChipIfaceCombination& combination) { |
| 1174 | uint32_t num_expanded_combos = 1; |
| 1175 | for (const auto& limit : combination.limits) { |
| 1176 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1177 | num_expanded_combos *= limit.types.size(); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | // Allocate the vector of expanded combos and reset all iface counts to 0 |
| 1182 | // in each combo. |
| 1183 | std::vector<std::map<IfaceType, size_t>> expanded_combos; |
| 1184 | expanded_combos.resize(num_expanded_combos); |
| 1185 | for (auto& expanded_combo : expanded_combos) { |
| 1186 | for (const auto type : |
| 1187 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1188 | expanded_combo[type] = 0; |
| 1189 | } |
| 1190 | } |
| 1191 | uint32_t span = num_expanded_combos; |
| 1192 | for (const auto& limit : combination.limits) { |
| 1193 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1194 | span /= limit.types.size(); |
| 1195 | for (uint32_t k = 0; k < num_expanded_combos; ++k) { |
| 1196 | const auto iface_type = |
| 1197 | limit.types[(k / span) % limit.types.size()]; |
| 1198 | expanded_combos[k][iface_type]++; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | return expanded_combos; |
| 1203 | } |
| 1204 | |
| 1205 | bool WifiChip::canExpandedIfaceCombinationSupportIfaceOfType( |
| 1206 | const std::map<IfaceType, size_t>& combo, IfaceType requested_type) { |
| 1207 | const auto current_combo = getCurrentIfaceCombination(); |
| 1208 | |
| 1209 | // Check if we have space for 1 more iface of |type| in this combo |
| 1210 | for (const auto type : |
| 1211 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1212 | size_t num_ifaces_needed = current_combo.at(type); |
| 1213 | if (type == requested_type) { |
| 1214 | num_ifaces_needed++; |
| 1215 | } |
| 1216 | size_t num_ifaces_allowed = combo.at(type); |
| 1217 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1218 | return false; |
| 1219 | } |
| 1220 | } |
| 1221 | return true; |
| 1222 | } |
| 1223 | |
| 1224 | // This method does the following: |
| 1225 | // a) Enumerate all possible iface combos by expanding the current |
| 1226 | // ChipIfaceCombination. |
| 1227 | // b) Check if the requested iface type can be added to the current mode. |
| 1228 | bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType type) { |
| 1229 | if (!isValidModeId(current_mode_id_)) { |
| 1230 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1231 | return false; |
| 1232 | } |
| 1233 | const auto combinations = getCurrentModeIfaceCombinations(); |
| 1234 | for (const auto& combination : combinations) { |
| 1235 | const auto expanded_combos = expandIfaceCombinations(combination); |
| 1236 | for (const auto& expanded_combo : expanded_combos) { |
| 1237 | if (canExpandedIfaceCombinationSupportIfaceOfType(expanded_combo, |
| 1238 | type)) { |
| 1239 | return true; |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | bool WifiChip::isValidModeId(ChipModeId mode_id) { |
| 1247 | for (const auto& mode : modes_) { |
| 1248 | if (mode.id == mode_id) { |
| 1249 | return true; |
| 1250 | } |
| 1251 | } |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1255 | // Return "wlan0", if "wlan0" is not already in use, else return "wlan1". |
| 1256 | // This is based on the assumption that we'll have a max of 2 concurrent |
| 1257 | // AP/STA ifaces. |
| 1258 | std::string WifiChip::allocateApOrStaIfaceName() { |
| 1259 | auto ap_iface = findUsingName(ap_ifaces_, getWlan0IfaceName()); |
| 1260 | auto sta_iface = findUsingName(sta_ifaces_, getWlan0IfaceName()); |
| 1261 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1262 | return getWlan0IfaceName(); |
| 1263 | } |
| 1264 | ap_iface = findUsingName(ap_ifaces_, getWlan1IfaceName()); |
| 1265 | sta_iface = findUsingName(sta_ifaces_, getWlan1IfaceName()); |
| 1266 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1267 | return getWlan1IfaceName(); |
| 1268 | } |
| 1269 | // This should never happen. We screwed up somewhere if it did. |
| 1270 | CHECK(0) << "wlan0 and wlan1 in use already!"; |
| 1271 | return {}; |
| 1272 | } |
| 1273 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1274 | bool WifiChip::writeRingbufferFilesInternal() { |
| 1275 | if (!removeOldFilesInternal()) { |
| 1276 | LOG(ERROR) << "Error occurred while deleting old tombstone files"; |
| 1277 | return false; |
| 1278 | } |
| 1279 | // write ringbuffers to file |
| 1280 | for (const auto& item : ringbuffer_map_) { |
| 1281 | const Ringbuffer& cur_buffer = item.second; |
| 1282 | if (cur_buffer.getData().empty()) { |
| 1283 | continue; |
| 1284 | } |
| 1285 | const std::string file_path_raw = |
| 1286 | kTombstoneFolderPath + item.first + "XXXXXXXXXX"; |
| 1287 | const int dump_fd = mkstemp(makeCharVec(file_path_raw).data()); |
| 1288 | if (dump_fd == -1) { |
| 1289 | LOG(ERROR) << "create file failed: " << strerror(errno); |
| 1290 | return false; |
| 1291 | } |
| 1292 | unique_fd file_auto_closer(dump_fd); |
| 1293 | for (const auto& cur_block : cur_buffer.getData()) { |
| 1294 | if (write(dump_fd, cur_block.data(), |
| 1295 | sizeof(cur_block[0]) * cur_block.size()) == -1) { |
| 1296 | LOG(ERROR) << "Error writing to file " << strerror(errno); |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | return true; |
| 1301 | } |
| 1302 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 1303 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 1304 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1305 | } // namespace wifi |
| 1306 | } // namespace hardware |
| 1307 | } // namespace android |