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 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 344 | std::set<sp<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 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 631 | Return<void> WifiChip::registerEventCallback_1_4( |
| 632 | const sp<IWifiChipEventCallback>& event_callback, |
| 633 | registerEventCallback_cb hidl_status_cb) { |
| 634 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 635 | &WifiChip::registerEventCallbackInternal_1_4, |
| 636 | hidl_status_cb, event_callback); |
| 637 | } |
| 638 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 639 | void WifiChip::invalidateAndRemoveAllIfaces() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 640 | invalidateAndClearAll(ap_ifaces_); |
| 641 | invalidateAndClearAll(nan_ifaces_); |
| 642 | invalidateAndClearAll(p2p_ifaces_); |
| 643 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 644 | // Since all the ifaces are invalid now, all RTT controller objects |
| 645 | // using those ifaces also need to be invalidated. |
| 646 | for (const auto& rtt : rtt_controllers_) { |
| 647 | rtt->invalidate(); |
| 648 | } |
| 649 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 652 | void WifiChip::invalidateAndRemoveDependencies( |
| 653 | const std::string& removed_iface_name) { |
| 654 | for (const auto& nan_iface : nan_ifaces_) { |
| 655 | if (nan_iface->getName() == removed_iface_name) { |
| 656 | invalidateAndClear(nan_ifaces_, nan_iface); |
| 657 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 658 | if (!callback |
| 659 | ->onIfaceRemoved(IfaceType::NAN, removed_iface_name) |
| 660 | .isOk()) { |
| 661 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | for (const auto& rtt : rtt_controllers_) { |
| 667 | if (rtt->getIfaceName() == removed_iface_name) { |
| 668 | invalidateAndClear(rtt_controllers_, rtt); |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 673 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 674 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | WifiStatus WifiChip::registerEventCallbackInternal( |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 678 | const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) { |
| 679 | // Deprecated support for this callback. |
| 680 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 683 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 684 | // Deprecated support for this callback. |
| 685 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; |
| 686 | } |
| 687 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 688 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 689 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 690 | return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 693 | WifiStatus WifiChip::configureChipInternal( |
| 694 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 695 | ChipModeId mode_id) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 696 | if (!isValidModeId(mode_id)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 697 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 698 | } |
| 699 | if (mode_id == current_mode_id_) { |
| 700 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 701 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 702 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 703 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 704 | if (status.code != WifiStatusCode::SUCCESS) { |
| 705 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 706 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
| 707 | LOG(ERROR) |
| 708 | << "Failed to invoke onChipReconfigureFailure callback"; |
| 709 | } |
| 710 | } |
| 711 | return status; |
| 712 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 713 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 714 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 715 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 716 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 717 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 718 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 719 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 720 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 721 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 725 | if (!isValidModeId(current_mode_id_)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 726 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 727 | current_mode_id_}; |
| 728 | } |
| 729 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 733 | WifiChip::requestChipDebugInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 734 | IWifiChip::ChipDebugInfo result; |
| 735 | legacy_hal::wifi_error legacy_status; |
| 736 | std::string driver_desc; |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 737 | const auto ifname = getFirstActiveWlanIfaceName(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 738 | std::tie(legacy_status, driver_desc) = |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 739 | legacy_hal_.lock()->getDriverVersion(ifname); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 740 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 741 | LOG(ERROR) << "Failed to get driver version: " |
| 742 | << legacyErrorToString(legacy_status); |
| 743 | WifiStatus status = createWifiStatusFromLegacyError( |
| 744 | legacy_status, "failed to get driver version"); |
| 745 | return {status, result}; |
| 746 | } |
| 747 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 748 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 749 | std::string firmware_desc; |
| 750 | std::tie(legacy_status, firmware_desc) = |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 751 | legacy_hal_.lock()->getFirmwareVersion(ifname); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 752 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 753 | LOG(ERROR) << "Failed to get firmware version: " |
| 754 | << legacyErrorToString(legacy_status); |
| 755 | WifiStatus status = createWifiStatusFromLegacyError( |
| 756 | legacy_status, "failed to get firmware version"); |
| 757 | return {status, result}; |
| 758 | } |
| 759 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 760 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 761 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 765 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 766 | legacy_hal::wifi_error legacy_status; |
| 767 | std::vector<uint8_t> driver_dump; |
| 768 | std::tie(legacy_status, driver_dump) = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 769 | legacy_hal_.lock()->requestDriverMemoryDump( |
| 770 | getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 771 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 772 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 773 | << legacyErrorToString(legacy_status); |
| 774 | return {createWifiStatusFromLegacyError(legacy_status), |
| 775 | std::vector<uint8_t>()}; |
| 776 | } |
| 777 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 781 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 782 | legacy_hal::wifi_error legacy_status; |
| 783 | std::vector<uint8_t> firmware_dump; |
| 784 | std::tie(legacy_status, firmware_dump) = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 785 | legacy_hal_.lock()->requestFirmwareMemoryDump( |
| 786 | getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 787 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 788 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 789 | << legacyErrorToString(legacy_status); |
| 790 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 791 | } |
| 792 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 796 | if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 797 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 798 | } |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 799 | std::string ifname = allocateApIfaceName(); |
Patrik Fimml | 6beae32 | 2019-10-09 17:34:01 +0200 | [diff] [blame] | 800 | sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_, iface_util_); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 801 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 802 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 803 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 804 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 805 | } |
| 806 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 807 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 808 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 812 | WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 813 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 814 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 815 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 816 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 820 | 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), nullptr}; |
| 824 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 825 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 828 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 829 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 830 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 831 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 832 | } |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 833 | // Invalidate & remove any dependent objects first. |
| 834 | // Note: This is probably not required because we never create |
| 835 | // nan/rtt objects over AP iface. But, there is no harm to do it |
| 836 | // here and not make that assumption all over the place. |
| 837 | invalidateAndRemoveDependencies(ifname); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 838 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 839 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 840 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 841 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 842 | } |
| 843 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 844 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 845 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 848 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 849 | if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::NAN)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 850 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 851 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 852 | // These are still assumed to be based on wlan0. |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 853 | std::string ifname = getFirstActiveWlanIfaceName(); |
Roshan Pius | 356d5a6 | 2019-05-17 15:07:34 -0700 | [diff] [blame] | 854 | sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_, iface_util_); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 855 | nan_ifaces_.push_back(iface); |
| 856 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 857 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 858 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 859 | } |
| 860 | } |
| 861 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 865 | WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 866 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 867 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 868 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 869 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 873 | 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), nullptr}; |
| 877 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 878 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 881 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 882 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 883 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 884 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 885 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 886 | invalidateAndClear(nan_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 887 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 888 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 889 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 890 | } |
| 891 | } |
| 892 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 893 | } |
| 894 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 895 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 896 | if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::P2P)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 897 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 898 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 899 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 900 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 901 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 902 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 903 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 904 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 905 | } |
| 906 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 907 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 911 | WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 912 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 913 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 914 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 915 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 919 | 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), nullptr}; |
| 923 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 924 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 927 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 928 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 929 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 930 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 931 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 932 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 933 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 934 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 935 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 936 | } |
| 937 | } |
| 938 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 939 | } |
| 940 | |
Ahmed ElArabawy | b23485d | 2019-12-09 15:24:16 -0800 | [diff] [blame] | 941 | std::pair<WifiStatus, sp<V1_3::IWifiStaIface>> |
| 942 | WifiChip::createStaIfaceInternal() { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 943 | if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::STA)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 944 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 945 | } |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 946 | std::string ifname = allocateStaIfaceName(); |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 947 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 948 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 949 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 950 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 951 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 952 | } |
| 953 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 954 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 955 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 959 | WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 960 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 961 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 962 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 963 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Ahmed ElArabawy | b23485d | 2019-12-09 15:24:16 -0800 | [diff] [blame] | 966 | std::pair<WifiStatus, sp<V1_3::IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 967 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 968 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 969 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 970 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 971 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 972 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 973 | } |
| 974 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 975 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 976 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 977 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 978 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 979 | } |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 980 | // Invalidate & remove any dependent objects first. |
| 981 | invalidateAndRemoveDependencies(ifname); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 982 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 983 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 984 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 985 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 986 | } |
| 987 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 988 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 989 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 990 | } |
| 991 | |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 992 | std::pair<WifiStatus, sp<V1_0::IWifiRttController>> |
| 993 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& /*bound_iface*/) { |
| 994 | LOG(ERROR) << "createRttController is not supported on this HAL"; |
Ahmed ElArabawy | 36defb3 | 2019-12-29 21:24:27 -0800 | [diff] [blame] | 995 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 996 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 997 | |
| 998 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 999 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1000 | legacy_hal::wifi_error legacy_status; |
| 1001 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 1002 | legacy_ring_buffer_status_vec; |
| 1003 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1004 | legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1005 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1006 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1007 | } |
| 1008 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 1009 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 1010 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 1011 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1012 | } |
| 1013 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 1014 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1018 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 1019 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 1020 | WifiStatus status = registerDebugRingBufferCallback(); |
| 1021 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1022 | return status; |
| 1023 | } |
| 1024 | legacy_hal::wifi_error legacy_status = |
| 1025 | legacy_hal_.lock()->startRingBufferLogging( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1026 | getFirstActiveWlanIfaceName(), ring_name, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1027 | static_cast< |
| 1028 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 1029 | verbose_level), |
| 1030 | max_interval_in_sec, min_data_size_in_bytes); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1031 | ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>( |
| 1032 | ring_name, Ringbuffer(kMaxBufferSizeBytes))); |
Roshan Pius | a63b53f | 2019-11-18 11:03:13 -0800 | [diff] [blame] | 1033 | // if verbose logging enabled, turn up HAL daemon logging as well. |
| 1034 | if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) { |
| 1035 | android::base::SetMinimumLogSeverity(android::base::DEBUG); |
| 1036 | } else { |
| 1037 | android::base::SetMinimumLogSeverity(android::base::VERBOSE); |
| 1038 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1039 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 1043 | const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1044 | WifiStatus status = registerDebugRingBufferCallback(); |
| 1045 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1046 | return status; |
| 1047 | } |
| 1048 | legacy_hal::wifi_error legacy_status = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1049 | legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(), |
| 1050 | ring_name); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1051 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1052 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Roger Wang | b294c76 | 2018-11-02 15:34:39 +0800 | [diff] [blame] | 1055 | WifiStatus WifiChip::flushRingBufferToFileInternal() { |
| 1056 | if (!writeRingbufferFilesInternal()) { |
| 1057 | LOG(ERROR) << "Error writing files to flash"; |
| 1058 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1059 | } |
| 1060 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1061 | } |
| 1062 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1063 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1064 | legacy_hal::wifi_error legacy_status = |
| 1065 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1066 | getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1067 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1070 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 1071 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1072 | legacy_hal::wifi_error legacy_status; |
| 1073 | legacy_hal::WakeReasonStats legacy_stats; |
| 1074 | std::tie(legacy_status, legacy_stats) = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1075 | legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1076 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1077 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1078 | } |
| 1079 | WifiDebugHostWakeReasonStats hidl_stats; |
| 1080 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 1081 | &hidl_stats)) { |
| 1082 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1083 | } |
| 1084 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1087 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1088 | legacy_hal::wifi_error legacy_status; |
| 1089 | if (enable) { |
| 1090 | android::wp<WifiChip> weak_ptr_this(this); |
| 1091 | const auto& on_alert_callback = [weak_ptr_this]( |
| 1092 | int32_t error_code, |
| 1093 | std::vector<uint8_t> debug_data) { |
| 1094 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1095 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1096 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1097 | return; |
| 1098 | } |
| 1099 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1100 | if (!callback->onDebugErrorAlert(error_code, debug_data) |
| 1101 | .isOk()) { |
| 1102 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 1103 | } |
| 1104 | } |
| 1105 | }; |
| 1106 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1107 | getFirstActiveWlanIfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1108 | } else { |
| 1109 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1110 | getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1111 | } |
| 1112 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1113 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1114 | |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1115 | WifiStatus WifiChip::selectTxPowerScenarioInternal( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1116 | V1_1::IWifiChip::TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1117 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1118 | getFirstActiveWlanIfaceName(), |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1119 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
| 1120 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 1123 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1124 | auto legacy_status = |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1125 | legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1126 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 1129 | WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) { |
| 1130 | auto legacy_status = legacy_hal_.lock()->setLatencyMode( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1131 | getFirstActiveWlanIfaceName(), |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 1132 | hidl_struct_util::convertHidlLatencyModeToLegacy(mode)); |
| 1133 | return createWifiStatusFromLegacyError(legacy_status); |
| 1134 | } |
| 1135 | |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1136 | WifiStatus WifiChip::registerEventCallbackInternal_1_2( |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1137 | const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) { |
| 1138 | // Deprecated support for this callback. |
| 1139 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1142 | WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2( |
| 1143 | TxPowerScenario scenario) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1144 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1145 | getFirstActiveWlanIfaceName(), |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1146 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario)); |
| 1147 | return createWifiStatusFromLegacyError(legacy_status); |
| 1148 | } |
| 1149 | |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1150 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() { |
| 1151 | legacy_hal::wifi_error legacy_status; |
| 1152 | uint32_t legacy_feature_set; |
| 1153 | uint32_t legacy_logger_feature_set; |
| 1154 | const auto ifname = getFirstActiveWlanIfaceName(); |
| 1155 | std::tie(legacy_status, legacy_feature_set) = |
| 1156 | legacy_hal_.lock()->getSupportedFeatureSet(ifname); |
| 1157 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1158 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 1159 | } |
| 1160 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 1161 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname); |
| 1162 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1163 | // some devices don't support querying logger feature set |
| 1164 | legacy_logger_feature_set = 0; |
| 1165 | } |
| 1166 | uint32_t hidl_caps; |
| 1167 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 1168 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 1169 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 1170 | } |
| 1171 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 1172 | } |
| 1173 | |
| 1174 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 1175 | WifiChip::createRttControllerInternal_1_4(const sp<IWifiIface>& bound_iface) { |
| 1176 | if (sta_ifaces_.size() == 0 && |
| 1177 | !canCurrentModeSupportIfaceOfType(IfaceType::STA)) { |
| 1178 | LOG(ERROR) |
| 1179 | << "createRttControllerInternal_1_4: Chip cannot support STAs " |
| 1180 | "(and RTT by extension)"; |
| 1181 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 1182 | } |
| 1183 | sp<WifiRttController> rtt = new WifiRttController( |
| 1184 | getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); |
| 1185 | rtt_controllers_.emplace_back(rtt); |
| 1186 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
| 1187 | } |
| 1188 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1189 | WifiStatus WifiChip::registerEventCallbackInternal_1_4( |
| 1190 | const sp<IWifiChipEventCallback>& event_callback) { |
| 1191 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 1192 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1193 | } |
| 1194 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1195 | } |
| 1196 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1197 | WifiStatus WifiChip::handleChipConfiguration( |
| 1198 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 1199 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1200 | // If the chip is already configured in a different mode, stop |
| 1201 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1202 | if (isValidModeId(current_mode_id_)) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1203 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ |
| 1204 | << " to mode " << mode_id; |
| 1205 | invalidateAndRemoveAllIfaces(); |
| 1206 | legacy_hal::wifi_error legacy_status = |
| 1207 | legacy_hal_.lock()->stop(lock, []() {}); |
| 1208 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1209 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 1210 | << legacyErrorToString(legacy_status); |
| 1211 | return createWifiStatusFromLegacyError(legacy_status); |
| 1212 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1213 | } |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1214 | // Firmware mode change not needed for V2 devices. |
| 1215 | bool success = true; |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1216 | if (mode_id == feature_flags::chip_mode_ids::kV1Sta) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1217 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1218 | } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1219 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 1220 | } |
| 1221 | if (!success) { |
| 1222 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1223 | } |
| 1224 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 1225 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1226 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 1227 | << legacyErrorToString(legacy_status); |
| 1228 | return createWifiStatusFromLegacyError(legacy_status); |
| 1229 | } |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1230 | // Every time the HAL is restarted, we need to register the |
| 1231 | // radio mode change callback. |
| 1232 | WifiStatus status = registerRadioModeChangeCallback(); |
| 1233 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1234 | // This probably is not a critical failure? |
| 1235 | LOG(ERROR) << "Failed to register radio mode change callback"; |
| 1236 | } |
chenpaul | f5eca29 | 2019-03-14 11:08:03 +0800 | [diff] [blame] | 1237 | // Extract and save the version information into property. |
| 1238 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> version_info; |
| 1239 | version_info = WifiChip::requestChipDebugInfoInternal(); |
| 1240 | if (WifiStatusCode::SUCCESS == version_info.first.code) { |
| 1241 | property_set("vendor.wlan.firmware.version", |
| 1242 | version_info.second.firmwareDescription.c_str()); |
| 1243 | property_set("vendor.wlan.driver.version", |
| 1244 | version_info.second.driverDescription.c_str()); |
| 1245 | } |
| 1246 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1247 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1248 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1249 | |
| 1250 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1251 | if (debug_ring_buffer_cb_registered_) { |
| 1252 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1253 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 1254 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1255 | android::wp<WifiChip> weak_ptr_this(this); |
| 1256 | const auto& on_ring_buffer_data_callback = |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1257 | [weak_ptr_this](const std::string& name, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1258 | const std::vector<uint8_t>& data, |
| 1259 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 1260 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1261 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1262 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1263 | return; |
| 1264 | } |
| 1265 | WifiDebugRingBufferStatus hidl_status; |
| 1266 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 1267 | status, &hidl_status)) { |
| 1268 | LOG(ERROR) << "Error converting ring buffer status"; |
| 1269 | return; |
| 1270 | } |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1271 | const auto& target = shared_ptr_this->ringbuffer_map_.find(name); |
| 1272 | if (target != shared_ptr_this->ringbuffer_map_.end()) { |
| 1273 | Ringbuffer& cur_buffer = target->second; |
| 1274 | cur_buffer.append(data); |
| 1275 | } else { |
| 1276 | LOG(ERROR) << "Ringname " << name << " not found"; |
| 1277 | return; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1278 | } |
| 1279 | }; |
| 1280 | legacy_hal::wifi_error legacy_status = |
| 1281 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1282 | getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1283 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1284 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1285 | debug_ring_buffer_cb_registered_ = true; |
| 1286 | } |
| 1287 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1290 | WifiStatus WifiChip::registerRadioModeChangeCallback() { |
| 1291 | android::wp<WifiChip> weak_ptr_this(this); |
| 1292 | const auto& on_radio_mode_change_callback = |
| 1293 | [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) { |
| 1294 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1295 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1296 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1297 | return; |
| 1298 | } |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1299 | std::vector<IWifiChipEventCallback::RadioModeInfo> |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1300 | hidl_radio_mode_infos; |
| 1301 | if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl( |
| 1302 | mac_infos, &hidl_radio_mode_infos)) { |
| 1303 | LOG(ERROR) << "Error converting wifi mac info"; |
| 1304 | return; |
| 1305 | } |
| 1306 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1307 | if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos) |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1308 | .isOk()) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1309 | LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4" |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1310 | << " callback on: " << toString(callback); |
| 1311 | } |
| 1312 | } |
| 1313 | }; |
| 1314 | legacy_hal::wifi_error legacy_status = |
| 1315 | legacy_hal_.lock()->registerRadioModeChangeCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1316 | getFirstActiveWlanIfaceName(), on_radio_mode_change_callback); |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1317 | return createWifiStatusFromLegacyError(legacy_status); |
| 1318 | } |
| 1319 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1320 | std::vector<IWifiChip::ChipIfaceCombination> |
| 1321 | WifiChip::getCurrentModeIfaceCombinations() { |
| 1322 | if (!isValidModeId(current_mode_id_)) { |
| 1323 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1324 | return {}; |
| 1325 | } |
| 1326 | for (const auto& mode : modes_) { |
| 1327 | if (mode.id == current_mode_id_) { |
| 1328 | return mode.availableCombinations; |
| 1329 | } |
| 1330 | } |
| 1331 | CHECK(0) << "Expected to find iface combinations for current mode!"; |
| 1332 | return {}; |
| 1333 | } |
| 1334 | |
| 1335 | // Returns a map indexed by IfaceType with the number of ifaces currently |
| 1336 | // created of the corresponding type. |
| 1337 | std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() { |
| 1338 | std::map<IfaceType, size_t> iface_counts; |
| 1339 | iface_counts[IfaceType::AP] = ap_ifaces_.size(); |
| 1340 | iface_counts[IfaceType::NAN] = nan_ifaces_.size(); |
| 1341 | iface_counts[IfaceType::P2P] = p2p_ifaces_.size(); |
| 1342 | iface_counts[IfaceType::STA] = sta_ifaces_.size(); |
| 1343 | return iface_counts; |
| 1344 | } |
| 1345 | |
| 1346 | // This expands the provided iface combinations to a more parseable |
| 1347 | // form. Returns a vector of available combinations possible with the number |
| 1348 | // of ifaces of each type in the combination. |
| 1349 | // This method is a port of HalDeviceManager.expandIfaceCombos() from framework. |
| 1350 | std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations( |
| 1351 | const IWifiChip::ChipIfaceCombination& combination) { |
| 1352 | uint32_t num_expanded_combos = 1; |
| 1353 | for (const auto& limit : combination.limits) { |
| 1354 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1355 | num_expanded_combos *= limit.types.size(); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | // Allocate the vector of expanded combos and reset all iface counts to 0 |
| 1360 | // in each combo. |
| 1361 | std::vector<std::map<IfaceType, size_t>> expanded_combos; |
| 1362 | expanded_combos.resize(num_expanded_combos); |
| 1363 | for (auto& expanded_combo : expanded_combos) { |
| 1364 | for (const auto type : |
| 1365 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1366 | expanded_combo[type] = 0; |
| 1367 | } |
| 1368 | } |
| 1369 | uint32_t span = num_expanded_combos; |
| 1370 | for (const auto& limit : combination.limits) { |
| 1371 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1372 | span /= limit.types.size(); |
| 1373 | for (uint32_t k = 0; k < num_expanded_combos; ++k) { |
| 1374 | const auto iface_type = |
| 1375 | limit.types[(k / span) % limit.types.size()]; |
| 1376 | expanded_combos[k][iface_type]++; |
| 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | return expanded_combos; |
| 1381 | } |
| 1382 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1383 | bool WifiChip::canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces( |
| 1384 | const std::map<IfaceType, size_t>& expanded_combo, |
| 1385 | IfaceType requested_type) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1386 | const auto current_combo = getCurrentIfaceCombination(); |
| 1387 | |
| 1388 | // Check if we have space for 1 more iface of |type| in this combo |
| 1389 | for (const auto type : |
| 1390 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1391 | size_t num_ifaces_needed = current_combo.at(type); |
| 1392 | if (type == requested_type) { |
| 1393 | num_ifaces_needed++; |
| 1394 | } |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1395 | size_t num_ifaces_allowed = expanded_combo.at(type); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1396 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1397 | return false; |
| 1398 | } |
| 1399 | } |
| 1400 | return true; |
| 1401 | } |
| 1402 | |
| 1403 | // This method does the following: |
| 1404 | // a) Enumerate all possible iface combos by expanding the current |
| 1405 | // ChipIfaceCombination. |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1406 | // b) Check if the requested iface type can be added to the current mode |
| 1407 | // with the iface combination that is already active. |
| 1408 | bool WifiChip::canCurrentModeSupportIfaceOfTypeWithCurrentIfaces( |
| 1409 | IfaceType requested_type) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1410 | if (!isValidModeId(current_mode_id_)) { |
| 1411 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1412 | return false; |
| 1413 | } |
| 1414 | const auto combinations = getCurrentModeIfaceCombinations(); |
| 1415 | for (const auto& combination : combinations) { |
| 1416 | const auto expanded_combos = expandIfaceCombinations(combination); |
| 1417 | for (const auto& expanded_combo : expanded_combos) { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1418 | if (canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces( |
| 1419 | expanded_combo, requested_type)) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1420 | return true; |
| 1421 | } |
| 1422 | } |
| 1423 | } |
| 1424 | return false; |
| 1425 | } |
| 1426 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1427 | // Note: This does not consider ifaces already active. It only checks if the |
| 1428 | // provided expanded iface combination can support the requested combo. |
| 1429 | bool WifiChip::canExpandedIfaceComboSupportIfaceCombo( |
| 1430 | const std::map<IfaceType, size_t>& expanded_combo, |
| 1431 | const std::map<IfaceType, size_t>& req_combo) { |
| 1432 | // Check if we have space for 1 more iface of |type| in this combo |
| 1433 | for (const auto type : |
| 1434 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1435 | if (req_combo.count(type) == 0) { |
| 1436 | // Iface of "type" not in the req_combo. |
| 1437 | continue; |
| 1438 | } |
| 1439 | size_t num_ifaces_needed = req_combo.at(type); |
| 1440 | size_t num_ifaces_allowed = expanded_combo.at(type); |
| 1441 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1442 | return false; |
| 1443 | } |
| 1444 | } |
| 1445 | return true; |
| 1446 | } |
| 1447 | // This method does the following: |
| 1448 | // a) Enumerate all possible iface combos by expanding the current |
| 1449 | // ChipIfaceCombination. |
| 1450 | // b) Check if the requested iface combo can be added to the current mode. |
| 1451 | // Note: This does not consider ifaces already active. It only checks if the |
| 1452 | // current mode can support the requested combo. |
| 1453 | bool WifiChip::canCurrentModeSupportIfaceCombo( |
| 1454 | const std::map<IfaceType, size_t>& req_combo) { |
| 1455 | if (!isValidModeId(current_mode_id_)) { |
| 1456 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1457 | return false; |
| 1458 | } |
| 1459 | const auto combinations = getCurrentModeIfaceCombinations(); |
| 1460 | for (const auto& combination : combinations) { |
| 1461 | const auto expanded_combos = expandIfaceCombinations(combination); |
| 1462 | for (const auto& expanded_combo : expanded_combos) { |
| 1463 | if (canExpandedIfaceComboSupportIfaceCombo(expanded_combo, |
| 1464 | req_combo)) { |
| 1465 | return true; |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | return false; |
| 1470 | } |
| 1471 | |
| 1472 | // This method does the following: |
| 1473 | // a) Enumerate all possible iface combos by expanding the current |
| 1474 | // ChipIfaceCombination. |
| 1475 | // b) Check if the requested iface type can be added to the current mode. |
| 1476 | bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType requested_type) { |
| 1477 | // Check if we can support atleast 1 iface of type. |
| 1478 | std::map<IfaceType, size_t> req_iface_combo; |
| 1479 | req_iface_combo[requested_type] = 1; |
| 1480 | return canCurrentModeSupportIfaceCombo(req_iface_combo); |
| 1481 | } |
| 1482 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1483 | bool WifiChip::isValidModeId(ChipModeId mode_id) { |
| 1484 | for (const auto& mode : modes_) { |
| 1485 | if (mode.id == mode_id) { |
| 1486 | return true; |
| 1487 | } |
| 1488 | } |
| 1489 | return false; |
| 1490 | } |
| 1491 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1492 | bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() { |
| 1493 | // Check if we can support atleast 1 STA & 1 AP concurrently. |
| 1494 | std::map<IfaceType, size_t> req_iface_combo; |
| 1495 | req_iface_combo[IfaceType::AP] = 1; |
| 1496 | req_iface_combo[IfaceType::STA] = 1; |
| 1497 | return canCurrentModeSupportIfaceCombo(req_iface_combo); |
| 1498 | } |
| 1499 | |
James Mattis | d2e4c07 | 2019-05-22 16:14:48 -0700 | [diff] [blame] | 1500 | bool WifiChip::isDualApAllowedInCurrentMode() { |
| 1501 | // Check if we can support atleast 1 STA & 1 AP concurrently. |
| 1502 | std::map<IfaceType, size_t> req_iface_combo; |
| 1503 | req_iface_combo[IfaceType::AP] = 2; |
| 1504 | return canCurrentModeSupportIfaceCombo(req_iface_combo); |
| 1505 | } |
| 1506 | |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1507 | std::string WifiChip::getFirstActiveWlanIfaceName() { |
Roshan Pius | 444473f | 2019-04-19 08:41:20 -0700 | [diff] [blame] | 1508 | if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName(); |
| 1509 | if (ap_ifaces_.size() > 0) return ap_ifaces_[0]->getName(); |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1510 | // This could happen if the chip call is made before any STA/AP |
| 1511 | // iface is created. Default to wlan0 for such cases. |
Roshan Pius | 444473f | 2019-04-19 08:41:20 -0700 | [diff] [blame] | 1512 | LOG(WARNING) << "No active wlan interfaces in use! Using default"; |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1513 | return getWlanIfaceName(0); |
| 1514 | } |
| 1515 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1516 | // Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx| |
| 1517 | // not already in use. |
| 1518 | // Note: This doesn't check the actual presence of these interfaces. |
| 1519 | std::string WifiChip::allocateApOrStaIfaceName(uint32_t start_idx) { |
| 1520 | for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) { |
| 1521 | const auto ifname = getWlanIfaceName(idx); |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 1522 | if (findUsingName(ap_ifaces_, ifname)) continue; |
| 1523 | if (findUsingName(sta_ifaces_, ifname)) continue; |
| 1524 | return ifname; |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1525 | } |
| 1526 | // This should never happen. We screwed up somewhere if it did. |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 1527 | CHECK(false) << "All wlan interfaces in use already!"; |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1528 | return {}; |
| 1529 | } |
| 1530 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1531 | // AP iface names start with idx 1 for modes supporting |
James Mattis | d2e4c07 | 2019-05-22 16:14:48 -0700 | [diff] [blame] | 1532 | // concurrent STA and not dual AP, else start with idx 0. |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1533 | std::string WifiChip::allocateApIfaceName() { |
James Mattis | d2e4c07 | 2019-05-22 16:14:48 -0700 | [diff] [blame] | 1534 | return allocateApOrStaIfaceName((isStaApConcurrencyAllowedInCurrentMode() && |
| 1535 | !isDualApAllowedInCurrentMode()) |
| 1536 | ? 1 |
| 1537 | : 0); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | // STA iface names start with idx 0. |
| 1541 | // Primary STA iface will always be 0. |
| 1542 | std::string WifiChip::allocateStaIfaceName() { |
| 1543 | return allocateApOrStaIfaceName(0); |
| 1544 | } |
| 1545 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1546 | bool WifiChip::writeRingbufferFilesInternal() { |
| 1547 | if (!removeOldFilesInternal()) { |
| 1548 | LOG(ERROR) << "Error occurred while deleting old tombstone files"; |
| 1549 | return false; |
| 1550 | } |
| 1551 | // write ringbuffers to file |
| 1552 | for (const auto& item : ringbuffer_map_) { |
| 1553 | const Ringbuffer& cur_buffer = item.second; |
| 1554 | if (cur_buffer.getData().empty()) { |
| 1555 | continue; |
| 1556 | } |
| 1557 | const std::string file_path_raw = |
| 1558 | kTombstoneFolderPath + item.first + "XXXXXXXXXX"; |
| 1559 | const int dump_fd = mkstemp(makeCharVec(file_path_raw).data()); |
| 1560 | if (dump_fd == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 1561 | PLOG(ERROR) << "create file failed"; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1562 | return false; |
| 1563 | } |
| 1564 | unique_fd file_auto_closer(dump_fd); |
| 1565 | for (const auto& cur_block : cur_buffer.getData()) { |
| 1566 | if (write(dump_fd, cur_block.data(), |
| 1567 | sizeof(cur_block[0]) * cur_block.size()) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 1568 | PLOG(ERROR) << "Error writing to file"; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | return true; |
| 1573 | } |
| 1574 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 1575 | } // namespace implementation |
Ahmed ElArabawy | f501a98 | 2019-07-23 15:02:22 -0700 | [diff] [blame] | 1576 | } // namespace V1_4 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1577 | } // namespace wifi |
| 1578 | } // namespace hardware |
| 1579 | } // namespace android |