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> |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 22 | #include <net/if.h> |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 23 | #include <sys/stat.h> |
| 24 | #include <sys/sysmacros.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 25 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 26 | #include "hidl_return_util.h" |
Roshan Pius | e2d0ab5 | 2016-12-05 15:24:20 -0800 | [diff] [blame] | 27 | #include "hidl_struct_util.h" |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 28 | #include "wifi_chip.h" |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 29 | #include "wifi_status_util.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 30 | |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 31 | #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" |
| 32 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 33 | namespace { |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 34 | using android::sp; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 35 | using android::base::unique_fd; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 36 | using android::hardware::hidl_string; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 37 | using android::hardware::hidl_vec; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 38 | using android::hardware::wifi::V1_0::ChipModeId; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 39 | using android::hardware::wifi::V1_0::IfaceType; |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 40 | using android::hardware::wifi::V1_0::IWifiChip; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 41 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 42 | constexpr char kCpioMagic[] = "070701"; |
Roger Wang | b294c76 | 2018-11-02 15:34:39 +0800 | [diff] [blame] | 43 | constexpr size_t kMaxBufferSizeBytes = 1024 * 1024 * 3; |
| 44 | constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60 * 10; |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 45 | constexpr uint32_t kMaxRingBufferFileNum = 20; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 46 | constexpr char kTombstoneFolderPath[] = "/data/vendor/tombstones/wifi/"; |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 47 | constexpr char kActiveWlanIfaceNameProperty[] = "wifi.active.interface"; |
| 48 | constexpr char kNoActiveWlanIfaceNamePropertyValue[] = ""; |
| 49 | constexpr unsigned kMaxWlanIfaces = 5; |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 50 | constexpr char kApBridgeIfacePrefix[] = "ap_br_"; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 51 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 52 | template <typename Iface> |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 53 | void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) { |
| 54 | iface->invalidate(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 55 | ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), ifaces.end()); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | template <typename Iface> |
| 59 | void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) { |
| 60 | for (const auto& iface : ifaces) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 61 | iface->invalidate(); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 62 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 63 | ifaces.clear(); |
| 64 | } |
| 65 | |
| 66 | template <typename Iface> |
| 67 | std::vector<hidl_string> getNames(std::vector<sp<Iface>>& ifaces) { |
| 68 | std::vector<hidl_string> names; |
| 69 | for (const auto& iface : ifaces) { |
| 70 | names.emplace_back(iface->getName()); |
| 71 | } |
| 72 | return names; |
| 73 | } |
| 74 | |
| 75 | template <typename Iface> |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 76 | sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces, const std::string& name) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 77 | std::vector<hidl_string> names; |
| 78 | for (const auto& iface : ifaces) { |
| 79 | if (name == iface->getName()) { |
| 80 | return iface; |
| 81 | } |
| 82 | } |
| 83 | return nullptr; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 84 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 85 | |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 86 | std::string getWlanIfaceName(unsigned idx) { |
| 87 | if (idx >= kMaxWlanIfaces) { |
| 88 | CHECK(false) << "Requested interface beyond wlan" << kMaxWlanIfaces; |
| 89 | return {}; |
| 90 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 91 | |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 92 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 93 | if (idx == 0 || idx == 1) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 94 | const char* altPropName = (idx == 0) ? "wifi.interface" : "wifi.concurrent.interface"; |
Roshan Pius | 5b33346 | 2019-03-01 14:07:22 -0800 | [diff] [blame] | 95 | auto res = property_get(altPropName, buffer.data(), nullptr); |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 96 | if (res > 0) return buffer.data(); |
| 97 | } |
Roshan Pius | 5b33346 | 2019-03-01 14:07:22 -0800 | [diff] [blame] | 98 | std::string propName = "wifi.interface." + std::to_string(idx); |
| 99 | auto res = property_get(propName.c_str(), buffer.data(), nullptr); |
| 100 | if (res > 0) return buffer.data(); |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 101 | |
| 102 | return "wlan" + std::to_string(idx); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 103 | } |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 104 | |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 105 | // Returns the dedicated iface name if defined. |
| 106 | // Returns two ifaces in bridged mode. |
| 107 | std::vector<std::string> getPredefinedApIfaceNames(bool is_bridged) { |
| 108 | std::vector<std::string> ifnames; |
Roshan Pius | 78cb599 | 2020-04-30 12:39:21 -0700 | [diff] [blame] | 109 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 110 | buffer.fill(0); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 111 | if (property_get("ro.vendor.wifi.sap.interface", buffer.data(), nullptr) == 0) { |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 112 | return ifnames; |
Roshan Pius | 78cb599 | 2020-04-30 12:39:21 -0700 | [diff] [blame] | 113 | } |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 114 | ifnames.push_back(buffer.data()); |
| 115 | if (is_bridged) { |
| 116 | buffer.fill(0); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 117 | if (property_get("ro.vendor.wifi.sap.concurrent.iface", buffer.data(), nullptr) == 0) { |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 118 | return ifnames; |
| 119 | } |
| 120 | ifnames.push_back(buffer.data()); |
| 121 | } |
| 122 | return ifnames; |
Roshan Pius | 78cb599 | 2020-04-30 12:39:21 -0700 | [diff] [blame] | 123 | } |
| 124 | |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 125 | std::string getPredefinedP2pIfaceName() { |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 126 | std::array<char, PROPERTY_VALUE_MAX> primaryIfaceName; |
| 127 | char p2pParentIfname[100]; |
| 128 | std::string p2pDevIfName = ""; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 129 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 130 | property_get("wifi.direct.interface", buffer.data(), "p2p0"); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 131 | if (strncmp(buffer.data(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) { |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 132 | /* Get the p2p parent interface name from p2p device interface name set |
| 133 | * in property */ |
| 134 | strncpy(p2pParentIfname, buffer.data() + strlen(P2P_MGMT_DEVICE_PREFIX), |
| 135 | strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX)); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 136 | if (property_get(kActiveWlanIfaceNameProperty, primaryIfaceName.data(), nullptr) == 0) { |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 137 | return buffer.data(); |
| 138 | } |
| 139 | /* Check if the parent interface derived from p2p device interface name |
| 140 | * is active */ |
| 141 | if (strncmp(p2pParentIfname, primaryIfaceName.data(), |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 142 | strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX)) != 0) { |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 143 | /* |
| 144 | * Update the predefined p2p device interface parent interface name |
| 145 | * with current active wlan interface |
| 146 | */ |
| 147 | p2pDevIfName += P2P_MGMT_DEVICE_PREFIX; |
| 148 | p2pDevIfName += primaryIfaceName.data(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 149 | LOG(INFO) << "update the p2p device interface name to " << p2pDevIfName.c_str(); |
Sunil Ravi | 7f2822a | 2021-10-15 16:55:53 -0700 | [diff] [blame] | 150 | return p2pDevIfName; |
| 151 | } |
| 152 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 153 | return buffer.data(); |
Roshan Pius | 9377a0d | 2017-10-06 13:18:54 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Roshan Pius | 5ba0a90 | 2020-04-14 11:55:42 -0700 | [diff] [blame] | 156 | // Returns the dedicated iface name if one is defined. |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 157 | std::string getPredefinedNanIfaceName() { |
Roshan Pius | 5ba0a90 | 2020-04-14 11:55:42 -0700 | [diff] [blame] | 158 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
| 159 | if (property_get("wifi.aware.interface", buffer.data(), nullptr) == 0) { |
| 160 | return {}; |
| 161 | } |
| 162 | return buffer.data(); |
| 163 | } |
| 164 | |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 165 | void setActiveWlanIfaceNameProperty(const std::string& ifname) { |
| 166 | auto res = property_set(kActiveWlanIfaceNameProperty, ifname.data()); |
| 167 | if (res != 0) { |
| 168 | PLOG(ERROR) << "Failed to set active wlan iface name property"; |
| 169 | } |
| 170 | } |
| 171 | |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 172 | // delete files that meet either conditions: |
| 173 | // 1. older than a predefined time in the wifi tombstone dir. |
| 174 | // 2. Files in excess to a predefined amount, starting from the oldest ones |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 175 | bool removeOldFilesInternal() { |
| 176 | time_t now = time(0); |
| 177 | const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 178 | std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(kTombstoneFolderPath), closedir); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 179 | if (!dir_dump) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 180 | PLOG(ERROR) << "Failed to open directory"; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 181 | return false; |
| 182 | } |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 183 | struct dirent* dp; |
| 184 | bool success = true; |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 185 | std::list<std::pair<const time_t, std::string>> valid_files; |
Josh Gao | a568e53 | 2018-06-04 18:16:00 -0700 | [diff] [blame] | 186 | while ((dp = readdir(dir_dump.get()))) { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 187 | if (dp->d_type != DT_REG) { |
| 188 | continue; |
| 189 | } |
| 190 | std::string cur_file_name(dp->d_name); |
| 191 | struct stat cur_file_stat; |
| 192 | std::string cur_file_path = kTombstoneFolderPath + cur_file_name; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 193 | if (stat(cur_file_path.c_str(), &cur_file_stat) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 194 | PLOG(ERROR) << "Failed to get file stat for " << cur_file_path; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 195 | success = false; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 196 | continue; |
| 197 | } |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 198 | const time_t cur_file_time = cur_file_stat.st_mtime; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 199 | valid_files.push_back(std::pair<const time_t, std::string>(cur_file_time, cur_file_path)); |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 200 | } |
| 201 | valid_files.sort(); // sort the list of files by last modified time from |
| 202 | // small to big. |
| 203 | uint32_t cur_file_count = valid_files.size(); |
| 204 | for (auto cur_file : valid_files) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 205 | if (cur_file_count > kMaxRingBufferFileNum || cur_file.first < delete_files_before) { |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 206 | if (unlink(cur_file.second.c_str()) != 0) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 207 | PLOG(ERROR) << "Error deleting file"; |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 208 | success = false; |
| 209 | } |
| 210 | cur_file_count--; |
| 211 | } else { |
| 212 | break; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | return success; |
| 216 | } |
| 217 | |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 218 | // Helper function for |cpioArchiveFilesInDir| |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 219 | bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name, size_t file_name_len) { |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 220 | std::array<char, 32 * 1024> read_buf; |
| 221 | ssize_t llen = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 222 | sprintf(read_buf.data(), "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X", |
| 223 | kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid, st.st_gid, |
| 224 | static_cast<int>(st.st_nlink), static_cast<int>(st.st_mtime), |
| 225 | static_cast<int>(st.st_size), major(st.st_dev), minor(st.st_dev), |
| 226 | major(st.st_rdev), minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0); |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 227 | if (write(out_fd, read_buf.data(), llen) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 228 | PLOG(ERROR) << "Error writing cpio header to file " << file_name; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | if (write(out_fd, file_name, file_name_len) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 232 | PLOG(ERROR) << "Error writing filename to file " << file_name; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | |
| 236 | // NUL Pad header up to 4 multiple bytes. |
| 237 | llen = (llen + file_name_len) % 4; |
| 238 | if (llen != 0) { |
| 239 | const uint32_t zero = 0; |
| 240 | if (write(out_fd, &zero, 4 - llen) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 241 | PLOG(ERROR) << "Error padding 0s to file " << file_name; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | // Helper function for |cpioArchiveFilesInDir| |
| 249 | size_t cpioWriteFileContent(int fd_read, int out_fd, struct stat& st) { |
| 250 | // writing content of file |
| 251 | std::array<char, 32 * 1024> read_buf; |
| 252 | ssize_t llen = st.st_size; |
| 253 | size_t n_error = 0; |
| 254 | while (llen > 0) { |
| 255 | ssize_t bytes_read = read(fd_read, read_buf.data(), read_buf.size()); |
| 256 | if (bytes_read == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 257 | PLOG(ERROR) << "Error reading file"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 258 | return ++n_error; |
| 259 | } |
| 260 | llen -= bytes_read; |
| 261 | if (write(out_fd, read_buf.data(), bytes_read) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 262 | PLOG(ERROR) << "Error writing data to file"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 263 | return ++n_error; |
| 264 | } |
| 265 | if (bytes_read == 0) { // this should never happen, but just in case |
| 266 | // to unstuck from while loop |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 267 | PLOG(ERROR) << "Unexpected read result"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 268 | n_error++; |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | llen = st.st_size % 4; |
| 273 | if (llen != 0) { |
| 274 | const uint32_t zero = 0; |
| 275 | if (write(out_fd, &zero, 4 - llen) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 276 | PLOG(ERROR) << "Error padding 0s to file"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 277 | return ++n_error; |
| 278 | } |
| 279 | } |
| 280 | return n_error; |
| 281 | } |
| 282 | |
| 283 | // Helper function for |cpioArchiveFilesInDir| |
| 284 | bool cpioWriteFileTrailer(int out_fd) { |
| 285 | std::array<char, 4096> read_buf; |
| 286 | read_buf.fill(0); |
| 287 | if (write(out_fd, read_buf.data(), |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 288 | sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0) + 4) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 289 | PLOG(ERROR) << "Error writing trailing bytes"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | return true; |
| 293 | } |
| 294 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 295 | // Archives all files in |input_dir| and writes result into |out_fd| |
| 296 | // Logic obtained from //external/toybox/toys/posix/cpio.c "Output cpio archive" |
| 297 | // portion |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 298 | size_t cpioArchiveFilesInDir(int out_fd, const char* input_dir) { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 299 | struct dirent* dp; |
| 300 | size_t n_error = 0; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 301 | std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(input_dir), closedir); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 302 | if (!dir_dump) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 303 | PLOG(ERROR) << "Failed to open directory"; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 304 | return ++n_error; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 305 | } |
Josh Gao | a568e53 | 2018-06-04 18:16:00 -0700 | [diff] [blame] | 306 | while ((dp = readdir(dir_dump.get()))) { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 307 | if (dp->d_type != DT_REG) { |
| 308 | continue; |
| 309 | } |
| 310 | std::string cur_file_name(dp->d_name); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 311 | struct stat st; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 312 | const std::string cur_file_path = kTombstoneFolderPath + cur_file_name; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 313 | if (stat(cur_file_path.c_str(), &st) == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 314 | PLOG(ERROR) << "Failed to get file stat for " << cur_file_path; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 315 | n_error++; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 316 | continue; |
| 317 | } |
| 318 | const int fd_read = open(cur_file_path.c_str(), O_RDONLY); |
| 319 | if (fd_read == -1) { |
Elliott Hughes | 4db4add | 2019-03-08 12:42:57 -0800 | [diff] [blame] | 320 | PLOG(ERROR) << "Failed to open file " << cur_file_path; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 321 | n_error++; |
| 322 | continue; |
| 323 | } |
xshu | f392fb4 | 2020-08-13 16:57:00 -0700 | [diff] [blame] | 324 | std::string file_name_with_last_modified_time = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 325 | cur_file_name + "-" + std::to_string(st.st_mtime); |
xshu | f392fb4 | 2020-08-13 16:57:00 -0700 | [diff] [blame] | 326 | // string.size() does not include the null terminator. The cpio FreeBSD |
| 327 | // file header expects the null character to be included in the length. |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 328 | const size_t file_name_len = file_name_with_last_modified_time.size() + 1; |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 329 | unique_fd file_auto_closer(fd_read); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 330 | if (!cpioWriteHeader(out_fd, st, file_name_with_last_modified_time.c_str(), |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 331 | file_name_len)) { |
| 332 | return ++n_error; |
| 333 | } |
| 334 | size_t write_error = cpioWriteFileContent(fd_read, out_fd, st); |
| 335 | if (write_error) { |
| 336 | return n_error + write_error; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 339 | if (!cpioWriteFileTrailer(out_fd)) { |
| 340 | return ++n_error; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 341 | } |
| 342 | return n_error; |
| 343 | } |
| 344 | |
| 345 | // Helper function to create a non-const char*. |
| 346 | std::vector<char> makeCharVec(const std::string& str) { |
| 347 | std::vector<char> vec(str.size() + 1); |
| 348 | vec.assign(str.begin(), str.end()); |
| 349 | vec.push_back('\0'); |
| 350 | return vec; |
| 351 | } |
| 352 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 353 | } // namespace |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 354 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 355 | namespace android { |
| 356 | namespace hardware { |
| 357 | namespace wifi { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 358 | namespace V1_6 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 359 | namespace implementation { |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 360 | using hidl_return_util::validateAndCall; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 361 | using hidl_return_util::validateAndCallWithLock; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 362 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 363 | WifiChip::WifiChip(ChipId chip_id, bool is_primary, |
| 364 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 365 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller, |
| 366 | const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util, |
| 367 | const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags, |
| 368 | const std::function<void(const std::string&)>& handler) |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 369 | : chip_id_(chip_id), |
| 370 | legacy_hal_(legacy_hal), |
| 371 | mode_controller_(mode_controller), |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 372 | iface_util_(iface_util), |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 373 | is_valid_(true), |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 374 | current_mode_id_(feature_flags::chip_mode_ids::kInvalid), |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 375 | modes_(feature_flags.lock()->getChipModes(is_primary)), |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 376 | debug_ring_buffer_cb_registered_(false), |
| 377 | subsystemCallbackHandler_(handler) { |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 378 | setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue); |
| 379 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 380 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 381 | void WifiChip::invalidate() { |
xshu | 37126c9 | 2018-04-13 16:24:45 -0700 | [diff] [blame] | 382 | if (!writeRingbufferFilesInternal()) { |
| 383 | LOG(ERROR) << "Error writing files to flash"; |
| 384 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 385 | invalidateAndRemoveAllIfaces(); |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 386 | setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 387 | legacy_hal_.reset(); |
| 388 | event_cb_handler_.invalidate(); |
| 389 | is_valid_ = false; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 392 | bool WifiChip::isValid() { |
| 393 | return is_valid_; |
| 394 | } |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 395 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 396 | std::set<sp<V1_4::IWifiChipEventCallback>> WifiChip::getEventCallbacks() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 397 | return event_cb_handler_.getCallbacks(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 400 | Return<void> WifiChip::getId(getId_cb hidl_status_cb) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 401 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, &WifiChip::getIdInternal, |
| 402 | hidl_status_cb); |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Jong Wook Kim | da830c9 | 2018-07-23 15:29:38 -0700 | [diff] [blame] | 405 | // Deprecated support for this callback |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 406 | Return<void> WifiChip::registerEventCallback(const sp<V1_0::IWifiChipEventCallback>& event_callback, |
| 407 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 408 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 409 | &WifiChip::registerEventCallbackInternal, hidl_status_cb, |
| 410 | event_callback); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 413 | Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 414 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 415 | &WifiChip::getCapabilitiesInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 418 | Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 419 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 420 | &WifiChip::getAvailableModesInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 423 | Return<void> WifiChip::configureChip(ChipModeId mode_id, configureChip_cb hidl_status_cb) { |
| 424 | return validateAndCallWithLock(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 425 | &WifiChip::configureChipInternal, hidl_status_cb, mode_id); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 428 | Return<void> WifiChip::getMode(getMode_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::getModeInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 433 | Return<void> WifiChip::requestChipDebugInfo(requestChipDebugInfo_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 434 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 435 | &WifiChip::requestChipDebugInfoInternal, hidl_status_cb); |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 438 | Return<void> WifiChip::requestDriverDebugDump(requestDriverDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 439 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 440 | &WifiChip::requestDriverDebugDumpInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 443 | Return<void> WifiChip::requestFirmwareDebugDump(requestFirmwareDebugDump_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 444 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 445 | &WifiChip::requestFirmwareDebugDumpInternal, hidl_status_cb); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 448 | Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 449 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 450 | &WifiChip::createApIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 453 | Return<void> WifiChip::createBridgedApIface(createBridgedApIface_cb hidl_status_cb) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 454 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 455 | &WifiChip::createBridgedApIfaceInternal, hidl_status_cb); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 456 | } |
| 457 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 458 | Return<void> WifiChip::getApIfaceNames(getApIfaceNames_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::getApIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 463 | Return<void> WifiChip::getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 464 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 465 | &WifiChip::getApIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 468 | Return<void> WifiChip::removeApIface(const hidl_string& ifname, removeApIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 469 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 470 | &WifiChip::removeApIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 471 | } |
| 472 | |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 473 | Return<void> WifiChip::removeIfaceInstanceFromBridgedApIface( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 474 | const hidl_string& ifname, const hidl_string& ifInstanceName, |
| 475 | removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) { |
| 476 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 477 | &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal, hidl_status_cb, |
| 478 | ifname, ifInstanceName); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 479 | } |
| 480 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 481 | Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 482 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 483 | &WifiChip::createNanIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 486 | Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 487 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 488 | &WifiChip::getNanIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 491 | Return<void> WifiChip::getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 492 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 493 | &WifiChip::getNanIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 496 | Return<void> WifiChip::removeNanIface(const hidl_string& ifname, removeNanIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 497 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 498 | &WifiChip::removeNanIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 501 | Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 502 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 503 | &WifiChip::createP2pIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 506 | Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_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::getP2pIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 511 | Return<void> WifiChip::getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 512 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 513 | &WifiChip::getP2pIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 516 | Return<void> WifiChip::removeP2pIface(const hidl_string& ifname, removeP2pIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 517 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 518 | &WifiChip::removeP2pIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 521 | Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 522 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 523 | &WifiChip::createStaIfaceInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 526 | Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 527 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 528 | &WifiChip::getStaIfaceNamesInternal, hidl_status_cb); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 531 | Return<void> WifiChip::getStaIface(const hidl_string& ifname, getStaIface_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, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 533 | &WifiChip::getStaIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 536 | Return<void> WifiChip::removeStaIface(const hidl_string& ifname, removeStaIface_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, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 538 | &WifiChip::removeStaIfaceInternal, hidl_status_cb, ifname); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 541 | Return<void> WifiChip::createRttController(const sp<IWifiIface>& bound_iface, |
| 542 | createRttController_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 543 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 544 | &WifiChip::createRttControllerInternal, hidl_status_cb, bound_iface); |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 547 | Return<void> WifiChip::getDebugRingBuffersStatus(getDebugRingBuffersStatus_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 548 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 549 | &WifiChip::getDebugRingBuffersStatusInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | Return<void> WifiChip::startLoggingToDebugRingBuffer( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 553 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 554 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes, |
| 555 | startLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 556 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 557 | &WifiChip::startLoggingToDebugRingBufferInternal, hidl_status_cb, |
| 558 | ring_name, verbose_level, max_interval_in_sec, min_data_size_in_bytes); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 561 | Return<void> WifiChip::forceDumpToDebugRingBuffer(const hidl_string& ring_name, |
| 562 | forceDumpToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 563 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 564 | &WifiChip::forceDumpToDebugRingBufferInternal, hidl_status_cb, |
| 565 | ring_name); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 568 | Return<void> WifiChip::flushRingBufferToFile(flushRingBufferToFile_cb hidl_status_cb) { |
Roger Wang | b294c76 | 2018-11-02 15:34:39 +0800 | [diff] [blame] | 569 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 570 | &WifiChip::flushRingBufferToFileInternal, hidl_status_cb); |
Roger Wang | b294c76 | 2018-11-02 15:34:39 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 573 | Return<void> WifiChip::stopLoggingToDebugRingBuffer( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 574 | stopLoggingToDebugRingBuffer_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 575 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 576 | &WifiChip::stopLoggingToDebugRingBufferInternal, hidl_status_cb); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 577 | } |
| 578 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 579 | Return<void> WifiChip::getDebugHostWakeReasonStats(getDebugHostWakeReasonStats_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 580 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 581 | &WifiChip::getDebugHostWakeReasonStatsInternal, hidl_status_cb); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 584 | Return<void> WifiChip::enableDebugErrorAlerts(bool enable, |
| 585 | enableDebugErrorAlerts_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 586 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 587 | &WifiChip::enableDebugErrorAlertsInternal, hidl_status_cb, enable); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 590 | Return<void> WifiChip::selectTxPowerScenario(V1_1::IWifiChip::TxPowerScenario scenario, |
| 591 | selectTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 592 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 593 | &WifiChip::selectTxPowerScenarioInternal, hidl_status_cb, scenario); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 596 | Return<void> WifiChip::resetTxPowerScenario(resetTxPowerScenario_cb hidl_status_cb) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 597 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 598 | &WifiChip::resetTxPowerScenarioInternal, hidl_status_cb); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 601 | Return<void> WifiChip::setLatencyMode(LatencyMode mode, setLatencyMode_cb hidl_status_cb) { |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 602 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 603 | &WifiChip::setLatencyModeInternal, hidl_status_cb, mode); |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 606 | Return<void> WifiChip::registerEventCallback_1_2( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 607 | const sp<V1_2::IWifiChipEventCallback>& event_callback, |
| 608 | registerEventCallback_cb hidl_status_cb) { |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 609 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 610 | &WifiChip::registerEventCallbackInternal_1_2, hidl_status_cb, |
| 611 | event_callback); |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 614 | Return<void> WifiChip::selectTxPowerScenario_1_2(TxPowerScenario scenario, |
| 615 | selectTxPowerScenario_cb hidl_status_cb) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 616 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 617 | &WifiChip::selectTxPowerScenarioInternal_1_2, hidl_status_cb, scenario); |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 620 | Return<void> WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) { |
| 621 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 622 | &WifiChip::getCapabilitiesInternal_1_3, hidl_status_cb); |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 625 | Return<void> WifiChip::getCapabilities_1_5(getCapabilities_1_5_cb hidl_status_cb) { |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 626 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 627 | &WifiChip::getCapabilitiesInternal_1_5, hidl_status_cb); |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 628 | } |
| 629 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 630 | Return<void> WifiChip::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 631 | if (handle != nullptr && handle->numFds >= 1) { |
xshu | 0a0fe51 | 2020-07-22 17:53:37 -0700 | [diff] [blame] | 632 | { |
| 633 | std::unique_lock<std::mutex> lk(lock_t); |
| 634 | for (const auto& item : ringbuffer_map_) { |
| 635 | forceDumpToDebugRingBufferInternal(item.first); |
| 636 | } |
| 637 | // unique_lock unlocked here |
| 638 | } |
| 639 | usleep(100 * 1000); // sleep for 100 milliseconds to wait for |
| 640 | // ringbuffer updates. |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 641 | int fd = handle->data[0]; |
| 642 | if (!writeRingbufferFilesInternal()) { |
| 643 | LOG(ERROR) << "Error writing files to flash"; |
| 644 | } |
xshu | 4cb3316 | 2018-01-24 15:40:06 -0800 | [diff] [blame] | 645 | uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 646 | if (n_error != 0) { |
| 647 | LOG(ERROR) << n_error << " errors occured in cpio function"; |
| 648 | } |
| 649 | fsync(fd); |
| 650 | } else { |
| 651 | LOG(ERROR) << "File handle error"; |
| 652 | } |
| 653 | return Void(); |
| 654 | } |
| 655 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 656 | Return<void> WifiChip::createRttController_1_4(const sp<IWifiIface>& bound_iface, |
| 657 | createRttController_1_4_cb hidl_status_cb) { |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 658 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 659 | &WifiChip::createRttControllerInternal_1_4, hidl_status_cb, bound_iface); |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 662 | Return<void> WifiChip::registerEventCallback_1_4( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 663 | const sp<V1_4::IWifiChipEventCallback>& event_callback, |
| 664 | registerEventCallback_cb hidl_status_cb) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 665 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 666 | &WifiChip::registerEventCallbackInternal_1_4, hidl_status_cb, |
| 667 | event_callback); |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 670 | Return<void> WifiChip::setMultiStaPrimaryConnection( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 671 | const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) { |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 672 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 673 | &WifiChip::setMultiStaPrimaryConnectionInternal, hidl_status_cb, ifname); |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 676 | Return<void> WifiChip::setMultiStaUseCase(MultiStaUseCase use_case, |
| 677 | setMultiStaUseCase_cb hidl_status_cb) { |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 678 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 679 | &WifiChip::setMultiStaUseCaseInternal, hidl_status_cb, use_case); |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 682 | Return<void> WifiChip::setCoexUnsafeChannels(const hidl_vec<CoexUnsafeChannel>& unsafeChannels, |
| 683 | hidl_bitfield<CoexRestriction> restrictions, |
| 684 | setCoexUnsafeChannels_cb hidl_status_cb) { |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame] | 685 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 686 | &WifiChip::setCoexUnsafeChannelsInternal, hidl_status_cb, unsafeChannels, |
| 687 | restrictions); |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame] | 688 | } |
| 689 | |
Kumar Anand | da62c38 | 2020-11-18 17:17:47 -0800 | [diff] [blame] | 690 | Return<void> WifiChip::setCountryCode(const hidl_array<int8_t, 2>& code, |
| 691 | setCountryCode_cb hidl_status_cb) { |
| 692 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_IFACE_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 693 | &WifiChip::setCountryCodeInternal, hidl_status_cb, code); |
Kumar Anand | da62c38 | 2020-11-18 17:17:47 -0800 | [diff] [blame] | 694 | } |
| 695 | |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 696 | Return<void> WifiChip::getUsableChannels( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 697 | WifiBand band, hidl_bitfield<V1_5::WifiIfaceMode> ifaceModeMask, |
| 698 | hidl_bitfield<V1_5::IWifiChip::UsableChannelFilter> filterMask, |
| 699 | getUsableChannels_cb _hidl_cb) { |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 700 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 701 | &WifiChip::getUsableChannelsInternal, _hidl_cb, band, ifaceModeMask, |
| 702 | filterMask); |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 705 | Return<void> WifiChip::triggerSubsystemRestart(triggerSubsystemRestart_cb hidl_status_cb) { |
chenpaul | c6f5703 | 2021-03-05 17:06:50 +0800 | [diff] [blame] | 706 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 707 | &WifiChip::triggerSubsystemRestartInternal, hidl_status_cb); |
chenpaul | c6f5703 | 2021-03-05 17:06:50 +0800 | [diff] [blame] | 708 | } |
| 709 | |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 710 | Return<void> WifiChip::createRttController_1_6(const sp<IWifiIface>& bound_iface, |
| 711 | createRttController_1_6_cb hidl_status_cb) { |
| 712 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 713 | &WifiChip::createRttControllerInternal_1_6, hidl_status_cb, bound_iface); |
| 714 | } |
| 715 | |
| 716 | Return<void> WifiChip::getUsableChannels_1_6( |
| 717 | WifiBand band, hidl_bitfield<V1_5::WifiIfaceMode> ifaceModeMask, |
Nate Jiang | 6e13599 | 2022-01-24 12:14:23 -0800 | [diff] [blame] | 718 | hidl_bitfield<V1_6::IWifiChip::UsableChannelFilter> filterMask, |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 719 | getUsableChannels_1_6_cb _hidl_cb) { |
| 720 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 721 | &WifiChip::getUsableChannelsInternal_1_6, _hidl_cb, band, ifaceModeMask, |
| 722 | filterMask); |
| 723 | } |
| 724 | |
Sunil Ravi | ef97d23 | 2022-01-24 10:39:56 -0800 | [diff] [blame] | 725 | Return<void> WifiChip::getSupportedRadioCombinationsMatrix( |
| 726 | getSupportedRadioCombinationsMatrix_cb hidl_status_cb) { |
| 727 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 728 | &WifiChip::getSupportedRadioCombinationsMatrixInternal, hidl_status_cb); |
| 729 | } |
| 730 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 731 | Return<void> WifiChip::getAvailableModes_1_6(getAvailableModes_1_6_cb hidl_status_cb) { |
| 732 | return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, |
| 733 | &WifiChip::getAvailableModesInternal_1_6, hidl_status_cb); |
| 734 | } |
| 735 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 736 | void WifiChip::invalidateAndRemoveAllIfaces() { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 737 | invalidateAndClearBridgedApAll(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 738 | invalidateAndClearAll(ap_ifaces_); |
| 739 | invalidateAndClearAll(nan_ifaces_); |
| 740 | invalidateAndClearAll(p2p_ifaces_); |
| 741 | invalidateAndClearAll(sta_ifaces_); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 742 | // Since all the ifaces are invalid now, all RTT controller objects |
| 743 | // using those ifaces also need to be invalidated. |
| 744 | for (const auto& rtt : rtt_controllers_) { |
| 745 | rtt->invalidate(); |
| 746 | } |
| 747 | rtt_controllers_.clear(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 750 | void WifiChip::invalidateAndRemoveDependencies(const std::string& removed_iface_name) { |
Jimmy Chen | 7a82ad8 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 751 | for (auto it = nan_ifaces_.begin(); it != nan_ifaces_.end();) { |
| 752 | auto nan_iface = *it; |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 753 | if (nan_iface->getName() == removed_iface_name) { |
Jimmy Chen | 7a82ad8 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 754 | nan_iface->invalidate(); |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 755 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 756 | if (!callback->onIfaceRemoved(IfaceType::NAN, removed_iface_name).isOk()) { |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 757 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 758 | } |
| 759 | } |
Jimmy Chen | 7a82ad8 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 760 | it = nan_ifaces_.erase(it); |
| 761 | } else { |
| 762 | ++it; |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 763 | } |
| 764 | } |
Jimmy Chen | 7a82ad8 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 765 | |
| 766 | for (auto it = rtt_controllers_.begin(); it != rtt_controllers_.end();) { |
| 767 | auto rtt = *it; |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 768 | if (rtt->getIfaceName() == removed_iface_name) { |
Jimmy Chen | 7a82ad8 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 769 | rtt->invalidate(); |
| 770 | it = rtt_controllers_.erase(it); |
| 771 | } else { |
| 772 | ++it; |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 777 | std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 778 | return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | WifiStatus WifiChip::registerEventCallbackInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 782 | const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) { |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 783 | // Deprecated support for this callback. |
| 784 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 787 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() { |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 788 | // Deprecated support for this callback. |
| 789 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; |
| 790 | } |
| 791 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 792 | std::pair<WifiStatus, std::vector<V1_0::IWifiChip::ChipMode>> |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 793 | WifiChip::getAvailableModesInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 794 | // Deprecated support -- use getAvailableModes_1_6. |
| 795 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 798 | WifiStatus WifiChip::configureChipInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 799 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 800 | if (!isValidModeId(mode_id)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 801 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 802 | } |
| 803 | if (mode_id == current_mode_id_) { |
| 804 | LOG(DEBUG) << "Already in the specified mode " << mode_id; |
| 805 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 806 | } |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 807 | WifiStatus status = handleChipConfiguration(lock, mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 808 | if (status.code != WifiStatusCode::SUCCESS) { |
| 809 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 810 | if (!callback->onChipReconfigureFailure(status).isOk()) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 811 | LOG(ERROR) << "Failed to invoke onChipReconfigureFailure callback"; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | return status; |
| 815 | } |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 816 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 817 | if (!callback->onChipReconfigured(mode_id).isOk()) { |
| 818 | LOG(ERROR) << "Failed to invoke onChipReconfigured callback"; |
| 819 | } |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 820 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 821 | current_mode_id_ = mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 822 | LOG(INFO) << "Configured chip in mode " << mode_id; |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 823 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 824 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 825 | legacy_hal_.lock()->registerSubsystemRestartCallbackHandler(subsystemCallbackHandler_); |
Ahmed ElArabawy | 2134bf7 | 2020-06-18 15:07:12 -0700 | [diff] [blame] | 826 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 827 | return status; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 831 | if (!isValidModeId(current_mode_id_)) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 832 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), current_mode_id_}; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 833 | } |
| 834 | return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 837 | std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> WifiChip::requestChipDebugInfoInternal() { |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 838 | V1_4::IWifiChip::ChipDebugInfo result; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 839 | legacy_hal::wifi_error legacy_status; |
| 840 | std::string driver_desc; |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 841 | const auto ifname = getFirstActiveWlanIfaceName(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 842 | std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(ifname); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 843 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 844 | LOG(ERROR) << "Failed to get driver version: " << legacyErrorToString(legacy_status); |
| 845 | WifiStatus status = |
| 846 | createWifiStatusFromLegacyError(legacy_status, "failed to get driver version"); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 847 | return {status, result}; |
| 848 | } |
| 849 | result.driverDescription = driver_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 850 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 851 | std::string firmware_desc; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 852 | std::tie(legacy_status, firmware_desc) = legacy_hal_.lock()->getFirmwareVersion(ifname); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 853 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 854 | LOG(ERROR) << "Failed to get firmware version: " << legacyErrorToString(legacy_status); |
| 855 | WifiStatus status = |
| 856 | createWifiStatusFromLegacyError(legacy_status, "failed to get firmware version"); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 857 | return {status, result}; |
| 858 | } |
| 859 | result.firmwareDescription = firmware_desc.c_str(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 860 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 861 | return {createWifiStatus(WifiStatusCode::SUCCESS), result}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 864 | std::pair<WifiStatus, std::vector<uint8_t>> WifiChip::requestDriverDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 865 | legacy_hal::wifi_error legacy_status; |
| 866 | std::vector<uint8_t> driver_dump; |
| 867 | std::tie(legacy_status, driver_dump) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 868 | legacy_hal_.lock()->requestDriverMemoryDump(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 869 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 870 | LOG(ERROR) << "Failed to get driver debug dump: " << legacyErrorToString(legacy_status); |
| 871 | return {createWifiStatusFromLegacyError(legacy_status), std::vector<uint8_t>()}; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 872 | } |
| 873 | return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 876 | std::pair<WifiStatus, std::vector<uint8_t>> WifiChip::requestFirmwareDebugDumpInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 877 | legacy_hal::wifi_error legacy_status; |
| 878 | std::vector<uint8_t> firmware_dump; |
| 879 | std::tie(legacy_status, firmware_dump) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 880 | legacy_hal_.lock()->requestFirmwareMemoryDump(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 881 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 882 | LOG(ERROR) << "Failed to get firmware debug dump: " << legacyErrorToString(legacy_status); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 883 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 884 | } |
| 885 | return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 886 | } |
| 887 | |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 888 | WifiStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) { |
| 889 | legacy_hal::wifi_error legacy_status; |
| 890 | legacy_status = legacy_hal_.lock()->createVirtualInterface( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 891 | apVirtIf, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::AP)); |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 892 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 893 | LOG(ERROR) << "Failed to add interface: " << apVirtIf << " " |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 894 | << legacyErrorToString(legacy_status); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 895 | return createWifiStatusFromLegacyError(legacy_status); |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 896 | } |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 897 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 898 | } |
| 899 | |
| 900 | sp<WifiApIface> WifiChip::newWifiApIface(std::string& ifname) { |
lesl | 420c4fc | 2020-11-23 19:33:04 +0800 | [diff] [blame] | 901 | std::vector<std::string> ap_instances; |
| 902 | for (auto const& it : br_ifaces_ap_instances_) { |
| 903 | if (it.first == ifname) { |
| 904 | ap_instances = it.second; |
| 905 | } |
| 906 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 907 | sp<WifiApIface> iface = new WifiApIface(ifname, ap_instances, legacy_hal_, iface_util_); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 908 | ap_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 909 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 910 | if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) { |
| 911 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 912 | } |
| 913 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 914 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 915 | return iface; |
| 916 | } |
| 917 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 918 | std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::createApIfaceInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 919 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP)) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 920 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 921 | } |
| 922 | std::string ifname = allocateApIfaceName(); |
| 923 | WifiStatus status = createVirtualApInterface(ifname); |
| 924 | if (status.code != WifiStatusCode::SUCCESS) { |
| 925 | return {status, {}}; |
| 926 | } |
| 927 | sp<WifiApIface> iface = newWifiApIface(ifname); |
| 928 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
| 929 | } |
| 930 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 931 | std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::createBridgedApIfaceInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 932 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::AP_BRIDGED)) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 933 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 934 | } |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 935 | std::vector<std::string> ap_instances = allocateBridgedApInstanceNames(); |
| 936 | if (ap_instances.size() < 2) { |
| 937 | LOG(ERROR) << "Fail to allocate two instances"; |
| 938 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 939 | } |
| 940 | std::string br_ifname = kApBridgeIfacePrefix + ap_instances[0]; |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 941 | for (int i = 0; i < 2; i++) { |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 942 | WifiStatus status = createVirtualApInterface(ap_instances[i]); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 943 | if (status.code != WifiStatusCode::SUCCESS) { |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 944 | if (i != 0) { // The failure happened when creating second virtual |
| 945 | // iface. |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 946 | legacy_hal_.lock()->deleteVirtualInterface( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 947 | ap_instances.front()); // Remove the first virtual iface. |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 948 | } |
| 949 | return {status, {}}; |
| 950 | } |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 951 | } |
| 952 | br_ifaces_ap_instances_[br_ifname] = ap_instances; |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 953 | if (!iface_util_->createBridge(br_ifname)) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 954 | LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str(); |
| 955 | invalidateAndClearBridgedAp(br_ifname); |
| 956 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 957 | } |
| 958 | for (auto const& instance : ap_instances) { |
| 959 | // Bind ap instance interface to AP bridge |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 960 | if (!iface_util_->addIfaceToBridge(br_ifname, instance)) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 961 | LOG(ERROR) << "Failed add if to Bridge - if_name=" << instance.c_str(); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 962 | invalidateAndClearBridgedAp(br_ifname); |
| 963 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 964 | } |
| 965 | } |
| 966 | sp<WifiApIface> iface = newWifiApIface(br_ifname); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 967 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 970 | std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getApIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 971 | if (ap_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 972 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 973 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 974 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 975 | } |
| 976 | |
lesl | 420c4fc | 2020-11-23 19:33:04 +0800 | [diff] [blame] | 977 | std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::getApIfaceInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 978 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 979 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 980 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 981 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 982 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 983 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 986 | WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 987 | const auto iface = findUsingName(ap_ifaces_, ifname); |
| 988 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 989 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 990 | } |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 991 | // Invalidate & remove any dependent objects first. |
| 992 | // Note: This is probably not required because we never create |
| 993 | // nan/rtt objects over AP iface. But, there is no harm to do it |
| 994 | // here and not make that assumption all over the place. |
| 995 | invalidateAndRemoveDependencies(ifname); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 996 | // Clear the bridge interface and the iface instance. |
| 997 | invalidateAndClearBridgedAp(ifname); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 998 | invalidateAndClear(ap_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 999 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1000 | if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) { |
| 1001 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 1002 | } |
| 1003 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 1004 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1005 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1006 | } |
| 1007 | |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1008 | WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1009 | const std::string& ifname, const std::string& ifInstanceName) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1010 | const auto iface = findUsingName(ap_ifaces_, ifname); |
lesl | 819e372 | 2021-01-07 09:49:04 +0800 | [diff] [blame] | 1011 | if (!iface.get() || ifInstanceName.empty()) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1012 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1013 | } |
| 1014 | // Requires to remove one of the instance in bridge mode |
| 1015 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1016 | if (it.first == ifname) { |
Les Lee | 03d642f | 2021-06-21 21:25:20 +0800 | [diff] [blame] | 1017 | std::vector<std::string> ap_instances = it.second; |
| 1018 | for (auto const& iface : ap_instances) { |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1019 | if (iface == ifInstanceName) { |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1020 | if (!iface_util_->removeIfaceFromBridge(it.first, iface)) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1021 | LOG(ERROR) << "Failed to remove interface: " << ifInstanceName << " from " |
| 1022 | << ifname; |
| 1023 | return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1024 | } |
George Burgess IV | 2c0a47d | 2021-01-20 21:14:13 -0800 | [diff] [blame] | 1025 | legacy_hal::wifi_error legacy_status = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1026 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1027 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1028 | LOG(ERROR) << "Failed to del interface: " << iface << " " |
| 1029 | << legacyErrorToString(legacy_status); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1030 | return createWifiStatusFromLegacyError(legacy_status); |
| 1031 | } |
Les Lee | 03d642f | 2021-06-21 21:25:20 +0800 | [diff] [blame] | 1032 | ap_instances.erase( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1033 | std::remove(ap_instances.begin(), ap_instances.end(), ifInstanceName), |
| 1034 | ap_instances.end()); |
Les Lee | 03d642f | 2021-06-21 21:25:20 +0800 | [diff] [blame] | 1035 | br_ifaces_ap_instances_[ifname] = ap_instances; |
| 1036 | break; |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | break; |
| 1040 | } |
| 1041 | } |
lesl | 669c906 | 2021-01-22 19:37:47 +0800 | [diff] [blame] | 1042 | iface->removeInstance(ifInstanceName); |
Les Lee | 03d642f | 2021-06-21 21:25:20 +0800 | [diff] [blame] | 1043 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
| 1044 | |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1045 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1046 | } |
| 1047 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1048 | std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::createNanIfaceInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1049 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::NAN)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1050 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Etan Cohen | c570040 | 2017-03-08 16:43:38 -0800 | [diff] [blame] | 1051 | } |
Roshan Pius | 5ba0a90 | 2020-04-14 11:55:42 -0700 | [diff] [blame] | 1052 | bool is_dedicated_iface = true; |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1053 | std::string ifname = getPredefinedNanIfaceName(); |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1054 | if (ifname.empty() || !iface_util_->ifNameToIndex(ifname)) { |
Roshan Pius | 5ba0a90 | 2020-04-14 11:55:42 -0700 | [diff] [blame] | 1055 | // Use the first shared STA iface (wlan0) if a dedicated aware iface is |
| 1056 | // not defined. |
| 1057 | ifname = getFirstActiveWlanIfaceName(); |
| 1058 | is_dedicated_iface = false; |
| 1059 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1060 | sp<WifiNanIface> iface = new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1061 | nan_ifaces_.push_back(iface); |
| 1062 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1063 | if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) { |
| 1064 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1065 | } |
| 1066 | } |
| 1067 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1070 | std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getNanIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1071 | if (nan_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1072 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 1073 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1074 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1077 | std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::getNanIfaceInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1078 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1079 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 1080 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1081 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 1082 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1083 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1086 | WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1087 | const auto iface = findUsingName(nan_ifaces_, ifname); |
| 1088 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1089 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 1090 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1091 | invalidateAndClear(nan_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1092 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1093 | if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) { |
| 1094 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1095 | } |
| 1096 | } |
| 1097 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1100 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1101 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::P2P)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1102 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 1103 | } |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1104 | std::string ifname = getPredefinedP2pIfaceName(); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1105 | sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_); |
| 1106 | p2p_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1107 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1108 | if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) { |
| 1109 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1110 | } |
| 1111 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1112 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1115 | std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getP2pIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1116 | if (p2p_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1117 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 1118 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1119 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1122 | std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1123 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 1124 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1125 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 1126 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1127 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1130 | WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1131 | const auto iface = findUsingName(p2p_ifaces_, ifname); |
| 1132 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1133 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 1134 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1135 | invalidateAndClear(p2p_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1136 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1137 | if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) { |
| 1138 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 1139 | } |
| 1140 | } |
| 1141 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1144 | std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> WifiChip::createStaIfaceInternal() { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1145 | if (!canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1146 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 1147 | } |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1148 | std::string ifname = allocateStaIfaceName(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1149 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->createVirtualInterface( |
| 1150 | ifname, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA)); |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 1151 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1152 | LOG(ERROR) << "Failed to add interface: " << ifname << " " |
| 1153 | << legacyErrorToString(legacy_status); |
| 1154 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1155 | } |
Roshan Pius | 99dab38 | 2019-02-14 07:57:10 -0800 | [diff] [blame] | 1156 | sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1157 | sta_ifaces_.push_back(iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1158 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1159 | if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) { |
| 1160 | LOG(ERROR) << "Failed to invoke onIfaceAdded callback"; |
| 1161 | } |
| 1162 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 1163 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1164 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1167 | std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getStaIfaceNamesInternal() { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1168 | if (sta_ifaces_.empty()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1169 | return {createWifiStatus(WifiStatusCode::SUCCESS), {}}; |
| 1170 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1171 | return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1174 | std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> WifiChip::getStaIfaceInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1175 | const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1176 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 1177 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1178 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr}; |
| 1179 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1180 | return {createWifiStatus(WifiStatusCode::SUCCESS), iface}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1183 | WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) { |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1184 | const auto iface = findUsingName(sta_ifaces_, ifname); |
| 1185 | if (!iface.get()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1186 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
Roshan Pius | bc66220 | 2017-01-30 17:07:42 -0800 | [diff] [blame] | 1187 | } |
Roshan Pius | 8236850 | 2019-05-16 12:53:02 -0700 | [diff] [blame] | 1188 | // Invalidate & remove any dependent objects first. |
| 1189 | invalidateAndRemoveDependencies(ifname); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1190 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(ifname); |
Sunil Ravi | ddab4bb | 2020-02-03 22:45:19 -0800 | [diff] [blame] | 1191 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1192 | LOG(ERROR) << "Failed to remove interface: " << ifname << " " |
| 1193 | << legacyErrorToString(legacy_status); |
| 1194 | } |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 1195 | invalidateAndClear(sta_ifaces_, iface); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1196 | for (const auto& callback : event_cb_handler_.getCallbacks()) { |
| 1197 | if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) { |
| 1198 | LOG(ERROR) << "Failed to invoke onIfaceRemoved callback"; |
| 1199 | } |
| 1200 | } |
Roshan Pius | 8574e7f | 2019-04-01 13:30:40 -0700 | [diff] [blame] | 1201 | setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1202 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 1203 | } |
| 1204 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1205 | std::pair<WifiStatus, sp<V1_0::IWifiRttController>> WifiChip::createRttControllerInternal( |
| 1206 | const sp<IWifiIface>& /*bound_iface*/) { |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1207 | LOG(ERROR) << "createRttController is not supported on this HAL"; |
Ahmed ElArabawy | 36defb3 | 2019-12-29 21:24:27 -0800 | [diff] [blame] | 1208 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 1209 | } |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1210 | |
| 1211 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 1212 | WifiChip::getDebugRingBuffersStatusInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1213 | legacy_hal::wifi_error legacy_status; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1214 | std::vector<legacy_hal::wifi_ring_buffer_status> legacy_ring_buffer_status_vec; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1215 | std::tie(legacy_status, legacy_ring_buffer_status_vec) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1216 | legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1217 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1218 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1219 | } |
| 1220 | std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec; |
| 1221 | if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1222 | legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1223 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1224 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1225 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_ring_buffer_status_vec}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | WifiStatus WifiChip::startLoggingToDebugRingBufferInternal( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1229 | const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level, |
| 1230 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1231 | WifiStatus status = registerDebugRingBufferCallback(); |
| 1232 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1233 | return status; |
| 1234 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1235 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRingBufferLogging( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1236 | getFirstActiveWlanIfaceName(), ring_name, |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1237 | static_cast<std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(verbose_level), |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1238 | max_interval_in_sec, min_data_size_in_bytes); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1239 | ringbuffer_map_.insert( |
| 1240 | std::pair<std::string, Ringbuffer>(ring_name, Ringbuffer(kMaxBufferSizeBytes))); |
Roshan Pius | a63b53f | 2019-11-18 11:03:13 -0800 | [diff] [blame] | 1241 | // if verbose logging enabled, turn up HAL daemon logging as well. |
| 1242 | if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) { |
| 1243 | android::base::SetMinimumLogSeverity(android::base::DEBUG); |
| 1244 | } else { |
| 1245 | android::base::SetMinimumLogSeverity(android::base::VERBOSE); |
| 1246 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1247 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1250 | WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(const hidl_string& ring_name) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1251 | WifiStatus status = registerDebugRingBufferCallback(); |
| 1252 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1253 | return status; |
| 1254 | } |
| 1255 | legacy_hal::wifi_error legacy_status = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1256 | legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(), ring_name); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1257 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1258 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Roger Wang | b294c76 | 2018-11-02 15:34:39 +0800 | [diff] [blame] | 1261 | WifiStatus WifiChip::flushRingBufferToFileInternal() { |
| 1262 | if (!writeRingbufferFilesInternal()) { |
| 1263 | LOG(ERROR) << "Error writing files to flash"; |
| 1264 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1265 | } |
| 1266 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1267 | } |
| 1268 | |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1269 | WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1270 | legacy_hal::wifi_error legacy_status = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1271 | legacy_hal_.lock()->deregisterRingBufferCallbackHandler(getFirstActiveWlanIfaceName()); |
xshu | 0a0fe51 | 2020-07-22 17:53:37 -0700 | [diff] [blame] | 1272 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1273 | debug_ring_buffer_cb_registered_ = false; |
| 1274 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1275 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1278 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 1279 | WifiChip::getDebugHostWakeReasonStatsInternal() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1280 | legacy_hal::wifi_error legacy_status; |
| 1281 | legacy_hal::WakeReasonStats legacy_stats; |
| 1282 | std::tie(legacy_status, legacy_stats) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1283 | legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1284 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1285 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1286 | } |
| 1287 | WifiDebugHostWakeReasonStats hidl_stats; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1288 | if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, &hidl_stats)) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1289 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1290 | } |
| 1291 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats}; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1294 | WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1295 | legacy_hal::wifi_error legacy_status; |
| 1296 | if (enable) { |
| 1297 | android::wp<WifiChip> weak_ptr_this(this); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1298 | const auto& on_alert_callback = [weak_ptr_this](int32_t error_code, |
| 1299 | std::vector<uint8_t> debug_data) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1300 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1301 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1302 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1303 | return; |
| 1304 | } |
| 1305 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1306 | if (!callback->onDebugErrorAlert(error_code, debug_data).isOk()) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1307 | LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback"; |
| 1308 | } |
| 1309 | } |
| 1310 | }; |
| 1311 | legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1312 | getFirstActiveWlanIfaceName(), on_alert_callback); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1313 | } else { |
| 1314 | legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1315 | getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1316 | } |
| 1317 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 1318 | } |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1319 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1320 | WifiStatus WifiChip::selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1321 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1322 | getFirstActiveWlanIfaceName(), |
| 1323 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario)); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1324 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Roshan Pius | 735ff43 | 2017-07-25 08:48:08 -0700 | [diff] [blame] | 1327 | WifiStatus WifiChip::resetTxPowerScenarioInternal() { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1328 | auto legacy_status = legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName()); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1329 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 1330 | } |
| 1331 | |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 1332 | WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) { |
| 1333 | auto legacy_status = legacy_hal_.lock()->setLatencyMode( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1334 | getFirstActiveWlanIfaceName(), hidl_struct_util::convertHidlLatencyModeToLegacy(mode)); |
Ahmed ElArabawy | eaf8240 | 2018-10-26 09:46:04 -0700 | [diff] [blame] | 1335 | return createWifiStatusFromLegacyError(legacy_status); |
| 1336 | } |
| 1337 | |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1338 | WifiStatus WifiChip::registerEventCallbackInternal_1_2( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1339 | const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1340 | // Deprecated support for this callback. |
| 1341 | return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED); |
Roshan Pius | 1ce92cf | 2018-01-22 16:12:19 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1344 | WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario) { |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1345 | auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1346 | getFirstActiveWlanIfaceName(), |
| 1347 | hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario)); |
Ahmed ElArabawy | 6a1accf | 2018-01-23 10:57:29 -0800 | [diff] [blame] | 1348 | return createWifiStatusFromLegacyError(legacy_status); |
| 1349 | } |
| 1350 | |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1351 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() { |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 1352 | // Deprecated support for this callback. |
| 1353 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0}; |
| 1354 | } |
| 1355 | |
| 1356 | std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_5() { |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1357 | legacy_hal::wifi_error legacy_status; |
Jimmy Chen | 1bdf1a7 | 2019-12-23 17:53:40 +0200 | [diff] [blame] | 1358 | uint64_t legacy_feature_set; |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1359 | uint32_t legacy_logger_feature_set; |
| 1360 | const auto ifname = getFirstActiveWlanIfaceName(); |
| 1361 | std::tie(legacy_status, legacy_feature_set) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1362 | legacy_hal_.lock()->getSupportedFeatureSet(ifname); |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1363 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1364 | return {createWifiStatusFromLegacyError(legacy_status), 0}; |
| 1365 | } |
| 1366 | std::tie(legacy_status, legacy_logger_feature_set) = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1367 | legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname); |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1368 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1369 | // some devices don't support querying logger feature set |
| 1370 | legacy_logger_feature_set = 0; |
| 1371 | } |
| 1372 | uint32_t hidl_caps; |
| 1373 | if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1374 | legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) { |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1375 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0}; |
| 1376 | } |
| 1377 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps}; |
| 1378 | } |
| 1379 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1380 | std::pair<WifiStatus, sp<V1_4::IWifiRttController>> WifiChip::createRttControllerInternal_1_4( |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1381 | const sp<IWifiIface>& /*bound_iface*/) { |
| 1382 | LOG(ERROR) << "createRttController_1_4 is not supported on this HAL"; |
| 1383 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
Ahmed ElArabawy | eeb5338 | 2019-10-10 20:18:31 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1386 | WifiStatus WifiChip::registerEventCallbackInternal_1_4( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1387 | const sp<V1_4::IWifiChipEventCallback>& event_callback) { |
Ahmed ElArabawy | fd809fc | 2019-11-15 18:19:15 -0800 | [diff] [blame] | 1388 | if (!event_cb_handler_.addCallback(event_callback)) { |
| 1389 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1390 | } |
| 1391 | return createWifiStatus(WifiStatusCode::SUCCESS); |
| 1392 | } |
| 1393 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1394 | WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(const std::string& ifname) { |
| 1395 | auto legacy_status = legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname); |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 1396 | return createWifiStatusFromLegacyError(legacy_status); |
| 1397 | } |
| 1398 | |
| 1399 | WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) { |
| 1400 | auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1401 | hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case)); |
Roshan Pius | e9d1e7d | 2020-11-04 11:44:16 -0800 | [diff] [blame] | 1402 | return createWifiStatusFromLegacyError(legacy_status); |
| 1403 | } |
| 1404 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1405 | WifiStatus WifiChip::setCoexUnsafeChannelsInternal(std::vector<CoexUnsafeChannel> unsafe_channels, |
| 1406 | uint32_t restrictions) { |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame] | 1407 | std::vector<legacy_hal::wifi_coex_unsafe_channel> legacy_unsafe_channels; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1408 | if (!hidl_struct_util::convertHidlVectorOfCoexUnsafeChannelToLegacy(unsafe_channels, |
| 1409 | &legacy_unsafe_channels)) { |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame] | 1410 | return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS); |
| 1411 | } |
Quang Luong | ab70a83 | 2020-12-14 13:01:32 -0800 | [diff] [blame] | 1412 | uint32_t legacy_restrictions = 0; |
| 1413 | if (restrictions & CoexRestriction::WIFI_DIRECT) { |
| 1414 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_DIRECT; |
| 1415 | } |
| 1416 | if (restrictions & CoexRestriction::SOFTAP) { |
| 1417 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::SOFTAP; |
| 1418 | } |
| 1419 | if (restrictions & CoexRestriction::WIFI_AWARE) { |
| 1420 | legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_AWARE; |
| 1421 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1422 | auto legacy_status = |
| 1423 | legacy_hal_.lock()->setCoexUnsafeChannels(legacy_unsafe_channels, legacy_restrictions); |
Quang Luong | 94bcce5 | 2020-11-25 17:52:19 -0800 | [diff] [blame] | 1424 | return createWifiStatusFromLegacyError(legacy_status); |
| 1425 | } |
| 1426 | |
Kumar Anand | da62c38 | 2020-11-18 17:17:47 -0800 | [diff] [blame] | 1427 | WifiStatus WifiChip::setCountryCodeInternal(const std::array<int8_t, 2>& code) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1428 | auto legacy_status = legacy_hal_.lock()->setCountryCode(getFirstActiveWlanIfaceName(), code); |
Kumar Anand | da62c38 | 2020-11-18 17:17:47 -0800 | [diff] [blame] | 1429 | return createWifiStatusFromLegacyError(legacy_status); |
| 1430 | } |
| 1431 | |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1432 | std::pair<WifiStatus, std::vector<V1_5::WifiUsableChannel>> WifiChip::getUsableChannelsInternal( |
| 1433 | WifiBand /*band*/, uint32_t /*ifaceModeMask*/, uint32_t /*filterMask*/) { |
| 1434 | LOG(ERROR) << "getUsableChannels is not supported on this HAL"; |
| 1435 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}}; |
| 1436 | } |
| 1437 | |
| 1438 | WifiStatus WifiChip::triggerSubsystemRestartInternal() { |
| 1439 | auto legacy_status = legacy_hal_.lock()->triggerSubsystemRestart(); |
| 1440 | return createWifiStatusFromLegacyError(legacy_status); |
| 1441 | } |
| 1442 | |
| 1443 | std::pair<WifiStatus, sp<V1_6::IWifiRttController>> WifiChip::createRttControllerInternal_1_6( |
| 1444 | const sp<IWifiIface>& bound_iface) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1445 | if (sta_ifaces_.size() == 0 && |
| 1446 | !canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType::STA)) { |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1447 | LOG(ERROR) << "createRttControllerInternal_1_6: Chip cannot support STAs " |
| 1448 | "(and RTT by extension)"; |
| 1449 | return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}}; |
| 1450 | } |
| 1451 | sp<WifiRttController> rtt = |
| 1452 | new WifiRttController(getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_); |
| 1453 | rtt_controllers_.emplace_back(rtt); |
| 1454 | return {createWifiStatus(WifiStatusCode::SUCCESS), rtt}; |
| 1455 | } |
| 1456 | |
| 1457 | std::pair<WifiStatus, std::vector<V1_6::WifiUsableChannel>> WifiChip::getUsableChannelsInternal_1_6( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1458 | WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask) { |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 1459 | legacy_hal::wifi_error legacy_status; |
| 1460 | std::vector<legacy_hal::wifi_usable_channel> legacy_usable_channels; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1461 | std::tie(legacy_status, legacy_usable_channels) = legacy_hal_.lock()->getUsableChannels( |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 1462 | hidl_struct_util::convertHidlWifiBandToLegacyMacBand(band), |
Kumar Anand | aea86e0 | 2021-02-10 16:22:31 -0800 | [diff] [blame] | 1463 | hidl_struct_util::convertHidlWifiIfaceModeToLegacy(ifaceModeMask), |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1464 | hidl_struct_util::convertHidlUsableChannelFilterToLegacy(filterMask)); |
Kumar Anand | aea86e0 | 2021-02-10 16:22:31 -0800 | [diff] [blame] | 1465 | |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 1466 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1467 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1468 | } |
Ahmed ElArabawy | 05571e4 | 2022-01-19 11:54:11 -0800 | [diff] [blame] | 1469 | std::vector<V1_6::WifiUsableChannel> hidl_usable_channels; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1470 | if (!hidl_struct_util::convertLegacyWifiUsableChannelsToHidl(legacy_usable_channels, |
| 1471 | &hidl_usable_channels)) { |
Kumar Anand | 2a630a3 | 2021-01-21 14:09:14 -0800 | [diff] [blame] | 1472 | return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}}; |
| 1473 | } |
| 1474 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_usable_channels}; |
| 1475 | } |
| 1476 | |
Sunil Ravi | ef97d23 | 2022-01-24 10:39:56 -0800 | [diff] [blame] | 1477 | std::pair<WifiStatus, V1_6::WifiRadioCombinationMatrix> |
| 1478 | WifiChip::getSupportedRadioCombinationsMatrixInternal() { |
| 1479 | legacy_hal::wifi_error legacy_status; |
| 1480 | legacy_hal::wifi_radio_combination_matrix* legacy_matrix; |
| 1481 | |
| 1482 | std::tie(legacy_status, legacy_matrix) = |
| 1483 | legacy_hal_.lock()->getSupportedRadioCombinationsMatrix(); |
| 1484 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
| 1485 | LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: " |
| 1486 | << legacyErrorToString(legacy_status); |
| 1487 | return {createWifiStatusFromLegacyError(legacy_status), {}}; |
| 1488 | } |
| 1489 | |
| 1490 | V1_6::WifiRadioCombinationMatrix hidl_matrix; |
| 1491 | if (!hidl_struct_util::convertLegacyRadioCombinationsMatrixToHidl(legacy_matrix, |
| 1492 | &hidl_matrix)) { |
| 1493 | LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToHidl() "; |
| 1494 | return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), {}}; |
| 1495 | } |
| 1496 | return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_matrix}; |
| 1497 | } |
| 1498 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1499 | std::pair<WifiStatus, std::vector<V1_6::IWifiChip::ChipMode>> |
| 1500 | WifiChip::getAvailableModesInternal_1_6() { |
| 1501 | return {createWifiStatus(WifiStatusCode::SUCCESS), modes_}; |
| 1502 | } |
| 1503 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1504 | WifiStatus WifiChip::handleChipConfiguration( |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1505 | /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1506 | // If the chip is already configured in a different mode, stop |
| 1507 | // the legacy HAL and then start it after firmware mode change. |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1508 | if (isValidModeId(current_mode_id_)) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1509 | LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ << " to mode " << mode_id; |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1510 | invalidateAndRemoveAllIfaces(); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1511 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop(lock, []() {}); |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1512 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1513 | LOG(ERROR) << "Failed to stop legacy HAL: " << legacyErrorToString(legacy_status); |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 1514 | return createWifiStatusFromLegacyError(legacy_status); |
| 1515 | } |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1516 | } |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1517 | // Firmware mode change not needed for V2 devices. |
| 1518 | bool success = true; |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1519 | if (mode_id == feature_flags::chip_mode_ids::kV1Sta) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1520 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA); |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 1521 | } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1522 | success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP); |
| 1523 | } |
| 1524 | if (!success) { |
| 1525 | return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN); |
| 1526 | } |
| 1527 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start(); |
| 1528 | if (legacy_status != legacy_hal::WIFI_SUCCESS) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1529 | LOG(ERROR) << "Failed to start legacy HAL: " << legacyErrorToString(legacy_status); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1530 | return createWifiStatusFromLegacyError(legacy_status); |
| 1531 | } |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1532 | // Every time the HAL is restarted, we need to register the |
| 1533 | // radio mode change callback. |
| 1534 | WifiStatus status = registerRadioModeChangeCallback(); |
| 1535 | if (status.code != WifiStatusCode::SUCCESS) { |
| 1536 | // This probably is not a critical failure? |
| 1537 | LOG(ERROR) << "Failed to register radio mode change callback"; |
| 1538 | } |
chenpaul | f5eca29 | 2019-03-14 11:08:03 +0800 | [diff] [blame] | 1539 | // Extract and save the version information into property. |
Jimmy Chen | d460df3 | 2019-11-29 17:31:22 +0200 | [diff] [blame] | 1540 | std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> version_info; |
chenpaul | f5eca29 | 2019-03-14 11:08:03 +0800 | [diff] [blame] | 1541 | version_info = WifiChip::requestChipDebugInfoInternal(); |
| 1542 | if (WifiStatusCode::SUCCESS == version_info.first.code) { |
| 1543 | property_set("vendor.wlan.firmware.version", |
| 1544 | version_info.second.firmwareDescription.c_str()); |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1545 | property_set("vendor.wlan.driver.version", version_info.second.driverDescription.c_str()); |
chenpaul | f5eca29 | 2019-03-14 11:08:03 +0800 | [diff] [blame] | 1546 | } |
| 1547 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1548 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 1549 | } |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1550 | |
| 1551 | WifiStatus WifiChip::registerDebugRingBufferCallback() { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1552 | if (debug_ring_buffer_cb_registered_) { |
| 1553 | return createWifiStatus(WifiStatusCode::SUCCESS); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1554 | } |
Roshan Pius | 3797e18 | 2017-03-30 18:01:54 -0700 | [diff] [blame] | 1555 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1556 | android::wp<WifiChip> weak_ptr_this(this); |
| 1557 | const auto& on_ring_buffer_data_callback = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1558 | [weak_ptr_this](const std::string& name, const std::vector<uint8_t>& data, |
| 1559 | const legacy_hal::wifi_ring_buffer_status& status) { |
| 1560 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1561 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1562 | LOG(ERROR) << "Callback invoked on an invalid object"; |
Veerendranath Jakkam | 25b3a6f | 2020-04-14 22:04:39 +0530 | [diff] [blame] | 1563 | return; |
| 1564 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1565 | WifiDebugRingBufferStatus hidl_status; |
| 1566 | if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(status, |
| 1567 | &hidl_status)) { |
| 1568 | LOG(ERROR) << "Error converting ring buffer status"; |
| 1569 | return; |
| 1570 | } |
| 1571 | { |
| 1572 | std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t); |
| 1573 | const auto& target = shared_ptr_this->ringbuffer_map_.find(name); |
| 1574 | if (target != shared_ptr_this->ringbuffer_map_.end()) { |
| 1575 | Ringbuffer& cur_buffer = target->second; |
| 1576 | cur_buffer.append(data); |
| 1577 | } else { |
| 1578 | LOG(ERROR) << "Ringname " << name << " not found"; |
| 1579 | return; |
| 1580 | } |
| 1581 | // unique_lock unlocked here |
| 1582 | } |
| 1583 | }; |
| 1584 | legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->registerRingBufferCallbackHandler( |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1585 | getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1586 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 1587 | if (legacy_status == legacy_hal::WIFI_SUCCESS) { |
| 1588 | debug_ring_buffer_cb_registered_ = true; |
| 1589 | } |
| 1590 | return createWifiStatusFromLegacyError(legacy_status); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1593 | WifiStatus WifiChip::registerRadioModeChangeCallback() { |
| 1594 | android::wp<WifiChip> weak_ptr_this(this); |
| 1595 | const auto& on_radio_mode_change_callback = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1596 | [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) { |
| 1597 | const auto shared_ptr_this = weak_ptr_this.promote(); |
| 1598 | if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) { |
| 1599 | LOG(ERROR) << "Callback invoked on an invalid object"; |
| 1600 | return; |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1601 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1602 | std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo> hidl_radio_mode_infos; |
| 1603 | if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(mac_infos, |
| 1604 | &hidl_radio_mode_infos)) { |
| 1605 | LOG(ERROR) << "Error converting wifi mac info"; |
| 1606 | return; |
| 1607 | } |
| 1608 | for (const auto& callback : shared_ptr_this->getEventCallbacks()) { |
| 1609 | if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos).isOk()) { |
| 1610 | LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4" |
| 1611 | << " callback on: " << toString(callback); |
| 1612 | } |
| 1613 | } |
| 1614 | }; |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1615 | legacy_hal::wifi_error legacy_status = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1616 | legacy_hal_.lock()->registerRadioModeChangeCallbackHandler( |
| 1617 | getFirstActiveWlanIfaceName(), on_radio_mode_change_callback); |
Roshan Pius | 85c6441 | 2018-01-22 17:58:40 -0800 | [diff] [blame] | 1618 | return createWifiStatusFromLegacyError(legacy_status); |
| 1619 | } |
| 1620 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1621 | std::vector<V1_6::IWifiChip::ChipConcurrencyCombination> |
| 1622 | WifiChip::getCurrentModeConcurrencyCombinations() { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1623 | if (!isValidModeId(current_mode_id_)) { |
| 1624 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1625 | return {}; |
| 1626 | } |
| 1627 | for (const auto& mode : modes_) { |
| 1628 | if (mode.id == current_mode_id_) { |
| 1629 | return mode.availableCombinations; |
| 1630 | } |
| 1631 | } |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1632 | CHECK(0) << "Expected to find concurrency combinations for current mode!"; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1633 | return {}; |
| 1634 | } |
| 1635 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1636 | // Returns a map indexed by IfaceConcurrencyType with the number of ifaces currently |
| 1637 | // created of the corresponding concurrency type. |
| 1638 | std::map<IfaceConcurrencyType, size_t> WifiChip::getCurrentConcurrencyCombination() { |
| 1639 | std::map<IfaceConcurrencyType, size_t> iface_counts; |
| 1640 | uint32_t num_ap = 0; |
| 1641 | uint32_t num_ap_bridged = 0; |
| 1642 | for (const auto& ap_iface : ap_ifaces_) { |
| 1643 | std::string ap_iface_name = ap_iface->getName(); |
| 1644 | if (br_ifaces_ap_instances_.count(ap_iface_name) > 0 && |
| 1645 | br_ifaces_ap_instances_[ap_iface_name].size() > 1) { |
| 1646 | num_ap_bridged++; |
| 1647 | } else { |
| 1648 | num_ap++; |
| 1649 | } |
| 1650 | } |
| 1651 | iface_counts[IfaceConcurrencyType::AP] = num_ap; |
| 1652 | iface_counts[IfaceConcurrencyType::AP_BRIDGED] = num_ap_bridged; |
| 1653 | iface_counts[IfaceConcurrencyType::NAN] = nan_ifaces_.size(); |
| 1654 | iface_counts[IfaceConcurrencyType::P2P] = p2p_ifaces_.size(); |
| 1655 | iface_counts[IfaceConcurrencyType::STA] = sta_ifaces_.size(); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1656 | return iface_counts; |
| 1657 | } |
| 1658 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1659 | // This expands the provided concurrency combinations to a more parseable |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1660 | // form. Returns a vector of available combinations possible with the number |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1661 | // of each concurrency type in the combination. |
| 1662 | // This method is a port of HalDeviceManager.expandConcurrencyCombos() from framework. |
| 1663 | std::vector<std::map<IfaceConcurrencyType, size_t>> WifiChip::expandConcurrencyCombinations( |
| 1664 | const V1_6::IWifiChip::ChipConcurrencyCombination& combination) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1665 | uint32_t num_expanded_combos = 1; |
| 1666 | for (const auto& limit : combination.limits) { |
| 1667 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1668 | num_expanded_combos *= limit.types.size(); |
| 1669 | } |
| 1670 | } |
| 1671 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1672 | // Allocate the vector of expanded combos and reset all concurrency type counts to 0 |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1673 | // in each combo. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1674 | std::vector<std::map<IfaceConcurrencyType, size_t>> expanded_combos; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1675 | expanded_combos.resize(num_expanded_combos); |
| 1676 | for (auto& expanded_combo : expanded_combos) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1677 | for (const auto type : |
| 1678 | {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, |
| 1679 | IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1680 | expanded_combo[type] = 0; |
| 1681 | } |
| 1682 | } |
| 1683 | uint32_t span = num_expanded_combos; |
| 1684 | for (const auto& limit : combination.limits) { |
| 1685 | for (uint32_t i = 0; i < limit.maxIfaces; i++) { |
| 1686 | span /= limit.types.size(); |
| 1687 | for (uint32_t k = 0; k < num_expanded_combos; ++k) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1688 | const auto iface_type = limit.types[(k / span) % limit.types.size()]; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1689 | expanded_combos[k][iface_type]++; |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | return expanded_combos; |
| 1694 | } |
| 1695 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1696 | bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes( |
| 1697 | const std::map<IfaceConcurrencyType, size_t>& expanded_combo, |
| 1698 | IfaceConcurrencyType requested_type) { |
| 1699 | const auto current_combo = getCurrentConcurrencyCombination(); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1700 | |
| 1701 | // Check if we have space for 1 more iface of |type| in this combo |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1702 | for (const auto type : |
| 1703 | {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, |
| 1704 | IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1705 | size_t num_ifaces_needed = current_combo.at(type); |
| 1706 | if (type == requested_type) { |
| 1707 | num_ifaces_needed++; |
| 1708 | } |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1709 | size_t num_ifaces_allowed = expanded_combo.at(type); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1710 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1711 | return false; |
| 1712 | } |
| 1713 | } |
| 1714 | return true; |
| 1715 | } |
| 1716 | |
| 1717 | // This method does the following: |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1718 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1719 | // ChipConcurrencyCombination. |
| 1720 | // b) Check if the requested concurrency type can be added to the current mode |
| 1721 | // with the concurrency combination that is already active. |
| 1722 | bool WifiChip::canCurrentModeSupportConcurrencyTypeWithCurrentTypes( |
| 1723 | IfaceConcurrencyType requested_type) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1724 | if (!isValidModeId(current_mode_id_)) { |
| 1725 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1726 | return false; |
| 1727 | } |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1728 | const auto combinations = getCurrentModeConcurrencyCombinations(); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1729 | for (const auto& combination : combinations) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1730 | const auto expanded_combos = expandConcurrencyCombinations(combination); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1731 | for (const auto& expanded_combo : expanded_combos) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1732 | if (canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes(expanded_combo, |
| 1733 | requested_type)) { |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1734 | return true; |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | return false; |
| 1739 | } |
| 1740 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1741 | // Note: This does not consider concurrency types already active. It only checks if the |
| 1742 | // provided expanded concurrency combination can support the requested combo. |
| 1743 | bool WifiChip::canExpandedConcurrencyComboSupportConcurrencyCombo( |
| 1744 | const std::map<IfaceConcurrencyType, size_t>& expanded_combo, |
| 1745 | const std::map<IfaceConcurrencyType, size_t>& req_combo) { |
| 1746 | // Check if we have space for 1 more |type| in this combo |
| 1747 | for (const auto type : |
| 1748 | {IfaceConcurrencyType::AP, IfaceConcurrencyType::AP_BRIDGED, IfaceConcurrencyType::NAN, |
| 1749 | IfaceConcurrencyType::P2P, IfaceConcurrencyType::STA}) { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1750 | if (req_combo.count(type) == 0) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1751 | // Concurrency type not in the req_combo. |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1752 | continue; |
| 1753 | } |
| 1754 | size_t num_ifaces_needed = req_combo.at(type); |
| 1755 | size_t num_ifaces_allowed = expanded_combo.at(type); |
| 1756 | if (num_ifaces_needed > num_ifaces_allowed) { |
| 1757 | return false; |
| 1758 | } |
| 1759 | } |
| 1760 | return true; |
| 1761 | } |
| 1762 | // This method does the following: |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1763 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1764 | // ChipConcurrencyCombination. |
| 1765 | // b) Check if the requested concurrency combo can be added to the current mode. |
| 1766 | // Note: This does not consider concurrency types already active. It only checks if the |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1767 | // current mode can support the requested combo. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1768 | bool WifiChip::canCurrentModeSupportConcurrencyCombo( |
| 1769 | const std::map<IfaceConcurrencyType, size_t>& req_combo) { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1770 | if (!isValidModeId(current_mode_id_)) { |
| 1771 | LOG(ERROR) << "Chip not configured in a mode yet"; |
| 1772 | return false; |
| 1773 | } |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1774 | const auto combinations = getCurrentModeConcurrencyCombinations(); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1775 | for (const auto& combination : combinations) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1776 | const auto expanded_combos = expandConcurrencyCombinations(combination); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1777 | for (const auto& expanded_combo : expanded_combos) { |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1778 | if (canExpandedConcurrencyComboSupportConcurrencyCombo(expanded_combo, req_combo)) { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1779 | return true; |
| 1780 | } |
| 1781 | } |
| 1782 | } |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | // This method does the following: |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1787 | // a) Enumerate all possible concurrency combos by expanding the current |
| 1788 | // ChipConcurrencyCombination. |
| 1789 | // b) Check if the requested concurrency type can be added to the current mode. |
| 1790 | bool WifiChip::canCurrentModeSupportConcurrencyType(IfaceConcurrencyType requested_type) { |
| 1791 | // Check if we can support at least 1 of the requested concurrency type. |
| 1792 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1793 | req_iface_combo[requested_type] = 1; |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1794 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 1797 | bool WifiChip::isValidModeId(ChipModeId mode_id) { |
| 1798 | for (const auto& mode : modes_) { |
| 1799 | if (mode.id == mode_id) { |
| 1800 | return true; |
| 1801 | } |
| 1802 | } |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1806 | bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() { |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1807 | // Check if we can support at least 1 STA & 1 AP concurrently. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1808 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
| 1809 | req_iface_combo[IfaceConcurrencyType::STA] = 1; |
| 1810 | req_iface_combo[IfaceConcurrencyType::AP] = 1; |
| 1811 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1814 | bool WifiChip::isDualStaConcurrencyAllowedInCurrentMode() { |
| 1815 | // Check if we can support at least 2 STA concurrently. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame] | 1816 | std::map<IfaceConcurrencyType, size_t> req_iface_combo; |
| 1817 | req_iface_combo[IfaceConcurrencyType::STA] = 2; |
| 1818 | return canCurrentModeSupportConcurrencyCombo(req_iface_combo); |
James Mattis | d2e4c07 | 2019-05-22 16:14:48 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1821 | std::string WifiChip::getFirstActiveWlanIfaceName() { |
Roshan Pius | 444473f | 2019-04-19 08:41:20 -0700 | [diff] [blame] | 1822 | if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName(); |
lesl | f012b65 | 2021-01-08 15:22:49 +0800 | [diff] [blame] | 1823 | if (ap_ifaces_.size() > 0) { |
| 1824 | // If the first active wlan iface is bridged iface. |
| 1825 | // Return first instance name. |
| 1826 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1827 | if (it.first == ap_ifaces_[0]->getName()) { |
| 1828 | return it.second[0]; |
| 1829 | } |
| 1830 | } |
| 1831 | return ap_ifaces_[0]->getName(); |
| 1832 | } |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1833 | // This could happen if the chip call is made before any STA/AP |
| 1834 | // iface is created. Default to wlan0 for such cases. |
Roshan Pius | 444473f | 2019-04-19 08:41:20 -0700 | [diff] [blame] | 1835 | LOG(WARNING) << "No active wlan interfaces in use! Using default"; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1836 | return getWlanIfaceNameWithType(IfaceType::STA, 0); |
Roshan Pius | 6036c02 | 2019-03-27 10:41:58 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1839 | // Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx| |
| 1840 | // not already in use. |
| 1841 | // Note: This doesn't check the actual presence of these interfaces. |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1842 | std::string WifiChip::allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx) { |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1843 | for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1844 | const auto ifname = getWlanIfaceNameWithType(type, idx); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1845 | if (findUsingNameFromBridgedApInstances(ifname)) continue; |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 1846 | if (findUsingName(ap_ifaces_, ifname)) continue; |
| 1847 | if (findUsingName(sta_ifaces_, ifname)) continue; |
| 1848 | return ifname; |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1849 | } |
| 1850 | // This should never happen. We screwed up somewhere if it did. |
Tomasz Wasilczyk | 77401d3 | 2018-12-20 12:42:54 -0800 | [diff] [blame] | 1851 | CHECK(false) << "All wlan interfaces in use already!"; |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 1852 | return {}; |
| 1853 | } |
| 1854 | |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1855 | uint32_t WifiChip::startIdxOfApIface() { |
| 1856 | if (isDualStaConcurrencyAllowedInCurrentMode()) { |
| 1857 | // When the HAL support dual STAs, AP should start with idx 2. |
| 1858 | return 2; |
| 1859 | } else if (isStaApConcurrencyAllowedInCurrentMode()) { |
| 1860 | // When the HAL support STA + AP but it doesn't support dual STAs. |
| 1861 | // AP should start with idx 1. |
| 1862 | return 1; |
| 1863 | } |
| 1864 | // No concurrency support. |
| 1865 | return 0; |
| 1866 | } |
| 1867 | |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1868 | // AP iface names start with idx 1 for modes supporting |
James Mattis | d2e4c07 | 2019-05-22 16:14:48 -0700 | [diff] [blame] | 1869 | // concurrent STA and not dual AP, else start with idx 0. |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1870 | std::string WifiChip::allocateApIfaceName() { |
Roshan Pius | 78cb599 | 2020-04-30 12:39:21 -0700 | [diff] [blame] | 1871 | // Check if we have a dedicated iface for AP. |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1872 | std::vector<std::string> ifnames = getPredefinedApIfaceNames(false); |
| 1873 | if (!ifnames.empty()) { |
| 1874 | return ifnames[0]; |
Roshan Pius | 78cb599 | 2020-04-30 12:39:21 -0700 | [diff] [blame] | 1875 | } |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1876 | return allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface()); |
| 1877 | } |
| 1878 | |
| 1879 | std::vector<std::string> WifiChip::allocateBridgedApInstanceNames() { |
| 1880 | // Check if we have a dedicated iface for AP. |
| 1881 | std::vector<std::string> instances = getPredefinedApIfaceNames(true); |
| 1882 | if (instances.size() == 2) { |
| 1883 | return instances; |
| 1884 | } else { |
| 1885 | int num_ifaces_need_to_allocate = 2 - instances.size(); |
| 1886 | for (int i = 0; i < num_ifaces_need_to_allocate; i++) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1887 | std::string instance_name = |
| 1888 | allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface() + i); |
lesl | 261818b | 2020-11-27 12:37:35 +0800 | [diff] [blame] | 1889 | if (!instance_name.empty()) { |
| 1890 | instances.push_back(instance_name); |
| 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | return instances; |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | // STA iface names start with idx 0. |
| 1898 | // Primary STA iface will always be 0. |
| 1899 | std::string WifiChip::allocateStaIfaceName() { |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1900 | return allocateApOrStaIfaceName(IfaceType::STA, 0); |
Roshan Pius | a3e5b7f | 2019-03-25 13:52:45 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1903 | bool WifiChip::writeRingbufferFilesInternal() { |
| 1904 | if (!removeOldFilesInternal()) { |
| 1905 | LOG(ERROR) << "Error occurred while deleting old tombstone files"; |
| 1906 | return false; |
| 1907 | } |
| 1908 | // write ringbuffers to file |
Veerendranath Jakkam | 25b3a6f | 2020-04-14 22:04:39 +0530 | [diff] [blame] | 1909 | { |
| 1910 | std::unique_lock<std::mutex> lk(lock_t); |
xshu | c905ea6 | 2021-07-11 19:57:02 -0700 | [diff] [blame] | 1911 | for (auto& item : ringbuffer_map_) { |
| 1912 | Ringbuffer& cur_buffer = item.second; |
Veerendranath Jakkam | 25b3a6f | 2020-04-14 22:04:39 +0530 | [diff] [blame] | 1913 | if (cur_buffer.getData().empty()) { |
| 1914 | continue; |
| 1915 | } |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1916 | const std::string file_path_raw = kTombstoneFolderPath + item.first + "XXXXXXXXXX"; |
Veerendranath Jakkam | 25b3a6f | 2020-04-14 22:04:39 +0530 | [diff] [blame] | 1917 | const int dump_fd = mkstemp(makeCharVec(file_path_raw).data()); |
| 1918 | if (dump_fd == -1) { |
| 1919 | PLOG(ERROR) << "create file failed"; |
| 1920 | return false; |
| 1921 | } |
| 1922 | unique_fd file_auto_closer(dump_fd); |
| 1923 | for (const auto& cur_block : cur_buffer.getData()) { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1924 | if (write(dump_fd, cur_block.data(), sizeof(cur_block[0]) * cur_block.size()) == |
| 1925 | -1) { |
Veerendranath Jakkam | 25b3a6f | 2020-04-14 22:04:39 +0530 | [diff] [blame] | 1926 | PLOG(ERROR) << "Error writing to file"; |
| 1927 | } |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1928 | } |
xshu | c905ea6 | 2021-07-11 19:57:02 -0700 | [diff] [blame] | 1929 | cur_buffer.clear(); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1930 | } |
xshu | 0a0fe51 | 2020-07-22 17:53:37 -0700 | [diff] [blame] | 1931 | // unique_lock unlocked here |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1932 | } |
| 1933 | return true; |
| 1934 | } |
| 1935 | |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1936 | std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) { |
| 1937 | std::string ifname; |
| 1938 | |
| 1939 | // let the legacy hal override the interface name |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1940 | legacy_hal::wifi_error err = legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname); |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 1941 | if (err == legacy_hal::WIFI_SUCCESS) return ifname; |
| 1942 | |
| 1943 | return getWlanIfaceName(idx); |
| 1944 | } |
| 1945 | |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1946 | void WifiChip::invalidateAndClearBridgedApAll() { |
| 1947 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1948 | for (auto const& iface : it.second) { |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1949 | iface_util_->removeIfaceFromBridge(it.first, iface); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1950 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
| 1951 | } |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1952 | iface_util_->deleteBridge(it.first); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1953 | } |
| 1954 | br_ifaces_ap_instances_.clear(); |
| 1955 | } |
| 1956 | |
| 1957 | void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) { |
| 1958 | if (br_name.empty()) return; |
| 1959 | // delete managed interfaces |
| 1960 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1961 | if (it.first == br_name) { |
| 1962 | for (auto const& iface : it.second) { |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1963 | iface_util_->removeIfaceFromBridge(br_name, iface); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1964 | legacy_hal_.lock()->deleteVirtualInterface(iface); |
| 1965 | } |
Roshan Pius | 8c1a67b | 2021-03-02 10:00:23 -0800 | [diff] [blame] | 1966 | iface_util_->deleteBridge(br_name); |
lesl | 94d2824 | 2020-11-18 22:17:37 +0800 | [diff] [blame] | 1967 | br_ifaces_ap_instances_.erase(br_name); |
| 1968 | break; |
| 1969 | } |
| 1970 | } |
| 1971 | return; |
| 1972 | } |
| 1973 | |
| 1974 | bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) { |
| 1975 | for (auto const& it : br_ifaces_ap_instances_) { |
| 1976 | if (it.first == name) { |
| 1977 | return true; |
| 1978 | } |
| 1979 | for (auto const& iface : it.second) { |
| 1980 | if (iface == name) { |
| 1981 | return true; |
| 1982 | } |
| 1983 | } |
| 1984 | } |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 1988 | } // namespace implementation |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 1989 | } // namespace V1_6 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1990 | } // namespace wifi |
| 1991 | } // namespace hardware |
| 1992 | } // namespace android |