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