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