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