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