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