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