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