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