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