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