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