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"; |
| 40 | constexpr size_t kMaxBufferSizeBytes = 1024 * 1024; |
| 41 | constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60; |
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 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 518 | Return<void> WifiChip::stopLoggingToDebugRingBuffer( |
| 519 | stopLoggingToDebugRingBuffer_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::stopLoggingToDebugRingBufferInternal, |
| 522 | hidl_status_cb); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 525 | Return<void> WifiChip::getDebugHostWakeReasonStats( |
| 526 | getDebugHostWakeReasonStats_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::getDebugHostWakeReasonStatsInternal, |
| 529 | hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 532 | Return<void> WifiChip::enableDebugErrorAlerts( |
| 533 | bool enable, enableDebugErrorAlerts_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::enableDebugErrorAlertsInternal, |
| 536 | hidl_status_cb, enable); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 539 | Return<void> WifiChip::selectTxPowerScenario( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 540 | V1_1::IWifiChip::TxPowerScenario scenario, |
| 541 | selectTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 542 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 543 | &WifiChip::selectTxPowerScenarioInternal, |
| 544 | hidl_status_cb, scenario); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 547 | Return<void> WifiChip::resetTxPowerScenario( |
| 548 | resetTxPowerScenario_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::resetTxPowerScenarioInternal, |
| 551 | hidl_status_cb); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 554 | Return<void> WifiChip::setLatencyMode(LatencyMode mode, |
| 555 | setLatencyMode_cb hidl_status_cb) { |
| 556 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 557 | &WifiChip::setLatencyModeInternal, hidl_status_cb, |
| 558 | mode); |
| 559 | } |
| 560 | |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 561 | Return<void> WifiChip::registerEventCallback_1_2( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 562 | const sp<V1_2::IWifiChipEventCallback>& event_callback, |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 563 | registerEventCallback_cb hidl_status_cb) { |
| 564 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 565 | &WifiChip::registerEventCallbackInternal_1_2, |
| 566 | hidl_status_cb, event_callback); |
| 567 | } |
| 568 | |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 569 | Return<void> WifiChip::selectTxPowerScenario_1_2( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 570 | TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 571 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 572 | &WifiChip::selectTxPowerScenarioInternal_1_2, |
| 573 | hidl_status_cb, scenario); |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 576 | Return<void> WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) { |
| 577 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 578 | &WifiChip::getCapabilitiesInternal_1_3, |
| 579 | hidl_status_cb); |
| 580 | } |
| 581 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 582 | Return<void> WifiChip::debug(const hidl_handle& handle, |
| 583 | const hidl_vec<hidl_string>&) { |
| 584 | if (handle != nullptr && handle->numFds >= 1) { |
| 585 | int fd = handle->data[0]; |
| 586 | if (!writeRingbufferFilesInternal()) { |
| 587 | LOG(ERROR) << "Error writing files to flash"; |
| 588 | } |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 589 | uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 590 | if (n_error != 0) { |
| 591 | LOG(ERROR) << n_error << " errors occured in cpio function"; |
| 592 | } |
| 593 | fsync(fd); |
| 594 | } else { |
| 595 | LOG(ERROR) << "File handle error"; |
| 596 | } |
| 597 | return Void(); |
| 598 | } |
| 599 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 600 | void WifiChip::invalidateAndRemoveAllIfaces() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 601 | invalidateAndClearAll(ap_ifaces_); |
| 602 | invalidateAndClearAll(nan_ifaces_); |
| 603 | invalidateAndClearAll(p2p_ifaces_); |
| 604 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 605 | // Since all the ifaces are invalid now, all RTT controller objects |
| 606 | // using those ifaces also need to be invalidated. |
| 607 | for (const auto& rtt : rtt_controllers_) { |
| 608 | rtt->invalidate(); |
| 609 | } |
| 610 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 613 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 614 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | WifiStatus WifiChip::registerEventCallbackInternal( |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 618 | const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) { |
| 619 | // Deprecated support for this callback. |
| 620 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 623 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 624 | // Deprecated support for this callback. |
| 625 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; |
| 626 | } |
| 627 | |
| 628 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 629 | legacy_hal::wifi_error legacy_status; |
| 630 | uint32_t legacy_feature_set; |
| 631 | uint32_t legacy_logger_feature_set; |
| 632 | std::tie(legacy_status, legacy_feature_set) = |
| 633 | legacy_hal_.lock()->getSupportedFeatureSet(getWlan0IfaceName()); |
| 634 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 635 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 636 | } |
| 637 | std::tie(legacy_status, legacy_logger_feature_set) = |
| 638 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(getWlan0IfaceName()); |
| 639 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Roshan Pius | 876220f | 2017-12-28 16:19:06 -0800 | [diff] [blame] | 640 | // some devices don't support querying logger feature set |
| 641 | legacy_logger_feature_set = 0; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 642 | } |
| 643 | uint32_t hidl_caps; |
| 644 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
| 645 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
| 646 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 647 | } |
| 648 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 651 | std::pair<WifiStatus, std::vector<IWifiChip::ChipMode>> |
| 652 | WifiChip::getAvailableModesInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 653 | return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 656 | WifiStatus WifiChip::configureChipInternal( |
| 657 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 658 | ChipModeId mode_id) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 659 | if (!isValidModeId(mode_id)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 660 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 661 | } |
| 662 | if (mode_id == current_mode_id_) { |
| 663 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 664 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 665 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 666 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 667 | if (status.code != WifiStatusCode::SUCCESS) { |
| 668 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 669 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
| 670 | LOG(ERROR) |
| 671 | << "Failed to invoke onChipReconfigureFailure callback"; |
| 672 | } |
| 673 | } |
| 674 | return status; |
| 675 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 676 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 677 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 678 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 679 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 680 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 681 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 682 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 683 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 687 | if (!isValidModeId(current_mode_id_)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 688 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), |
| 689 | current_mode_id_}; |
| 690 | } |
| 691 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 695 | WifiChip::requestChipDebugInfoInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 696 | IWifiChip::ChipDebugInfo result; |
| 697 | legacy_hal::wifi_error legacy_status; |
| 698 | std::string driver_desc; |
| 699 | std::tie(legacy_status, driver_desc) = |
| 700 | legacy_hal_.lock()->getDriverVersion(getWlan0IfaceName()); |
| 701 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 702 | LOG(ERROR) << "Failed to get driver version: " |
| 703 | << legacyErrorToString(legacy_status); |
| 704 | WifiStatus status = createWifiStatusFromLegacyError( |
| 705 | legacy_status, "failed to get driver version"); |
| 706 | return {status, result}; |
| 707 | } |
| 708 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 709 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 710 | std::string firmware_desc; |
| 711 | std::tie(legacy_status, firmware_desc) = |
| 712 | legacy_hal_.lock()->getFirmwareVersion(getWlan0IfaceName()); |
| 713 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 714 | LOG(ERROR) << "Failed to get firmware version: " |
| 715 | << legacyErrorToString(legacy_status); |
| 716 | WifiStatus status = createWifiStatusFromLegacyError( |
| 717 | legacy_status, "failed to get firmware version"); |
| 718 | return {status, result}; |
| 719 | } |
| 720 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 721 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 722 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 726 | WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 727 | legacy_hal::wifi_error legacy_status; |
| 728 | std::vector<uint8_t> driver_dump; |
| 729 | std::tie(legacy_status, driver_dump) = |
| 730 | legacy_hal_.lock()->requestDriverMemoryDump(getWlan0IfaceName()); |
| 731 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 732 | LOG(ERROR) << "Failed to get driver debug dump: " |
| 733 | << legacyErrorToString(legacy_status); |
| 734 | return {createWifiStatusFromLegacyError(legacy_status), |
| 735 | std::vector<uint8_t>()}; |
| 736 | } |
| 737 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 741 | WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 742 | legacy_hal::wifi_error legacy_status; |
| 743 | std::vector<uint8_t> firmware_dump; |
| 744 | std::tie(legacy_status, firmware_dump) = |
| 745 | legacy_hal_.lock()->requestFirmwareMemoryDump(getWlan0IfaceName()); |
| 746 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 747 | LOG(ERROR) << "Failed to get firmware debug dump: " |
| 748 | << legacyErrorToString(legacy_status); |
| 749 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 750 | } |
| 751 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 755 | if (!canCurrentModeSupportIfaceOfType(IfaceType::AP)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 756 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 757 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 758 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 759 | sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_); |
| 760 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 761 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 762 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 763 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 764 | } |
| 765 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 766 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 770 | WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 771 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 772 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 773 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 774 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 778 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 779 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 780 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 781 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 782 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 783 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 786 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 787 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 788 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 789 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 790 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 791 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 792 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 793 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 794 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 795 | } |
| 796 | } |
| 797 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 798 | } |
| 799 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 800 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 801 | if (!canCurrentModeSupportIfaceOfType(IfaceType::NAN)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 802 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 803 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 804 | // These are still assumed to be based on wlan0. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 805 | std::string ifname = getWlan0IfaceName(); |
| 806 | sp<WifiNanIface> iface = new WifiNanIface(ifname, legacy_hal_); |
| 807 | nan_ifaces_.push_back(iface); |
| 808 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 809 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 810 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 811 | } |
| 812 | } |
| 813 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 817 | WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 818 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 819 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 820 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 821 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 825 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 826 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 827 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 828 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 829 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 830 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 833 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 834 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 835 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 836 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 837 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 838 | invalidateAndClear(nan_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::NAN, ifname).isOk()) { |
| 841 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 842 | } |
| 843 | } |
| 844 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 847 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 848 | if (!canCurrentModeSupportIfaceOfType(IfaceType::P2P)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 849 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 850 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 851 | std::string ifname = getP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 852 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 853 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 854 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 855 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 856 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 857 | } |
| 858 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 859 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 863 | WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 864 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 865 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 866 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 867 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 871 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 872 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 873 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 874 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 875 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 876 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 879 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 880 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 881 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 882 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 883 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 884 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 885 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 886 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 887 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 888 | } |
| 889 | } |
| 890 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 893 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 894 | if (!canCurrentModeSupportIfaceOfType(IfaceType::STA)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 895 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 896 | } |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 897 | std::string ifname = allocateApOrStaIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 898 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_); |
| 899 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 900 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 901 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 902 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 903 | } |
| 904 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 905 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | std::pair<WifiStatus, std::vector<hidl_string>> |
| 909 | WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 910 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 911 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 912 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 913 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 917 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 918 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 919 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 920 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 921 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 922 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 925 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 926 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 927 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 928 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 929 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 930 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 931 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 932 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 933 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 934 | } |
| 935 | } |
| 936 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 937 | } |
| 938 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 939 | std::pair<WifiStatus, sp<IWifiRttController>> |
| 940 | WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) { |
Etan Cohen | 7240a1a | 2018-08-29 08:14:09 -0700 | [diff] [blame] | 941 | if (sta_ifaces_.size() == 0 && |
| 942 | !canCurrentModeSupportIfaceOfType(IfaceType::STA)) { |
| 943 | LOG(ERROR) << "createRttControllerInternal: Chip cannot support STAs " |
| 944 | "(and RTT by extension)"; |
| 945 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 946 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 947 | sp<WifiRttController> rtt = |
| 948 | new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_); |
| 949 | rtt_controllers_.emplace_back(rtt); |
| 950 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 951 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 952 | |
| 953 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 954 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 955 | legacy_hal::wifi_error legacy_status; |
| 956 | std::vector<legacy_hal::wifi_ring_buffer_status> |
| 957 | legacy_ring_buffer_status_vec; |
| 958 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
| 959 | legacy_hal_.lock()->getRingBuffersStatus(getWlan0IfaceName()); |
| 960 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 961 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 962 | } |
| 963 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 964 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
| 965 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
| 966 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 967 | } |
| 968 | return {createWifiStatus(WifiStatusCode::SUCCESS), |
| 969 | hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 973 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 974 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
| 975 | WifiStatus status = registerDebugRingBufferCallback(); |
| 976 | if (status.code != WifiStatusCode::SUCCESS) { |
| 977 | return status; |
| 978 | } |
| 979 | legacy_hal::wifi_error legacy_status = |
| 980 | legacy_hal_.lock()->startRingBufferLogging( |
| 981 | getWlan0IfaceName(), ring_name, |
| 982 | static_cast< |
| 983 | std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>( |
| 984 | verbose_level), |
| 985 | max_interval_in_sec, min_data_size_in_bytes); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 986 | ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>( |
| 987 | ring_name, Ringbuffer(kMaxBufferSizeBytes))); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 988 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal( |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 992 | const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 993 | WifiStatus status = registerDebugRingBufferCallback(); |
| 994 | if (status.code != WifiStatusCode::SUCCESS) { |
| 995 | return status; |
| 996 | } |
| 997 | legacy_hal::wifi_error legacy_status = |
| 998 | legacy_hal_.lock()->getRingBufferData(getWlan0IfaceName(), ring_name); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 999 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1000 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1003 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1004 | legacy_hal::wifi_error legacy_status = |
| 1005 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler( |
| 1006 | getWlan0IfaceName()); |
| 1007 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1010 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 1011 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1012 | legacy_hal::wifi_error legacy_status; |
| 1013 | legacy_hal::WakeReasonStats legacy_stats; |
| 1014 | std::tie(legacy_status, legacy_stats) = |
| 1015 | legacy_hal_.lock()->getWakeReasonStats(getWlan0IfaceName()); |
| 1016 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1017 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1018 | } |
| 1019 | WifiDebugHostWakeReasonStats hidl_stats; |
| 1020 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, |
| 1021 | &hidl_stats)) { |
| 1022 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1023 | } |
| 1024 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1027 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1028 | legacy_hal::wifi_error legacy_status; |
| 1029 | if (enable) { |
| 1030 | android::wp<WifiChip> weak_ptr_this(this); |
| 1031 | const auto& on_alert_callback = [weak_ptr_this]( |
| 1032 | int32_t error_code, |
| 1033 | std::vector<uint8_t> debug_data) { |
| 1034 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1035 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1036 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1037 | return; |
| 1038 | } |
| 1039 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1040 | if (!callback->onDebugErrorAlert(error_code, debug_data) |
| 1041 | .isOk()) { |
| 1042 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 1043 | } |
| 1044 | } |
| 1045 | }; |
| 1046 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1047 | getWlan0IfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1048 | } else { |
| 1049 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Roshan Pius | acededb | 2017-10-06 14:59:26 -0700 | [diff] [blame] | 1050 | getWlan0IfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1051 | } |
| 1052 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1053 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1054 | |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1055 | WifiStatus WifiChip::selectTxPowerScenarioInternal( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1056 | V1_1::IWifiChip::TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1057 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 1058 | getWlan0IfaceName(), |
| 1059 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
| 1060 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 1063 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1064 | auto legacy_status = |
| 1065 | legacy_hal_.lock()->resetTxPowerScenario(getWlan0IfaceName()); |
| 1066 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 1069 | WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) { |
| 1070 | auto legacy_status = legacy_hal_.lock()->setLatencyMode( |
| 1071 | getWlan0IfaceName(), |
| 1072 | hidl_struct_util::convertHidlLatencyModeToLegacy(mode)); |
| 1073 | return createWifiStatusFromLegacyError(legacy_status); |
| 1074 | } |
| 1075 | |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1076 | WifiStatus WifiChip::registerEventCallbackInternal_1_2( |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1077 | const sp<V1_2::IWifiChipEventCallback>& event_callback) { |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1078 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 1079 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1080 | } |
| 1081 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1082 | } |
| 1083 | |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1084 | WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2( |
| 1085 | TxPowerScenario scenario) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1086 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
| 1087 | getWlan0IfaceName(), |
| 1088 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario)); |
| 1089 | return createWifiStatusFromLegacyError(legacy_status); |
| 1090 | } |
| 1091 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1092 | WifiStatus WifiChip::handleChipConfiguration( |
| 1093 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, |
| 1094 | ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1095 | // If the chip is already configured in a different mode, stop |
| 1096 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1097 | if (isValidModeId(current_mode_id_)) { |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1098 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ |
| 1099 | << " to mode " << mode_id; |
| 1100 | invalidateAndRemoveAllIfaces(); |
| 1101 | legacy_hal::wifi_error legacy_status = |
| 1102 | legacy_hal_.lock()->stop(lock, []() {}); |
| 1103 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1104 | LOG(ERROR) << "Failed to stop legacy HAL: " |
| 1105 | << legacyErrorToString(legacy_status); |
| 1106 | return createWifiStatusFromLegacyError(legacy_status); |
| 1107 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1108 | } |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1109 | // Firmware mode change not needed for V2 devices. |
| 1110 | bool success = true; |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1111 | if (mode_id == feature_flags::chip_mode_ids::kV1Sta) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1112 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1113 | } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1114 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 1115 | } |
| 1116 | if (!success) { |
| 1117 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1118 | } |
| 1119 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 1120 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1121 | LOG(ERROR) << "Failed to start legacy HAL: " |
| 1122 | << legacyErrorToString(legacy_status); |
| 1123 | return createWifiStatusFromLegacyError(legacy_status); |
| 1124 | } |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1125 | // Every time the HAL is restarted, we need to register the |
| 1126 | // radio mode change callback. |
| 1127 | WifiStatus status = registerRadioModeChangeCallback(); |
| 1128 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1129 | // This probably is not a critical failure? |
| 1130 | LOG(ERROR) << "Failed to register radio mode change callback"; |
| 1131 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1132 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1133 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1134 | |
| 1135 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1136 | if (debug_ring_buffer_cb_registered_) { |
| 1137 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1138 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 1139 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1140 | android::wp<WifiChip> weak_ptr_this(this); |
| 1141 | const auto& on_ring_buffer_data_callback = |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1142 | [weak_ptr_this](const std::string& name, |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1143 | const std::vector<uint8_t>& data, |
| 1144 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 1145 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1146 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1147 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1148 | return; |
| 1149 | } |
| 1150 | WifiDebugRingBufferStatus hidl_status; |
| 1151 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl( |
| 1152 | status, &hidl_status)) { |
| 1153 | LOG(ERROR) << "Error converting ring buffer status"; |
| 1154 | return; |
| 1155 | } |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1156 | const auto& target = shared_ptr_this->ringbuffer_map_.find(name); |
| 1157 | if (target != shared_ptr_this->ringbuffer_map_.end()) { |
| 1158 | Ringbuffer& cur_buffer = target->second; |
| 1159 | cur_buffer.append(data); |
| 1160 | } else { |
| 1161 | LOG(ERROR) << "Ringname " << name << " not found"; |
| 1162 | return; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1163 | } |
| 1164 | }; |
| 1165 | legacy_hal::wifi_error legacy_status = |
| 1166 | legacy_hal_.lock()->registerRingBufferCallbackHandler( |
| 1167 | getWlan0IfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1168 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1169 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1170 | debug_ring_buffer_cb_registered_ = true; |
| 1171 | } |
| 1172 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1175 | WifiStatus WifiChip::registerRadioModeChangeCallback() { |
| 1176 | android::wp<WifiChip> weak_ptr_this(this); |
| 1177 | const auto& on_radio_mode_change_callback = |
| 1178 | [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) { |
| 1179 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1180 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1181 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1182 | return; |
| 1183 | } |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1184 | std::vector<V1_2::IWifiChipEventCallback::RadioModeInfo> |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1185 | hidl_radio_mode_infos; |
| 1186 | if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl( |
| 1187 | mac_infos, &hidl_radio_mode_infos)) { |
| 1188 | LOG(ERROR) << "Error converting wifi mac info"; |
| 1189 | return; |
| 1190 | } |
| 1191 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1192 | if (!callback->onRadioModeChange(hidl_radio_mode_infos) |
| 1193 | .isOk()) { |
| 1194 | LOG(ERROR) << "Failed to invoke onRadioModeChange" |
| 1195 | << " callback on: " << toString(callback); |
| 1196 | } |
| 1197 | } |
| 1198 | }; |
| 1199 | legacy_hal::wifi_error legacy_status = |
| 1200 | legacy_hal_.lock()->registerRadioModeChangeCallbackHandler( |
| 1201 | getWlan0IfaceName(), on_radio_mode_change_callback); |
| 1202 | return createWifiStatusFromLegacyError(legacy_status); |
| 1203 | } |
| 1204 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1205 | std::vector<IWifiChip::ChipIfaceCombination> |
| 1206 | WifiChip::getCurrentModeIfaceCombinations() { |
| 1207 | if (!isValidModeId(current_mode_id_)) { |
| 1208 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1209 | return {}; |
| 1210 | } |
| 1211 | for (const auto& mode : modes_) { |
| 1212 | if (mode.id == current_mode_id_) { |
| 1213 | return mode.availableCombinations; |
| 1214 | } |
| 1215 | } |
| 1216 | CHECK(0) << "Expected to find iface combinations for current mode!"; |
| 1217 | return {}; |
| 1218 | } |
| 1219 | |
| 1220 | // Returns a map indexed by IfaceType with the number of ifaces currently |
| 1221 | // created of the corresponding type. |
| 1222 | std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() { |
| 1223 | std::map<IfaceType, size_t> iface_counts; |
| 1224 | iface_counts[IfaceType::AP] = ap_ifaces_.size(); |
| 1225 | iface_counts[IfaceType::NAN] = nan_ifaces_.size(); |
| 1226 | iface_counts[IfaceType::P2P] = p2p_ifaces_.size(); |
| 1227 | iface_counts[IfaceType::STA] = sta_ifaces_.size(); |
| 1228 | return iface_counts; |
| 1229 | } |
| 1230 | |
| 1231 | // This expands the provided iface combinations to a more parseable |
| 1232 | // form. Returns a vector of available combinations possible with the number |
| 1233 | // of ifaces of each type in the combination. |
| 1234 | // This method is a port of HalDeviceManager.expandIfaceCombos() from framework. |
| 1235 | std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations( |
| 1236 | const IWifiChip::ChipIfaceCombination& combination) { |
| 1237 | uint32_t num_expanded_combos = 1; |
| 1238 | for (const auto& limit : combination.limits) { |
| 1239 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1240 | num_expanded_combos *= limit.types.size(); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | // Allocate the vector of expanded combos and reset all iface counts to 0 |
| 1245 | // in each combo. |
| 1246 | std::vector<std::map<IfaceType, size_t>> expanded_combos; |
| 1247 | expanded_combos.resize(num_expanded_combos); |
| 1248 | for (auto& expanded_combo : expanded_combos) { |
| 1249 | for (const auto type : |
| 1250 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1251 | expanded_combo[type] = 0; |
| 1252 | } |
| 1253 | } |
| 1254 | uint32_t span = num_expanded_combos; |
| 1255 | for (const auto& limit : combination.limits) { |
| 1256 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1257 | span /= limit.types.size(); |
| 1258 | for (uint32_t k = 0; k < num_expanded_combos; ++k) { |
| 1259 | const auto iface_type = |
| 1260 | limit.types[(k / span) % limit.types.size()]; |
| 1261 | expanded_combos[k][iface_type]++; |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | return expanded_combos; |
| 1266 | } |
| 1267 | |
| 1268 | bool WifiChip::canExpandedIfaceCombinationSupportIfaceOfType( |
| 1269 | const std::map<IfaceType, size_t>& combo, IfaceType requested_type) { |
| 1270 | const auto current_combo = getCurrentIfaceCombination(); |
| 1271 | |
| 1272 | // Check if we have space for 1 more iface of |type| in this combo |
| 1273 | for (const auto type : |
| 1274 | {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) { |
| 1275 | size_t num_ifaces_needed = current_combo.at(type); |
| 1276 | if (type == requested_type) { |
| 1277 | num_ifaces_needed++; |
| 1278 | } |
| 1279 | size_t num_ifaces_allowed = combo.at(type); |
| 1280 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1281 | return false; |
| 1282 | } |
| 1283 | } |
| 1284 | return true; |
| 1285 | } |
| 1286 | |
| 1287 | // This method does the following: |
| 1288 | // a) Enumerate all possible iface combos by expanding the current |
| 1289 | // ChipIfaceCombination. |
| 1290 | // b) Check if the requested iface type can be added to the current mode. |
| 1291 | bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType type) { |
| 1292 | if (!isValidModeId(current_mode_id_)) { |
| 1293 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1294 | return false; |
| 1295 | } |
| 1296 | const auto combinations = getCurrentModeIfaceCombinations(); |
| 1297 | for (const auto& combination : combinations) { |
| 1298 | const auto expanded_combos = expandIfaceCombinations(combination); |
| 1299 | for (const auto& expanded_combo : expanded_combos) { |
| 1300 | if (canExpandedIfaceCombinationSupportIfaceOfType(expanded_combo, |
| 1301 | type)) { |
| 1302 | return true; |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
| 1309 | bool WifiChip::isValidModeId(ChipModeId mode_id) { |
| 1310 | for (const auto& mode : modes_) { |
| 1311 | if (mode.id == mode_id) { |
| 1312 | return true; |
| 1313 | } |
| 1314 | } |
| 1315 | return false; |
| 1316 | } |
| 1317 | |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1318 | // Return "wlan0", if "wlan0" is not already in use, else return "wlan1". |
| 1319 | // This is based on the assumption that we'll have a max of 2 concurrent |
| 1320 | // AP/STA ifaces. |
| 1321 | std::string WifiChip::allocateApOrStaIfaceName() { |
| 1322 | auto ap_iface = findUsingName(ap_ifaces_, getWlan0IfaceName()); |
| 1323 | auto sta_iface = findUsingName(sta_ifaces_, getWlan0IfaceName()); |
| 1324 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1325 | return getWlan0IfaceName(); |
| 1326 | } |
| 1327 | ap_iface = findUsingName(ap_ifaces_, getWlan1IfaceName()); |
| 1328 | sta_iface = findUsingName(sta_ifaces_, getWlan1IfaceName()); |
| 1329 | if (!ap_iface.get() && !sta_iface.get()) { |
| 1330 | return getWlan1IfaceName(); |
| 1331 | } |
| 1332 | // This should never happen. We screwed up somewhere if it did. |
| 1333 | CHECK(0) << "wlan0 and wlan1 in use already!"; |
| 1334 | return {}; |
| 1335 | } |
| 1336 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1337 | bool WifiChip::writeRingbufferFilesInternal() { |
| 1338 | if (!removeOldFilesInternal()) { |
| 1339 | LOG(ERROR) << "Error occurred while deleting old tombstone files"; |
| 1340 | return false; |
| 1341 | } |
| 1342 | // write ringbuffers to file |
| 1343 | for (const auto& item : ringbuffer_map_) { |
| 1344 | const Ringbuffer& cur_buffer = item.second; |
| 1345 | if (cur_buffer.getData().empty()) { |
| 1346 | continue; |
| 1347 | } |
| 1348 | const std::string file_path_raw = |
| 1349 | kTombstoneFolderPath + item.first + "XXXXXXXXXX"; |
| 1350 | const int dump_fd = mkstemp(makeCharVec(file_path_raw).data()); |
| 1351 | if (dump_fd == -1) { |
| 1352 | LOG(ERROR) << "create file failed: " << strerror(errno); |
| 1353 | return false; |
| 1354 | } |
| 1355 | unique_fd file_auto_closer(dump_fd); |
| 1356 | for (const auto& cur_block : cur_buffer.getData()) { |
| 1357 | if (write(dump_fd, cur_block.data(), |
| 1358 | sizeof(cur_block[0]) * cur_block.size()) == -1) { |
| 1359 | LOG(ERROR) << "Error writing to file " << strerror(errno); |
| 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 1366 | } // namespace implementation |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 1367 | } // namespace V1_3 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1368 | } // namespace wifi |
| 1369 | } // namespace hardware |
| 1370 | } // namespace android |