blob: 95478a419d6b60f6d91b0e33f18ca9479f424f6c [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
Roshan Pius35d958c2016-10-06 16:47:38 -070031namespace {
Jong Wook Kimda830c92018-07-23 15:29:38 -070032using android::sp;
xshu5899e8e2018-01-09 15:36:03 -080033using android::base::unique_fd;
Roshan Pius35d958c2016-10-06 16:47:38 -070034using android::hardware::hidl_string;
Roshan Piusabcf78f2017-10-06 16:30:38 -070035using android::hardware::hidl_vec;
Roshan Pius2c06a3f2016-12-15 17:51:40 -080036using android::hardware::wifi::V1_0::ChipModeId;
Roshan Pius52947fb2016-11-18 11:38:07 -080037using android::hardware::wifi::V1_0::IfaceType;
Roshan Pius675609b2017-10-31 14:24:58 -070038using android::hardware::wifi::V1_0::IWifiChip;
Roshan Pius52947fb2016-11-18 11:38:07 -080039
xshu5899e8e2018-01-09 15:36:03 -080040constexpr char kCpioMagic[] = "070701";
Roger Wangb294c762018-11-02 15:34:39 +080041constexpr size_t kMaxBufferSizeBytes = 1024 * 1024 * 3;
42constexpr uint32_t kMaxRingBufferFileAgeSeconds = 60 * 60 * 10;
xshu37126c92018-04-13 16:24:45 -070043constexpr uint32_t kMaxRingBufferFileNum = 20;
xshu5899e8e2018-01-09 15:36:03 -080044constexpr char kTombstoneFolderPath[] = "/data/vendor/tombstones/wifi/";
Roshan Pius8574e7f2019-04-01 13:30:40 -070045constexpr char kActiveWlanIfaceNameProperty[] = "wifi.active.interface";
46constexpr char kNoActiveWlanIfaceNamePropertyValue[] = "";
47constexpr unsigned kMaxWlanIfaces = 5;
lesl94d28242020-11-18 22:17:37 +080048constexpr char kApBridgeIfacePrefix[] = "ap_br_";
xshu5899e8e2018-01-09 15:36:03 -080049
Roshan Pius35d958c2016-10-06 16:47:38 -070050template <typename Iface>
Roshan Pius675609b2017-10-31 14:24:58 -070051void invalidateAndClear(std::vector<sp<Iface>>& ifaces, sp<Iface> iface) {
52 iface->invalidate();
53 ifaces.erase(std::remove(ifaces.begin(), ifaces.end(), iface),
54 ifaces.end());
55}
56
57template <typename Iface>
58void invalidateAndClearAll(std::vector<sp<Iface>>& ifaces) {
59 for (const auto& iface : ifaces) {
Roshan Piusabcf78f2017-10-06 16:30:38 -070060 iface->invalidate();
Roshan Piusabcf78f2017-10-06 16:30:38 -070061 }
Roshan Pius675609b2017-10-31 14:24:58 -070062 ifaces.clear();
63}
64
65template <typename Iface>
66std::vector<hidl_string> getNames(std::vector<sp<Iface>>& ifaces) {
67 std::vector<hidl_string> names;
68 for (const auto& iface : ifaces) {
69 names.emplace_back(iface->getName());
70 }
71 return names;
72}
73
74template <typename Iface>
75sp<Iface> findUsingName(std::vector<sp<Iface>>& ifaces,
76 const std::string& name) {
77 std::vector<hidl_string> names;
78 for (const auto& iface : ifaces) {
79 if (name == iface->getName()) {
80 return iface;
81 }
82 }
83 return nullptr;
Roshan 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) {
94 const char* altPropName =
95 (idx == 0) ? "wifi.interface" : "wifi.concurrent.interface";
Roshan Pius5b333462019-03-01 14:07:22 -080096 auto res = property_get(altPropName, buffer.data(), nullptr);
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -080097 if (res > 0) return buffer.data();
98 }
Roshan Pius5b333462019-03-01 14:07:22 -080099 std::string propName = "wifi.interface." + std::to_string(idx);
100 auto res = property_get(propName.c_str(), buffer.data(), nullptr);
101 if (res > 0) return buffer.data();
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -0800102
103 return "wlan" + std::to_string(idx);
Roshan Pius9377a0d2017-10-06 13:18:54 -0700104}
Roshan Pius9377a0d2017-10-06 13:18:54 -0700105
lesl261818b2020-11-27 12:37:35 +0800106// Returns the dedicated iface name if defined.
107// Returns two ifaces in bridged mode.
108std::vector<std::string> getPredefinedApIfaceNames(bool is_bridged) {
109 std::vector<std::string> ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700110 std::array<char, PROPERTY_VALUE_MAX> buffer;
lesl261818b2020-11-27 12:37:35 +0800111 buffer.fill(0);
Roshan Pius78cb5992020-04-30 12:39:21 -0700112 if (property_get("ro.vendor.wifi.sap.interface", buffer.data(), nullptr) ==
113 0) {
lesl261818b2020-11-27 12:37:35 +0800114 return ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700115 }
lesl261818b2020-11-27 12:37:35 +0800116 ifnames.push_back(buffer.data());
117 if (is_bridged) {
118 buffer.fill(0);
lesl5a46c952020-12-14 17:14:12 +0800119 if (property_get("ro.vendor.wifi.sap.concurrent.iface", buffer.data(),
120 nullptr) == 0) {
lesl261818b2020-11-27 12:37:35 +0800121 return ifnames;
122 }
123 ifnames.push_back(buffer.data());
124 }
125 return ifnames;
Roshan Pius78cb5992020-04-30 12:39:21 -0700126}
127
lesl261818b2020-11-27 12:37:35 +0800128std::string getPredefinedP2pIfaceName() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700129 std::array<char, PROPERTY_VALUE_MAX> buffer;
130 property_get("wifi.direct.interface", buffer.data(), "p2p0");
131 return buffer.data();
Roshan Pius9377a0d2017-10-06 13:18:54 -0700132}
133
Roshan Pius5ba0a902020-04-14 11:55:42 -0700134// Returns the dedicated iface name if one is defined.
lesl261818b2020-11-27 12:37:35 +0800135std::string getPredefinedNanIfaceName() {
Roshan Pius5ba0a902020-04-14 11:55:42 -0700136 std::array<char, PROPERTY_VALUE_MAX> buffer;
137 if (property_get("wifi.aware.interface", buffer.data(), nullptr) == 0) {
138 return {};
139 }
140 return buffer.data();
141}
142
Roshan Pius8574e7f2019-04-01 13:30:40 -0700143void setActiveWlanIfaceNameProperty(const std::string& ifname) {
144 auto res = property_set(kActiveWlanIfaceNameProperty, ifname.data());
145 if (res != 0) {
146 PLOG(ERROR) << "Failed to set active wlan iface name property";
147 }
148}
149
xshu37126c92018-04-13 16:24:45 -0700150// delete files that meet either conditions:
151// 1. older than a predefined time in the wifi tombstone dir.
152// 2. Files in excess to a predefined amount, starting from the oldest ones
xshu5899e8e2018-01-09 15:36:03 -0800153bool removeOldFilesInternal() {
154 time_t now = time(0);
155 const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds;
Josh Gaoa568e532018-06-04 18:16:00 -0700156 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(
157 opendir(kTombstoneFolderPath), closedir);
xshu5899e8e2018-01-09 15:36:03 -0800158 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800159 PLOG(ERROR) << "Failed to open directory";
xshu5899e8e2018-01-09 15:36:03 -0800160 return false;
161 }
xshu5899e8e2018-01-09 15:36:03 -0800162 struct dirent* dp;
163 bool success = true;
xshu37126c92018-04-13 16:24:45 -0700164 std::list<std::pair<const time_t, std::string>> valid_files;
Josh Gaoa568e532018-06-04 18:16:00 -0700165 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800166 if (dp->d_type != DT_REG) {
167 continue;
168 }
169 std::string cur_file_name(dp->d_name);
170 struct stat cur_file_stat;
171 std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
xshu4cb33162018-01-24 15:40:06 -0800172 if (stat(cur_file_path.c_str(), &cur_file_stat) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800173 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800174 success = false;
xshu4cb33162018-01-24 15:40:06 -0800175 continue;
176 }
xshu37126c92018-04-13 16:24:45 -0700177 const time_t cur_file_time = cur_file_stat.st_mtime;
178 valid_files.push_back(
179 std::pair<const time_t, std::string>(cur_file_time, cur_file_path));
180 }
181 valid_files.sort(); // sort the list of files by last modified time from
182 // small to big.
183 uint32_t cur_file_count = valid_files.size();
184 for (auto cur_file : valid_files) {
185 if (cur_file_count > kMaxRingBufferFileNum ||
186 cur_file.first < delete_files_before) {
187 if (unlink(cur_file.second.c_str()) != 0) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800188 PLOG(ERROR) << "Error deleting file";
xshu37126c92018-04-13 16:24:45 -0700189 success = false;
190 }
191 cur_file_count--;
192 } else {
193 break;
xshu5899e8e2018-01-09 15:36:03 -0800194 }
195 }
196 return success;
197}
198
xshu4cb33162018-01-24 15:40:06 -0800199// Helper function for |cpioArchiveFilesInDir|
200bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name,
201 size_t file_name_len) {
202 std::array<char, 32 * 1024> read_buf;
203 ssize_t llen =
204 sprintf(read_buf.data(),
205 "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
206 kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid,
207 st.st_gid, static_cast<int>(st.st_nlink),
208 static_cast<int>(st.st_mtime), static_cast<int>(st.st_size),
209 major(st.st_dev), minor(st.st_dev), major(st.st_rdev),
210 minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
211 if (write(out_fd, read_buf.data(), llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800212 PLOG(ERROR) << "Error writing cpio header to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800213 return false;
214 }
215 if (write(out_fd, file_name, file_name_len) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800216 PLOG(ERROR) << "Error writing filename to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800217 return false;
218 }
219
220 // NUL Pad header up to 4 multiple bytes.
221 llen = (llen + file_name_len) % 4;
222 if (llen != 0) {
223 const uint32_t zero = 0;
224 if (write(out_fd, &zero, 4 - llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800225 PLOG(ERROR) << "Error padding 0s to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800226 return false;
227 }
228 }
229 return true;
230}
231
232// Helper function for |cpioArchiveFilesInDir|
233size_t cpioWriteFileContent(int fd_read, int out_fd, struct stat& st) {
234 // writing content of file
235 std::array<char, 32 * 1024> read_buf;
236 ssize_t llen = st.st_size;
237 size_t n_error = 0;
238 while (llen > 0) {
239 ssize_t bytes_read = read(fd_read, read_buf.data(), read_buf.size());
240 if (bytes_read == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800241 PLOG(ERROR) << "Error reading file";
xshu4cb33162018-01-24 15:40:06 -0800242 return ++n_error;
243 }
244 llen -= bytes_read;
245 if (write(out_fd, read_buf.data(), bytes_read) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800246 PLOG(ERROR) << "Error writing data to file";
xshu4cb33162018-01-24 15:40:06 -0800247 return ++n_error;
248 }
249 if (bytes_read == 0) { // this should never happen, but just in case
250 // to unstuck from while loop
Elliott Hughes4db4add2019-03-08 12:42:57 -0800251 PLOG(ERROR) << "Unexpected read result";
xshu4cb33162018-01-24 15:40:06 -0800252 n_error++;
253 break;
254 }
255 }
256 llen = st.st_size % 4;
257 if (llen != 0) {
258 const uint32_t zero = 0;
259 if (write(out_fd, &zero, 4 - llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800260 PLOG(ERROR) << "Error padding 0s to file";
xshu4cb33162018-01-24 15:40:06 -0800261 return ++n_error;
262 }
263 }
264 return n_error;
265}
266
267// Helper function for |cpioArchiveFilesInDir|
268bool cpioWriteFileTrailer(int out_fd) {
269 std::array<char, 4096> read_buf;
270 read_buf.fill(0);
271 if (write(out_fd, read_buf.data(),
272 sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1,
273 0x0b, 0) +
274 4) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800275 PLOG(ERROR) << "Error writing trailing bytes";
xshu4cb33162018-01-24 15:40:06 -0800276 return false;
277 }
278 return true;
279}
280
xshu5899e8e2018-01-09 15:36:03 -0800281// Archives all files in |input_dir| and writes result into |out_fd|
282// Logic obtained from //external/toybox/toys/posix/cpio.c "Output cpio archive"
283// portion
xshu4cb33162018-01-24 15:40:06 -0800284size_t cpioArchiveFilesInDir(int out_fd, const char* input_dir) {
xshu5899e8e2018-01-09 15:36:03 -0800285 struct dirent* dp;
286 size_t n_error = 0;
Josh Gaoa568e532018-06-04 18:16:00 -0700287 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(input_dir),
288 closedir);
xshu5899e8e2018-01-09 15:36:03 -0800289 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800290 PLOG(ERROR) << "Failed to open directory";
xshu4cb33162018-01-24 15:40:06 -0800291 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800292 }
Josh Gaoa568e532018-06-04 18:16:00 -0700293 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800294 if (dp->d_type != DT_REG) {
295 continue;
296 }
297 std::string cur_file_name(dp->d_name);
xshu5899e8e2018-01-09 15:36:03 -0800298 struct stat st;
xshu5899e8e2018-01-09 15:36:03 -0800299 const std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
xshu4cb33162018-01-24 15:40:06 -0800300 if (stat(cur_file_path.c_str(), &st) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800301 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800302 n_error++;
xshu4cb33162018-01-24 15:40:06 -0800303 continue;
304 }
305 const int fd_read = open(cur_file_path.c_str(), O_RDONLY);
306 if (fd_read == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800307 PLOG(ERROR) << "Failed to open file " << cur_file_path;
xshu4cb33162018-01-24 15:40:06 -0800308 n_error++;
309 continue;
310 }
xshuf392fb42020-08-13 16:57:00 -0700311 std::string file_name_with_last_modified_time =
312 cur_file_name + "-" + std::to_string(st.st_mtime);
313 // string.size() does not include the null terminator. The cpio FreeBSD
314 // file header expects the null character to be included in the length.
315 const size_t file_name_len =
316 file_name_with_last_modified_time.size() + 1;
xshu4cb33162018-01-24 15:40:06 -0800317 unique_fd file_auto_closer(fd_read);
xshuf392fb42020-08-13 16:57:00 -0700318 if (!cpioWriteHeader(out_fd, st,
319 file_name_with_last_modified_time.c_str(),
xshu4cb33162018-01-24 15:40:06 -0800320 file_name_len)) {
321 return ++n_error;
322 }
323 size_t write_error = cpioWriteFileContent(fd_read, out_fd, st);
324 if (write_error) {
325 return n_error + write_error;
xshu5899e8e2018-01-09 15:36:03 -0800326 }
327 }
xshu4cb33162018-01-24 15:40:06 -0800328 if (!cpioWriteFileTrailer(out_fd)) {
329 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800330 }
331 return n_error;
332}
333
334// Helper function to create a non-const char*.
335std::vector<char> makeCharVec(const std::string& str) {
336 std::vector<char> vec(str.size() + 1);
337 vec.assign(str.begin(), str.end());
338 vec.push_back('\0');
339 return vec;
340}
341
Roshan Piusabcf78f2017-10-06 16:30:38 -0700342} // namespace
Roshan Pius35d958c2016-10-06 16:47:38 -0700343
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700344namespace android {
345namespace hardware {
346namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +0200347namespace V1_5 {
Roshan Pius79a99752016-10-04 13:03:58 -0700348namespace implementation {
Roshan Pius3c868522016-10-27 12:43:49 -0700349using hidl_return_util::validateAndCall;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800350using hidl_return_util::validateAndCallWithLock;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700351
Roshan Pius52947fb2016-11-18 11:38:07 -0800352WifiChip::WifiChip(
Jimmy Chen2dddd792019-12-23 17:50:39 +0200353 ChipId chip_id, bool is_primary,
354 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
Roshan Pius200a17d2017-11-01 13:03:35 -0700355 const std::weak_ptr<mode_controller::WifiModeController> mode_controller,
Roshan Pius99dab382019-02-14 07:57:10 -0800356 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700357 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags,
358 const std::function<void(const std::string&)>& handler)
Roshan Pius52947fb2016-11-18 11:38:07 -0800359 : chip_id_(chip_id),
360 legacy_hal_(legacy_hal),
361 mode_controller_(mode_controller),
Roshan Pius99dab382019-02-14 07:57:10 -0800362 iface_util_(iface_util),
Roshan Pius52947fb2016-11-18 11:38:07 -0800363 is_valid_(true),
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800364 current_mode_id_(feature_flags::chip_mode_ids::kInvalid),
Jimmy Chen2dddd792019-12-23 17:50:39 +0200365 modes_(feature_flags.lock()->getChipModes(is_primary)),
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700366 debug_ring_buffer_cb_registered_(false),
367 subsystemCallbackHandler_(handler) {
Roshan Pius8574e7f2019-04-01 13:30:40 -0700368 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
369}
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700370
Roshan Piusaabe5752016-09-29 09:03:59 -0700371void WifiChip::invalidate() {
xshu37126c92018-04-13 16:24:45 -0700372 if (!writeRingbufferFilesInternal()) {
373 LOG(ERROR) << "Error writing files to flash";
374 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700375 invalidateAndRemoveAllIfaces();
Roshan Pius8574e7f2019-04-01 13:30:40 -0700376 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700377 legacy_hal_.reset();
378 event_cb_handler_.invalidate();
379 is_valid_ = false;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700380}
381
Roshan Piusabcf78f2017-10-06 16:30:38 -0700382bool WifiChip::isValid() { return is_valid_; }
Roshan Pius3c868522016-10-27 12:43:49 -0700383
Jimmy Chend460df32019-11-29 17:31:22 +0200384std::set<sp<V1_4::IWifiChipEventCallback>> WifiChip::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700385 return event_cb_handler_.getCallbacks();
Roshan Pius203cb032016-12-14 17:41:20 -0800386}
387
Roshan Pius5c055462016-10-11 08:27:27 -0700388Return<void> WifiChip::getId(getId_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700389 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
390 &WifiChip::getIdInternal, hidl_status_cb);
Roshan Piuscd566bd2016-10-10 08:03:42 -0700391}
392
Jong Wook Kimda830c92018-07-23 15:29:38 -0700393// Deprecated support for this callback
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700394Return<void> WifiChip::registerEventCallback(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800395 const sp<V1_0::IWifiChipEventCallback>& event_callback,
Roshan Pius5c055462016-10-11 08:27:27 -0700396 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700397 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
398 &WifiChip::registerEventCallbackInternal,
399 hidl_status_cb, event_callback);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700400}
401
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700402Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700403 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
404 &WifiChip::getCapabilitiesInternal, hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700405}
406
Roshan Pius5c055462016-10-11 08:27:27 -0700407Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700408 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
409 &WifiChip::getAvailableModesInternal,
410 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700411}
412
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800413Return<void> WifiChip::configureChip(ChipModeId mode_id,
Roshan Pius5c055462016-10-11 08:27:27 -0700414 configureChip_cb hidl_status_cb) {
Roshan Piusba38d9c2017-12-08 07:32:08 -0800415 return validateAndCallWithLock(
416 this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
417 &WifiChip::configureChipInternal, hidl_status_cb, mode_id);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700418}
419
Roshan Pius5c055462016-10-11 08:27:27 -0700420Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700421 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
422 &WifiChip::getModeInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700423}
424
Roshan Pius5c055462016-10-11 08:27:27 -0700425Return<void> WifiChip::requestChipDebugInfo(
426 requestChipDebugInfo_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700427 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
428 &WifiChip::requestChipDebugInfoInternal,
429 hidl_status_cb);
Roshan Pius5c055462016-10-11 08:27:27 -0700430}
431
432Return<void> WifiChip::requestDriverDebugDump(
433 requestDriverDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700434 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
435 &WifiChip::requestDriverDebugDumpInternal,
436 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700437}
438
Roshan Pius5c055462016-10-11 08:27:27 -0700439Return<void> WifiChip::requestFirmwareDebugDump(
440 requestFirmwareDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700441 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
442 &WifiChip::requestFirmwareDebugDumpInternal,
443 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700444}
445
Roshan Pius5c055462016-10-11 08:27:27 -0700446Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700447 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
448 &WifiChip::createApIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700449}
450
lesl94d28242020-11-18 22:17:37 +0800451Return<void> WifiChip::createBridgedApIface(
452 createBridgedApIface_cb hidl_status_cb) {
453 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
454 &WifiChip::createBridgedApIfaceInternal,
455 hidl_status_cb);
456}
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
Roshan Pius5c055462016-10-11 08:27:27 -0700463Return<void> WifiChip::getApIface(const hidl_string& ifname,
464 getApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700465 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
466 &WifiChip::getApIfaceInternal, hidl_status_cb,
467 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700468}
469
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800470Return<void> WifiChip::removeApIface(const hidl_string& ifname,
471 removeApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700472 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
473 &WifiChip::removeApIfaceInternal, hidl_status_cb,
474 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800475}
476
lesl94d28242020-11-18 22:17:37 +0800477Return<void> WifiChip::removeIfaceInstanceFromBridgedApIface(
478 const hidl_string& ifname, const hidl_string& ifInstanceName,
479 removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) {
480 return validateAndCall(
481 this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
482 &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal,
483 hidl_status_cb, ifname, ifInstanceName);
484}
485
Roshan Pius5c055462016-10-11 08:27:27 -0700486Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700487 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
488 &WifiChip::createNanIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700489}
490
Roshan Pius5c055462016-10-11 08:27:27 -0700491Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700492 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
493 &WifiChip::getNanIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700494}
495
496Return<void> WifiChip::getNanIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700497 getNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700498 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
499 &WifiChip::getNanIfaceInternal, hidl_status_cb,
500 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700501}
502
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800503Return<void> WifiChip::removeNanIface(const hidl_string& ifname,
504 removeNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700505 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
506 &WifiChip::removeNanIfaceInternal, hidl_status_cb,
507 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800508}
509
Roshan Pius5c055462016-10-11 08:27:27 -0700510Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700511 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
512 &WifiChip::createP2pIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700513}
514
Roshan Pius5c055462016-10-11 08:27:27 -0700515Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700516 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
517 &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700518}
519
520Return<void> WifiChip::getP2pIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700521 getP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700522 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
523 &WifiChip::getP2pIfaceInternal, hidl_status_cb,
524 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700525}
526
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800527Return<void> WifiChip::removeP2pIface(const hidl_string& ifname,
528 removeP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700529 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
530 &WifiChip::removeP2pIfaceInternal, hidl_status_cb,
531 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800532}
533
Roshan Pius5c055462016-10-11 08:27:27 -0700534Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700535 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
536 &WifiChip::createStaIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700537}
538
Roshan Pius5c055462016-10-11 08:27:27 -0700539Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700540 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
541 &WifiChip::getStaIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700542}
543
544Return<void> WifiChip::getStaIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700545 getStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700546 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
547 &WifiChip::getStaIfaceInternal, hidl_status_cb,
548 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700549}
550
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800551Return<void> WifiChip::removeStaIface(const hidl_string& ifname,
552 removeStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700553 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
554 &WifiChip::removeStaIfaceInternal, hidl_status_cb,
555 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800556}
557
Roshan Pius5c055462016-10-11 08:27:27 -0700558Return<void> WifiChip::createRttController(
559 const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700560 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
561 &WifiChip::createRttControllerInternal,
562 hidl_status_cb, bound_iface);
Roshan Pius59268282016-10-06 20:23:47 -0700563}
564
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700565Return<void> WifiChip::getDebugRingBuffersStatus(
566 getDebugRingBuffersStatus_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700567 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
568 &WifiChip::getDebugRingBuffersStatusInternal,
569 hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700570}
571
572Return<void> WifiChip::startLoggingToDebugRingBuffer(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700573 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
574 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes,
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700575 startLoggingToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700576 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
577 &WifiChip::startLoggingToDebugRingBufferInternal,
578 hidl_status_cb, ring_name, verbose_level,
579 max_interval_in_sec, min_data_size_in_bytes);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700580}
581
582Return<void> WifiChip::forceDumpToDebugRingBuffer(
583 const hidl_string& ring_name,
584 forceDumpToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700585 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
586 &WifiChip::forceDumpToDebugRingBufferInternal,
587 hidl_status_cb, ring_name);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700588}
589
Roger Wangb294c762018-11-02 15:34:39 +0800590Return<void> WifiChip::flushRingBufferToFile(
591 flushRingBufferToFile_cb hidl_status_cb) {
592 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
593 &WifiChip::flushRingBufferToFileInternal,
594 hidl_status_cb);
595}
596
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800597Return<void> WifiChip::stopLoggingToDebugRingBuffer(
598 stopLoggingToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700599 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
600 &WifiChip::stopLoggingToDebugRingBufferInternal,
601 hidl_status_cb);
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800602}
603
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700604Return<void> WifiChip::getDebugHostWakeReasonStats(
605 getDebugHostWakeReasonStats_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700606 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
607 &WifiChip::getDebugHostWakeReasonStatsInternal,
608 hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700609}
610
Roshan Pius203cb032016-12-14 17:41:20 -0800611Return<void> WifiChip::enableDebugErrorAlerts(
612 bool enable, enableDebugErrorAlerts_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700613 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
614 &WifiChip::enableDebugErrorAlertsInternal,
615 hidl_status_cb, enable);
Roshan Pius203cb032016-12-14 17:41:20 -0800616}
617
Roshan Pius735ff432017-07-25 08:48:08 -0700618Return<void> WifiChip::selectTxPowerScenario(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700619 V1_1::IWifiChip::TxPowerScenario scenario,
620 selectTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700621 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
622 &WifiChip::selectTxPowerScenarioInternal,
623 hidl_status_cb, scenario);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700624}
625
Roshan Pius735ff432017-07-25 08:48:08 -0700626Return<void> WifiChip::resetTxPowerScenario(
627 resetTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700628 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
629 &WifiChip::resetTxPowerScenarioInternal,
630 hidl_status_cb);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700631}
632
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700633Return<void> WifiChip::setLatencyMode(LatencyMode mode,
634 setLatencyMode_cb hidl_status_cb) {
635 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
636 &WifiChip::setLatencyModeInternal, hidl_status_cb,
637 mode);
638}
639
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800640Return<void> WifiChip::registerEventCallback_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700641 const sp<V1_2::IWifiChipEventCallback>& event_callback,
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800642 registerEventCallback_cb hidl_status_cb) {
643 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
644 &WifiChip::registerEventCallbackInternal_1_2,
645 hidl_status_cb, event_callback);
646}
647
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800648Return<void> WifiChip::selectTxPowerScenario_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700649 TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800650 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700651 &WifiChip::selectTxPowerScenarioInternal_1_2,
652 hidl_status_cb, scenario);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800653}
654
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700655Return<void> WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) {
656 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
657 &WifiChip::getCapabilitiesInternal_1_3,
658 hidl_status_cb);
659}
660
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200661Return<void> WifiChip::getCapabilities_1_5(
662 getCapabilities_1_5_cb hidl_status_cb) {
663 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
664 &WifiChip::getCapabilitiesInternal_1_5,
665 hidl_status_cb);
666}
667
xshu5899e8e2018-01-09 15:36:03 -0800668Return<void> WifiChip::debug(const hidl_handle& handle,
669 const hidl_vec<hidl_string>&) {
670 if (handle != nullptr && handle->numFds >= 1) {
xshu0a0fe512020-07-22 17:53:37 -0700671 {
672 std::unique_lock<std::mutex> lk(lock_t);
673 for (const auto& item : ringbuffer_map_) {
674 forceDumpToDebugRingBufferInternal(item.first);
675 }
676 // unique_lock unlocked here
677 }
678 usleep(100 * 1000); // sleep for 100 milliseconds to wait for
679 // ringbuffer updates.
xshu5899e8e2018-01-09 15:36:03 -0800680 int fd = handle->data[0];
681 if (!writeRingbufferFilesInternal()) {
682 LOG(ERROR) << "Error writing files to flash";
683 }
xshu4cb33162018-01-24 15:40:06 -0800684 uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath);
xshu5899e8e2018-01-09 15:36:03 -0800685 if (n_error != 0) {
686 LOG(ERROR) << n_error << " errors occured in cpio function";
687 }
688 fsync(fd);
689 } else {
690 LOG(ERROR) << "File handle error";
691 }
692 return Void();
693}
694
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700695Return<void> WifiChip::createRttController_1_4(
696 const sp<IWifiIface>& bound_iface,
697 createRttController_1_4_cb hidl_status_cb) {
698 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
699 &WifiChip::createRttControllerInternal_1_4,
700 hidl_status_cb, bound_iface);
701}
702
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800703Return<void> WifiChip::registerEventCallback_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200704 const sp<V1_4::IWifiChipEventCallback>& event_callback,
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800705 registerEventCallback_cb hidl_status_cb) {
706 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
707 &WifiChip::registerEventCallbackInternal_1_4,
708 hidl_status_cb, event_callback);
709}
710
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800711Return<void> WifiChip::setMultiStaPrimaryConnection(
712 const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) {
713 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
714 &WifiChip::setMultiStaPrimaryConnectionInternal,
715 hidl_status_cb, ifname);
716}
717
718Return<void> WifiChip::setMultiStaUseCase(
719 MultiStaUseCase use_case, setMultiStaUseCase_cb hidl_status_cb) {
720 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
721 &WifiChip::setMultiStaUseCaseInternal,
722 hidl_status_cb, use_case);
723}
724
Quang Luong94bcce52020-11-25 17:52:19 -0800725Return<void> WifiChip::setCoexUnsafeChannels(
726 const hidl_vec<CoexUnsafeChannel>& unsafeChannels,
727 hidl_bitfield<IfaceType> restrictions,
728 setCoexUnsafeChannels_cb hidl_status_cb) {
729 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
730 &WifiChip::setCoexUnsafeChannelsInternal,
731 hidl_status_cb, unsafeChannels, restrictions);
732}
733
Roshan Pius35d958c2016-10-06 16:47:38 -0700734void WifiChip::invalidateAndRemoveAllIfaces() {
lesl94d28242020-11-18 22:17:37 +0800735 invalidateAndClearBridgedApAll();
Roshan Pius675609b2017-10-31 14:24:58 -0700736 invalidateAndClearAll(ap_ifaces_);
737 invalidateAndClearAll(nan_ifaces_);
738 invalidateAndClearAll(p2p_ifaces_);
739 invalidateAndClearAll(sta_ifaces_);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700740 // Since all the ifaces are invalid now, all RTT controller objects
741 // using those ifaces also need to be invalidated.
742 for (const auto& rtt : rtt_controllers_) {
743 rtt->invalidate();
744 }
745 rtt_controllers_.clear();
Roshan Pius35d958c2016-10-06 16:47:38 -0700746}
747
Roshan Pius82368502019-05-16 12:53:02 -0700748void WifiChip::invalidateAndRemoveDependencies(
749 const std::string& removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200750 for (auto it = nan_ifaces_.begin(); it != nan_ifaces_.end();) {
751 auto nan_iface = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700752 if (nan_iface->getName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200753 nan_iface->invalidate();
Roshan Pius82368502019-05-16 12:53:02 -0700754 for (const auto& callback : event_cb_handler_.getCallbacks()) {
755 if (!callback
756 ->onIfaceRemoved(IfaceType::NAN, removed_iface_name)
757 .isOk()) {
758 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
759 }
760 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200761 it = nan_ifaces_.erase(it);
762 } else {
763 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700764 }
765 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200766
767 for (auto it = rtt_controllers_.begin(); it != rtt_controllers_.end();) {
768 auto rtt = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700769 if (rtt->getIfaceName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200770 rtt->invalidate();
771 it = rtt_controllers_.erase(it);
772 } else {
773 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700774 }
775 }
776}
777
Roshan Pius3c868522016-10-27 12:43:49 -0700778std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700779 return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700780}
781
782WifiStatus WifiChip::registerEventCallbackInternal(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800783 const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) {
784 // Deprecated support for this callback.
785 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius3c868522016-10-27 12:43:49 -0700786}
787
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700788std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() {
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700789 // Deprecated support for this callback.
790 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
791}
792
Jimmy Chend460df32019-11-29 17:31:22 +0200793std::pair<WifiStatus, std::vector<V1_4::IWifiChip::ChipMode>>
Roshan Pius3c868522016-10-27 12:43:49 -0700794WifiChip::getAvailableModesInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700795 return {createWifiStatus(WifiStatusCode::SUCCESS), modes_};
Roshan Pius3c868522016-10-27 12:43:49 -0700796}
797
Roshan Piusba38d9c2017-12-08 07:32:08 -0800798WifiStatus WifiChip::configureChipInternal(
799 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
800 ChipModeId mode_id) {
Roshan Piuscc338202017-11-02 13:54:09 -0700801 if (!isValidModeId(mode_id)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700802 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
803 }
804 if (mode_id == current_mode_id_) {
805 LOG(DEBUG) << "Already in the specified mode " << mode_id;
806 return createWifiStatus(WifiStatusCode::SUCCESS);
807 }
Roshan Piusba38d9c2017-12-08 07:32:08 -0800808 WifiStatus status = handleChipConfiguration(lock, mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700809 if (status.code != WifiStatusCode::SUCCESS) {
810 for (const auto& callback : event_cb_handler_.getCallbacks()) {
811 if (!callback->onChipReconfigureFailure(status).isOk()) {
812 LOG(ERROR)
813 << "Failed to invoke onChipReconfigureFailure callback";
814 }
815 }
816 return status;
817 }
Roshan Piusd37341f2017-01-31 13:13:28 -0800818 for (const auto& callback : event_cb_handler_.getCallbacks()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700819 if (!callback->onChipReconfigured(mode_id).isOk()) {
820 LOG(ERROR) << "Failed to invoke onChipReconfigured callback";
821 }
Roshan Pius52947fb2016-11-18 11:38:07 -0800822 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700823 current_mode_id_ = mode_id;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800824 LOG(INFO) << "Configured chip in mode " << mode_id;
Roshan Pius8574e7f2019-04-01 13:30:40 -0700825 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700826
827 legacy_hal_.lock()->registerSubsystemRestartCallbackHandler(
828 subsystemCallbackHandler_);
829
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800830 return status;
Roshan Pius3c868522016-10-27 12:43:49 -0700831}
832
833std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700834 if (!isValidModeId(current_mode_id_)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700835 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE),
836 current_mode_id_};
837 }
838 return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700839}
840
Jimmy Chend460df32019-11-29 17:31:22 +0200841std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo>
Roshan Pius3c868522016-10-27 12:43:49 -0700842WifiChip::requestChipDebugInfoInternal() {
Jimmy Chend460df32019-11-29 17:31:22 +0200843 V1_4::IWifiChip::ChipDebugInfo result;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700844 legacy_hal::wifi_error legacy_status;
845 std::string driver_desc;
Roshan Pius6036c022019-03-27 10:41:58 -0700846 const auto ifname = getFirstActiveWlanIfaceName();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700847 std::tie(legacy_status, driver_desc) =
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -0800848 legacy_hal_.lock()->getDriverVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700849 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
850 LOG(ERROR) << "Failed to get driver version: "
851 << legacyErrorToString(legacy_status);
852 WifiStatus status = createWifiStatusFromLegacyError(
853 legacy_status, "failed to get driver version");
854 return {status, result};
855 }
856 result.driverDescription = driver_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700857
Roshan Piusabcf78f2017-10-06 16:30:38 -0700858 std::string firmware_desc;
859 std::tie(legacy_status, firmware_desc) =
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -0800860 legacy_hal_.lock()->getFirmwareVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700861 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
862 LOG(ERROR) << "Failed to get firmware version: "
863 << legacyErrorToString(legacy_status);
864 WifiStatus status = createWifiStatusFromLegacyError(
865 legacy_status, "failed to get firmware version");
866 return {status, result};
867 }
868 result.firmwareDescription = firmware_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700869
Roshan Piusabcf78f2017-10-06 16:30:38 -0700870 return {createWifiStatus(WifiStatusCode::SUCCESS), result};
Roshan Pius3c868522016-10-27 12:43:49 -0700871}
872
873std::pair<WifiStatus, std::vector<uint8_t>>
874WifiChip::requestDriverDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700875 legacy_hal::wifi_error legacy_status;
876 std::vector<uint8_t> driver_dump;
877 std::tie(legacy_status, driver_dump) =
Roshan Pius6036c022019-03-27 10:41:58 -0700878 legacy_hal_.lock()->requestDriverMemoryDump(
879 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700880 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
881 LOG(ERROR) << "Failed to get driver debug dump: "
882 << legacyErrorToString(legacy_status);
883 return {createWifiStatusFromLegacyError(legacy_status),
884 std::vector<uint8_t>()};
885 }
886 return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700887}
888
889std::pair<WifiStatus, std::vector<uint8_t>>
890WifiChip::requestFirmwareDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700891 legacy_hal::wifi_error legacy_status;
892 std::vector<uint8_t> firmware_dump;
893 std::tie(legacy_status, firmware_dump) =
Roshan Pius6036c022019-03-27 10:41:58 -0700894 legacy_hal_.lock()->requestFirmwareMemoryDump(
895 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700896 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
897 LOG(ERROR) << "Failed to get firmware debug dump: "
898 << legacyErrorToString(legacy_status);
899 return {createWifiStatusFromLegacyError(legacy_status), {}};
900 }
901 return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700902}
903
lesl94d28242020-11-18 22:17:37 +0800904WifiStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) {
905 legacy_hal::wifi_error legacy_status;
906 legacy_status = legacy_hal_.lock()->createVirtualInterface(
907 apVirtIf,
908 hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::AP));
Sunil Raviddab4bb2020-02-03 22:45:19 -0800909 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
lesl94d28242020-11-18 22:17:37 +0800910 LOG(ERROR) << "Failed to add interface: " << apVirtIf << " "
Sunil Raviddab4bb2020-02-03 22:45:19 -0800911 << legacyErrorToString(legacy_status);
lesl94d28242020-11-18 22:17:37 +0800912 return createWifiStatusFromLegacyError(legacy_status);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800913 }
lesl94d28242020-11-18 22:17:37 +0800914 return createWifiStatus(WifiStatusCode::SUCCESS);
915}
916
917sp<WifiApIface> WifiChip::newWifiApIface(std::string& ifname) {
lesl420c4fc2020-11-23 19:33:04 +0800918 std::vector<std::string> ap_instances;
919 for (auto const& it : br_ifaces_ap_instances_) {
920 if (it.first == ifname) {
921 ap_instances = it.second;
922 }
923 }
924 sp<WifiApIface> iface =
925 new WifiApIface(ifname, ap_instances, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -0700926 ap_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700927 for (const auto& callback : event_cb_handler_.getCallbacks()) {
928 if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) {
929 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
930 }
931 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700932 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
lesl94d28242020-11-18 22:17:37 +0800933 return iface;
934}
935
lesl420c4fc2020-11-23 19:33:04 +0800936std::pair<WifiStatus, sp<V1_5::IWifiApIface>>
937WifiChip::createApIfaceInternal() {
lesl94d28242020-11-18 22:17:37 +0800938 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
939 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
940 }
941 std::string ifname = allocateApIfaceName();
942 WifiStatus status = createVirtualApInterface(ifname);
943 if (status.code != WifiStatusCode::SUCCESS) {
944 return {status, {}};
945 }
946 sp<WifiApIface> iface = newWifiApIface(ifname);
947 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
948}
949
lesl420c4fc2020-11-23 19:33:04 +0800950std::pair<WifiStatus, sp<V1_5::IWifiApIface>>
lesl94d28242020-11-18 22:17:37 +0800951WifiChip::createBridgedApIfaceInternal() {
952 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
953 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
954 }
lesl261818b2020-11-27 12:37:35 +0800955 std::vector<std::string> ap_instances = allocateBridgedApInstanceNames();
956 if (ap_instances.size() < 2) {
957 LOG(ERROR) << "Fail to allocate two instances";
958 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
959 }
960 std::string br_ifname = kApBridgeIfacePrefix + ap_instances[0];
lesl94d28242020-11-18 22:17:37 +0800961 for (int i = 0; i < 2; i++) {
lesl261818b2020-11-27 12:37:35 +0800962 WifiStatus status = createVirtualApInterface(ap_instances[i]);
lesl94d28242020-11-18 22:17:37 +0800963 if (status.code != WifiStatusCode::SUCCESS) {
lesl261818b2020-11-27 12:37:35 +0800964 if (i != 0) { // The failure happened when creating second virtual
965 // iface.
lesl94d28242020-11-18 22:17:37 +0800966 legacy_hal_.lock()->deleteVirtualInterface(
lesl261818b2020-11-27 12:37:35 +0800967 ap_instances.front()); // Remove the first virtual iface.
lesl94d28242020-11-18 22:17:37 +0800968 }
969 return {status, {}};
970 }
lesl94d28242020-11-18 22:17:37 +0800971 }
972 br_ifaces_ap_instances_[br_ifname] = ap_instances;
973 if (!iface_util_.lock()->createBridge(br_ifname)) {
974 LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str();
975 invalidateAndClearBridgedAp(br_ifname);
976 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
977 }
978 for (auto const& instance : ap_instances) {
979 // Bind ap instance interface to AP bridge
980 if (!iface_util_.lock()->addIfaceToBridge(br_ifname, instance)) {
981 LOG(ERROR) << "Failed add if to Bridge - if_name="
982 << instance.c_str();
983 invalidateAndClearBridgedAp(br_ifname);
984 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
985 }
986 }
987 sp<WifiApIface> iface = newWifiApIface(br_ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700988 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700989}
990
991std::pair<WifiStatus, std::vector<hidl_string>>
992WifiChip::getApIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -0700993 if (ap_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700994 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
995 }
Roshan Pius675609b2017-10-31 14:24:58 -0700996 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -0700997}
998
lesl420c4fc2020-11-23 19:33:04 +0800999std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::getApIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001000 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001001 const auto iface = findUsingName(ap_ifaces_, ifname);
1002 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001003 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1004 }
Roshan Pius675609b2017-10-31 14:24:58 -07001005 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001006}
1007
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001008WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001009 const auto iface = findUsingName(ap_ifaces_, ifname);
1010 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001011 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001012 }
Roshan Pius82368502019-05-16 12:53:02 -07001013 // Invalidate & remove any dependent objects first.
1014 // Note: This is probably not required because we never create
1015 // nan/rtt objects over AP iface. But, there is no harm to do it
1016 // here and not make that assumption all over the place.
1017 invalidateAndRemoveDependencies(ifname);
lesl94d28242020-11-18 22:17:37 +08001018 // Clear the bridge interface and the iface instance.
1019 invalidateAndClearBridgedAp(ifname);
Roshan Pius675609b2017-10-31 14:24:58 -07001020 invalidateAndClear(ap_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001021 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1022 if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) {
1023 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1024 }
1025 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001026 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001027 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001028}
1029
lesl94d28242020-11-18 22:17:37 +08001030WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal(
1031 const std::string& ifname, const std::string& ifInstanceName) {
1032 legacy_hal::wifi_error legacy_status;
1033 const auto iface = findUsingName(ap_ifaces_, ifname);
1034 if (!iface.get() || !ifInstanceName.empty()) {
1035 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1036 }
1037 // Requires to remove one of the instance in bridge mode
1038 for (auto const& it : br_ifaces_ap_instances_) {
1039 if (it.first == ifname) {
1040 for (auto const& iface : it.second) {
1041 if (iface == ifInstanceName) {
1042 if (!iface_util_.lock()->removeIfaceFromBridge(it.first,
1043 iface)) {
1044 LOG(ERROR) << "Failed to remove interface: " << iface
1045 << " from " << ifname << ", error: "
1046 << legacyErrorToString(legacy_status);
1047 return createWifiStatus(
1048 WifiStatusCode::ERROR_NOT_AVAILABLE);
1049 }
1050 legacy_status =
1051 legacy_hal_.lock()->deleteVirtualInterface(iface);
1052 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1053 LOG(ERROR) << "Failed to del interface: " << iface
1054 << " " << legacyErrorToString(legacy_status);
1055 return createWifiStatusFromLegacyError(legacy_status);
1056 }
1057 }
1058 }
1059 break;
1060 }
1061 }
1062 br_ifaces_ap_instances_.erase(ifInstanceName);
1063 return createWifiStatus(WifiStatusCode::SUCCESS);
1064}
1065
Jimmy Chend460df32019-11-29 17:31:22 +02001066std::pair<WifiStatus, sp<V1_4::IWifiNanIface>>
1067WifiChip::createNanIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001068 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::NAN)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001069 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Etan Cohenc5700402017-03-08 16:43:38 -08001070 }
Roshan Pius5ba0a902020-04-14 11:55:42 -07001071 bool is_dedicated_iface = true;
lesl261818b2020-11-27 12:37:35 +08001072 std::string ifname = getPredefinedNanIfaceName();
Nate Jiang63f34ed2020-05-20 23:22:51 -07001073 if (ifname.empty() || !iface_util_.lock()->ifNameToIndex(ifname)) {
Roshan Pius5ba0a902020-04-14 11:55:42 -07001074 // Use the first shared STA iface (wlan0) if a dedicated aware iface is
1075 // not defined.
1076 ifname = getFirstActiveWlanIfaceName();
1077 is_dedicated_iface = false;
1078 }
1079 sp<WifiNanIface> iface =
1080 new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_);
Roshan Piuscc338202017-11-02 13:54:09 -07001081 nan_ifaces_.push_back(iface);
1082 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1083 if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
1084 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1085 }
1086 }
1087 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001088}
1089
1090std::pair<WifiStatus, std::vector<hidl_string>>
1091WifiChip::getNanIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001092 if (nan_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001093 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1094 }
Roshan Pius675609b2017-10-31 14:24:58 -07001095 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001096}
1097
Jimmy Chend460df32019-11-29 17:31:22 +02001098std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::getNanIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001099 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001100 const auto iface = findUsingName(nan_ifaces_, ifname);
1101 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001102 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1103 }
Roshan Pius675609b2017-10-31 14:24:58 -07001104 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001105}
1106
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001107WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001108 const auto iface = findUsingName(nan_ifaces_, ifname);
1109 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001110 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001111 }
Roshan Pius675609b2017-10-31 14:24:58 -07001112 invalidateAndClear(nan_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001113 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1114 if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) {
1115 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1116 }
1117 }
1118 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001119}
1120
Roshan Pius3c868522016-10-27 12:43:49 -07001121std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001122 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::P2P)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001123 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001124 }
lesl261818b2020-11-27 12:37:35 +08001125 std::string ifname = getPredefinedP2pIfaceName();
Roshan Pius675609b2017-10-31 14:24:58 -07001126 sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_);
1127 p2p_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001128 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1129 if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) {
1130 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1131 }
1132 }
Roshan Pius675609b2017-10-31 14:24:58 -07001133 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001134}
1135
1136std::pair<WifiStatus, std::vector<hidl_string>>
1137WifiChip::getP2pIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001138 if (p2p_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001139 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1140 }
Roshan Pius675609b2017-10-31 14:24:58 -07001141 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001142}
1143
1144std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001145 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001146 const auto iface = findUsingName(p2p_ifaces_, ifname);
1147 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001148 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1149 }
Roshan Pius675609b2017-10-31 14:24:58 -07001150 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001151}
1152
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001153WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001154 const auto iface = findUsingName(p2p_ifaces_, ifname);
1155 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001156 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001157 }
Roshan Pius675609b2017-10-31 14:24:58 -07001158 invalidateAndClear(p2p_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001159 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1160 if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) {
1161 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1162 }
1163 }
1164 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001165}
1166
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001167std::pair<WifiStatus, sp<V1_5::IWifiStaIface>>
Ahmed ElArabawyb23485d2019-12-09 15:24:16 -08001168WifiChip::createStaIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001169 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::STA)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001170 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001171 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001172 std::string ifname = allocateStaIfaceName();
Sunil Raviddab4bb2020-02-03 22:45:19 -08001173 legacy_hal::wifi_error legacy_status =
1174 legacy_hal_.lock()->createVirtualInterface(
1175 ifname,
1176 hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
1177 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1178 LOG(ERROR) << "Failed to add interface: " << ifname << " "
1179 << legacyErrorToString(legacy_status);
1180 return {createWifiStatusFromLegacyError(legacy_status), {}};
1181 }
Roshan Pius99dab382019-02-14 07:57:10 -08001182 sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -07001183 sta_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001184 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1185 if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
1186 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1187 }
1188 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001189 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Pius675609b2017-10-31 14:24:58 -07001190 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001191}
1192
1193std::pair<WifiStatus, std::vector<hidl_string>>
1194WifiChip::getStaIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001195 if (sta_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001196 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1197 }
Roshan Pius675609b2017-10-31 14:24:58 -07001198 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001199}
1200
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001201std::pair<WifiStatus, sp<V1_5::IWifiStaIface>> WifiChip::getStaIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001202 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001203 const auto iface = findUsingName(sta_ifaces_, ifname);
1204 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001205 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1206 }
Roshan Pius675609b2017-10-31 14:24:58 -07001207 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001208}
1209
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001210WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001211 const auto iface = findUsingName(sta_ifaces_, ifname);
1212 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001213 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001214 }
Roshan Pius82368502019-05-16 12:53:02 -07001215 // Invalidate & remove any dependent objects first.
1216 invalidateAndRemoveDependencies(ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -08001217 legacy_hal::wifi_error legacy_status =
1218 legacy_hal_.lock()->deleteVirtualInterface(ifname);
1219 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1220 LOG(ERROR) << "Failed to remove interface: " << ifname << " "
1221 << legacyErrorToString(legacy_status);
1222 }
Roshan Pius675609b2017-10-31 14:24:58 -07001223 invalidateAndClear(sta_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001224 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1225 if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) {
1226 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1227 }
1228 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001229 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001230 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001231}
1232
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001233std::pair<WifiStatus, sp<V1_0::IWifiRttController>>
1234WifiChip::createRttControllerInternal(const sp<IWifiIface>& /*bound_iface*/) {
1235 LOG(ERROR) << "createRttController is not supported on this HAL";
Ahmed ElArabawy36defb32019-12-29 21:24:27 -08001236 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
Roshan Pius3c868522016-10-27 12:43:49 -07001237}
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001238
1239std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
1240WifiChip::getDebugRingBuffersStatusInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001241 legacy_hal::wifi_error legacy_status;
1242 std::vector<legacy_hal::wifi_ring_buffer_status>
1243 legacy_ring_buffer_status_vec;
1244 std::tie(legacy_status, legacy_ring_buffer_status_vec) =
Roshan Pius6036c022019-03-27 10:41:58 -07001245 legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001246 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1247 return {createWifiStatusFromLegacyError(legacy_status), {}};
1248 }
1249 std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec;
1250 if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl(
1251 legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) {
1252 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1253 }
1254 return {createWifiStatus(WifiStatusCode::SUCCESS),
1255 hidl_ring_buffer_status_vec};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001256}
1257
1258WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
Roshan Piusabcf78f2017-10-06 16:30:38 -07001259 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
1260 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) {
1261 WifiStatus status = registerDebugRingBufferCallback();
1262 if (status.code != WifiStatusCode::SUCCESS) {
1263 return status;
1264 }
1265 legacy_hal::wifi_error legacy_status =
1266 legacy_hal_.lock()->startRingBufferLogging(
Roshan Pius6036c022019-03-27 10:41:58 -07001267 getFirstActiveWlanIfaceName(), ring_name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001268 static_cast<
1269 std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(
1270 verbose_level),
1271 max_interval_in_sec, min_data_size_in_bytes);
xshu5899e8e2018-01-09 15:36:03 -08001272 ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>(
1273 ring_name, Ringbuffer(kMaxBufferSizeBytes)));
Roshan Piusa63b53f2019-11-18 11:03:13 -08001274 // if verbose logging enabled, turn up HAL daemon logging as well.
1275 if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) {
1276 android::base::SetMinimumLogSeverity(android::base::DEBUG);
1277 } else {
1278 android::base::SetMinimumLogSeverity(android::base::VERBOSE);
1279 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001280 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001281}
1282
1283WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(
Roshan Piuse2d0ab52016-12-05 15:24:20 -08001284 const hidl_string& ring_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001285 WifiStatus status = registerDebugRingBufferCallback();
1286 if (status.code != WifiStatusCode::SUCCESS) {
1287 return status;
1288 }
1289 legacy_hal::wifi_error legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001290 legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(),
1291 ring_name);
xshu5899e8e2018-01-09 15:36:03 -08001292
Roshan Piusabcf78f2017-10-06 16:30:38 -07001293 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001294}
1295
Roger Wangb294c762018-11-02 15:34:39 +08001296WifiStatus WifiChip::flushRingBufferToFileInternal() {
1297 if (!writeRingbufferFilesInternal()) {
1298 LOG(ERROR) << "Error writing files to flash";
1299 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1300 }
1301 return createWifiStatus(WifiStatusCode::SUCCESS);
1302}
1303
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001304WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001305 legacy_hal::wifi_error legacy_status =
1306 legacy_hal_.lock()->deregisterRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001307 getFirstActiveWlanIfaceName());
xshu0a0fe512020-07-22 17:53:37 -07001308 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1309 debug_ring_buffer_cb_registered_ = false;
1310 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001311 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001312}
1313
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001314std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
1315WifiChip::getDebugHostWakeReasonStatsInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001316 legacy_hal::wifi_error legacy_status;
1317 legacy_hal::WakeReasonStats legacy_stats;
1318 std::tie(legacy_status, legacy_stats) =
Roshan Pius6036c022019-03-27 10:41:58 -07001319 legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001320 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1321 return {createWifiStatusFromLegacyError(legacy_status), {}};
1322 }
1323 WifiDebugHostWakeReasonStats hidl_stats;
1324 if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats,
1325 &hidl_stats)) {
1326 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1327 }
1328 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001329}
1330
Roshan Pius203cb032016-12-14 17:41:20 -08001331WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001332 legacy_hal::wifi_error legacy_status;
1333 if (enable) {
1334 android::wp<WifiChip> weak_ptr_this(this);
1335 const auto& on_alert_callback = [weak_ptr_this](
1336 int32_t error_code,
1337 std::vector<uint8_t> debug_data) {
1338 const auto shared_ptr_this = weak_ptr_this.promote();
1339 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1340 LOG(ERROR) << "Callback invoked on an invalid object";
1341 return;
1342 }
1343 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
1344 if (!callback->onDebugErrorAlert(error_code, debug_data)
1345 .isOk()) {
1346 LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback";
1347 }
1348 }
1349 };
1350 legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001351 getFirstActiveWlanIfaceName(), on_alert_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001352 } else {
1353 legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001354 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001355 }
1356 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius203cb032016-12-14 17:41:20 -08001357}
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001358
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001359WifiStatus WifiChip::selectTxPowerScenarioInternal(
Jong Wook Kimda830c92018-07-23 15:29:38 -07001360 V1_1::IWifiChip::TxPowerScenario scenario) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001361 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001362 getFirstActiveWlanIfaceName(),
Roshan Piusabcf78f2017-10-06 16:30:38 -07001363 hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario));
1364 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001365}
1366
Roshan Pius735ff432017-07-25 08:48:08 -07001367WifiStatus WifiChip::resetTxPowerScenarioInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001368 auto legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001369 legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001370 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001371}
1372
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001373WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) {
1374 auto legacy_status = legacy_hal_.lock()->setLatencyMode(
Roshan Pius6036c022019-03-27 10:41:58 -07001375 getFirstActiveWlanIfaceName(),
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001376 hidl_struct_util::convertHidlLatencyModeToLegacy(mode));
1377 return createWifiStatusFromLegacyError(legacy_status);
1378}
1379
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001380WifiStatus WifiChip::registerEventCallbackInternal_1_2(
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001381 const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) {
1382 // Deprecated support for this callback.
1383 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001384}
1385
Jong Wook Kimda830c92018-07-23 15:29:38 -07001386WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(
1387 TxPowerScenario scenario) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001388 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001389 getFirstActiveWlanIfaceName(),
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001390 hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario));
1391 return createWifiStatusFromLegacyError(legacy_status);
1392}
1393
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001394std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() {
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001395 // Deprecated support for this callback.
1396 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
1397}
1398
1399std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_5() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001400 legacy_hal::wifi_error legacy_status;
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001401 uint64_t legacy_feature_set;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001402 uint32_t legacy_logger_feature_set;
1403 const auto ifname = getFirstActiveWlanIfaceName();
1404 std::tie(legacy_status, legacy_feature_set) =
1405 legacy_hal_.lock()->getSupportedFeatureSet(ifname);
1406 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1407 return {createWifiStatusFromLegacyError(legacy_status), 0};
1408 }
1409 std::tie(legacy_status, legacy_logger_feature_set) =
1410 legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname);
1411 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1412 // some devices don't support querying logger feature set
1413 legacy_logger_feature_set = 0;
1414 }
1415 uint32_t hidl_caps;
1416 if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities(
1417 legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) {
1418 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0};
1419 }
1420 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps};
1421}
1422
Jimmy Chend460df32019-11-29 17:31:22 +02001423std::pair<WifiStatus, sp<V1_4::IWifiRttController>>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001424WifiChip::createRttControllerInternal_1_4(const sp<IWifiIface>& bound_iface) {
1425 if (sta_ifaces_.size() == 0 &&
1426 !canCurrentModeSupportIfaceOfType(IfaceType::STA)) {
1427 LOG(ERROR)
1428 << "createRttControllerInternal_1_4: Chip cannot support STAs "
1429 "(and RTT by extension)";
1430 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
1431 }
1432 sp<WifiRttController> rtt = new WifiRttController(
1433 getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_);
1434 rtt_controllers_.emplace_back(rtt);
1435 return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
1436}
1437
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001438WifiStatus WifiChip::registerEventCallbackInternal_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +02001439 const sp<V1_4::IWifiChipEventCallback>& event_callback) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001440 if (!event_cb_handler_.addCallback(event_callback)) {
1441 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1442 }
1443 return createWifiStatus(WifiStatusCode::SUCCESS);
1444}
1445
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001446WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(
1447 const std::string& ifname) {
1448 auto legacy_status =
1449 legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname);
1450 return createWifiStatusFromLegacyError(legacy_status);
1451}
1452
1453WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) {
1454 auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase(
1455 hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case));
1456 return createWifiStatusFromLegacyError(legacy_status);
1457}
1458
Quang Luong94bcce52020-11-25 17:52:19 -08001459WifiStatus WifiChip::setCoexUnsafeChannelsInternal(
1460 std::vector<CoexUnsafeChannel> unsafe_channels, uint32_t restrictions) {
1461 std::vector<legacy_hal::wifi_coex_unsafe_channel> legacy_unsafe_channels;
1462 if (!hidl_struct_util::convertHidlVectorOfCoexUnsafeChannelToLegacy(
1463 unsafe_channels, &legacy_unsafe_channels)) {
1464 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1465 }
1466 auto legacy_status = legacy_hal_.lock()->setCoexUnsafeChannels(
1467 legacy_unsafe_channels, restrictions);
1468 return createWifiStatusFromLegacyError(legacy_status);
1469}
1470
Roshan Piusba38d9c2017-12-08 07:32:08 -08001471WifiStatus WifiChip::handleChipConfiguration(
1472 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
1473 ChipModeId mode_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001474 // If the chip is already configured in a different mode, stop
1475 // the legacy HAL and then start it after firmware mode change.
Roshan Piuscc338202017-11-02 13:54:09 -07001476 if (isValidModeId(current_mode_id_)) {
Roshan Piusba38d9c2017-12-08 07:32:08 -08001477 LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_
1478 << " to mode " << mode_id;
1479 invalidateAndRemoveAllIfaces();
1480 legacy_hal::wifi_error legacy_status =
1481 legacy_hal_.lock()->stop(lock, []() {});
1482 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1483 LOG(ERROR) << "Failed to stop legacy HAL: "
1484 << legacyErrorToString(legacy_status);
1485 return createWifiStatusFromLegacyError(legacy_status);
1486 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001487 }
Roshan Piuscc338202017-11-02 13:54:09 -07001488 // Firmware mode change not needed for V2 devices.
1489 bool success = true;
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001490 if (mode_id == feature_flags::chip_mode_ids::kV1Sta) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001491 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001492 } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001493 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
1494 }
1495 if (!success) {
1496 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1497 }
1498 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
1499 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1500 LOG(ERROR) << "Failed to start legacy HAL: "
1501 << legacyErrorToString(legacy_status);
1502 return createWifiStatusFromLegacyError(legacy_status);
1503 }
Roshan Pius85c64412018-01-22 17:58:40 -08001504 // Every time the HAL is restarted, we need to register the
1505 // radio mode change callback.
1506 WifiStatus status = registerRadioModeChangeCallback();
1507 if (status.code != WifiStatusCode::SUCCESS) {
1508 // This probably is not a critical failure?
1509 LOG(ERROR) << "Failed to register radio mode change callback";
1510 }
chenpaulf5eca292019-03-14 11:08:03 +08001511 // Extract and save the version information into property.
Jimmy Chend460df32019-11-29 17:31:22 +02001512 std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> version_info;
chenpaulf5eca292019-03-14 11:08:03 +08001513 version_info = WifiChip::requestChipDebugInfoInternal();
1514 if (WifiStatusCode::SUCCESS == version_info.first.code) {
1515 property_set("vendor.wlan.firmware.version",
1516 version_info.second.firmwareDescription.c_str());
1517 property_set("vendor.wlan.driver.version",
1518 version_info.second.driverDescription.c_str());
1519 }
1520
Roshan Piusabcf78f2017-10-06 16:30:38 -07001521 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001522}
Roshan Pius48185b22016-12-15 19:10:30 -08001523
1524WifiStatus WifiChip::registerDebugRingBufferCallback() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001525 if (debug_ring_buffer_cb_registered_) {
1526 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius48185b22016-12-15 19:10:30 -08001527 }
Roshan Pius3797e182017-03-30 18:01:54 -07001528
Roshan Piusabcf78f2017-10-06 16:30:38 -07001529 android::wp<WifiChip> weak_ptr_this(this);
1530 const auto& on_ring_buffer_data_callback =
xshu5899e8e2018-01-09 15:36:03 -08001531 [weak_ptr_this](const std::string& name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001532 const std::vector<uint8_t>& data,
1533 const legacy_hal::wifi_ring_buffer_status& status) {
1534 const auto shared_ptr_this = weak_ptr_this.promote();
1535 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1536 LOG(ERROR) << "Callback invoked on an invalid object";
1537 return;
1538 }
1539 WifiDebugRingBufferStatus hidl_status;
1540 if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(
1541 status, &hidl_status)) {
1542 LOG(ERROR) << "Error converting ring buffer status";
1543 return;
1544 }
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301545 {
1546 std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t);
1547 const auto& target =
1548 shared_ptr_this->ringbuffer_map_.find(name);
1549 if (target != shared_ptr_this->ringbuffer_map_.end()) {
1550 Ringbuffer& cur_buffer = target->second;
1551 cur_buffer.append(data);
1552 } else {
1553 LOG(ERROR) << "Ringname " << name << " not found";
1554 return;
1555 }
xshu0a0fe512020-07-22 17:53:37 -07001556 // unique_lock unlocked here
Roshan Piusabcf78f2017-10-06 16:30:38 -07001557 }
1558 };
1559 legacy_hal::wifi_error legacy_status =
1560 legacy_hal_.lock()->registerRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001561 getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback);
Roshan Pius48185b22016-12-15 19:10:30 -08001562
Roshan Piusabcf78f2017-10-06 16:30:38 -07001563 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1564 debug_ring_buffer_cb_registered_ = true;
1565 }
1566 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius48185b22016-12-15 19:10:30 -08001567}
1568
Roshan Pius85c64412018-01-22 17:58:40 -08001569WifiStatus WifiChip::registerRadioModeChangeCallback() {
1570 android::wp<WifiChip> weak_ptr_this(this);
1571 const auto& on_radio_mode_change_callback =
1572 [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) {
1573 const auto shared_ptr_this = weak_ptr_this.promote();
1574 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1575 LOG(ERROR) << "Callback invoked on an invalid object";
1576 return;
1577 }
Jimmy Chend460df32019-11-29 17:31:22 +02001578 std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo>
Roshan Pius85c64412018-01-22 17:58:40 -08001579 hidl_radio_mode_infos;
1580 if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(
1581 mac_infos, &hidl_radio_mode_infos)) {
1582 LOG(ERROR) << "Error converting wifi mac info";
1583 return;
1584 }
1585 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001586 if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos)
Roshan Pius85c64412018-01-22 17:58:40 -08001587 .isOk()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001588 LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4"
Roshan Pius85c64412018-01-22 17:58:40 -08001589 << " callback on: " << toString(callback);
1590 }
1591 }
1592 };
1593 legacy_hal::wifi_error legacy_status =
1594 legacy_hal_.lock()->registerRadioModeChangeCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001595 getFirstActiveWlanIfaceName(), on_radio_mode_change_callback);
Roshan Pius85c64412018-01-22 17:58:40 -08001596 return createWifiStatusFromLegacyError(legacy_status);
1597}
1598
Jimmy Chend460df32019-11-29 17:31:22 +02001599std::vector<V1_4::IWifiChip::ChipIfaceCombination>
Roshan Piuscc338202017-11-02 13:54:09 -07001600WifiChip::getCurrentModeIfaceCombinations() {
1601 if (!isValidModeId(current_mode_id_)) {
1602 LOG(ERROR) << "Chip not configured in a mode yet";
1603 return {};
1604 }
1605 for (const auto& mode : modes_) {
1606 if (mode.id == current_mode_id_) {
1607 return mode.availableCombinations;
1608 }
1609 }
1610 CHECK(0) << "Expected to find iface combinations for current mode!";
1611 return {};
1612}
1613
1614// Returns a map indexed by IfaceType with the number of ifaces currently
1615// created of the corresponding type.
1616std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() {
1617 std::map<IfaceType, size_t> iface_counts;
1618 iface_counts[IfaceType::AP] = ap_ifaces_.size();
1619 iface_counts[IfaceType::NAN] = nan_ifaces_.size();
1620 iface_counts[IfaceType::P2P] = p2p_ifaces_.size();
1621 iface_counts[IfaceType::STA] = sta_ifaces_.size();
1622 return iface_counts;
1623}
1624
1625// This expands the provided iface combinations to a more parseable
1626// form. Returns a vector of available combinations possible with the number
1627// of ifaces of each type in the combination.
1628// This method is a port of HalDeviceManager.expandIfaceCombos() from framework.
1629std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations(
Jimmy Chend460df32019-11-29 17:31:22 +02001630 const V1_4::IWifiChip::ChipIfaceCombination& combination) {
Roshan Piuscc338202017-11-02 13:54:09 -07001631 uint32_t num_expanded_combos = 1;
1632 for (const auto& limit : combination.limits) {
1633 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1634 num_expanded_combos *= limit.types.size();
1635 }
1636 }
1637
1638 // Allocate the vector of expanded combos and reset all iface counts to 0
1639 // in each combo.
1640 std::vector<std::map<IfaceType, size_t>> expanded_combos;
1641 expanded_combos.resize(num_expanded_combos);
1642 for (auto& expanded_combo : expanded_combos) {
1643 for (const auto type :
1644 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1645 expanded_combo[type] = 0;
1646 }
1647 }
1648 uint32_t span = num_expanded_combos;
1649 for (const auto& limit : combination.limits) {
1650 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1651 span /= limit.types.size();
1652 for (uint32_t k = 0; k < num_expanded_combos; ++k) {
1653 const auto iface_type =
1654 limit.types[(k / span) % limit.types.size()];
1655 expanded_combos[k][iface_type]++;
1656 }
1657 }
1658 }
1659 return expanded_combos;
1660}
1661
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001662bool WifiChip::canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1663 const std::map<IfaceType, size_t>& expanded_combo,
1664 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001665 const auto current_combo = getCurrentIfaceCombination();
1666
1667 // Check if we have space for 1 more iface of |type| in this combo
1668 for (const auto type :
1669 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1670 size_t num_ifaces_needed = current_combo.at(type);
1671 if (type == requested_type) {
1672 num_ifaces_needed++;
1673 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001674 size_t num_ifaces_allowed = expanded_combo.at(type);
Roshan Piuscc338202017-11-02 13:54:09 -07001675 if (num_ifaces_needed > num_ifaces_allowed) {
1676 return false;
1677 }
1678 }
1679 return true;
1680}
1681
1682// This method does the following:
1683// a) Enumerate all possible iface combos by expanding the current
1684// ChipIfaceCombination.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001685// b) Check if the requested iface type can be added to the current mode
1686// with the iface combination that is already active.
1687bool WifiChip::canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(
1688 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001689 if (!isValidModeId(current_mode_id_)) {
1690 LOG(ERROR) << "Chip not configured in a mode yet";
1691 return false;
1692 }
1693 const auto combinations = getCurrentModeIfaceCombinations();
1694 for (const auto& combination : combinations) {
1695 const auto expanded_combos = expandIfaceCombinations(combination);
1696 for (const auto& expanded_combo : expanded_combos) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001697 if (canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1698 expanded_combo, requested_type)) {
Roshan Piuscc338202017-11-02 13:54:09 -07001699 return true;
1700 }
1701 }
1702 }
1703 return false;
1704}
1705
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001706// Note: This does not consider ifaces already active. It only checks if the
1707// provided expanded iface combination can support the requested combo.
1708bool WifiChip::canExpandedIfaceComboSupportIfaceCombo(
1709 const std::map<IfaceType, size_t>& expanded_combo,
1710 const std::map<IfaceType, size_t>& req_combo) {
1711 // Check if we have space for 1 more iface of |type| in this combo
1712 for (const auto type :
1713 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1714 if (req_combo.count(type) == 0) {
1715 // Iface of "type" not in the req_combo.
1716 continue;
1717 }
1718 size_t num_ifaces_needed = req_combo.at(type);
1719 size_t num_ifaces_allowed = expanded_combo.at(type);
1720 if (num_ifaces_needed > num_ifaces_allowed) {
1721 return false;
1722 }
1723 }
1724 return true;
1725}
1726// This method does the following:
1727// a) Enumerate all possible iface combos by expanding the current
1728// ChipIfaceCombination.
1729// b) Check if the requested iface combo can be added to the current mode.
1730// Note: This does not consider ifaces already active. It only checks if the
1731// current mode can support the requested combo.
1732bool WifiChip::canCurrentModeSupportIfaceCombo(
1733 const std::map<IfaceType, size_t>& req_combo) {
1734 if (!isValidModeId(current_mode_id_)) {
1735 LOG(ERROR) << "Chip not configured in a mode yet";
1736 return false;
1737 }
1738 const auto combinations = getCurrentModeIfaceCombinations();
1739 for (const auto& combination : combinations) {
1740 const auto expanded_combos = expandIfaceCombinations(combination);
1741 for (const auto& expanded_combo : expanded_combos) {
1742 if (canExpandedIfaceComboSupportIfaceCombo(expanded_combo,
1743 req_combo)) {
1744 return true;
1745 }
1746 }
1747 }
1748 return false;
1749}
1750
1751// This method does the following:
1752// a) Enumerate all possible iface combos by expanding the current
1753// ChipIfaceCombination.
1754// b) Check if the requested iface type can be added to the current mode.
1755bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType requested_type) {
lesl261818b2020-11-27 12:37:35 +08001756 // Check if we can support at least 1 iface of type.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001757 std::map<IfaceType, size_t> req_iface_combo;
1758 req_iface_combo[requested_type] = 1;
1759 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1760}
1761
Roshan Piuscc338202017-11-02 13:54:09 -07001762bool WifiChip::isValidModeId(ChipModeId mode_id) {
1763 for (const auto& mode : modes_) {
1764 if (mode.id == mode_id) {
1765 return true;
1766 }
1767 }
1768 return false;
1769}
1770
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001771bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() {
lesl261818b2020-11-27 12:37:35 +08001772 // Check if we can support at least 1 STA & 1 AP concurrently.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001773 std::map<IfaceType, size_t> req_iface_combo;
1774 req_iface_combo[IfaceType::AP] = 1;
1775 req_iface_combo[IfaceType::STA] = 1;
1776 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1777}
1778
lesl261818b2020-11-27 12:37:35 +08001779bool WifiChip::isDualStaConcurrencyAllowedInCurrentMode() {
1780 // Check if we can support at least 2 STA concurrently.
James Mattisd2e4c072019-05-22 16:14:48 -07001781 std::map<IfaceType, size_t> req_iface_combo;
lesl261818b2020-11-27 12:37:35 +08001782 req_iface_combo[IfaceType::STA] = 2;
James Mattisd2e4c072019-05-22 16:14:48 -07001783 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1784}
1785
Roshan Pius6036c022019-03-27 10:41:58 -07001786std::string WifiChip::getFirstActiveWlanIfaceName() {
Roshan Pius444473f2019-04-19 08:41:20 -07001787 if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName();
1788 if (ap_ifaces_.size() > 0) return ap_ifaces_[0]->getName();
Roshan Pius6036c022019-03-27 10:41:58 -07001789 // This could happen if the chip call is made before any STA/AP
1790 // iface is created. Default to wlan0 for such cases.
Roshan Pius444473f2019-04-19 08:41:20 -07001791 LOG(WARNING) << "No active wlan interfaces in use! Using default";
Jimmy Chen2dddd792019-12-23 17:50:39 +02001792 return getWlanIfaceNameWithType(IfaceType::STA, 0);
Roshan Pius6036c022019-03-27 10:41:58 -07001793}
1794
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001795// Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx|
1796// not already in use.
1797// Note: This doesn't check the actual presence of these interfaces.
Jimmy Chen2dddd792019-12-23 17:50:39 +02001798std::string WifiChip::allocateApOrStaIfaceName(IfaceType type,
1799 uint32_t start_idx) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001800 for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001801 const auto ifname = getWlanIfaceNameWithType(type, idx);
lesl94d28242020-11-18 22:17:37 +08001802 if (findUsingNameFromBridgedApInstances(ifname)) continue;
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001803 if (findUsingName(ap_ifaces_, ifname)) continue;
1804 if (findUsingName(sta_ifaces_, ifname)) continue;
1805 return ifname;
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001806 }
1807 // This should never happen. We screwed up somewhere if it did.
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001808 CHECK(false) << "All wlan interfaces in use already!";
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001809 return {};
1810}
1811
lesl261818b2020-11-27 12:37:35 +08001812uint32_t WifiChip::startIdxOfApIface() {
1813 if (isDualStaConcurrencyAllowedInCurrentMode()) {
1814 // When the HAL support dual STAs, AP should start with idx 2.
1815 return 2;
1816 } else if (isStaApConcurrencyAllowedInCurrentMode()) {
1817 // When the HAL support STA + AP but it doesn't support dual STAs.
1818 // AP should start with idx 1.
1819 return 1;
1820 }
1821 // No concurrency support.
1822 return 0;
1823}
1824
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001825// AP iface names start with idx 1 for modes supporting
James Mattisd2e4c072019-05-22 16:14:48 -07001826// concurrent STA and not dual AP, else start with idx 0.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001827std::string WifiChip::allocateApIfaceName() {
Roshan Pius78cb5992020-04-30 12:39:21 -07001828 // Check if we have a dedicated iface for AP.
lesl261818b2020-11-27 12:37:35 +08001829 std::vector<std::string> ifnames = getPredefinedApIfaceNames(false);
1830 if (!ifnames.empty()) {
1831 return ifnames[0];
Roshan Pius78cb5992020-04-30 12:39:21 -07001832 }
lesl261818b2020-11-27 12:37:35 +08001833 return allocateApOrStaIfaceName(IfaceType::AP, startIdxOfApIface());
1834}
1835
1836std::vector<std::string> WifiChip::allocateBridgedApInstanceNames() {
1837 // Check if we have a dedicated iface for AP.
1838 std::vector<std::string> instances = getPredefinedApIfaceNames(true);
1839 if (instances.size() == 2) {
1840 return instances;
1841 } else {
1842 int num_ifaces_need_to_allocate = 2 - instances.size();
1843 for (int i = 0; i < num_ifaces_need_to_allocate; i++) {
lesl5a46c952020-12-14 17:14:12 +08001844 std::string instance_name = allocateApOrStaIfaceName(
1845 IfaceType::AP, startIdxOfApIface() + i);
lesl261818b2020-11-27 12:37:35 +08001846 if (!instance_name.empty()) {
1847 instances.push_back(instance_name);
1848 }
1849 }
1850 }
1851 return instances;
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001852}
1853
1854// STA iface names start with idx 0.
1855// Primary STA iface will always be 0.
1856std::string WifiChip::allocateStaIfaceName() {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001857 return allocateApOrStaIfaceName(IfaceType::STA, 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001858}
1859
xshu5899e8e2018-01-09 15:36:03 -08001860bool WifiChip::writeRingbufferFilesInternal() {
1861 if (!removeOldFilesInternal()) {
1862 LOG(ERROR) << "Error occurred while deleting old tombstone files";
1863 return false;
1864 }
1865 // write ringbuffers to file
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301866 {
1867 std::unique_lock<std::mutex> lk(lock_t);
1868 for (const auto& item : ringbuffer_map_) {
1869 const Ringbuffer& cur_buffer = item.second;
1870 if (cur_buffer.getData().empty()) {
1871 continue;
1872 }
1873 const std::string file_path_raw =
1874 kTombstoneFolderPath + item.first + "XXXXXXXXXX";
1875 const int dump_fd = mkstemp(makeCharVec(file_path_raw).data());
1876 if (dump_fd == -1) {
1877 PLOG(ERROR) << "create file failed";
1878 return false;
1879 }
1880 unique_fd file_auto_closer(dump_fd);
1881 for (const auto& cur_block : cur_buffer.getData()) {
1882 if (write(dump_fd, cur_block.data(),
1883 sizeof(cur_block[0]) * cur_block.size()) == -1) {
1884 PLOG(ERROR) << "Error writing to file";
1885 }
xshu5899e8e2018-01-09 15:36:03 -08001886 }
1887 }
xshu0a0fe512020-07-22 17:53:37 -07001888 // unique_lock unlocked here
xshu5899e8e2018-01-09 15:36:03 -08001889 }
1890 return true;
1891}
1892
Jimmy Chen2dddd792019-12-23 17:50:39 +02001893std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) {
1894 std::string ifname;
1895
1896 // let the legacy hal override the interface name
1897 legacy_hal::wifi_error err =
1898 legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname);
1899 if (err == legacy_hal::WIFI_SUCCESS) return ifname;
1900
1901 return getWlanIfaceName(idx);
1902}
1903
lesl94d28242020-11-18 22:17:37 +08001904void WifiChip::invalidateAndClearBridgedApAll() {
1905 for (auto const& it : br_ifaces_ap_instances_) {
1906 for (auto const& iface : it.second) {
1907 iface_util_.lock()->removeIfaceFromBridge(it.first, iface);
1908 legacy_hal_.lock()->deleteVirtualInterface(iface);
1909 }
1910 iface_util_.lock()->deleteBridge(it.first);
1911 }
1912 br_ifaces_ap_instances_.clear();
1913}
1914
1915void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) {
1916 if (br_name.empty()) return;
1917 // delete managed interfaces
1918 for (auto const& it : br_ifaces_ap_instances_) {
1919 if (it.first == br_name) {
1920 for (auto const& iface : it.second) {
1921 iface_util_.lock()->removeIfaceFromBridge(br_name, iface);
1922 legacy_hal_.lock()->deleteVirtualInterface(iface);
1923 }
1924 iface_util_.lock()->deleteBridge(br_name);
1925 br_ifaces_ap_instances_.erase(br_name);
1926 break;
1927 }
1928 }
1929 return;
1930}
1931
1932bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) {
1933 for (auto const& it : br_ifaces_ap_instances_) {
1934 if (it.first == name) {
1935 return true;
1936 }
1937 for (auto const& iface : it.second) {
1938 if (iface == name) {
1939 return true;
1940 }
1941 }
1942 }
1943 return false;
1944}
1945
Roshan Pius79a99752016-10-04 13:03:58 -07001946} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +02001947} // namespace V1_5
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001948} // namespace wifi
1949} // namespace hardware
1950} // namespace android