blob: c1ce766a4ff98e7874ab711433a259fba4334e1f [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001/*
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
xshu5899e8e2018-01-09 15:36:03 -080017#include <fcntl.h>
18
Roshan Pius3c4e8a32016-10-03 14:53:58 -070019#include <android-base/logging.h>
xshu5899e8e2018-01-09 15:36:03 -080020#include <android-base/unique_fd.h>
Roshan Pius9377a0d2017-10-06 13:18:54 -070021#include <cutils/properties.h>
lesl94d28242020-11-18 22:17:37 +080022#include <net/if.h>
xshu5899e8e2018-01-09 15:36:03 -080023#include <sys/stat.h>
24#include <sys/sysmacros.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070025
Roshan Pius3c868522016-10-27 12:43:49 -070026#include "hidl_return_util.h"
Roshan Piuse2d0ab52016-12-05 15:24:20 -080027#include "hidl_struct_util.h"
Roshan Pius3c868522016-10-27 12:43:49 -070028#include "wifi_chip.h"
Roshan Pius5c055462016-10-11 08:27:27 -070029#include "wifi_status_util.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070030
Sunil Ravi7f2822a2021-10-15 16:55:53 -070031#define P2P_MGMT_DEVICE_PREFIX "p2p-dev-"
32
Roshan Pius35d958c2016-10-06 16:47:38 -070033namespace {
Jong Wook Kimda830c92018-07-23 15:29:38 -070034using android::sp;
xshu5899e8e2018-01-09 15:36:03 -080035using android::base::unique_fd;
Roshan Pius35d958c2016-10-06 16:47:38 -070036using android::hardware::hidl_string;
Roshan Piusabcf78f2017-10-06 16:30:38 -070037using android::hardware::hidl_vec;
Roshan Pius2c06a3f2016-12-15 17:51:40 -080038using android::hardware::wifi::V1_0::ChipModeId;
Roshan Pius52947fb2016-11-18 11:38:07 -080039using android::hardware::wifi::V1_0::IfaceType;
Roshan Pius675609b2017-10-31 14:24:58 -070040using android::hardware::wifi::V1_0::IWifiChip;
Roshan Pius52947fb2016-11-18 11:38:07 -080041
xshu5899e8e2018-01-09 15:36:03 -080042constexpr char kCpioMagic[] = "070701";
Roger Wangb294c762018-11-02 15:34:39 +080043constexpr size_t kMaxBufferSizeBytes = 1024 * 1024 * 3;
44constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60 * 10;
xshu37126c92018-04-13 16:24:45 -070045constexpr uint32_t kMaxRingBufferFileNum = 20;
xshu5899e8e2018-01-09 15:36:03 -080046constexpr char kTombstoneFolderPath[] = "/data/vendor/tombstones/wifi/";
Roshan Pius8574e7f2019-04-01 13:30:40 -070047constexpr char kActiveWlanIfaceNameProperty[] = "wifi.active.interface";
48constexpr char kNoActiveWlanIfaceNamePropertyValue[] = "";
49constexpr unsigned kMaxWlanIfaces = 5;
lesl94d28242020-11-18 22:17:37 +080050constexpr char kApBridgeIfacePrefix[] = "ap_br_";
xshu5899e8e2018-01-09 15:36:03 -080051
Roshan Pius35d958c2016-10-06 16:47:38 -070052template <typename Iface>
Roshan Pius675609b2017-10-31 14:24:58 -070053void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) {
54 iface->invalidate();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080055 ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface), ifaces.end());
Roshan Pius675609b2017-10-31 14:24:58 -070056}
57
58template <typename Iface>
59void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) {
60 for (const auto& iface : ifaces) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070061 iface->invalidate();
Roshan Piusabcf78f2017-10-06 16:30:38 -070062 }
Roshan Pius675609b2017-10-31 14:24:58 -070063 ifaces.clear();
64}
65
66template <typename Iface>
67std::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
75template <typename Iface>
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080076sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces, const std::string& name) {
Roshan Pius675609b2017-10-31 14:24:58 -070077 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 Pius35d958c2016-10-06 16:47:38 -070084}
Roshan Pius9377a0d2017-10-06 13:18:54 -070085
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -080086std::string getWlanIfaceName(unsigned idx) {
87 if (idx >= kMaxWlanIfaces) {
88 CHECK(false) << "Requested interface beyond wlan" << kMaxWlanIfaces;
89 return {};
90 }
Roshan Pius9377a0d2017-10-06 13:18:54 -070091
Roshan Pius8e3c7ef2017-11-03 09:43:08 -070092 std::array<char, PROPERTY_VALUE_MAX> buffer;
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -080093 if (idx == 0 || idx == 1) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080094 const char* altPropName = (idx == 0) ? "wifi.interface" : "wifi.concurrent.interface";
Roshan Pius5b333462019-03-01 14:07:22 -080095 auto res = property_get(altPropName, buffer.data(), nullptr);
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -080096 if (res > 0) return buffer.data();
97 }
Roshan Pius5b333462019-03-01 14:07:22 -080098 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 Wasilczyk77401d32018-12-20 12:42:54 -0800101
102 return "wlan" + std::to_string(idx);
Roshan Pius9377a0d2017-10-06 13:18:54 -0700103}
Roshan Pius9377a0d2017-10-06 13:18:54 -0700104
lesl261818b2020-11-27 12:37:35 +0800105// Returns the dedicated iface name if defined.
106// Returns two ifaces in bridged mode.
107std::vector<std::string> getPredefinedApIfaceNames(bool is_bridged) {
108 std::vector<std::string> ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700109 std::array<char, PROPERTY_VALUE_MAX> buffer;
lesl261818b2020-11-27 12:37:35 +0800110 buffer.fill(0);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800111 if (property_get("ro.vendor.wifi.sap.interface", buffer.data(), nullptr) == 0) {
lesl261818b2020-11-27 12:37:35 +0800112 return ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700113 }
lesl261818b2020-11-27 12:37:35 +0800114 ifnames.push_back(buffer.data());
115 if (is_bridged) {
116 buffer.fill(0);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800117 if (property_get("ro.vendor.wifi.sap.concurrent.iface", buffer.data(), nullptr) == 0) {
lesl261818b2020-11-27 12:37:35 +0800118 return ifnames;
119 }
120 ifnames.push_back(buffer.data());
121 }
122 return ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700123}
124
lesl261818b2020-11-27 12:37:35 +0800125std::string getPredefinedP2pIfaceName() {
Sunil Ravi7f2822a2021-10-15 16:55:53 -0700126 std::array<char, PROPERTY_VALUE_MAX> primaryIfaceName;
127 char p2pParentIfname[100];
128 std::string p2pDevIfName = "";
Roshan Piusabcf78f2017-10-06 16:30:38 -0700129 std::array<char, PROPERTY_VALUE_MAX> buffer;
130 property_get("wifi.direct.interface", buffer.data(), "p2p0");
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800131 if (strncmp(buffer.data(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
Sunil Ravi7f2822a2021-10-15 16:55:53 -0700132 /* 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 ElArabawy687ce132022-01-11 16:42:48 -0800136 if (property_get(kActiveWlanIfaceNameProperty, primaryIfaceName.data(), nullptr) == 0) {
Sunil Ravi7f2822a2021-10-15 16:55:53 -0700137 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 ElArabawy687ce132022-01-11 16:42:48 -0800142 strlen(buffer.data()) - strlen(P2P_MGMT_DEVICE_PREFIX)) != 0) {
Sunil Ravi7f2822a2021-10-15 16:55:53 -0700143 /*
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 ElArabawy687ce132022-01-11 16:42:48 -0800149 LOG(INFO) << "update the p2p device interface name to " << p2pDevIfName.c_str();
Sunil Ravi7f2822a2021-10-15 16:55:53 -0700150 return p2pDevIfName;
151 }
152 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700153 return buffer.data();
Roshan Pius9377a0d2017-10-06 13:18:54 -0700154}
155
Roshan Pius5ba0a902020-04-14 11:55:42 -0700156// Returns the dedicated iface name if one is defined.
lesl261818b2020-11-27 12:37:35 +0800157std::string getPredefinedNanIfaceName() {
Roshan Pius5ba0a902020-04-14 11:55:42 -0700158 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 Pius8574e7f2019-04-01 13:30:40 -0700165void 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
xshu37126c92018-04-13 16:24:45 -0700172// 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
xshu5899e8e2018-01-09 15:36:03 -0800175bool removeOldFilesInternal() {
176 time_t now = time(0);
177 const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800178 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(kTombstoneFolderPath), closedir);
xshu5899e8e2018-01-09 15:36:03 -0800179 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800180 PLOG(ERROR) << "Failed to open directory";
xshu5899e8e2018-01-09 15:36:03 -0800181 return false;
182 }
xshu5899e8e2018-01-09 15:36:03 -0800183 struct dirent* dp;
184 bool success = true;
xshu37126c92018-04-13 16:24:45 -0700185 std::list<std::pair<const time_t, std::string>> valid_files;
Josh Gaoa568e532018-06-04 18:16:00 -0700186 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800187 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;
xshu4cb33162018-01-24 15:40:06 -0800193 if (stat(cur_file_path.c_str(), &cur_file_stat) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800194 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800195 success = false;
xshu4cb33162018-01-24 15:40:06 -0800196 continue;
197 }
xshu37126c92018-04-13 16:24:45 -0700198 const time_t cur_file_time = cur_file_stat.st_mtime;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800199 valid_files.push_back(std::pair<const time_t, std::string>(cur_file_time, cur_file_path));
xshu37126c92018-04-13 16:24:45 -0700200 }
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 ElArabawy687ce132022-01-11 16:42:48 -0800205 if (cur_file_count > kMaxRingBufferFileNum || cur_file.first < delete_files_before) {
xshu37126c92018-04-13 16:24:45 -0700206 if (unlink(cur_file.second.c_str()) != 0) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800207 PLOG(ERROR) << "Error deleting file";
xshu37126c92018-04-13 16:24:45 -0700208 success = false;
209 }
210 cur_file_count--;
211 } else {
212 break;
xshu5899e8e2018-01-09 15:36:03 -0800213 }
214 }
215 return success;
216}
217
xshu4cb33162018-01-24 15:40:06 -0800218// Helper function for |cpioArchiveFilesInDir|
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800219bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name, size_t file_name_len) {
xshu4cb33162018-01-24 15:40:06 -0800220 std::array<char, 32 * 1024> read_buf;
221 ssize_t llen =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800222 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);
xshu4cb33162018-01-24 15:40:06 -0800227 if (write(out_fd, read_buf.data(), llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800228 PLOG(ERROR) << "Error writing cpio header to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800229 return false;
230 }
231 if (write(out_fd, file_name, file_name_len) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800232 PLOG(ERROR) << "Error writing filename to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800233 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 Hughes4db4add2019-03-08 12:42:57 -0800241 PLOG(ERROR) << "Error padding 0s to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800242 return false;
243 }
244 }
245 return true;
246}
247
248// Helper function for |cpioArchiveFilesInDir|
249size_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 Hughes4db4add2019-03-08 12:42:57 -0800257 PLOG(ERROR) << "Error reading file";
xshu4cb33162018-01-24 15:40:06 -0800258 return ++n_error;
259 }
260 llen -= bytes_read;
261 if (write(out_fd, read_buf.data(), bytes_read) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800262 PLOG(ERROR) << "Error writing data to file";
xshu4cb33162018-01-24 15:40:06 -0800263 return ++n_error;
264 }
265 if (bytes_read == 0) { // this should never happen, but just in case
266 // to unstuck from while loop
Elliott Hughes4db4add2019-03-08 12:42:57 -0800267 PLOG(ERROR) << "Unexpected read result";
xshu4cb33162018-01-24 15:40:06 -0800268 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 Hughes4db4add2019-03-08 12:42:57 -0800276 PLOG(ERROR) << "Error padding 0s to file";
xshu4cb33162018-01-24 15:40:06 -0800277 return ++n_error;
278 }
279 }
280 return n_error;
281}
282
283// Helper function for |cpioArchiveFilesInDir|
284bool 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 ElArabawy687ce132022-01-11 16:42:48 -0800288 sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0) + 4) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800289 PLOG(ERROR) << "Error writing trailing bytes";
xshu4cb33162018-01-24 15:40:06 -0800290 return false;
291 }
292 return true;
293}
294
xshu5899e8e2018-01-09 15:36:03 -0800295// 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
xshu4cb33162018-01-24 15:40:06 -0800298size_t cpioArchiveFilesInDir(int out_fd, const char* input_dir) {
xshu5899e8e2018-01-09 15:36:03 -0800299 struct dirent* dp;
300 size_t n_error = 0;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800301 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(input_dir), closedir);
xshu5899e8e2018-01-09 15:36:03 -0800302 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800303 PLOG(ERROR) << "Failed to open directory";
xshu4cb33162018-01-24 15:40:06 -0800304 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800305 }
Josh Gaoa568e532018-06-04 18:16:00 -0700306 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800307 if (dp->d_type != DT_REG) {
308 continue;
309 }
310 std::string cur_file_name(dp->d_name);
xshu5899e8e2018-01-09 15:36:03 -0800311 struct stat st;
xshu5899e8e2018-01-09 15:36:03 -0800312 const std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
xshu4cb33162018-01-24 15:40:06 -0800313 if (stat(cur_file_path.c_str(), &st) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800314 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800315 n_error++;
xshu4cb33162018-01-24 15:40:06 -0800316 continue;
317 }
318 const int fd_read = open(cur_file_path.c_str(), O_RDONLY);
319 if (fd_read == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800320 PLOG(ERROR) << "Failed to open file " << cur_file_path;
xshu4cb33162018-01-24 15:40:06 -0800321 n_error++;
322 continue;
323 }
xshuf392fb42020-08-13 16:57:00 -0700324 std::string file_name_with_last_modified_time =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800325 cur_file_name + "-" + std::to_string(st.st_mtime);
xshuf392fb42020-08-13 16:57:00 -0700326 // 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 ElArabawy687ce132022-01-11 16:42:48 -0800328 const size_t file_name_len = file_name_with_last_modified_time.size() + 1;
xshu4cb33162018-01-24 15:40:06 -0800329 unique_fd file_auto_closer(fd_read);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800330 if (!cpioWriteHeader(out_fd, st, file_name_with_last_modified_time.c_str(),
xshu4cb33162018-01-24 15:40:06 -0800331 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;
xshu5899e8e2018-01-09 15:36:03 -0800337 }
338 }
xshu4cb33162018-01-24 15:40:06 -0800339 if (!cpioWriteFileTrailer(out_fd)) {
340 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800341 }
342 return n_error;
343}
344
345// Helper function to create a non-const char*.
346std::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 Piusabcf78f2017-10-06 16:30:38 -0700353} // namespace
Roshan Pius35d958c2016-10-06 16:47:38 -0700354
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700355namespace android {
356namespace hardware {
357namespace wifi {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800358namespace V1_6 {
Roshan Pius79a99752016-10-04 13:03:58 -0700359namespace implementation {
Roshan Pius3c868522016-10-27 12:43:49 -0700360using hidl_return_util::validateAndCall;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800361using hidl_return_util::validateAndCallWithLock;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700362
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800363WifiChip::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 Pius52947fb2016-11-18 11:38:07 -0800369 : chip_id_(chip_id),
370 legacy_hal_(legacy_hal),
371 mode_controller_(mode_controller),
Roshan Pius99dab382019-02-14 07:57:10 -0800372 iface_util_(iface_util),
Roshan Pius52947fb2016-11-18 11:38:07 -0800373 is_valid_(true),
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800374 current_mode_id_(feature_flags::chip_mode_ids::kInvalid),
Jimmy Chen2dddd792019-12-23 17:50:39 +0200375 modes_(feature_flags.lock()->getChipModes(is_primary)),
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700376 debug_ring_buffer_cb_registered_(false),
377 subsystemCallbackHandler_(handler) {
Roshan Pius8574e7f2019-04-01 13:30:40 -0700378 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
379}
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700380
Roshan Piusaabe5752016-09-29 09:03:59 -0700381void WifiChip::invalidate() {
xshu37126c92018-04-13 16:24:45 -0700382 if (!writeRingbufferFilesInternal()) {
383 LOG(ERROR) << "Error writing files to flash";
384 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700385 invalidateAndRemoveAllIfaces();
Roshan Pius8574e7f2019-04-01 13:30:40 -0700386 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700387 legacy_hal_.reset();
388 event_cb_handler_.invalidate();
389 is_valid_ = false;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700390}
391
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800392bool WifiChip::isValid() {
393 return is_valid_;
394}
Roshan Pius3c868522016-10-27 12:43:49 -0700395
Jimmy Chend460df32019-11-29 17:31:22 +0200396std::set<sp<V1_4::IWifiChipEventCallback>> WifiChip::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700397 return event_cb_handler_.getCallbacks();
Roshan Pius203cb032016-12-14 17:41:20 -0800398}
399
Roshan Pius5c055462016-10-11 08:27:27 -0700400Return<void> WifiChip::getId(getId_cb hidl_status_cb) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800401 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID, &WifiChip::getIdInternal,
402 hidl_status_cb);
Roshan Piuscd566bd2016-10-10 08:03:42 -0700403}
404
Jong Wook Kimda830c92018-07-23 15:29:38 -0700405// Deprecated support for this callback
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800406Return<void> WifiChip::registerEventCallback(const sp<V1_0::IWifiChipEventCallback>& event_callback,
407 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700408 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800409 &WifiChip::registerEventCallbackInternal, hidl_status_cb,
410 event_callback);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700411}
412
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700413Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700414 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
415 &WifiChip::getCapabilitiesInternal, hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700416}
417
Roshan Pius5c055462016-10-11 08:27:27 -0700418Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700419 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800420 &WifiChip::getAvailableModesInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700421}
422
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800423Return<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 Pius3c4e8a32016-10-03 14:53:58 -0700426}
427
Roshan Pius5c055462016-10-11 08:27:27 -0700428Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700429 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
430 &WifiChip::getModeInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700431}
432
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800433Return<void> WifiChip::requestChipDebugInfo(requestChipDebugInfo_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700434 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800435 &WifiChip::requestChipDebugInfoInternal, hidl_status_cb);
Roshan Pius5c055462016-10-11 08:27:27 -0700436}
437
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800438Return<void> WifiChip::requestDriverDebugDump(requestDriverDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700439 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800440 &WifiChip::requestDriverDebugDumpInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700441}
442
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800443Return<void> WifiChip::requestFirmwareDebugDump(requestFirmwareDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700444 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800445 &WifiChip::requestFirmwareDebugDumpInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700446}
447
Roshan Pius5c055462016-10-11 08:27:27 -0700448Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700449 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
450 &WifiChip::createApIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700451}
452
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800453Return<void> WifiChip::createBridgedApIface(createBridgedApIface_cb hidl_status_cb) {
lesl94d28242020-11-18 22:17:37 +0800454 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800455 &WifiChip::createBridgedApIfaceInternal, hidl_status_cb);
lesl94d28242020-11-18 22:17:37 +0800456}
457
Roshan Pius5c055462016-10-11 08:27:27 -0700458Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700459 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
460 &WifiChip::getApIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700461}
462
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800463Return<void> WifiChip::getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700464 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800465 &WifiChip::getApIfaceInternal, hidl_status_cb, ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700466}
467
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800468Return<void> WifiChip::removeApIface(const hidl_string& ifname, removeApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700469 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800470 &WifiChip::removeApIfaceInternal, hidl_status_cb, ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800471}
472
lesl94d28242020-11-18 22:17:37 +0800473Return<void> WifiChip::removeIfaceInstanceFromBridgedApIface(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800474 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);
lesl94d28242020-11-18 22:17:37 +0800479}
480
Roshan Pius5c055462016-10-11 08:27:27 -0700481Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700482 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
483 &WifiChip::createNanIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700484}
485
Roshan Pius5c055462016-10-11 08:27:27 -0700486Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700487 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
488 &WifiChip::getNanIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700489}
490
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800491Return<void> WifiChip::getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700492 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800493 &WifiChip::getNanIfaceInternal, hidl_status_cb, ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700494}
495
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800496Return<void> WifiChip::removeNanIface(const hidl_string& ifname, removeNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700497 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800498 &WifiChip::removeNanIfaceInternal, hidl_status_cb, ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800499}
500
Roshan Pius5c055462016-10-11 08:27:27 -0700501Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700502 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
503 &WifiChip::createP2pIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700504}
505
Roshan Pius5c055462016-10-11 08:27:27 -0700506Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700507 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
508 &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700509}
510
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800511Return<void> WifiChip::getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700512 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800513 &WifiChip::getP2pIfaceInternal, hidl_status_cb, ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700514}
515
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800516Return<void> WifiChip::removeP2pIface(const hidl_string& ifname, removeP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700517 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800518 &WifiChip::removeP2pIfaceInternal, hidl_status_cb, ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800519}
520
Roshan Pius5c055462016-10-11 08:27:27 -0700521Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700522 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
523 &WifiChip::createStaIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700524}
525
Roshan Pius5c055462016-10-11 08:27:27 -0700526Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700527 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
528 &WifiChip::getStaIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700529}
530
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800531Return<void> WifiChip::getStaIface(const hidl_string& ifname, getStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700532 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800533 &WifiChip::getStaIfaceInternal, hidl_status_cb, ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700534}
535
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800536Return<void> WifiChip::removeStaIface(const hidl_string& ifname, removeStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700537 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800538 &WifiChip::removeStaIfaceInternal, hidl_status_cb, ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800539}
540
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800541Return<void> WifiChip::createRttController(const sp<IWifiIface>& bound_iface,
542 createRttController_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700543 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800544 &WifiChip::createRttControllerInternal, hidl_status_cb, bound_iface);
Roshan Pius59268282016-10-06 20:23:47 -0700545}
546
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800547Return<void> WifiChip::getDebugRingBuffersStatus(getDebugRingBuffersStatus_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700548 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800549 &WifiChip::getDebugRingBuffersStatusInternal, hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700550}
551
552Return<void> WifiChip::startLoggingToDebugRingBuffer(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800553 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 Piusabcf78f2017-10-06 16:30:38 -0700556 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800557 &WifiChip::startLoggingToDebugRingBufferInternal, hidl_status_cb,
558 ring_name, verbose_level, max_interval_in_sec, min_data_size_in_bytes);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700559}
560
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800561Return<void> WifiChip::forceDumpToDebugRingBuffer(const hidl_string& ring_name,
562 forceDumpToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700563 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800564 &WifiChip::forceDumpToDebugRingBufferInternal, hidl_status_cb,
565 ring_name);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700566}
567
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800568Return<void> WifiChip::flushRingBufferToFile(flushRingBufferToFile_cb hidl_status_cb) {
Roger Wangb294c762018-11-02 15:34:39 +0800569 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800570 &WifiChip::flushRingBufferToFileInternal, hidl_status_cb);
Roger Wangb294c762018-11-02 15:34:39 +0800571}
572
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800573Return<void> WifiChip::stopLoggingToDebugRingBuffer(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800574 stopLoggingToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700575 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800576 &WifiChip::stopLoggingToDebugRingBufferInternal, hidl_status_cb);
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800577}
578
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800579Return<void> WifiChip::getDebugHostWakeReasonStats(getDebugHostWakeReasonStats_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700580 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800581 &WifiChip::getDebugHostWakeReasonStatsInternal, hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700582}
583
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800584Return<void> WifiChip::enableDebugErrorAlerts(bool enable,
585 enableDebugErrorAlerts_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700586 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800587 &WifiChip::enableDebugErrorAlertsInternal, hidl_status_cb, enable);
Roshan Pius203cb032016-12-14 17:41:20 -0800588}
589
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800590Return<void> WifiChip::selectTxPowerScenario(V1_1::IWifiChip::TxPowerScenario scenario,
591 selectTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700592 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800593 &WifiChip::selectTxPowerScenarioInternal, hidl_status_cb, scenario);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700594}
595
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800596Return<void> WifiChip::resetTxPowerScenario(resetTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700597 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800598 &WifiChip::resetTxPowerScenarioInternal, hidl_status_cb);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700599}
600
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800601Return<void> WifiChip::setLatencyMode(LatencyMode mode, setLatencyMode_cb hidl_status_cb) {
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700602 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800603 &WifiChip::setLatencyModeInternal, hidl_status_cb, mode);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700604}
605
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800606Return<void> WifiChip::registerEventCallback_1_2(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800607 const sp<V1_2::IWifiChipEventCallback>& event_callback,
608 registerEventCallback_cb hidl_status_cb) {
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800609 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800610 &WifiChip::registerEventCallbackInternal_1_2, hidl_status_cb,
611 event_callback);
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800612}
613
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800614Return<void> WifiChip::selectTxPowerScenario_1_2(TxPowerScenario scenario,
615 selectTxPowerScenario_cb hidl_status_cb) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800616 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800617 &WifiChip::selectTxPowerScenarioInternal_1_2, hidl_status_cb, scenario);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800618}
619
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700620Return<void> WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) {
621 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800622 &WifiChip::getCapabilitiesInternal_1_3, hidl_status_cb);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700623}
624
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800625Return<void> WifiChip::getCapabilities_1_5(getCapabilities_1_5_cb hidl_status_cb) {
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200626 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800627 &WifiChip::getCapabilitiesInternal_1_5, hidl_status_cb);
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200628}
629
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800630Return<void> WifiChip::debug(const hidl_handle& handle, const hidl_vec<hidl_string>&) {
xshu5899e8e2018-01-09 15:36:03 -0800631 if (handle != nullptr && handle->numFds >= 1) {
xshu0a0fe512020-07-22 17:53:37 -0700632 {
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.
xshu5899e8e2018-01-09 15:36:03 -0800641 int fd = handle->data[0];
642 if (!writeRingbufferFilesInternal()) {
643 LOG(ERROR) << "Error writing files to flash";
644 }
xshu4cb33162018-01-24 15:40:06 -0800645 uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath);
xshu5899e8e2018-01-09 15:36:03 -0800646 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 ElArabawy687ce132022-01-11 16:42:48 -0800656Return<void> WifiChip::createRttController_1_4(const sp<IWifiIface>& bound_iface,
657 createRttController_1_4_cb hidl_status_cb) {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700658 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800659 &WifiChip::createRttControllerInternal_1_4, hidl_status_cb, bound_iface);
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700660}
661
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800662Return<void> WifiChip::registerEventCallback_1_4(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800663 const sp<V1_4::IWifiChipEventCallback>& event_callback,
664 registerEventCallback_cb hidl_status_cb) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800665 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800666 &WifiChip::registerEventCallbackInternal_1_4, hidl_status_cb,
667 event_callback);
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800668}
669
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800670Return<void> WifiChip::setMultiStaPrimaryConnection(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800671 const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) {
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800672 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800673 &WifiChip::setMultiStaPrimaryConnectionInternal, hidl_status_cb, ifname);
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800674}
675
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800676Return<void> WifiChip::setMultiStaUseCase(MultiStaUseCase use_case,
677 setMultiStaUseCase_cb hidl_status_cb) {
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800678 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800679 &WifiChip::setMultiStaUseCaseInternal, hidl_status_cb, use_case);
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800680}
681
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800682Return<void> WifiChip::setCoexUnsafeChannels(const hidl_vec<CoexUnsafeChannel>& unsafeChannels,
683 hidl_bitfield<CoexRestriction> restrictions,
684 setCoexUnsafeChannels_cb hidl_status_cb) {
Quang Luong94bcce52020-11-25 17:52:19 -0800685 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800686 &WifiChip::setCoexUnsafeChannelsInternal, hidl_status_cb, unsafeChannels,
687 restrictions);
Quang Luong94bcce52020-11-25 17:52:19 -0800688}
689
Kumar Anandda62c382020-11-18 17:17:47 -0800690Return<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 ElArabawy687ce132022-01-11 16:42:48 -0800693 &WifiChip::setCountryCodeInternal, hidl_status_cb, code);
Kumar Anandda62c382020-11-18 17:17:47 -0800694}
695
Kumar Anand2a630a32021-01-21 14:09:14 -0800696Return<void> WifiChip::getUsableChannels(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800697 WifiBand band, hidl_bitfield<V1_5::WifiIfaceMode> ifaceModeMask,
698 hidl_bitfield<V1_5::IWifiChip::UsableChannelFilter> filterMask,
699 getUsableChannels_cb _hidl_cb) {
Kumar Anand2a630a32021-01-21 14:09:14 -0800700 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800701 &WifiChip::getUsableChannelsInternal, _hidl_cb, band, ifaceModeMask,
702 filterMask);
Kumar Anand2a630a32021-01-21 14:09:14 -0800703}
704
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800705Return<void> WifiChip::triggerSubsystemRestart(triggerSubsystemRestart_cb hidl_status_cb) {
chenpaulc6f57032021-03-05 17:06:50 +0800706 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800707 &WifiChip::triggerSubsystemRestartInternal, hidl_status_cb);
chenpaulc6f57032021-03-05 17:06:50 +0800708}
709
Roshan Pius35d958c2016-10-06 16:47:38 -0700710void WifiChip::invalidateAndRemoveAllIfaces() {
lesl94d28242020-11-18 22:17:37 +0800711 invalidateAndClearBridgedApAll();
Roshan Pius675609b2017-10-31 14:24:58 -0700712 invalidateAndClearAll(ap_ifaces_);
713 invalidateAndClearAll(nan_ifaces_);
714 invalidateAndClearAll(p2p_ifaces_);
715 invalidateAndClearAll(sta_ifaces_);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700716 // Since all the ifaces are invalid now, all RTT controller objects
717 // using those ifaces also need to be invalidated.
718 for (const auto& rtt : rtt_controllers_) {
719 rtt->invalidate();
720 }
721 rtt_controllers_.clear();
Roshan Pius35d958c2016-10-06 16:47:38 -0700722}
723
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800724void WifiChip::invalidateAndRemoveDependencies(const std::string& removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200725 for (auto it = nan_ifaces_.begin(); it != nan_ifaces_.end();) {
726 auto nan_iface = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700727 if (nan_iface->getName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200728 nan_iface->invalidate();
Roshan Pius82368502019-05-16 12:53:02 -0700729 for (const auto& callback : event_cb_handler_.getCallbacks()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800730 if (!callback->onIfaceRemoved(IfaceType::NAN, removed_iface_name).isOk()) {
Roshan Pius82368502019-05-16 12:53:02 -0700731 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
732 }
733 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200734 it = nan_ifaces_.erase(it);
735 } else {
736 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700737 }
738 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200739
740 for (auto it = rtt_controllers_.begin(); it != rtt_controllers_.end();) {
741 auto rtt = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700742 if (rtt->getIfaceName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200743 rtt->invalidate();
744 it = rtt_controllers_.erase(it);
745 } else {
746 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700747 }
748 }
749}
750
Roshan Pius3c868522016-10-27 12:43:49 -0700751std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700752 return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700753}
754
755WifiStatus WifiChip::registerEventCallbackInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800756 const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) {
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800757 // Deprecated support for this callback.
758 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius3c868522016-10-27 12:43:49 -0700759}
760
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700761std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() {
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700762 // Deprecated support for this callback.
763 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
764}
765
Jimmy Chend460df32019-11-29 17:31:22 +0200766std::pair<WifiStatus, std::vector<V1_4::IWifiChip::ChipMode>>
Roshan Pius3c868522016-10-27 12:43:49 -0700767WifiChip::getAvailableModesInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700768 return {createWifiStatus(WifiStatusCode::SUCCESS), modes_};
Roshan Pius3c868522016-10-27 12:43:49 -0700769}
770
Roshan Piusba38d9c2017-12-08 07:32:08 -0800771WifiStatus WifiChip::configureChipInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800772 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id) {
Roshan Piuscc338202017-11-02 13:54:09 -0700773 if (!isValidModeId(mode_id)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700774 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
775 }
776 if (mode_id == current_mode_id_) {
777 LOG(DEBUG) << "Already in the specified mode " << mode_id;
778 return createWifiStatus(WifiStatusCode::SUCCESS);
779 }
Roshan Piusba38d9c2017-12-08 07:32:08 -0800780 WifiStatus status = handleChipConfiguration(lock, mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700781 if (status.code != WifiStatusCode::SUCCESS) {
782 for (const auto& callback : event_cb_handler_.getCallbacks()) {
783 if (!callback->onChipReconfigureFailure(status).isOk()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800784 LOG(ERROR) << "Failed to invoke onChipReconfigureFailure callback";
Roshan Piusabcf78f2017-10-06 16:30:38 -0700785 }
786 }
787 return status;
788 }
Roshan Piusd37341f2017-01-31 13:13:28 -0800789 for (const auto& callback : event_cb_handler_.getCallbacks()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700790 if (!callback->onChipReconfigured(mode_id).isOk()) {
791 LOG(ERROR) << "Failed to invoke onChipReconfigured callback";
792 }
Roshan Pius52947fb2016-11-18 11:38:07 -0800793 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700794 current_mode_id_ = mode_id;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800795 LOG(INFO) << "Configured chip in mode " << mode_id;
Roshan Pius8574e7f2019-04-01 13:30:40 -0700796 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700797
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800798 legacy_hal_.lock()->registerSubsystemRestartCallbackHandler(subsystemCallbackHandler_);
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700799
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800800 return status;
Roshan Pius3c868522016-10-27 12:43:49 -0700801}
802
803std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700804 if (!isValidModeId(current_mode_id_)) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800805 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), current_mode_id_};
Roshan Piusabcf78f2017-10-06 16:30:38 -0700806 }
807 return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700808}
809
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800810std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> WifiChip::requestChipDebugInfoInternal() {
Jimmy Chend460df32019-11-29 17:31:22 +0200811 V1_4::IWifiChip::ChipDebugInfo result;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700812 legacy_hal::wifi_error legacy_status;
813 std::string driver_desc;
Roshan Pius6036c022019-03-27 10:41:58 -0700814 const auto ifname = getFirstActiveWlanIfaceName();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800815 std::tie(legacy_status, driver_desc) = legacy_hal_.lock()->getDriverVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700816 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800817 LOG(ERROR) << "Failed to get driver version: " << legacyErrorToString(legacy_status);
818 WifiStatus status =
819 createWifiStatusFromLegacyError(legacy_status, "failed to get driver version");
Roshan Piusabcf78f2017-10-06 16:30:38 -0700820 return {status, result};
821 }
822 result.driverDescription = driver_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700823
Roshan Piusabcf78f2017-10-06 16:30:38 -0700824 std::string firmware_desc;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800825 std::tie(legacy_status, firmware_desc) = legacy_hal_.lock()->getFirmwareVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700826 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800827 LOG(ERROR) << "Failed to get firmware version: " << legacyErrorToString(legacy_status);
828 WifiStatus status =
829 createWifiStatusFromLegacyError(legacy_status, "failed to get firmware version");
Roshan Piusabcf78f2017-10-06 16:30:38 -0700830 return {status, result};
831 }
832 result.firmwareDescription = firmware_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700833
Roshan Piusabcf78f2017-10-06 16:30:38 -0700834 return {createWifiStatus(WifiStatusCode::SUCCESS), result};
Roshan Pius3c868522016-10-27 12:43:49 -0700835}
836
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800837std::pair<WifiStatus, std::vector<uint8_t>> WifiChip::requestDriverDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700838 legacy_hal::wifi_error legacy_status;
839 std::vector<uint8_t> driver_dump;
840 std::tie(legacy_status, driver_dump) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800841 legacy_hal_.lock()->requestDriverMemoryDump(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700842 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800843 LOG(ERROR) << "Failed to get driver debug dump: " << legacyErrorToString(legacy_status);
844 return {createWifiStatusFromLegacyError(legacy_status), std::vector<uint8_t>()};
Roshan Piusabcf78f2017-10-06 16:30:38 -0700845 }
846 return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700847}
848
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800849std::pair<WifiStatus, std::vector<uint8_t>> WifiChip::requestFirmwareDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700850 legacy_hal::wifi_error legacy_status;
851 std::vector<uint8_t> firmware_dump;
852 std::tie(legacy_status, firmware_dump) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800853 legacy_hal_.lock()->requestFirmwareMemoryDump(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700854 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800855 LOG(ERROR) << "Failed to get firmware debug dump: " << legacyErrorToString(legacy_status);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700856 return {createWifiStatusFromLegacyError(legacy_status), {}};
857 }
858 return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700859}
860
lesl94d28242020-11-18 22:17:37 +0800861WifiStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) {
862 legacy_hal::wifi_error legacy_status;
863 legacy_status = legacy_hal_.lock()->createVirtualInterface(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800864 apVirtIf, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::AP));
Sunil Raviddab4bb2020-02-03 22:45:19 -0800865 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
lesl94d28242020-11-18 22:17:37 +0800866 LOG(ERROR) << "Failed to add interface: " << apVirtIf << " "
Sunil Raviddab4bb2020-02-03 22:45:19 -0800867 << legacyErrorToString(legacy_status);
lesl94d28242020-11-18 22:17:37 +0800868 return createWifiStatusFromLegacyError(legacy_status);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800869 }
lesl94d28242020-11-18 22:17:37 +0800870 return createWifiStatus(WifiStatusCode::SUCCESS);
871}
872
873sp<WifiApIface> WifiChip::newWifiApIface(std::string& ifname) {
lesl420c4fc2020-11-23 19:33:04 +0800874 std::vector<std::string> ap_instances;
875 for (auto const& it : br_ifaces_ap_instances_) {
876 if (it.first == ifname) {
877 ap_instances = it.second;
878 }
879 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800880 sp<WifiApIface> iface = new WifiApIface(ifname, ap_instances, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -0700881 ap_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700882 for (const auto& callback : event_cb_handler_.getCallbacks()) {
883 if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) {
884 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
885 }
886 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700887 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
lesl94d28242020-11-18 22:17:37 +0800888 return iface;
889}
890
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800891std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::createApIfaceInternal() {
lesl94d28242020-11-18 22:17:37 +0800892 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
893 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
894 }
895 std::string ifname = allocateApIfaceName();
896 WifiStatus status = createVirtualApInterface(ifname);
897 if (status.code != WifiStatusCode::SUCCESS) {
898 return {status, {}};
899 }
900 sp<WifiApIface> iface = newWifiApIface(ifname);
901 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
902}
903
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800904std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::createBridgedApIfaceInternal() {
lesl94d28242020-11-18 22:17:37 +0800905 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
906 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
907 }
lesl261818b2020-11-27 12:37:35 +0800908 std::vector<std::string> ap_instances = allocateBridgedApInstanceNames();
909 if (ap_instances.size() < 2) {
910 LOG(ERROR) << "Fail to allocate two instances";
911 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
912 }
913 std::string br_ifname = kApBridgeIfacePrefix + ap_instances[0];
lesl94d28242020-11-18 22:17:37 +0800914 for (int i = 0; i < 2; i++) {
lesl261818b2020-11-27 12:37:35 +0800915 WifiStatus status = createVirtualApInterface(ap_instances[i]);
lesl94d28242020-11-18 22:17:37 +0800916 if (status.code != WifiStatusCode::SUCCESS) {
lesl261818b2020-11-27 12:37:35 +0800917 if (i != 0) { // The failure happened when creating second virtual
918 // iface.
lesl94d28242020-11-18 22:17:37 +0800919 legacy_hal_.lock()->deleteVirtualInterface(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800920 ap_instances.front()); // Remove the first virtual iface.
lesl94d28242020-11-18 22:17:37 +0800921 }
922 return {status, {}};
923 }
lesl94d28242020-11-18 22:17:37 +0800924 }
925 br_ifaces_ap_instances_[br_ifname] = ap_instances;
Roshan Pius8c1a67b2021-03-02 10:00:23 -0800926 if (!iface_util_->createBridge(br_ifname)) {
lesl94d28242020-11-18 22:17:37 +0800927 LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str();
928 invalidateAndClearBridgedAp(br_ifname);
929 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
930 }
931 for (auto const& instance : ap_instances) {
932 // Bind ap instance interface to AP bridge
Roshan Pius8c1a67b2021-03-02 10:00:23 -0800933 if (!iface_util_->addIfaceToBridge(br_ifname, instance)) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800934 LOG(ERROR) << "Failed add if to Bridge - if_name=" << instance.c_str();
lesl94d28242020-11-18 22:17:37 +0800935 invalidateAndClearBridgedAp(br_ifname);
936 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
937 }
938 }
939 sp<WifiApIface> iface = newWifiApIface(br_ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700940 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700941}
942
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800943std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getApIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -0700944 if (ap_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700945 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
946 }
Roshan Pius675609b2017-10-31 14:24:58 -0700947 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -0700948}
949
lesl420c4fc2020-11-23 19:33:04 +0800950std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::getApIfaceInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800951 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -0700952 const auto iface = findUsingName(ap_ifaces_, ifname);
953 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700954 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
955 }
Roshan Pius675609b2017-10-31 14:24:58 -0700956 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700957}
958
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800959WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -0700960 const auto iface = findUsingName(ap_ifaces_, ifname);
961 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700962 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -0800963 }
Roshan Pius82368502019-05-16 12:53:02 -0700964 // Invalidate & remove any dependent objects first.
965 // Note: This is probably not required because we never create
966 // nan/rtt objects over AP iface. But, there is no harm to do it
967 // here and not make that assumption all over the place.
968 invalidateAndRemoveDependencies(ifname);
lesl94d28242020-11-18 22:17:37 +0800969 // Clear the bridge interface and the iface instance.
970 invalidateAndClearBridgedAp(ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700971 invalidateAndClear(ap_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700972 for (const auto& callback : event_cb_handler_.getCallbacks()) {
973 if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) {
974 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
975 }
976 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700977 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700978 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800979}
980
lesl94d28242020-11-18 22:17:37 +0800981WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800982 const std::string& ifname, const std::string& ifInstanceName) {
lesl94d28242020-11-18 22:17:37 +0800983 const auto iface = findUsingName(ap_ifaces_, ifname);
lesl819e3722021-01-07 09:49:04 +0800984 if (!iface.get() || ifInstanceName.empty()) {
lesl94d28242020-11-18 22:17:37 +0800985 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
986 }
987 // Requires to remove one of the instance in bridge mode
988 for (auto const& it : br_ifaces_ap_instances_) {
989 if (it.first == ifname) {
Les Lee03d642f2021-06-21 21:25:20 +0800990 std::vector<std::string> ap_instances = it.second;
991 for (auto const& iface : ap_instances) {
lesl94d28242020-11-18 22:17:37 +0800992 if (iface == ifInstanceName) {
Roshan Pius8c1a67b2021-03-02 10:00:23 -0800993 if (!iface_util_->removeIfaceFromBridge(it.first, iface)) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800994 LOG(ERROR) << "Failed to remove interface: " << ifInstanceName << " from "
995 << ifname;
996 return createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE);
lesl94d28242020-11-18 22:17:37 +0800997 }
George Burgess IV2c0a47d2021-01-20 21:14:13 -0800998 legacy_hal::wifi_error legacy_status =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800999 legacy_hal_.lock()->deleteVirtualInterface(iface);
lesl94d28242020-11-18 22:17:37 +08001000 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001001 LOG(ERROR) << "Failed to del interface: " << iface << " "
1002 << legacyErrorToString(legacy_status);
lesl94d28242020-11-18 22:17:37 +08001003 return createWifiStatusFromLegacyError(legacy_status);
1004 }
Les Lee03d642f2021-06-21 21:25:20 +08001005 ap_instances.erase(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001006 std::remove(ap_instances.begin(), ap_instances.end(), ifInstanceName),
1007 ap_instances.end());
Les Lee03d642f2021-06-21 21:25:20 +08001008 br_ifaces_ap_instances_[ifname] = ap_instances;
1009 break;
lesl94d28242020-11-18 22:17:37 +08001010 }
1011 }
1012 break;
1013 }
1014 }
lesl669c9062021-01-22 19:37:47 +08001015 iface->removeInstance(ifInstanceName);
Les Lee03d642f2021-06-21 21:25:20 +08001016 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
1017
lesl94d28242020-11-18 22:17:37 +08001018 return createWifiStatus(WifiStatusCode::SUCCESS);
1019}
1020
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001021std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::createNanIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001022 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::NAN)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001023 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Etan Cohenc5700402017-03-08 16:43:38 -08001024 }
Roshan Pius5ba0a902020-04-14 11:55:42 -07001025 bool is_dedicated_iface = true;
lesl261818b2020-11-27 12:37:35 +08001026 std::string ifname = getPredefinedNanIfaceName();
Roshan Pius8c1a67b2021-03-02 10:00:23 -08001027 if (ifname.empty() || !iface_util_->ifNameToIndex(ifname)) {
Roshan Pius5ba0a902020-04-14 11:55:42 -07001028 // Use the first shared STA iface (wlan0) if a dedicated aware iface is
1029 // not defined.
1030 ifname = getFirstActiveWlanIfaceName();
1031 is_dedicated_iface = false;
1032 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001033 sp<WifiNanIface> iface = new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_);
Roshan Piuscc338202017-11-02 13:54:09 -07001034 nan_ifaces_.push_back(iface);
1035 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1036 if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
1037 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1038 }
1039 }
1040 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001041}
1042
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001043std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getNanIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001044 if (nan_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001045 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1046 }
Roshan Pius675609b2017-10-31 14:24:58 -07001047 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001048}
1049
Jimmy Chend460df32019-11-29 17:31:22 +02001050std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::getNanIfaceInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001051 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001052 const auto iface = findUsingName(nan_ifaces_, ifname);
1053 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001054 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1055 }
Roshan Pius675609b2017-10-31 14:24:58 -07001056 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001057}
1058
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001059WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001060 const auto iface = findUsingName(nan_ifaces_, ifname);
1061 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001062 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001063 }
Roshan Pius675609b2017-10-31 14:24:58 -07001064 invalidateAndClear(nan_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001065 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1066 if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) {
1067 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1068 }
1069 }
1070 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001071}
1072
Roshan Pius3c868522016-10-27 12:43:49 -07001073std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001074 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::P2P)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001075 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001076 }
lesl261818b2020-11-27 12:37:35 +08001077 std::string ifname = getPredefinedP2pIfaceName();
Roshan Pius675609b2017-10-31 14:24:58 -07001078 sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_);
1079 p2p_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001080 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1081 if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) {
1082 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1083 }
1084 }
Roshan Pius675609b2017-10-31 14:24:58 -07001085 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001086}
1087
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001088std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getP2pIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001089 if (p2p_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001090 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1091 }
Roshan Pius675609b2017-10-31 14:24:58 -07001092 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001093}
1094
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001095std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001096 const auto iface = findUsingName(p2p_ifaces_, ifname);
1097 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001098 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1099 }
Roshan Pius675609b2017-10-31 14:24:58 -07001100 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001101}
1102
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001103WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001104 const auto iface = findUsingName(p2p_ifaces_, ifname);
1105 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001106 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001107 }
Roshan Pius675609b2017-10-31 14:24:58 -07001108 invalidateAndClear(p2p_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001109 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1110 if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) {
1111 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1112 }
1113 }
1114 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001115}
1116
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001117std::pair<WifiStatus, sp<V1_5::IWifiStaIface>> WifiChip::createStaIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001118 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::STA)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001119 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001120 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001121 std::string ifname = allocateStaIfaceName();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001122 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->createVirtualInterface(
1123 ifname, hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
Sunil Raviddab4bb2020-02-03 22:45:19 -08001124 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1125 LOG(ERROR) << "Failed to add interface: " << ifname << " "
1126 << legacyErrorToString(legacy_status);
1127 return {createWifiStatusFromLegacyError(legacy_status), {}};
1128 }
Roshan Pius99dab382019-02-14 07:57:10 -08001129 sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -07001130 sta_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001131 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1132 if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
1133 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1134 }
1135 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001136 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Pius675609b2017-10-31 14:24:58 -07001137 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001138}
1139
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001140std::pair<WifiStatus, std::vector<hidl_string>> WifiChip::getStaIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001141 if (sta_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001142 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1143 }
Roshan Pius675609b2017-10-31 14:24:58 -07001144 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001145}
1146
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001147std::pair<WifiStatus, sp<V1_5::IWifiStaIface>> WifiChip::getStaIfaceInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001148 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001149 const auto iface = findUsingName(sta_ifaces_, ifname);
1150 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001151 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1152 }
Roshan Pius675609b2017-10-31 14:24:58 -07001153 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001154}
1155
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001156WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001157 const auto iface = findUsingName(sta_ifaces_, ifname);
1158 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001159 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001160 }
Roshan Pius82368502019-05-16 12:53:02 -07001161 // Invalidate & remove any dependent objects first.
1162 invalidateAndRemoveDependencies(ifname);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001163 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->deleteVirtualInterface(ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -08001164 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1165 LOG(ERROR) << "Failed to remove interface: " << ifname << " "
1166 << legacyErrorToString(legacy_status);
1167 }
Roshan Pius675609b2017-10-31 14:24:58 -07001168 invalidateAndClear(sta_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001169 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1170 if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) {
1171 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1172 }
1173 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001174 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001175 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001176}
1177
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001178std::pair<WifiStatus, sp<V1_0::IWifiRttController>> WifiChip::createRttControllerInternal(
1179 const sp<IWifiIface>& /*bound_iface*/) {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001180 LOG(ERROR) << "createRttController is not supported on this HAL";
Ahmed ElArabawy36defb32019-12-29 21:24:27 -08001181 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
Roshan Pius3c868522016-10-27 12:43:49 -07001182}
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001183
1184std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
1185WifiChip::getDebugRingBuffersStatusInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001186 legacy_hal::wifi_error legacy_status;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001187 std::vector<legacy_hal::wifi_ring_buffer_status> legacy_ring_buffer_status_vec;
Roshan Piusabcf78f2017-10-06 16:30:38 -07001188 std::tie(legacy_status, legacy_ring_buffer_status_vec) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001189 legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001190 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1191 return {createWifiStatusFromLegacyError(legacy_status), {}};
1192 }
1193 std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec;
1194 if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001195 legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001196 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1197 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001198 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_ring_buffer_status_vec};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001199}
1200
1201WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001202 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
1203 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001204 WifiStatus status = registerDebugRingBufferCallback();
1205 if (status.code != WifiStatusCode::SUCCESS) {
1206 return status;
1207 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001208 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->startRingBufferLogging(
Roshan Pius6036c022019-03-27 10:41:58 -07001209 getFirstActiveWlanIfaceName(), ring_name,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001210 static_cast<std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(verbose_level),
Roshan Piusabcf78f2017-10-06 16:30:38 -07001211 max_interval_in_sec, min_data_size_in_bytes);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001212 ringbuffer_map_.insert(
1213 std::pair<std::string, Ringbuffer>(ring_name, Ringbuffer(kMaxBufferSizeBytes)));
Roshan Piusa63b53f2019-11-18 11:03:13 -08001214 // if verbose logging enabled, turn up HAL daemon logging as well.
1215 if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) {
1216 android::base::SetMinimumLogSeverity(android::base::DEBUG);
1217 } else {
1218 android::base::SetMinimumLogSeverity(android::base::VERBOSE);
1219 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001220 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001221}
1222
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001223WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(const hidl_string& ring_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001224 WifiStatus status = registerDebugRingBufferCallback();
1225 if (status.code != WifiStatusCode::SUCCESS) {
1226 return status;
1227 }
1228 legacy_hal::wifi_error legacy_status =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001229 legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(), ring_name);
xshu5899e8e2018-01-09 15:36:03 -08001230
Roshan Piusabcf78f2017-10-06 16:30:38 -07001231 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001232}
1233
Roger Wangb294c762018-11-02 15:34:39 +08001234WifiStatus WifiChip::flushRingBufferToFileInternal() {
1235 if (!writeRingbufferFilesInternal()) {
1236 LOG(ERROR) << "Error writing files to flash";
1237 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1238 }
1239 return createWifiStatus(WifiStatusCode::SUCCESS);
1240}
1241
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001242WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001243 legacy_hal::wifi_error legacy_status =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001244 legacy_hal_.lock()->deregisterRingBufferCallbackHandler(getFirstActiveWlanIfaceName());
xshu0a0fe512020-07-22 17:53:37 -07001245 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1246 debug_ring_buffer_cb_registered_ = false;
1247 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001248 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001249}
1250
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001251std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
1252WifiChip::getDebugHostWakeReasonStatsInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001253 legacy_hal::wifi_error legacy_status;
1254 legacy_hal::WakeReasonStats legacy_stats;
1255 std::tie(legacy_status, legacy_stats) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001256 legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001257 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1258 return {createWifiStatusFromLegacyError(legacy_status), {}};
1259 }
1260 WifiDebugHostWakeReasonStats hidl_stats;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001261 if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats, &hidl_stats)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001262 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1263 }
1264 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001265}
1266
Roshan Pius203cb032016-12-14 17:41:20 -08001267WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001268 legacy_hal::wifi_error legacy_status;
1269 if (enable) {
1270 android::wp<WifiChip> weak_ptr_this(this);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001271 const auto& on_alert_callback = [weak_ptr_this](int32_t error_code,
1272 std::vector<uint8_t> debug_data) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001273 const auto shared_ptr_this = weak_ptr_this.promote();
1274 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1275 LOG(ERROR) << "Callback invoked on an invalid object";
1276 return;
1277 }
1278 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001279 if (!callback->onDebugErrorAlert(error_code, debug_data).isOk()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001280 LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback";
1281 }
1282 }
1283 };
1284 legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001285 getFirstActiveWlanIfaceName(), on_alert_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001286 } else {
1287 legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001288 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001289 }
1290 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius203cb032016-12-14 17:41:20 -08001291}
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001292
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001293WifiStatus WifiChip::selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001294 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001295 getFirstActiveWlanIfaceName(),
1296 hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario));
Roshan Piusabcf78f2017-10-06 16:30:38 -07001297 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001298}
1299
Roshan Pius735ff432017-07-25 08:48:08 -07001300WifiStatus WifiChip::resetTxPowerScenarioInternal() {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001301 auto legacy_status = legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001302 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001303}
1304
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001305WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) {
1306 auto legacy_status = legacy_hal_.lock()->setLatencyMode(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001307 getFirstActiveWlanIfaceName(), hidl_struct_util::convertHidlLatencyModeToLegacy(mode));
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001308 return createWifiStatusFromLegacyError(legacy_status);
1309}
1310
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001311WifiStatus WifiChip::registerEventCallbackInternal_1_2(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001312 const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001313 // Deprecated support for this callback.
1314 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001315}
1316
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001317WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001318 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001319 getFirstActiveWlanIfaceName(),
1320 hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario));
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001321 return createWifiStatusFromLegacyError(legacy_status);
1322}
1323
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001324std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() {
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001325 // Deprecated support for this callback.
1326 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
1327}
1328
1329std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_5() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001330 legacy_hal::wifi_error legacy_status;
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001331 uint64_t legacy_feature_set;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001332 uint32_t legacy_logger_feature_set;
1333 const auto ifname = getFirstActiveWlanIfaceName();
1334 std::tie(legacy_status, legacy_feature_set) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001335 legacy_hal_.lock()->getSupportedFeatureSet(ifname);
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001336 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1337 return {createWifiStatusFromLegacyError(legacy_status), 0};
1338 }
1339 std::tie(legacy_status, legacy_logger_feature_set) =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001340 legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname);
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001341 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1342 // some devices don't support querying logger feature set
1343 legacy_logger_feature_set = 0;
1344 }
1345 uint32_t hidl_caps;
1346 if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001347 legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001348 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0};
1349 }
1350 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps};
1351}
1352
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001353std::pair<WifiStatus, sp<V1_4::IWifiRttController>> WifiChip::createRttControllerInternal_1_4(
1354 const sp<IWifiIface>& bound_iface) {
1355 if (sta_ifaces_.size() == 0 && !canCurrentModeSupportIfaceOfType(IfaceType::STA)) {
1356 LOG(ERROR) << "createRttControllerInternal_1_4: Chip cannot support STAs "
1357 "(and RTT by extension)";
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001358 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
1359 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001360 sp<WifiRttController> rtt =
1361 new WifiRttController(getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_);
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001362 rtt_controllers_.emplace_back(rtt);
1363 return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
1364}
1365
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001366WifiStatus WifiChip::registerEventCallbackInternal_1_4(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001367 const sp<V1_4::IWifiChipEventCallback>& event_callback) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001368 if (!event_cb_handler_.addCallback(event_callback)) {
1369 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1370 }
1371 return createWifiStatus(WifiStatusCode::SUCCESS);
1372}
1373
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001374WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(const std::string& ifname) {
1375 auto legacy_status = legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname);
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001376 return createWifiStatusFromLegacyError(legacy_status);
1377}
1378
1379WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) {
1380 auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001381 hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case));
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001382 return createWifiStatusFromLegacyError(legacy_status);
1383}
1384
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001385WifiStatus WifiChip::setCoexUnsafeChannelsInternal(std::vector<CoexUnsafeChannel> unsafe_channels,
1386 uint32_t restrictions) {
Quang Luong94bcce52020-11-25 17:52:19 -08001387 std::vector<legacy_hal::wifi_coex_unsafe_channel> legacy_unsafe_channels;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001388 if (!hidl_struct_util::convertHidlVectorOfCoexUnsafeChannelToLegacy(unsafe_channels,
1389 &legacy_unsafe_channels)) {
Quang Luong94bcce52020-11-25 17:52:19 -08001390 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1391 }
Quang Luongab70a832020-12-14 13:01:32 -08001392 uint32_t legacy_restrictions = 0;
1393 if (restrictions & CoexRestriction::WIFI_DIRECT) {
1394 legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_DIRECT;
1395 }
1396 if (restrictions & CoexRestriction::SOFTAP) {
1397 legacy_restrictions |= legacy_hal::wifi_coex_restriction::SOFTAP;
1398 }
1399 if (restrictions & CoexRestriction::WIFI_AWARE) {
1400 legacy_restrictions |= legacy_hal::wifi_coex_restriction::WIFI_AWARE;
1401 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001402 auto legacy_status =
1403 legacy_hal_.lock()->setCoexUnsafeChannels(legacy_unsafe_channels, legacy_restrictions);
Quang Luong94bcce52020-11-25 17:52:19 -08001404 return createWifiStatusFromLegacyError(legacy_status);
1405}
1406
Kumar Anandda62c382020-11-18 17:17:47 -08001407WifiStatus WifiChip::setCountryCodeInternal(const std::array<int8_t, 2>& code) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001408 auto legacy_status = legacy_hal_.lock()->setCountryCode(getFirstActiveWlanIfaceName(), code);
Kumar Anandda62c382020-11-18 17:17:47 -08001409 return createWifiStatusFromLegacyError(legacy_status);
1410}
1411
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001412std::pair<WifiStatus, std::vector<WifiUsableChannel>> WifiChip::getUsableChannelsInternal(
1413 WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask) {
Kumar Anand2a630a32021-01-21 14:09:14 -08001414 legacy_hal::wifi_error legacy_status;
1415 std::vector<legacy_hal::wifi_usable_channel> legacy_usable_channels;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001416 std::tie(legacy_status, legacy_usable_channels) = legacy_hal_.lock()->getUsableChannels(
Kumar Anand2a630a32021-01-21 14:09:14 -08001417 hidl_struct_util::convertHidlWifiBandToLegacyMacBand(band),
Kumar Anandaea86e02021-02-10 16:22:31 -08001418 hidl_struct_util::convertHidlWifiIfaceModeToLegacy(ifaceModeMask),
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001419 hidl_struct_util::convertHidlUsableChannelFilterToLegacy(filterMask));
Kumar Anandaea86e02021-02-10 16:22:31 -08001420
Kumar Anand2a630a32021-01-21 14:09:14 -08001421 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1422 return {createWifiStatusFromLegacyError(legacy_status), {}};
1423 }
1424 std::vector<WifiUsableChannel> hidl_usable_channels;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001425 if (!hidl_struct_util::convertLegacyWifiUsableChannelsToHidl(legacy_usable_channels,
1426 &hidl_usable_channels)) {
Kumar Anand2a630a32021-01-21 14:09:14 -08001427 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1428 }
1429 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_usable_channels};
1430}
1431
chenpaulc6f57032021-03-05 17:06:50 +08001432WifiStatus WifiChip::triggerSubsystemRestartInternal() {
1433 auto legacy_status = legacy_hal_.lock()->triggerSubsystemRestart();
1434 return createWifiStatusFromLegacyError(legacy_status);
1435}
1436
Roshan Piusba38d9c2017-12-08 07:32:08 -08001437WifiStatus WifiChip::handleChipConfiguration(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001438 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001439 // If the chip is already configured in a different mode, stop
1440 // the legacy HAL and then start it after firmware mode change.
Roshan Piuscc338202017-11-02 13:54:09 -07001441 if (isValidModeId(current_mode_id_)) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001442 LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_ << " to mode " << mode_id;
Roshan Piusba38d9c2017-12-08 07:32:08 -08001443 invalidateAndRemoveAllIfaces();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001444 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->stop(lock, []() {});
Roshan Piusba38d9c2017-12-08 07:32:08 -08001445 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001446 LOG(ERROR) << "Failed to stop legacy HAL: " << legacyErrorToString(legacy_status);
Roshan Piusba38d9c2017-12-08 07:32:08 -08001447 return createWifiStatusFromLegacyError(legacy_status);
1448 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001449 }
Roshan Piuscc338202017-11-02 13:54:09 -07001450 // Firmware mode change not needed for V2 devices.
1451 bool success = true;
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001452 if (mode_id == feature_flags::chip_mode_ids::kV1Sta) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001453 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001454 } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001455 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
1456 }
1457 if (!success) {
1458 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1459 }
1460 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
1461 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001462 LOG(ERROR) << "Failed to start legacy HAL: " << legacyErrorToString(legacy_status);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001463 return createWifiStatusFromLegacyError(legacy_status);
1464 }
Roshan Pius85c64412018-01-22 17:58:40 -08001465 // Every time the HAL is restarted, we need to register the
1466 // radio mode change callback.
1467 WifiStatus status = registerRadioModeChangeCallback();
1468 if (status.code != WifiStatusCode::SUCCESS) {
1469 // This probably is not a critical failure?
1470 LOG(ERROR) << "Failed to register radio mode change callback";
1471 }
chenpaulf5eca292019-03-14 11:08:03 +08001472 // Extract and save the version information into property.
Jimmy Chend460df32019-11-29 17:31:22 +02001473 std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> version_info;
chenpaulf5eca292019-03-14 11:08:03 +08001474 version_info = WifiChip::requestChipDebugInfoInternal();
1475 if (WifiStatusCode::SUCCESS == version_info.first.code) {
1476 property_set("vendor.wlan.firmware.version",
1477 version_info.second.firmwareDescription.c_str());
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001478 property_set("vendor.wlan.driver.version", version_info.second.driverDescription.c_str());
chenpaulf5eca292019-03-14 11:08:03 +08001479 }
1480
Roshan Piusabcf78f2017-10-06 16:30:38 -07001481 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001482}
Roshan Pius48185b22016-12-15 19:10:30 -08001483
1484WifiStatus WifiChip::registerDebugRingBufferCallback() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001485 if (debug_ring_buffer_cb_registered_) {
1486 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius48185b22016-12-15 19:10:30 -08001487 }
Roshan Pius3797e182017-03-30 18:01:54 -07001488
Roshan Piusabcf78f2017-10-06 16:30:38 -07001489 android::wp<WifiChip> weak_ptr_this(this);
1490 const auto& on_ring_buffer_data_callback =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001491 [weak_ptr_this](const std::string& name, const std::vector<uint8_t>& data,
1492 const legacy_hal::wifi_ring_buffer_status& status) {
1493 const auto shared_ptr_this = weak_ptr_this.promote();
1494 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1495 LOG(ERROR) << "Callback invoked on an invalid object";
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301496 return;
1497 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001498 WifiDebugRingBufferStatus hidl_status;
1499 if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(status,
1500 &hidl_status)) {
1501 LOG(ERROR) << "Error converting ring buffer status";
1502 return;
1503 }
1504 {
1505 std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t);
1506 const auto& target = shared_ptr_this->ringbuffer_map_.find(name);
1507 if (target != shared_ptr_this->ringbuffer_map_.end()) {
1508 Ringbuffer& cur_buffer = target->second;
1509 cur_buffer.append(data);
1510 } else {
1511 LOG(ERROR) << "Ringname " << name << " not found";
1512 return;
1513 }
1514 // unique_lock unlocked here
1515 }
1516 };
1517 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->registerRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001518 getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback);
Roshan Pius48185b22016-12-15 19:10:30 -08001519
Roshan Piusabcf78f2017-10-06 16:30:38 -07001520 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1521 debug_ring_buffer_cb_registered_ = true;
1522 }
1523 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius48185b22016-12-15 19:10:30 -08001524}
1525
Roshan Pius85c64412018-01-22 17:58:40 -08001526WifiStatus WifiChip::registerRadioModeChangeCallback() {
1527 android::wp<WifiChip> weak_ptr_this(this);
1528 const auto& on_radio_mode_change_callback =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001529 [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) {
1530 const auto shared_ptr_this = weak_ptr_this.promote();
1531 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1532 LOG(ERROR) << "Callback invoked on an invalid object";
1533 return;
Roshan Pius85c64412018-01-22 17:58:40 -08001534 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001535 std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo> hidl_radio_mode_infos;
1536 if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(mac_infos,
1537 &hidl_radio_mode_infos)) {
1538 LOG(ERROR) << "Error converting wifi mac info";
1539 return;
1540 }
1541 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
1542 if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos).isOk()) {
1543 LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4"
1544 << " callback on: " << toString(callback);
1545 }
1546 }
1547 };
Roshan Pius85c64412018-01-22 17:58:40 -08001548 legacy_hal::wifi_error legacy_status =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001549 legacy_hal_.lock()->registerRadioModeChangeCallbackHandler(
1550 getFirstActiveWlanIfaceName(), on_radio_mode_change_callback);
Roshan Pius85c64412018-01-22 17:58:40 -08001551 return createWifiStatusFromLegacyError(legacy_status);
1552}
1553
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001554std::vector<V1_4::IWifiChip::ChipIfaceCombination> WifiChip::getCurrentModeIfaceCombinations() {
Roshan Piuscc338202017-11-02 13:54:09 -07001555 if (!isValidModeId(current_mode_id_)) {
1556 LOG(ERROR) << "Chip not configured in a mode yet";
1557 return {};
1558 }
1559 for (const auto& mode : modes_) {
1560 if (mode.id == current_mode_id_) {
1561 return mode.availableCombinations;
1562 }
1563 }
1564 CHECK(0) << "Expected to find iface combinations for current mode!";
1565 return {};
1566}
1567
1568// Returns a map indexed by IfaceType with the number of ifaces currently
1569// created of the corresponding type.
1570std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() {
1571 std::map<IfaceType, size_t> iface_counts;
1572 iface_counts[IfaceType::AP] = ap_ifaces_.size();
1573 iface_counts[IfaceType::NAN] = nan_ifaces_.size();
1574 iface_counts[IfaceType::P2P] = p2p_ifaces_.size();
1575 iface_counts[IfaceType::STA] = sta_ifaces_.size();
1576 return iface_counts;
1577}
1578
1579// This expands the provided iface combinations to a more parseable
1580// form. Returns a vector of available combinations possible with the number
1581// of ifaces of each type in the combination.
1582// This method is a port of HalDeviceManager.expandIfaceCombos() from framework.
1583std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001584 const V1_4::IWifiChip::ChipIfaceCombination& combination) {
Roshan Piuscc338202017-11-02 13:54:09 -07001585 uint32_t num_expanded_combos = 1;
1586 for (const auto& limit : combination.limits) {
1587 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1588 num_expanded_combos *= limit.types.size();
1589 }
1590 }
1591
1592 // Allocate the vector of expanded combos and reset all iface counts to 0
1593 // in each combo.
1594 std::vector<std::map<IfaceType, size_t>> expanded_combos;
1595 expanded_combos.resize(num_expanded_combos);
1596 for (auto& expanded_combo : expanded_combos) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001597 for (const auto type : {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
Roshan Piuscc338202017-11-02 13:54:09 -07001598 expanded_combo[type] = 0;
1599 }
1600 }
1601 uint32_t span = num_expanded_combos;
1602 for (const auto& limit : combination.limits) {
1603 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1604 span /= limit.types.size();
1605 for (uint32_t k = 0; k < num_expanded_combos; ++k) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001606 const auto iface_type = limit.types[(k / span) % limit.types.size()];
Roshan Piuscc338202017-11-02 13:54:09 -07001607 expanded_combos[k][iface_type]++;
1608 }
1609 }
1610 }
1611 return expanded_combos;
1612}
1613
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001614bool WifiChip::canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001615 const std::map<IfaceType, size_t>& expanded_combo, IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001616 const auto current_combo = getCurrentIfaceCombination();
1617
1618 // Check if we have space for 1 more iface of |type| in this combo
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001619 for (const auto type : {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
Roshan Piuscc338202017-11-02 13:54:09 -07001620 size_t num_ifaces_needed = current_combo.at(type);
1621 if (type == requested_type) {
1622 num_ifaces_needed++;
1623 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001624 size_t num_ifaces_allowed = expanded_combo.at(type);
Roshan Piuscc338202017-11-02 13:54:09 -07001625 if (num_ifaces_needed > num_ifaces_allowed) {
1626 return false;
1627 }
1628 }
1629 return true;
1630}
1631
1632// This method does the following:
1633// a) Enumerate all possible iface combos by expanding the current
1634// ChipIfaceCombination.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001635// b) Check if the requested iface type can be added to the current mode
1636// with the iface combination that is already active.
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001637bool WifiChip::canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001638 if (!isValidModeId(current_mode_id_)) {
1639 LOG(ERROR) << "Chip not configured in a mode yet";
1640 return false;
1641 }
1642 const auto combinations = getCurrentModeIfaceCombinations();
1643 for (const auto& combination : combinations) {
1644 const auto expanded_combos = expandIfaceCombinations(combination);
1645 for (const auto& expanded_combo : expanded_combos) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001646 if (canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(expanded_combo,
1647 requested_type)) {
Roshan Piuscc338202017-11-02 13:54:09 -07001648 return true;
1649 }
1650 }
1651 }
1652 return false;
1653}
1654
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001655// Note: This does not consider ifaces already active. It only checks if the
1656// provided expanded iface combination can support the requested combo.
1657bool WifiChip::canExpandedIfaceComboSupportIfaceCombo(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001658 const std::map<IfaceType, size_t>& expanded_combo,
1659 const std::map<IfaceType, size_t>& req_combo) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001660 // Check if we have space for 1 more iface of |type| in this combo
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001661 for (const auto type : {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001662 if (req_combo.count(type) == 0) {
1663 // Iface of "type" not in the req_combo.
1664 continue;
1665 }
1666 size_t num_ifaces_needed = req_combo.at(type);
1667 size_t num_ifaces_allowed = expanded_combo.at(type);
1668 if (num_ifaces_needed > num_ifaces_allowed) {
1669 return false;
1670 }
1671 }
1672 return true;
1673}
1674// This method does the following:
1675// a) Enumerate all possible iface combos by expanding the current
1676// ChipIfaceCombination.
1677// b) Check if the requested iface combo can be added to the current mode.
1678// Note: This does not consider ifaces already active. It only checks if the
1679// current mode can support the requested combo.
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001680bool WifiChip::canCurrentModeSupportIfaceCombo(const std::map<IfaceType, size_t>& req_combo) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001681 if (!isValidModeId(current_mode_id_)) {
1682 LOG(ERROR) << "Chip not configured in a mode yet";
1683 return false;
1684 }
1685 const auto combinations = getCurrentModeIfaceCombinations();
1686 for (const auto& combination : combinations) {
1687 const auto expanded_combos = expandIfaceCombinations(combination);
1688 for (const auto& expanded_combo : expanded_combos) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001689 if (canExpandedIfaceComboSupportIfaceCombo(expanded_combo, req_combo)) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001690 return true;
1691 }
1692 }
1693 }
1694 return false;
1695}
1696
1697// This method does the following:
1698// a) Enumerate all possible iface combos by expanding the current
1699// ChipIfaceCombination.
1700// b) Check if the requested iface type can be added to the current mode.
1701bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType requested_type) {
lesl261818b2020-11-27 12:37:35 +08001702 // Check if we can support at least 1 iface of type.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001703 std::map<IfaceType, size_t> req_iface_combo;
1704 req_iface_combo[requested_type] = 1;
1705 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1706}
1707
Roshan Piuscc338202017-11-02 13:54:09 -07001708bool WifiChip::isValidModeId(ChipModeId mode_id) {
1709 for (const auto& mode : modes_) {
1710 if (mode.id == mode_id) {
1711 return true;
1712 }
1713 }
1714 return false;
1715}
1716
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001717bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() {
lesl261818b2020-11-27 12:37:35 +08001718 // Check if we can support at least 1 STA & 1 AP concurrently.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001719 std::map<IfaceType, size_t> req_iface_combo;
1720 req_iface_combo[IfaceType::AP] = 1;
1721 req_iface_combo[IfaceType::STA] = 1;
1722 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1723}
1724
lesl261818b2020-11-27 12:37:35 +08001725bool WifiChip::isDualStaConcurrencyAllowedInCurrentMode() {
1726 // Check if we can support at least 2 STA concurrently.
James Mattisd2e4c072019-05-22 16:14:48 -07001727 std::map<IfaceType, size_t> req_iface_combo;
lesl261818b2020-11-27 12:37:35 +08001728 req_iface_combo[IfaceType::STA] = 2;
James Mattisd2e4c072019-05-22 16:14:48 -07001729 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1730}
1731
Roshan Pius6036c022019-03-27 10:41:58 -07001732std::string WifiChip::getFirstActiveWlanIfaceName() {
Roshan Pius444473f2019-04-19 08:41:20 -07001733 if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName();
leslf012b652021-01-08 15:22:49 +08001734 if (ap_ifaces_.size() > 0) {
1735 // If the first active wlan iface is bridged iface.
1736 // Return first instance name.
1737 for (auto const& it : br_ifaces_ap_instances_) {
1738 if (it.first == ap_ifaces_[0]->getName()) {
1739 return it.second[0];
1740 }
1741 }
1742 return ap_ifaces_[0]->getName();
1743 }
Roshan Pius6036c022019-03-27 10:41:58 -07001744 // This could happen if the chip call is made before any STA/AP
1745 // iface is created. Default to wlan0 for such cases.
Roshan Pius444473f2019-04-19 08:41:20 -07001746 LOG(WARNING) << "No active wlan interfaces in use! Using default";
Jimmy Chen2dddd792019-12-23 17:50:39 +02001747 return getWlanIfaceNameWithType(IfaceType::STA, 0);
Roshan Pius6036c022019-03-27 10:41:58 -07001748}
1749
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001750// Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx|
1751// not already in use.
1752// Note: This doesn't check the actual presence of these interfaces.
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001753std::string WifiChip::allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001754 for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001755 const auto ifname = getWlanIfaceNameWithType(type, idx);
lesl94d28242020-11-18 22:17:37 +08001756 if (findUsingNameFromBridgedApInstances(ifname)) continue;
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001757 if (findUsingName(ap_ifaces_, ifname)) continue;
1758 if (findUsingName(sta_ifaces_, ifname)) continue;
1759 return ifname;
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001760 }
1761 // This should never happen. We screwed up somewhere if it did.
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001762 CHECK(false) << "All wlan interfaces in use already!";
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001763 return {};
1764}
1765
lesl261818b2020-11-27 12:37:35 +08001766uint32_t WifiChip::startIdxOfApIface() {
1767 if (isDualStaConcurrencyAllowedInCurrentMode()) {
1768 // When the HAL support dual STAs, AP should start with idx 2.
1769 return 2;
1770 } else if (isStaApConcurrencyAllowedInCurrentMode()) {
1771 // When the HAL support STA + AP but it doesn't support dual STAs.
1772 // AP should start with idx 1.
1773 return 1;
1774 }
1775 // No concurrency support.
1776 return 0;
1777}
1778
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001779// AP iface names start with idx 1 for modes supporting
James Mattisd2e4c072019-05-22 16:14:48 -07001780// concurrent STA and not dual AP, else start with idx 0.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001781std::string WifiChip::allocateApIfaceName() {
Roshan Pius78cb5992020-04-30 12:39:21 -07001782 // Check if we have a dedicated iface for AP.
lesl261818b2020-11-27 12:37:35 +08001783 std::vector<std::string> ifnames = getPredefinedApIfaceNames(false);
1784 if (!ifnames.empty()) {
1785 return ifnames[0];
Roshan Pius78cb5992020-04-30 12:39:21 -07001786 }
lesl261818b2020-11-27 12:37:35 +08001787 return allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface());
1788}
1789
1790std::vector<std::string> WifiChip::allocateBridgedApInstanceNames() {
1791 // Check if we have a dedicated iface for AP.
1792 std::vector<std::string> instances = getPredefinedApIfaceNames(true);
1793 if (instances.size() == 2) {
1794 return instances;
1795 } else {
1796 int num_ifaces_need_to_allocate = 2 - instances.size();
1797 for (int i = 0; i < num_ifaces_need_to_allocate; i++) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001798 std::string instance_name =
1799 allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface() + i);
lesl261818b2020-11-27 12:37:35 +08001800 if (!instance_name.empty()) {
1801 instances.push_back(instance_name);
1802 }
1803 }
1804 }
1805 return instances;
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001806}
1807
1808// STA iface names start with idx 0.
1809// Primary STA iface will always be 0.
1810std::string WifiChip::allocateStaIfaceName() {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001811 return allocateApOrStaIfaceName(IfaceType::STA, 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001812}
1813
xshu5899e8e2018-01-09 15:36:03 -08001814bool WifiChip::writeRingbufferFilesInternal() {
1815 if (!removeOldFilesInternal()) {
1816 LOG(ERROR) << "Error occurred while deleting old tombstone files";
1817 return false;
1818 }
1819 // write ringbuffers to file
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301820 {
1821 std::unique_lock<std::mutex> lk(lock_t);
xshuc905ea62021-07-11 19:57:02 -07001822 for (auto& item : ringbuffer_map_) {
1823 Ringbuffer& cur_buffer = item.second;
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301824 if (cur_buffer.getData().empty()) {
1825 continue;
1826 }
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001827 const std::string file_path_raw = kTombstoneFolderPath + item.first + "XXXXXXXXXX";
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301828 const int dump_fd = mkstemp(makeCharVec(file_path_raw).data());
1829 if (dump_fd == -1) {
1830 PLOG(ERROR) << "create file failed";
1831 return false;
1832 }
1833 unique_fd file_auto_closer(dump_fd);
1834 for (const auto& cur_block : cur_buffer.getData()) {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001835 if (write(dump_fd, cur_block.data(), sizeof(cur_block[0]) * cur_block.size()) ==
1836 -1) {
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301837 PLOG(ERROR) << "Error writing to file";
1838 }
xshu5899e8e2018-01-09 15:36:03 -08001839 }
xshuc905ea62021-07-11 19:57:02 -07001840 cur_buffer.clear();
xshu5899e8e2018-01-09 15:36:03 -08001841 }
xshu0a0fe512020-07-22 17:53:37 -07001842 // unique_lock unlocked here
xshu5899e8e2018-01-09 15:36:03 -08001843 }
1844 return true;
1845}
1846
Jimmy Chen2dddd792019-12-23 17:50:39 +02001847std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) {
1848 std::string ifname;
1849
1850 // let the legacy hal override the interface name
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001851 legacy_hal::wifi_error err = legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname);
Jimmy Chen2dddd792019-12-23 17:50:39 +02001852 if (err == legacy_hal::WIFI_SUCCESS) return ifname;
1853
1854 return getWlanIfaceName(idx);
1855}
1856
lesl94d28242020-11-18 22:17:37 +08001857void WifiChip::invalidateAndClearBridgedApAll() {
1858 for (auto const& it : br_ifaces_ap_instances_) {
1859 for (auto const& iface : it.second) {
Roshan Pius8c1a67b2021-03-02 10:00:23 -08001860 iface_util_->removeIfaceFromBridge(it.first, iface);
lesl94d28242020-11-18 22:17:37 +08001861 legacy_hal_.lock()->deleteVirtualInterface(iface);
1862 }
Roshan Pius8c1a67b2021-03-02 10:00:23 -08001863 iface_util_->deleteBridge(it.first);
lesl94d28242020-11-18 22:17:37 +08001864 }
1865 br_ifaces_ap_instances_.clear();
1866}
1867
1868void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) {
1869 if (br_name.empty()) return;
1870 // delete managed interfaces
1871 for (auto const& it : br_ifaces_ap_instances_) {
1872 if (it.first == br_name) {
1873 for (auto const& iface : it.second) {
Roshan Pius8c1a67b2021-03-02 10:00:23 -08001874 iface_util_->removeIfaceFromBridge(br_name, iface);
lesl94d28242020-11-18 22:17:37 +08001875 legacy_hal_.lock()->deleteVirtualInterface(iface);
1876 }
Roshan Pius8c1a67b2021-03-02 10:00:23 -08001877 iface_util_->deleteBridge(br_name);
lesl94d28242020-11-18 22:17:37 +08001878 br_ifaces_ap_instances_.erase(br_name);
1879 break;
1880 }
1881 }
1882 return;
1883}
1884
1885bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) {
1886 for (auto const& it : br_ifaces_ap_instances_) {
1887 if (it.first == name) {
1888 return true;
1889 }
1890 for (auto const& iface : it.second) {
1891 if (iface == name) {
1892 return true;
1893 }
1894 }
1895 }
1896 return false;
1897}
1898
Roshan Pius79a99752016-10-04 13:03:58 -07001899} // namespace implementation
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001900} // namespace V1_6
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001901} // namespace wifi
1902} // namespace hardware
1903} // namespace android