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