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