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