blob: f5842fe93478c009d48fb69ab240ae272f16d9bb [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
Roshan Pius78cb5992020-04-30 12:39:21 -0700106// Returns the dedicated iface name if one is defined.
107std::string getApIfaceName() {
108 std::array<char, PROPERTY_VALUE_MAX> buffer;
109 if (property_get("ro.vendor.wifi.sap.interface", buffer.data(), nullptr) ==
110 0) {
111 return {};
112 }
113 return buffer.data();
114}
115
Roshan Pius9377a0d2017-10-06 13:18:54 -0700116std::string getP2pIfaceName() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700117 std::array<char, PROPERTY_VALUE_MAX> buffer;
118 property_get("wifi.direct.interface", buffer.data(), "p2p0");
119 return buffer.data();
Roshan Pius9377a0d2017-10-06 13:18:54 -0700120}
121
Roshan Pius5ba0a902020-04-14 11:55:42 -0700122// Returns the dedicated iface name if one is defined.
123std::string getNanIfaceName() {
124 std::array<char, PROPERTY_VALUE_MAX> buffer;
125 if (property_get("wifi.aware.interface", buffer.data(), nullptr) == 0) {
126 return {};
127 }
128 return buffer.data();
129}
130
Roshan Pius8574e7f2019-04-01 13:30:40 -0700131void setActiveWlanIfaceNameProperty(const std::string& ifname) {
132 auto res = property_set(kActiveWlanIfaceNameProperty, ifname.data());
133 if (res != 0) {
134 PLOG(ERROR) << "Failed to set active wlan iface name property";
135 }
136}
137
xshu37126c92018-04-13 16:24:45 -0700138// delete files that meet either conditions:
139// 1. older than a predefined time in the wifi tombstone dir.
140// 2. Files in excess to a predefined amount, starting from the oldest ones
xshu5899e8e2018-01-09 15:36:03 -0800141bool removeOldFilesInternal() {
142 time_t now = time(0);
143 const time_t delete_files_before = now - kMaxRingBufferFileAgeSeconds;
Josh Gaoa568e532018-06-04 18:16:00 -0700144 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(
145 opendir(kTombstoneFolderPath), closedir);
xshu5899e8e2018-01-09 15:36:03 -0800146 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800147 PLOG(ERROR) << "Failed to open directory";
xshu5899e8e2018-01-09 15:36:03 -0800148 return false;
149 }
xshu5899e8e2018-01-09 15:36:03 -0800150 struct dirent* dp;
151 bool success = true;
xshu37126c92018-04-13 16:24:45 -0700152 std::list<std::pair<const time_t, std::string>> valid_files;
Josh Gaoa568e532018-06-04 18:16:00 -0700153 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800154 if (dp->d_type != DT_REG) {
155 continue;
156 }
157 std::string cur_file_name(dp->d_name);
158 struct stat cur_file_stat;
159 std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
xshu4cb33162018-01-24 15:40:06 -0800160 if (stat(cur_file_path.c_str(), &cur_file_stat) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800161 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800162 success = false;
xshu4cb33162018-01-24 15:40:06 -0800163 continue;
164 }
xshu37126c92018-04-13 16:24:45 -0700165 const time_t cur_file_time = cur_file_stat.st_mtime;
166 valid_files.push_back(
167 std::pair<const time_t, std::string>(cur_file_time, cur_file_path));
168 }
169 valid_files.sort(); // sort the list of files by last modified time from
170 // small to big.
171 uint32_t cur_file_count = valid_files.size();
172 for (auto cur_file : valid_files) {
173 if (cur_file_count > kMaxRingBufferFileNum ||
174 cur_file.first < delete_files_before) {
175 if (unlink(cur_file.second.c_str()) != 0) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800176 PLOG(ERROR) << "Error deleting file";
xshu37126c92018-04-13 16:24:45 -0700177 success = false;
178 }
179 cur_file_count--;
180 } else {
181 break;
xshu5899e8e2018-01-09 15:36:03 -0800182 }
183 }
184 return success;
185}
186
xshu4cb33162018-01-24 15:40:06 -0800187// Helper function for |cpioArchiveFilesInDir|
188bool cpioWriteHeader(int out_fd, struct stat& st, const char* file_name,
189 size_t file_name_len) {
190 std::array<char, 32 * 1024> read_buf;
191 ssize_t llen =
192 sprintf(read_buf.data(),
193 "%s%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X%08X",
194 kCpioMagic, static_cast<int>(st.st_ino), st.st_mode, st.st_uid,
195 st.st_gid, static_cast<int>(st.st_nlink),
196 static_cast<int>(st.st_mtime), static_cast<int>(st.st_size),
197 major(st.st_dev), minor(st.st_dev), major(st.st_rdev),
198 minor(st.st_rdev), static_cast<uint32_t>(file_name_len), 0);
199 if (write(out_fd, read_buf.data(), llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800200 PLOG(ERROR) << "Error writing cpio header to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800201 return false;
202 }
203 if (write(out_fd, file_name, file_name_len) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800204 PLOG(ERROR) << "Error writing filename to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800205 return false;
206 }
207
208 // NUL Pad header up to 4 multiple bytes.
209 llen = (llen + file_name_len) % 4;
210 if (llen != 0) {
211 const uint32_t zero = 0;
212 if (write(out_fd, &zero, 4 - llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800213 PLOG(ERROR) << "Error padding 0s to file " << file_name;
xshu4cb33162018-01-24 15:40:06 -0800214 return false;
215 }
216 }
217 return true;
218}
219
220// Helper function for |cpioArchiveFilesInDir|
221size_t cpioWriteFileContent(int fd_read, int out_fd, struct stat& st) {
222 // writing content of file
223 std::array<char, 32 * 1024> read_buf;
224 ssize_t llen = st.st_size;
225 size_t n_error = 0;
226 while (llen > 0) {
227 ssize_t bytes_read = read(fd_read, read_buf.data(), read_buf.size());
228 if (bytes_read == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800229 PLOG(ERROR) << "Error reading file";
xshu4cb33162018-01-24 15:40:06 -0800230 return ++n_error;
231 }
232 llen -= bytes_read;
233 if (write(out_fd, read_buf.data(), bytes_read) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800234 PLOG(ERROR) << "Error writing data to file";
xshu4cb33162018-01-24 15:40:06 -0800235 return ++n_error;
236 }
237 if (bytes_read == 0) { // this should never happen, but just in case
238 // to unstuck from while loop
Elliott Hughes4db4add2019-03-08 12:42:57 -0800239 PLOG(ERROR) << "Unexpected read result";
xshu4cb33162018-01-24 15:40:06 -0800240 n_error++;
241 break;
242 }
243 }
244 llen = st.st_size % 4;
245 if (llen != 0) {
246 const uint32_t zero = 0;
247 if (write(out_fd, &zero, 4 - llen) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800248 PLOG(ERROR) << "Error padding 0s to file";
xshu4cb33162018-01-24 15:40:06 -0800249 return ++n_error;
250 }
251 }
252 return n_error;
253}
254
255// Helper function for |cpioArchiveFilesInDir|
256bool cpioWriteFileTrailer(int out_fd) {
257 std::array<char, 4096> read_buf;
258 read_buf.fill(0);
259 if (write(out_fd, read_buf.data(),
260 sprintf(read_buf.data(), "070701%040X%056X%08XTRAILER!!!", 1,
261 0x0b, 0) +
262 4) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800263 PLOG(ERROR) << "Error writing trailing bytes";
xshu4cb33162018-01-24 15:40:06 -0800264 return false;
265 }
266 return true;
267}
268
xshu5899e8e2018-01-09 15:36:03 -0800269// Archives all files in |input_dir| and writes result into |out_fd|
270// Logic obtained from //external/toybox/toys/posix/cpio.c "Output cpio archive"
271// portion
xshu4cb33162018-01-24 15:40:06 -0800272size_t cpioArchiveFilesInDir(int out_fd, const char* input_dir) {
xshu5899e8e2018-01-09 15:36:03 -0800273 struct dirent* dp;
274 size_t n_error = 0;
Josh Gaoa568e532018-06-04 18:16:00 -0700275 std::unique_ptr<DIR, decltype(&closedir)> dir_dump(opendir(input_dir),
276 closedir);
xshu5899e8e2018-01-09 15:36:03 -0800277 if (!dir_dump) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800278 PLOG(ERROR) << "Failed to open directory";
xshu4cb33162018-01-24 15:40:06 -0800279 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800280 }
Josh Gaoa568e532018-06-04 18:16:00 -0700281 while ((dp = readdir(dir_dump.get()))) {
xshu5899e8e2018-01-09 15:36:03 -0800282 if (dp->d_type != DT_REG) {
283 continue;
284 }
285 std::string cur_file_name(dp->d_name);
xshu5899e8e2018-01-09 15:36:03 -0800286 struct stat st;
xshu5899e8e2018-01-09 15:36:03 -0800287 const std::string cur_file_path = kTombstoneFolderPath + cur_file_name;
xshu4cb33162018-01-24 15:40:06 -0800288 if (stat(cur_file_path.c_str(), &st) == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800289 PLOG(ERROR) << "Failed to get file stat for " << cur_file_path;
xshu5899e8e2018-01-09 15:36:03 -0800290 n_error++;
xshu4cb33162018-01-24 15:40:06 -0800291 continue;
292 }
293 const int fd_read = open(cur_file_path.c_str(), O_RDONLY);
294 if (fd_read == -1) {
Elliott Hughes4db4add2019-03-08 12:42:57 -0800295 PLOG(ERROR) << "Failed to open file " << cur_file_path;
xshu4cb33162018-01-24 15:40:06 -0800296 n_error++;
297 continue;
298 }
xshuf392fb42020-08-13 16:57:00 -0700299 std::string file_name_with_last_modified_time =
300 cur_file_name + "-" + std::to_string(st.st_mtime);
301 // string.size() does not include the null terminator. The cpio FreeBSD
302 // file header expects the null character to be included in the length.
303 const size_t file_name_len =
304 file_name_with_last_modified_time.size() + 1;
xshu4cb33162018-01-24 15:40:06 -0800305 unique_fd file_auto_closer(fd_read);
xshuf392fb42020-08-13 16:57:00 -0700306 if (!cpioWriteHeader(out_fd, st,
307 file_name_with_last_modified_time.c_str(),
xshu4cb33162018-01-24 15:40:06 -0800308 file_name_len)) {
309 return ++n_error;
310 }
311 size_t write_error = cpioWriteFileContent(fd_read, out_fd, st);
312 if (write_error) {
313 return n_error + write_error;
xshu5899e8e2018-01-09 15:36:03 -0800314 }
315 }
xshu4cb33162018-01-24 15:40:06 -0800316 if (!cpioWriteFileTrailer(out_fd)) {
317 return ++n_error;
xshu5899e8e2018-01-09 15:36:03 -0800318 }
319 return n_error;
320}
321
322// Helper function to create a non-const char*.
323std::vector<char> makeCharVec(const std::string& str) {
324 std::vector<char> vec(str.size() + 1);
325 vec.assign(str.begin(), str.end());
326 vec.push_back('\0');
327 return vec;
328}
329
Roshan Piusabcf78f2017-10-06 16:30:38 -0700330} // namespace
Roshan Pius35d958c2016-10-06 16:47:38 -0700331
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700332namespace android {
333namespace hardware {
334namespace wifi {
Jimmy Chend460df32019-11-29 17:31:22 +0200335namespace V1_5 {
Roshan Pius79a99752016-10-04 13:03:58 -0700336namespace implementation {
Roshan Pius3c868522016-10-27 12:43:49 -0700337using hidl_return_util::validateAndCall;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800338using hidl_return_util::validateAndCallWithLock;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700339
Roshan Pius52947fb2016-11-18 11:38:07 -0800340WifiChip::WifiChip(
Jimmy Chen2dddd792019-12-23 17:50:39 +0200341 ChipId chip_id, bool is_primary,
342 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
Roshan Pius200a17d2017-11-01 13:03:35 -0700343 const std::weak_ptr<mode_controller::WifiModeController> mode_controller,
Roshan Pius99dab382019-02-14 07:57:10 -0800344 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700345 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags,
346 const std::function<void(const std::string&)>& handler)
Roshan Pius52947fb2016-11-18 11:38:07 -0800347 : chip_id_(chip_id),
348 legacy_hal_(legacy_hal),
349 mode_controller_(mode_controller),
Roshan Pius99dab382019-02-14 07:57:10 -0800350 iface_util_(iface_util),
Roshan Pius52947fb2016-11-18 11:38:07 -0800351 is_valid_(true),
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800352 current_mode_id_(feature_flags::chip_mode_ids::kInvalid),
Jimmy Chen2dddd792019-12-23 17:50:39 +0200353 modes_(feature_flags.lock()->getChipModes(is_primary)),
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700354 debug_ring_buffer_cb_registered_(false),
355 subsystemCallbackHandler_(handler) {
Roshan Pius8574e7f2019-04-01 13:30:40 -0700356 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
357}
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700358
Roshan Piusaabe5752016-09-29 09:03:59 -0700359void WifiChip::invalidate() {
xshu37126c92018-04-13 16:24:45 -0700360 if (!writeRingbufferFilesInternal()) {
361 LOG(ERROR) << "Error writing files to flash";
362 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700363 invalidateAndRemoveAllIfaces();
Roshan Pius8574e7f2019-04-01 13:30:40 -0700364 setActiveWlanIfaceNameProperty(kNoActiveWlanIfaceNamePropertyValue);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700365 legacy_hal_.reset();
366 event_cb_handler_.invalidate();
367 is_valid_ = false;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700368}
369
Roshan Piusabcf78f2017-10-06 16:30:38 -0700370bool WifiChip::isValid() { return is_valid_; }
Roshan Pius3c868522016-10-27 12:43:49 -0700371
Jimmy Chend460df32019-11-29 17:31:22 +0200372std::set<sp<V1_4::IWifiChipEventCallback>> WifiChip::getEventCallbacks() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700373 return event_cb_handler_.getCallbacks();
Roshan Pius203cb032016-12-14 17:41:20 -0800374}
375
Roshan Pius5c055462016-10-11 08:27:27 -0700376Return<void> WifiChip::getId(getId_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700377 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
378 &WifiChip::getIdInternal, hidl_status_cb);
Roshan Piuscd566bd2016-10-10 08:03:42 -0700379}
380
Jong Wook Kimda830c92018-07-23 15:29:38 -0700381// Deprecated support for this callback
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700382Return<void> WifiChip::registerEventCallback(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800383 const sp<V1_0::IWifiChipEventCallback>& event_callback,
Roshan Pius5c055462016-10-11 08:27:27 -0700384 registerEventCallback_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700385 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
386 &WifiChip::registerEventCallbackInternal,
387 hidl_status_cb, event_callback);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700388}
389
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700390Return<void> WifiChip::getCapabilities(getCapabilities_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700391 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
392 &WifiChip::getCapabilitiesInternal, hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700393}
394
Roshan Pius5c055462016-10-11 08:27:27 -0700395Return<void> WifiChip::getAvailableModes(getAvailableModes_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700396 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
397 &WifiChip::getAvailableModesInternal,
398 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700399}
400
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800401Return<void> WifiChip::configureChip(ChipModeId mode_id,
Roshan Pius5c055462016-10-11 08:27:27 -0700402 configureChip_cb hidl_status_cb) {
Roshan Piusba38d9c2017-12-08 07:32:08 -0800403 return validateAndCallWithLock(
404 this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
405 &WifiChip::configureChipInternal, hidl_status_cb, mode_id);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700406}
407
Roshan Pius5c055462016-10-11 08:27:27 -0700408Return<void> WifiChip::getMode(getMode_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700409 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
410 &WifiChip::getModeInternal, hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700411}
412
Roshan Pius5c055462016-10-11 08:27:27 -0700413Return<void> WifiChip::requestChipDebugInfo(
414 requestChipDebugInfo_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700415 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
416 &WifiChip::requestChipDebugInfoInternal,
417 hidl_status_cb);
Roshan Pius5c055462016-10-11 08:27:27 -0700418}
419
420Return<void> WifiChip::requestDriverDebugDump(
421 requestDriverDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700422 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
423 &WifiChip::requestDriverDebugDumpInternal,
424 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700425}
426
Roshan Pius5c055462016-10-11 08:27:27 -0700427Return<void> WifiChip::requestFirmwareDebugDump(
428 requestFirmwareDebugDump_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700429 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
430 &WifiChip::requestFirmwareDebugDumpInternal,
431 hidl_status_cb);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700432}
433
Roshan Pius5c055462016-10-11 08:27:27 -0700434Return<void> WifiChip::createApIface(createApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700435 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
436 &WifiChip::createApIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700437}
438
lesl94d28242020-11-18 22:17:37 +0800439Return<void> WifiChip::createBridgedApIface(
440 createBridgedApIface_cb hidl_status_cb) {
441 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
442 &WifiChip::createBridgedApIfaceInternal,
443 hidl_status_cb);
444}
445
Roshan Pius5c055462016-10-11 08:27:27 -0700446Return<void> WifiChip::getApIfaceNames(getApIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700447 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
448 &WifiChip::getApIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700449}
450
Roshan Pius5c055462016-10-11 08:27:27 -0700451Return<void> WifiChip::getApIface(const hidl_string& ifname,
452 getApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700453 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
454 &WifiChip::getApIfaceInternal, hidl_status_cb,
455 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700456}
457
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800458Return<void> WifiChip::removeApIface(const hidl_string& ifname,
459 removeApIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700460 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
461 &WifiChip::removeApIfaceInternal, hidl_status_cb,
462 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800463}
464
lesl94d28242020-11-18 22:17:37 +0800465Return<void> WifiChip::removeIfaceInstanceFromBridgedApIface(
466 const hidl_string& ifname, const hidl_string& ifInstanceName,
467 removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) {
468 return validateAndCall(
469 this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
470 &WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal,
471 hidl_status_cb, ifname, ifInstanceName);
472}
473
Roshan Pius5c055462016-10-11 08:27:27 -0700474Return<void> WifiChip::createNanIface(createNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700475 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
476 &WifiChip::createNanIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700477}
478
Roshan Pius5c055462016-10-11 08:27:27 -0700479Return<void> WifiChip::getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700480 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
481 &WifiChip::getNanIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700482}
483
484Return<void> WifiChip::getNanIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700485 getNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700486 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
487 &WifiChip::getNanIfaceInternal, hidl_status_cb,
488 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700489}
490
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800491Return<void> WifiChip::removeNanIface(const hidl_string& ifname,
492 removeNanIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700493 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
494 &WifiChip::removeNanIfaceInternal, hidl_status_cb,
495 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800496}
497
Roshan Pius5c055462016-10-11 08:27:27 -0700498Return<void> WifiChip::createP2pIface(createP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700499 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
500 &WifiChip::createP2pIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700501}
502
Roshan Pius5c055462016-10-11 08:27:27 -0700503Return<void> WifiChip::getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700504 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
505 &WifiChip::getP2pIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700506}
507
508Return<void> WifiChip::getP2pIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700509 getP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700510 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
511 &WifiChip::getP2pIfaceInternal, hidl_status_cb,
512 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700513}
514
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800515Return<void> WifiChip::removeP2pIface(const hidl_string& ifname,
516 removeP2pIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700517 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
518 &WifiChip::removeP2pIfaceInternal, hidl_status_cb,
519 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800520}
521
Roshan Pius5c055462016-10-11 08:27:27 -0700522Return<void> WifiChip::createStaIface(createStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700523 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
524 &WifiChip::createStaIfaceInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700525}
526
Roshan Pius5c055462016-10-11 08:27:27 -0700527Return<void> WifiChip::getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700528 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
529 &WifiChip::getStaIfaceNamesInternal, hidl_status_cb);
Roshan Pius35d958c2016-10-06 16:47:38 -0700530}
531
532Return<void> WifiChip::getStaIface(const hidl_string& ifname,
Roshan Pius5c055462016-10-11 08:27:27 -0700533 getStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700534 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
535 &WifiChip::getStaIfaceInternal, hidl_status_cb,
536 ifname);
Roshan Pius35d958c2016-10-06 16:47:38 -0700537}
538
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800539Return<void> WifiChip::removeStaIface(const hidl_string& ifname,
540 removeStaIface_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700541 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
542 &WifiChip::removeStaIfaceInternal, hidl_status_cb,
543 ifname);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800544}
545
Roshan Pius5c055462016-10-11 08:27:27 -0700546Return<void> WifiChip::createRttController(
547 const sp<IWifiIface>& bound_iface, createRttController_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700548 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
549 &WifiChip::createRttControllerInternal,
550 hidl_status_cb, bound_iface);
Roshan Pius59268282016-10-06 20:23:47 -0700551}
552
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700553Return<void> WifiChip::getDebugRingBuffersStatus(
554 getDebugRingBuffersStatus_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700555 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
556 &WifiChip::getDebugRingBuffersStatusInternal,
557 hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700558}
559
560Return<void> WifiChip::startLoggingToDebugRingBuffer(
Roshan Piusabcf78f2017-10-06 16:30:38 -0700561 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
562 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes,
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700563 startLoggingToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700564 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
565 &WifiChip::startLoggingToDebugRingBufferInternal,
566 hidl_status_cb, ring_name, verbose_level,
567 max_interval_in_sec, min_data_size_in_bytes);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700568}
569
570Return<void> WifiChip::forceDumpToDebugRingBuffer(
571 const hidl_string& ring_name,
572 forceDumpToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700573 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
574 &WifiChip::forceDumpToDebugRingBufferInternal,
575 hidl_status_cb, ring_name);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700576}
577
Roger Wangb294c762018-11-02 15:34:39 +0800578Return<void> WifiChip::flushRingBufferToFile(
579 flushRingBufferToFile_cb hidl_status_cb) {
580 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
581 &WifiChip::flushRingBufferToFileInternal,
582 hidl_status_cb);
583}
584
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800585Return<void> WifiChip::stopLoggingToDebugRingBuffer(
586 stopLoggingToDebugRingBuffer_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700587 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
588 &WifiChip::stopLoggingToDebugRingBufferInternal,
589 hidl_status_cb);
Roshan Pius8c0c8e92017-02-24 08:07:42 -0800590}
591
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700592Return<void> WifiChip::getDebugHostWakeReasonStats(
593 getDebugHostWakeReasonStats_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700594 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
595 &WifiChip::getDebugHostWakeReasonStatsInternal,
596 hidl_status_cb);
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700597}
598
Roshan Pius203cb032016-12-14 17:41:20 -0800599Return<void> WifiChip::enableDebugErrorAlerts(
600 bool enable, enableDebugErrorAlerts_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700601 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
602 &WifiChip::enableDebugErrorAlertsInternal,
603 hidl_status_cb, enable);
Roshan Pius203cb032016-12-14 17:41:20 -0800604}
605
Roshan Pius735ff432017-07-25 08:48:08 -0700606Return<void> WifiChip::selectTxPowerScenario(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700607 V1_1::IWifiChip::TxPowerScenario scenario,
608 selectTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700609 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
610 &WifiChip::selectTxPowerScenarioInternal,
611 hidl_status_cb, scenario);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700612}
613
Roshan Pius735ff432017-07-25 08:48:08 -0700614Return<void> WifiChip::resetTxPowerScenario(
615 resetTxPowerScenario_cb hidl_status_cb) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700616 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
617 &WifiChip::resetTxPowerScenarioInternal,
618 hidl_status_cb);
Roshan Piusdbd83ef2017-06-20 12:05:40 -0700619}
620
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700621Return<void> WifiChip::setLatencyMode(LatencyMode mode,
622 setLatencyMode_cb hidl_status_cb) {
623 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
624 &WifiChip::setLatencyModeInternal, hidl_status_cb,
625 mode);
626}
627
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800628Return<void> WifiChip::registerEventCallback_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700629 const sp<V1_2::IWifiChipEventCallback>& event_callback,
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800630 registerEventCallback_cb hidl_status_cb) {
631 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
632 &WifiChip::registerEventCallbackInternal_1_2,
633 hidl_status_cb, event_callback);
634}
635
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800636Return<void> WifiChip::selectTxPowerScenario_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700637 TxPowerScenario scenario, selectTxPowerScenario_cb hidl_status_cb) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800638 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
Jong Wook Kimda830c92018-07-23 15:29:38 -0700639 &WifiChip::selectTxPowerScenarioInternal_1_2,
640 hidl_status_cb, scenario);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800641}
642
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700643Return<void> WifiChip::getCapabilities_1_3(getCapabilities_cb hidl_status_cb) {
644 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
645 &WifiChip::getCapabilitiesInternal_1_3,
646 hidl_status_cb);
647}
648
Jimmy Chen1bdf1a72019-12-23 17:53:40 +0200649Return<void> WifiChip::getCapabilities_1_5(
650 getCapabilities_1_5_cb hidl_status_cb) {
651 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
652 &WifiChip::getCapabilitiesInternal_1_5,
653 hidl_status_cb);
654}
655
xshu5899e8e2018-01-09 15:36:03 -0800656Return<void> WifiChip::debug(const hidl_handle& handle,
657 const hidl_vec<hidl_string>&) {
658 if (handle != nullptr && handle->numFds >= 1) {
xshu0a0fe512020-07-22 17:53:37 -0700659 {
660 std::unique_lock<std::mutex> lk(lock_t);
661 for (const auto& item : ringbuffer_map_) {
662 forceDumpToDebugRingBufferInternal(item.first);
663 }
664 // unique_lock unlocked here
665 }
666 usleep(100 * 1000); // sleep for 100 milliseconds to wait for
667 // ringbuffer updates.
xshu5899e8e2018-01-09 15:36:03 -0800668 int fd = handle->data[0];
669 if (!writeRingbufferFilesInternal()) {
670 LOG(ERROR) << "Error writing files to flash";
671 }
xshu4cb33162018-01-24 15:40:06 -0800672 uint32_t n_error = cpioArchiveFilesInDir(fd, kTombstoneFolderPath);
xshu5899e8e2018-01-09 15:36:03 -0800673 if (n_error != 0) {
674 LOG(ERROR) << n_error << " errors occured in cpio function";
675 }
676 fsync(fd);
677 } else {
678 LOG(ERROR) << "File handle error";
679 }
680 return Void();
681}
682
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700683Return<void> WifiChip::createRttController_1_4(
684 const sp<IWifiIface>& bound_iface,
685 createRttController_1_4_cb hidl_status_cb) {
686 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
687 &WifiChip::createRttControllerInternal_1_4,
688 hidl_status_cb, bound_iface);
689}
690
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800691Return<void> WifiChip::registerEventCallback_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +0200692 const sp<V1_4::IWifiChipEventCallback>& event_callback,
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800693 registerEventCallback_cb hidl_status_cb) {
694 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
695 &WifiChip::registerEventCallbackInternal_1_4,
696 hidl_status_cb, event_callback);
697}
698
Roshan Piuse9d1e7d2020-11-04 11:44:16 -0800699Return<void> WifiChip::setMultiStaPrimaryConnection(
700 const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) {
701 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
702 &WifiChip::setMultiStaPrimaryConnectionInternal,
703 hidl_status_cb, ifname);
704}
705
706Return<void> WifiChip::setMultiStaUseCase(
707 MultiStaUseCase use_case, setMultiStaUseCase_cb hidl_status_cb) {
708 return validateAndCall(this, WifiStatusCode::ERROR_WIFI_CHIP_INVALID,
709 &WifiChip::setMultiStaUseCaseInternal,
710 hidl_status_cb, use_case);
711}
712
Roshan Pius35d958c2016-10-06 16:47:38 -0700713void WifiChip::invalidateAndRemoveAllIfaces() {
lesl94d28242020-11-18 22:17:37 +0800714 invalidateAndClearBridgedApAll();
Roshan Pius675609b2017-10-31 14:24:58 -0700715 invalidateAndClearAll(ap_ifaces_);
716 invalidateAndClearAll(nan_ifaces_);
717 invalidateAndClearAll(p2p_ifaces_);
718 invalidateAndClearAll(sta_ifaces_);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700719 // Since all the ifaces are invalid now, all RTT controller objects
720 // using those ifaces also need to be invalidated.
721 for (const auto& rtt : rtt_controllers_) {
722 rtt->invalidate();
723 }
724 rtt_controllers_.clear();
Roshan Pius35d958c2016-10-06 16:47:38 -0700725}
726
Roshan Pius82368502019-05-16 12:53:02 -0700727void WifiChip::invalidateAndRemoveDependencies(
728 const std::string& removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200729 for (auto it = nan_ifaces_.begin(); it != nan_ifaces_.end();) {
730 auto nan_iface = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700731 if (nan_iface->getName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200732 nan_iface->invalidate();
Roshan Pius82368502019-05-16 12:53:02 -0700733 for (const auto& callback : event_cb_handler_.getCallbacks()) {
734 if (!callback
735 ->onIfaceRemoved(IfaceType::NAN, removed_iface_name)
736 .isOk()) {
737 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
738 }
739 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200740 it = nan_ifaces_.erase(it);
741 } else {
742 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700743 }
744 }
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200745
746 for (auto it = rtt_controllers_.begin(); it != rtt_controllers_.end();) {
747 auto rtt = *it;
Roshan Pius82368502019-05-16 12:53:02 -0700748 if (rtt->getIfaceName() == removed_iface_name) {
Jimmy Chen7a82ad82019-11-29 17:31:22 +0200749 rtt->invalidate();
750 it = rtt_controllers_.erase(it);
751 } else {
752 ++it;
Roshan Pius82368502019-05-16 12:53:02 -0700753 }
754 }
755}
756
Roshan Pius3c868522016-10-27 12:43:49 -0700757std::pair<WifiStatus, ChipId> WifiChip::getIdInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700758 return {createWifiStatus(WifiStatusCode::SUCCESS), chip_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700759}
760
761WifiStatus WifiChip::registerEventCallbackInternal(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800762 const sp<V1_0::IWifiChipEventCallback>& /* event_callback */) {
763 // Deprecated support for this callback.
764 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius3c868522016-10-27 12:43:49 -0700765}
766
Roshan Pius7d08d7a2016-10-27 14:35:05 -0700767std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal() {
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700768 // Deprecated support for this callback.
769 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
770}
771
Jimmy Chend460df32019-11-29 17:31:22 +0200772std::pair<WifiStatus, std::vector<V1_4::IWifiChip::ChipMode>>
Roshan Pius3c868522016-10-27 12:43:49 -0700773WifiChip::getAvailableModesInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700774 return {createWifiStatus(WifiStatusCode::SUCCESS), modes_};
Roshan Pius3c868522016-10-27 12:43:49 -0700775}
776
Roshan Piusba38d9c2017-12-08 07:32:08 -0800777WifiStatus WifiChip::configureChipInternal(
778 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
779 ChipModeId mode_id) {
Roshan Piuscc338202017-11-02 13:54:09 -0700780 if (!isValidModeId(mode_id)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700781 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
782 }
783 if (mode_id == current_mode_id_) {
784 LOG(DEBUG) << "Already in the specified mode " << mode_id;
785 return createWifiStatus(WifiStatusCode::SUCCESS);
786 }
Roshan Piusba38d9c2017-12-08 07:32:08 -0800787 WifiStatus status = handleChipConfiguration(lock, mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700788 if (status.code != WifiStatusCode::SUCCESS) {
789 for (const auto& callback : event_cb_handler_.getCallbacks()) {
790 if (!callback->onChipReconfigureFailure(status).isOk()) {
791 LOG(ERROR)
792 << "Failed to invoke onChipReconfigureFailure callback";
793 }
794 }
795 return status;
796 }
Roshan Piusd37341f2017-01-31 13:13:28 -0800797 for (const auto& callback : event_cb_handler_.getCallbacks()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700798 if (!callback->onChipReconfigured(mode_id).isOk()) {
799 LOG(ERROR) << "Failed to invoke onChipReconfigured callback";
800 }
Roshan Pius52947fb2016-11-18 11:38:07 -0800801 }
Roshan Piusabcf78f2017-10-06 16:30:38 -0700802 current_mode_id_ = mode_id;
Roshan Piusba38d9c2017-12-08 07:32:08 -0800803 LOG(INFO) << "Configured chip in mode " << mode_id;
Roshan Pius8574e7f2019-04-01 13:30:40 -0700804 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Ahmed ElArabawy2134bf72020-06-18 15:07:12 -0700805
806 legacy_hal_.lock()->registerSubsystemRestartCallbackHandler(
807 subsystemCallbackHandler_);
808
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800809 return status;
Roshan Pius3c868522016-10-27 12:43:49 -0700810}
811
812std::pair<WifiStatus, uint32_t> WifiChip::getModeInternal() {
Roshan Piuscc338202017-11-02 13:54:09 -0700813 if (!isValidModeId(current_mode_id_)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700814 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE),
815 current_mode_id_};
816 }
817 return {createWifiStatus(WifiStatusCode::SUCCESS), current_mode_id_};
Roshan Pius3c868522016-10-27 12:43:49 -0700818}
819
Jimmy Chend460df32019-11-29 17:31:22 +0200820std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo>
Roshan Pius3c868522016-10-27 12:43:49 -0700821WifiChip::requestChipDebugInfoInternal() {
Jimmy Chend460df32019-11-29 17:31:22 +0200822 V1_4::IWifiChip::ChipDebugInfo result;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700823 legacy_hal::wifi_error legacy_status;
824 std::string driver_desc;
Roshan Pius6036c022019-03-27 10:41:58 -0700825 const auto ifname = getFirstActiveWlanIfaceName();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700826 std::tie(legacy_status, driver_desc) =
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -0800827 legacy_hal_.lock()->getDriverVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700828 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
829 LOG(ERROR) << "Failed to get driver version: "
830 << legacyErrorToString(legacy_status);
831 WifiStatus status = createWifiStatusFromLegacyError(
832 legacy_status, "failed to get driver version");
833 return {status, result};
834 }
835 result.driverDescription = driver_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700836
Roshan Piusabcf78f2017-10-06 16:30:38 -0700837 std::string firmware_desc;
838 std::tie(legacy_status, firmware_desc) =
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -0800839 legacy_hal_.lock()->getFirmwareVersion(ifname);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700840 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
841 LOG(ERROR) << "Failed to get firmware version: "
842 << legacyErrorToString(legacy_status);
843 WifiStatus status = createWifiStatusFromLegacyError(
844 legacy_status, "failed to get firmware version");
845 return {status, result};
846 }
847 result.firmwareDescription = firmware_desc.c_str();
Roshan Pius3c868522016-10-27 12:43:49 -0700848
Roshan Piusabcf78f2017-10-06 16:30:38 -0700849 return {createWifiStatus(WifiStatusCode::SUCCESS), result};
Roshan Pius3c868522016-10-27 12:43:49 -0700850}
851
852std::pair<WifiStatus, std::vector<uint8_t>>
853WifiChip::requestDriverDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700854 legacy_hal::wifi_error legacy_status;
855 std::vector<uint8_t> driver_dump;
856 std::tie(legacy_status, driver_dump) =
Roshan Pius6036c022019-03-27 10:41:58 -0700857 legacy_hal_.lock()->requestDriverMemoryDump(
858 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700859 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
860 LOG(ERROR) << "Failed to get driver debug dump: "
861 << legacyErrorToString(legacy_status);
862 return {createWifiStatusFromLegacyError(legacy_status),
863 std::vector<uint8_t>()};
864 }
865 return {createWifiStatus(WifiStatusCode::SUCCESS), driver_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700866}
867
868std::pair<WifiStatus, std::vector<uint8_t>>
869WifiChip::requestFirmwareDebugDumpInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700870 legacy_hal::wifi_error legacy_status;
871 std::vector<uint8_t> firmware_dump;
872 std::tie(legacy_status, firmware_dump) =
Roshan Pius6036c022019-03-27 10:41:58 -0700873 legacy_hal_.lock()->requestFirmwareMemoryDump(
874 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700875 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
876 LOG(ERROR) << "Failed to get firmware debug dump: "
877 << legacyErrorToString(legacy_status);
878 return {createWifiStatusFromLegacyError(legacy_status), {}};
879 }
880 return {createWifiStatus(WifiStatusCode::SUCCESS), firmware_dump};
Roshan Pius3c868522016-10-27 12:43:49 -0700881}
882
lesl94d28242020-11-18 22:17:37 +0800883WifiStatus WifiChip::createVirtualApInterface(const std::string& apVirtIf) {
884 legacy_hal::wifi_error legacy_status;
885 legacy_status = legacy_hal_.lock()->createVirtualInterface(
886 apVirtIf,
887 hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::AP));
Sunil Raviddab4bb2020-02-03 22:45:19 -0800888 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
lesl94d28242020-11-18 22:17:37 +0800889 LOG(ERROR) << "Failed to add interface: " << apVirtIf << " "
Sunil Raviddab4bb2020-02-03 22:45:19 -0800890 << legacyErrorToString(legacy_status);
lesl94d28242020-11-18 22:17:37 +0800891 return createWifiStatusFromLegacyError(legacy_status);
Sunil Raviddab4bb2020-02-03 22:45:19 -0800892 }
lesl94d28242020-11-18 22:17:37 +0800893 return createWifiStatus(WifiStatusCode::SUCCESS);
894}
895
896sp<WifiApIface> WifiChip::newWifiApIface(std::string& ifname) {
Patrik Fimml6beae322019-10-09 17:34:01 +0200897 sp<WifiApIface> iface = new WifiApIface(ifname, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -0700898 ap_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700899 for (const auto& callback : event_cb_handler_.getCallbacks()) {
900 if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) {
901 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
902 }
903 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700904 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
lesl94d28242020-11-18 22:17:37 +0800905 return iface;
906}
907
908std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::createApIfaceInternal() {
909 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
910 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
911 }
912 std::string ifname = allocateApIfaceName();
913 WifiStatus status = createVirtualApInterface(ifname);
914 if (status.code != WifiStatusCode::SUCCESS) {
915 return {status, {}};
916 }
917 sp<WifiApIface> iface = newWifiApIface(ifname);
918 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
919}
920
921std::pair<WifiStatus, sp<IWifiApIface>>
922WifiChip::createBridgedApIfaceInternal() {
923 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
924 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
925 }
926 std::string br_ifname = kApBridgeIfacePrefix + allocateApIfaceName();
927 std::vector<std::string> ap_instances;
928 for (int i = 0; i < 2; i++) {
929 // TODO: b/173999527, it should use idx from 2 when STA+STA support, but
930 // need to check vendor support or not.
931 std::string ifaceInstanceName = allocateApOrStaIfaceName(
932 IfaceType::AP, isStaApConcurrencyAllowedInCurrentMode() ? 1 : 0);
933 WifiStatus status = createVirtualApInterface(ifaceInstanceName);
934 if (status.code != WifiStatusCode::SUCCESS) {
935 if (ap_instances.size() != 0) {
936 legacy_hal_.lock()->deleteVirtualInterface(
937 ap_instances.front());
938 }
939 return {status, {}};
940 }
941 ap_instances.push_back(ifaceInstanceName);
942 }
943 br_ifaces_ap_instances_[br_ifname] = ap_instances;
944 if (!iface_util_.lock()->createBridge(br_ifname)) {
945 LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str();
946 invalidateAndClearBridgedAp(br_ifname);
947 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
948 }
949 for (auto const& instance : ap_instances) {
950 // Bind ap instance interface to AP bridge
951 if (!iface_util_.lock()->addIfaceToBridge(br_ifname, instance)) {
952 LOG(ERROR) << "Failed add if to Bridge - if_name="
953 << instance.c_str();
954 invalidateAndClearBridgedAp(br_ifname);
955 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
956 }
957 }
958 sp<WifiApIface> iface = newWifiApIface(br_ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700959 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700960}
961
962std::pair<WifiStatus, std::vector<hidl_string>>
963WifiChip::getApIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -0700964 if (ap_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700965 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
966 }
Roshan Pius675609b2017-10-31 14:24:58 -0700967 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -0700968}
969
970std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800971 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -0700972 const auto iface = findUsingName(ap_ifaces_, ifname);
973 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700974 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
975 }
Roshan Pius675609b2017-10-31 14:24:58 -0700976 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700977}
978
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800979WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -0700980 const auto iface = findUsingName(ap_ifaces_, ifname);
981 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700982 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -0800983 }
Roshan Pius82368502019-05-16 12:53:02 -0700984 // Invalidate & remove any dependent objects first.
985 // Note: This is probably not required because we never create
986 // nan/rtt objects over AP iface. But, there is no harm to do it
987 // here and not make that assumption all over the place.
988 invalidateAndRemoveDependencies(ifname);
lesl94d28242020-11-18 22:17:37 +0800989 // Clear the bridge interface and the iface instance.
990 invalidateAndClearBridgedAp(ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700991 invalidateAndClear(ap_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700992 for (const auto& callback : event_cb_handler_.getCallbacks()) {
993 if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) {
994 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
995 }
996 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700997 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -0700998 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800999}
1000
lesl94d28242020-11-18 22:17:37 +08001001WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal(
1002 const std::string& ifname, const std::string& ifInstanceName) {
1003 legacy_hal::wifi_error legacy_status;
1004 const auto iface = findUsingName(ap_ifaces_, ifname);
1005 if (!iface.get() || !ifInstanceName.empty()) {
1006 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1007 }
1008 // Requires to remove one of the instance in bridge mode
1009 for (auto const& it : br_ifaces_ap_instances_) {
1010 if (it.first == ifname) {
1011 for (auto const& iface : it.second) {
1012 if (iface == ifInstanceName) {
1013 if (!iface_util_.lock()->removeIfaceFromBridge(it.first,
1014 iface)) {
1015 LOG(ERROR) << "Failed to remove interface: " << iface
1016 << " from " << ifname << ", error: "
1017 << legacyErrorToString(legacy_status);
1018 return createWifiStatus(
1019 WifiStatusCode::ERROR_NOT_AVAILABLE);
1020 }
1021 legacy_status =
1022 legacy_hal_.lock()->deleteVirtualInterface(iface);
1023 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1024 LOG(ERROR) << "Failed to del interface: " << iface
1025 << " " << legacyErrorToString(legacy_status);
1026 return createWifiStatusFromLegacyError(legacy_status);
1027 }
1028 }
1029 }
1030 break;
1031 }
1032 }
1033 br_ifaces_ap_instances_.erase(ifInstanceName);
1034 return createWifiStatus(WifiStatusCode::SUCCESS);
1035}
1036
Jimmy Chend460df32019-11-29 17:31:22 +02001037std::pair<WifiStatus, sp<V1_4::IWifiNanIface>>
1038WifiChip::createNanIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001039 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::NAN)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001040 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Etan Cohenc5700402017-03-08 16:43:38 -08001041 }
Roshan Pius5ba0a902020-04-14 11:55:42 -07001042 bool is_dedicated_iface = true;
1043 std::string ifname = getNanIfaceName();
Nate Jiang63f34ed2020-05-20 23:22:51 -07001044 if (ifname.empty() || !iface_util_.lock()->ifNameToIndex(ifname)) {
Roshan Pius5ba0a902020-04-14 11:55:42 -07001045 // Use the first shared STA iface (wlan0) if a dedicated aware iface is
1046 // not defined.
1047 ifname = getFirstActiveWlanIfaceName();
1048 is_dedicated_iface = false;
1049 }
1050 sp<WifiNanIface> iface =
1051 new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_);
Roshan Piuscc338202017-11-02 13:54:09 -07001052 nan_ifaces_.push_back(iface);
1053 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1054 if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
1055 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1056 }
1057 }
1058 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001059}
1060
1061std::pair<WifiStatus, std::vector<hidl_string>>
1062WifiChip::getNanIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001063 if (nan_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001064 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1065 }
Roshan Pius675609b2017-10-31 14:24:58 -07001066 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001067}
1068
Jimmy Chend460df32019-11-29 17:31:22 +02001069std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::getNanIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001070 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001071 const auto iface = findUsingName(nan_ifaces_, ifname);
1072 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001073 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1074 }
Roshan Pius675609b2017-10-31 14:24:58 -07001075 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001076}
1077
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001078WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001079 const auto iface = findUsingName(nan_ifaces_, ifname);
1080 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001081 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001082 }
Roshan Pius675609b2017-10-31 14:24:58 -07001083 invalidateAndClear(nan_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001084 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1085 if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) {
1086 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1087 }
1088 }
1089 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001090}
1091
Roshan Pius3c868522016-10-27 12:43:49 -07001092std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001093 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::P2P)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001094 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001095 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001096 std::string ifname = getP2pIfaceName();
Roshan Pius675609b2017-10-31 14:24:58 -07001097 sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_);
1098 p2p_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001099 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1100 if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) {
1101 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1102 }
1103 }
Roshan Pius675609b2017-10-31 14:24:58 -07001104 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001105}
1106
1107std::pair<WifiStatus, std::vector<hidl_string>>
1108WifiChip::getP2pIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001109 if (p2p_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001110 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1111 }
Roshan Pius675609b2017-10-31 14:24:58 -07001112 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001113}
1114
1115std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001116 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001117 const auto iface = findUsingName(p2p_ifaces_, ifname);
1118 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001119 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1120 }
Roshan Pius675609b2017-10-31 14:24:58 -07001121 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001122}
1123
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001124WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001125 const auto iface = findUsingName(p2p_ifaces_, ifname);
1126 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001127 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001128 }
Roshan Pius675609b2017-10-31 14:24:58 -07001129 invalidateAndClear(p2p_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001130 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1131 if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) {
1132 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1133 }
1134 }
1135 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001136}
1137
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001138std::pair<WifiStatus, sp<V1_5::IWifiStaIface>>
Ahmed ElArabawyb23485d2019-12-09 15:24:16 -08001139WifiChip::createStaIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001140 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::STA)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001141 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001142 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001143 std::string ifname = allocateStaIfaceName();
Sunil Raviddab4bb2020-02-03 22:45:19 -08001144 legacy_hal::wifi_error legacy_status =
1145 legacy_hal_.lock()->createVirtualInterface(
1146 ifname,
1147 hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
1148 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1149 LOG(ERROR) << "Failed to add interface: " << ifname << " "
1150 << legacyErrorToString(legacy_status);
1151 return {createWifiStatusFromLegacyError(legacy_status), {}};
1152 }
Roshan Pius99dab382019-02-14 07:57:10 -08001153 sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -07001154 sta_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001155 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1156 if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
1157 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1158 }
1159 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001160 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Pius675609b2017-10-31 14:24:58 -07001161 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001162}
1163
1164std::pair<WifiStatus, std::vector<hidl_string>>
1165WifiChip::getStaIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001166 if (sta_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001167 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1168 }
Roshan Pius675609b2017-10-31 14:24:58 -07001169 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001170}
1171
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001172std::pair<WifiStatus, sp<V1_5::IWifiStaIface>> WifiChip::getStaIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001173 const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001174 const auto iface = findUsingName(sta_ifaces_, ifname);
1175 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001176 return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
1177 }
Roshan Pius675609b2017-10-31 14:24:58 -07001178 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001179}
1180
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001181WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001182 const auto iface = findUsingName(sta_ifaces_, ifname);
1183 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001184 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001185 }
Roshan Pius82368502019-05-16 12:53:02 -07001186 // Invalidate & remove any dependent objects first.
1187 invalidateAndRemoveDependencies(ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -08001188 legacy_hal::wifi_error legacy_status =
1189 legacy_hal_.lock()->deleteVirtualInterface(ifname);
1190 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1191 LOG(ERROR) << "Failed to remove interface: " << ifname << " "
1192 << legacyErrorToString(legacy_status);
1193 }
Roshan Pius675609b2017-10-31 14:24:58 -07001194 invalidateAndClear(sta_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001195 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1196 if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) {
1197 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1198 }
1199 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001200 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001201 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001202}
1203
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001204std::pair<WifiStatus, sp<V1_0::IWifiRttController>>
1205WifiChip::createRttControllerInternal(const sp<IWifiIface>& /*bound_iface*/) {
1206 LOG(ERROR) << "createRttController is not supported on this HAL";
Ahmed ElArabawy36defb32019-12-29 21:24:27 -08001207 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
Roshan Pius3c868522016-10-27 12:43:49 -07001208}
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001209
1210std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
1211WifiChip::getDebugRingBuffersStatusInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001212 legacy_hal::wifi_error legacy_status;
1213 std::vector<legacy_hal::wifi_ring_buffer_status>
1214 legacy_ring_buffer_status_vec;
1215 std::tie(legacy_status, legacy_ring_buffer_status_vec) =
Roshan Pius6036c022019-03-27 10:41:58 -07001216 legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001217 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1218 return {createWifiStatusFromLegacyError(legacy_status), {}};
1219 }
1220 std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec;
1221 if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl(
1222 legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) {
1223 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1224 }
1225 return {createWifiStatus(WifiStatusCode::SUCCESS),
1226 hidl_ring_buffer_status_vec};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001227}
1228
1229WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
Roshan Piusabcf78f2017-10-06 16:30:38 -07001230 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
1231 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) {
1232 WifiStatus status = registerDebugRingBufferCallback();
1233 if (status.code != WifiStatusCode::SUCCESS) {
1234 return status;
1235 }
1236 legacy_hal::wifi_error legacy_status =
1237 legacy_hal_.lock()->startRingBufferLogging(
Roshan Pius6036c022019-03-27 10:41:58 -07001238 getFirstActiveWlanIfaceName(), ring_name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001239 static_cast<
1240 std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(
1241 verbose_level),
1242 max_interval_in_sec, min_data_size_in_bytes);
xshu5899e8e2018-01-09 15:36:03 -08001243 ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>(
1244 ring_name, Ringbuffer(kMaxBufferSizeBytes)));
Roshan Piusa63b53f2019-11-18 11:03:13 -08001245 // if verbose logging enabled, turn up HAL daemon logging as well.
1246 if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) {
1247 android::base::SetMinimumLogSeverity(android::base::DEBUG);
1248 } else {
1249 android::base::SetMinimumLogSeverity(android::base::VERBOSE);
1250 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001251 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001252}
1253
1254WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(
Roshan Piuse2d0ab52016-12-05 15:24:20 -08001255 const hidl_string& ring_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001256 WifiStatus status = registerDebugRingBufferCallback();
1257 if (status.code != WifiStatusCode::SUCCESS) {
1258 return status;
1259 }
1260 legacy_hal::wifi_error legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001261 legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(),
1262 ring_name);
xshu5899e8e2018-01-09 15:36:03 -08001263
Roshan Piusabcf78f2017-10-06 16:30:38 -07001264 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001265}
1266
Roger Wangb294c762018-11-02 15:34:39 +08001267WifiStatus WifiChip::flushRingBufferToFileInternal() {
1268 if (!writeRingbufferFilesInternal()) {
1269 LOG(ERROR) << "Error writing files to flash";
1270 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1271 }
1272 return createWifiStatus(WifiStatusCode::SUCCESS);
1273}
1274
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001275WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001276 legacy_hal::wifi_error legacy_status =
1277 legacy_hal_.lock()->deregisterRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001278 getFirstActiveWlanIfaceName());
xshu0a0fe512020-07-22 17:53:37 -07001279 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1280 debug_ring_buffer_cb_registered_ = false;
1281 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001282 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001283}
1284
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001285std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
1286WifiChip::getDebugHostWakeReasonStatsInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001287 legacy_hal::wifi_error legacy_status;
1288 legacy_hal::WakeReasonStats legacy_stats;
1289 std::tie(legacy_status, legacy_stats) =
Roshan Pius6036c022019-03-27 10:41:58 -07001290 legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001291 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1292 return {createWifiStatusFromLegacyError(legacy_status), {}};
1293 }
1294 WifiDebugHostWakeReasonStats hidl_stats;
1295 if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats,
1296 &hidl_stats)) {
1297 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1298 }
1299 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001300}
1301
Roshan Pius203cb032016-12-14 17:41:20 -08001302WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001303 legacy_hal::wifi_error legacy_status;
1304 if (enable) {
1305 android::wp<WifiChip> weak_ptr_this(this);
1306 const auto& on_alert_callback = [weak_ptr_this](
1307 int32_t error_code,
1308 std::vector<uint8_t> debug_data) {
1309 const auto shared_ptr_this = weak_ptr_this.promote();
1310 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1311 LOG(ERROR) << "Callback invoked on an invalid object";
1312 return;
1313 }
1314 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
1315 if (!callback->onDebugErrorAlert(error_code, debug_data)
1316 .isOk()) {
1317 LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback";
1318 }
1319 }
1320 };
1321 legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001322 getFirstActiveWlanIfaceName(), on_alert_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001323 } else {
1324 legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001325 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001326 }
1327 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius203cb032016-12-14 17:41:20 -08001328}
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001329
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001330WifiStatus WifiChip::selectTxPowerScenarioInternal(
Jong Wook Kimda830c92018-07-23 15:29:38 -07001331 V1_1::IWifiChip::TxPowerScenario scenario) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001332 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001333 getFirstActiveWlanIfaceName(),
Roshan Piusabcf78f2017-10-06 16:30:38 -07001334 hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario));
1335 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001336}
1337
Roshan Pius735ff432017-07-25 08:48:08 -07001338WifiStatus WifiChip::resetTxPowerScenarioInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001339 auto legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001340 legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001341 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001342}
1343
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001344WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) {
1345 auto legacy_status = legacy_hal_.lock()->setLatencyMode(
Roshan Pius6036c022019-03-27 10:41:58 -07001346 getFirstActiveWlanIfaceName(),
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001347 hidl_struct_util::convertHidlLatencyModeToLegacy(mode));
1348 return createWifiStatusFromLegacyError(legacy_status);
1349}
1350
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001351WifiStatus WifiChip::registerEventCallbackInternal_1_2(
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001352 const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) {
1353 // Deprecated support for this callback.
1354 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001355}
1356
Jong Wook Kimda830c92018-07-23 15:29:38 -07001357WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(
1358 TxPowerScenario scenario) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001359 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001360 getFirstActiveWlanIfaceName(),
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001361 hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario));
1362 return createWifiStatusFromLegacyError(legacy_status);
1363}
1364
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001365std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() {
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001366 // Deprecated support for this callback.
1367 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
1368}
1369
1370std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_5() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001371 legacy_hal::wifi_error legacy_status;
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001372 uint64_t legacy_feature_set;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001373 uint32_t legacy_logger_feature_set;
1374 const auto ifname = getFirstActiveWlanIfaceName();
1375 std::tie(legacy_status, legacy_feature_set) =
1376 legacy_hal_.lock()->getSupportedFeatureSet(ifname);
1377 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1378 return {createWifiStatusFromLegacyError(legacy_status), 0};
1379 }
1380 std::tie(legacy_status, legacy_logger_feature_set) =
1381 legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname);
1382 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1383 // some devices don't support querying logger feature set
1384 legacy_logger_feature_set = 0;
1385 }
1386 uint32_t hidl_caps;
1387 if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities(
1388 legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) {
1389 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0};
1390 }
1391 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps};
1392}
1393
Jimmy Chend460df32019-11-29 17:31:22 +02001394std::pair<WifiStatus, sp<V1_4::IWifiRttController>>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001395WifiChip::createRttControllerInternal_1_4(const sp<IWifiIface>& bound_iface) {
1396 if (sta_ifaces_.size() == 0 &&
1397 !canCurrentModeSupportIfaceOfType(IfaceType::STA)) {
1398 LOG(ERROR)
1399 << "createRttControllerInternal_1_4: Chip cannot support STAs "
1400 "(and RTT by extension)";
1401 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
1402 }
1403 sp<WifiRttController> rtt = new WifiRttController(
1404 getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_);
1405 rtt_controllers_.emplace_back(rtt);
1406 return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
1407}
1408
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001409WifiStatus WifiChip::registerEventCallbackInternal_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +02001410 const sp<V1_4::IWifiChipEventCallback>& event_callback) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001411 if (!event_cb_handler_.addCallback(event_callback)) {
1412 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1413 }
1414 return createWifiStatus(WifiStatusCode::SUCCESS);
1415}
1416
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001417WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(
1418 const std::string& ifname) {
1419 auto legacy_status =
1420 legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname);
1421 return createWifiStatusFromLegacyError(legacy_status);
1422}
1423
1424WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) {
1425 auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase(
1426 hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case));
1427 return createWifiStatusFromLegacyError(legacy_status);
1428}
1429
Roshan Piusba38d9c2017-12-08 07:32:08 -08001430WifiStatus WifiChip::handleChipConfiguration(
1431 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
1432 ChipModeId mode_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001433 // If the chip is already configured in a different mode, stop
1434 // the legacy HAL and then start it after firmware mode change.
Roshan Piuscc338202017-11-02 13:54:09 -07001435 if (isValidModeId(current_mode_id_)) {
Roshan Piusba38d9c2017-12-08 07:32:08 -08001436 LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_
1437 << " to mode " << mode_id;
1438 invalidateAndRemoveAllIfaces();
1439 legacy_hal::wifi_error legacy_status =
1440 legacy_hal_.lock()->stop(lock, []() {});
1441 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1442 LOG(ERROR) << "Failed to stop legacy HAL: "
1443 << legacyErrorToString(legacy_status);
1444 return createWifiStatusFromLegacyError(legacy_status);
1445 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001446 }
Roshan Piuscc338202017-11-02 13:54:09 -07001447 // Firmware mode change not needed for V2 devices.
1448 bool success = true;
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001449 if (mode_id == feature_flags::chip_mode_ids::kV1Sta) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001450 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001451 } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001452 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
1453 }
1454 if (!success) {
1455 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1456 }
1457 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
1458 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1459 LOG(ERROR) << "Failed to start legacy HAL: "
1460 << legacyErrorToString(legacy_status);
1461 return createWifiStatusFromLegacyError(legacy_status);
1462 }
Roshan Pius85c64412018-01-22 17:58:40 -08001463 // Every time the HAL is restarted, we need to register the
1464 // radio mode change callback.
1465 WifiStatus status = registerRadioModeChangeCallback();
1466 if (status.code != WifiStatusCode::SUCCESS) {
1467 // This probably is not a critical failure?
1468 LOG(ERROR) << "Failed to register radio mode change callback";
1469 }
chenpaulf5eca292019-03-14 11:08:03 +08001470 // Extract and save the version information into property.
Jimmy Chend460df32019-11-29 17:31:22 +02001471 std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> version_info;
chenpaulf5eca292019-03-14 11:08:03 +08001472 version_info = WifiChip::requestChipDebugInfoInternal();
1473 if (WifiStatusCode::SUCCESS == version_info.first.code) {
1474 property_set("vendor.wlan.firmware.version",
1475 version_info.second.firmwareDescription.c_str());
1476 property_set("vendor.wlan.driver.version",
1477 version_info.second.driverDescription.c_str());
1478 }
1479
Roshan Piusabcf78f2017-10-06 16:30:38 -07001480 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001481}
Roshan Pius48185b22016-12-15 19:10:30 -08001482
1483WifiStatus WifiChip::registerDebugRingBufferCallback() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001484 if (debug_ring_buffer_cb_registered_) {
1485 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius48185b22016-12-15 19:10:30 -08001486 }
Roshan Pius3797e182017-03-30 18:01:54 -07001487
Roshan Piusabcf78f2017-10-06 16:30:38 -07001488 android::wp<WifiChip> weak_ptr_this(this);
1489 const auto& on_ring_buffer_data_callback =
xshu5899e8e2018-01-09 15:36:03 -08001490 [weak_ptr_this](const std::string& name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001491 const std::vector<uint8_t>& data,
1492 const legacy_hal::wifi_ring_buffer_status& status) {
1493 const auto shared_ptr_this = weak_ptr_this.promote();
1494 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1495 LOG(ERROR) << "Callback invoked on an invalid object";
1496 return;
1497 }
1498 WifiDebugRingBufferStatus hidl_status;
1499 if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(
1500 status, &hidl_status)) {
1501 LOG(ERROR) << "Error converting ring buffer status";
1502 return;
1503 }
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301504 {
1505 std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t);
1506 const auto& target =
1507 shared_ptr_this->ringbuffer_map_.find(name);
1508 if (target != shared_ptr_this->ringbuffer_map_.end()) {
1509 Ringbuffer& cur_buffer = target->second;
1510 cur_buffer.append(data);
1511 } else {
1512 LOG(ERROR) << "Ringname " << name << " not found";
1513 return;
1514 }
xshu0a0fe512020-07-22 17:53:37 -07001515 // unique_lock unlocked here
Roshan Piusabcf78f2017-10-06 16:30:38 -07001516 }
1517 };
1518 legacy_hal::wifi_error legacy_status =
1519 legacy_hal_.lock()->registerRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001520 getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback);
Roshan Pius48185b22016-12-15 19:10:30 -08001521
Roshan Piusabcf78f2017-10-06 16:30:38 -07001522 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1523 debug_ring_buffer_cb_registered_ = true;
1524 }
1525 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius48185b22016-12-15 19:10:30 -08001526}
1527
Roshan Pius85c64412018-01-22 17:58:40 -08001528WifiStatus WifiChip::registerRadioModeChangeCallback() {
1529 android::wp<WifiChip> weak_ptr_this(this);
1530 const auto& on_radio_mode_change_callback =
1531 [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) {
1532 const auto shared_ptr_this = weak_ptr_this.promote();
1533 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1534 LOG(ERROR) << "Callback invoked on an invalid object";
1535 return;
1536 }
Jimmy Chend460df32019-11-29 17:31:22 +02001537 std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo>
Roshan Pius85c64412018-01-22 17:58:40 -08001538 hidl_radio_mode_infos;
1539 if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(
1540 mac_infos, &hidl_radio_mode_infos)) {
1541 LOG(ERROR) << "Error converting wifi mac info";
1542 return;
1543 }
1544 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001545 if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos)
Roshan Pius85c64412018-01-22 17:58:40 -08001546 .isOk()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001547 LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4"
Roshan Pius85c64412018-01-22 17:58:40 -08001548 << " callback on: " << toString(callback);
1549 }
1550 }
1551 };
1552 legacy_hal::wifi_error legacy_status =
1553 legacy_hal_.lock()->registerRadioModeChangeCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001554 getFirstActiveWlanIfaceName(), on_radio_mode_change_callback);
Roshan Pius85c64412018-01-22 17:58:40 -08001555 return createWifiStatusFromLegacyError(legacy_status);
1556}
1557
Jimmy Chend460df32019-11-29 17:31:22 +02001558std::vector<V1_4::IWifiChip::ChipIfaceCombination>
Roshan Piuscc338202017-11-02 13:54:09 -07001559WifiChip::getCurrentModeIfaceCombinations() {
1560 if (!isValidModeId(current_mode_id_)) {
1561 LOG(ERROR) << "Chip not configured in a mode yet";
1562 return {};
1563 }
1564 for (const auto& mode : modes_) {
1565 if (mode.id == current_mode_id_) {
1566 return mode.availableCombinations;
1567 }
1568 }
1569 CHECK(0) << "Expected to find iface combinations for current mode!";
1570 return {};
1571}
1572
1573// Returns a map indexed by IfaceType with the number of ifaces currently
1574// created of the corresponding type.
1575std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() {
1576 std::map<IfaceType, size_t> iface_counts;
1577 iface_counts[IfaceType::AP] = ap_ifaces_.size();
1578 iface_counts[IfaceType::NAN] = nan_ifaces_.size();
1579 iface_counts[IfaceType::P2P] = p2p_ifaces_.size();
1580 iface_counts[IfaceType::STA] = sta_ifaces_.size();
1581 return iface_counts;
1582}
1583
1584// This expands the provided iface combinations to a more parseable
1585// form. Returns a vector of available combinations possible with the number
1586// of ifaces of each type in the combination.
1587// This method is a port of HalDeviceManager.expandIfaceCombos() from framework.
1588std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations(
Jimmy Chend460df32019-11-29 17:31:22 +02001589 const V1_4::IWifiChip::ChipIfaceCombination& combination) {
Roshan Piuscc338202017-11-02 13:54:09 -07001590 uint32_t num_expanded_combos = 1;
1591 for (const auto& limit : combination.limits) {
1592 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1593 num_expanded_combos *= limit.types.size();
1594 }
1595 }
1596
1597 // Allocate the vector of expanded combos and reset all iface counts to 0
1598 // in each combo.
1599 std::vector<std::map<IfaceType, size_t>> expanded_combos;
1600 expanded_combos.resize(num_expanded_combos);
1601 for (auto& expanded_combo : expanded_combos) {
1602 for (const auto type :
1603 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1604 expanded_combo[type] = 0;
1605 }
1606 }
1607 uint32_t span = num_expanded_combos;
1608 for (const auto& limit : combination.limits) {
1609 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1610 span /= limit.types.size();
1611 for (uint32_t k = 0; k < num_expanded_combos; ++k) {
1612 const auto iface_type =
1613 limit.types[(k / span) % limit.types.size()];
1614 expanded_combos[k][iface_type]++;
1615 }
1616 }
1617 }
1618 return expanded_combos;
1619}
1620
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001621bool WifiChip::canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1622 const std::map<IfaceType, size_t>& expanded_combo,
1623 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001624 const auto current_combo = getCurrentIfaceCombination();
1625
1626 // Check if we have space for 1 more iface of |type| in this combo
1627 for (const auto type :
1628 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1629 size_t num_ifaces_needed = current_combo.at(type);
1630 if (type == requested_type) {
1631 num_ifaces_needed++;
1632 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001633 size_t num_ifaces_allowed = expanded_combo.at(type);
Roshan Piuscc338202017-11-02 13:54:09 -07001634 if (num_ifaces_needed > num_ifaces_allowed) {
1635 return false;
1636 }
1637 }
1638 return true;
1639}
1640
1641// This method does the following:
1642// a) Enumerate all possible iface combos by expanding the current
1643// ChipIfaceCombination.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001644// b) Check if the requested iface type can be added to the current mode
1645// with the iface combination that is already active.
1646bool WifiChip::canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(
1647 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001648 if (!isValidModeId(current_mode_id_)) {
1649 LOG(ERROR) << "Chip not configured in a mode yet";
1650 return false;
1651 }
1652 const auto combinations = getCurrentModeIfaceCombinations();
1653 for (const auto& combination : combinations) {
1654 const auto expanded_combos = expandIfaceCombinations(combination);
1655 for (const auto& expanded_combo : expanded_combos) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001656 if (canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1657 expanded_combo, requested_type)) {
Roshan Piuscc338202017-11-02 13:54:09 -07001658 return true;
1659 }
1660 }
1661 }
1662 return false;
1663}
1664
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001665// Note: This does not consider ifaces already active. It only checks if the
1666// provided expanded iface combination can support the requested combo.
1667bool WifiChip::canExpandedIfaceComboSupportIfaceCombo(
1668 const std::map<IfaceType, size_t>& expanded_combo,
1669 const std::map<IfaceType, size_t>& req_combo) {
1670 // Check if we have space for 1 more iface of |type| in this combo
1671 for (const auto type :
1672 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1673 if (req_combo.count(type) == 0) {
1674 // Iface of "type" not in the req_combo.
1675 continue;
1676 }
1677 size_t num_ifaces_needed = req_combo.at(type);
1678 size_t num_ifaces_allowed = expanded_combo.at(type);
1679 if (num_ifaces_needed > num_ifaces_allowed) {
1680 return false;
1681 }
1682 }
1683 return true;
1684}
1685// This method does the following:
1686// a) Enumerate all possible iface combos by expanding the current
1687// ChipIfaceCombination.
1688// b) Check if the requested iface combo can be added to the current mode.
1689// Note: This does not consider ifaces already active. It only checks if the
1690// current mode can support the requested combo.
1691bool WifiChip::canCurrentModeSupportIfaceCombo(
1692 const std::map<IfaceType, size_t>& req_combo) {
1693 if (!isValidModeId(current_mode_id_)) {
1694 LOG(ERROR) << "Chip not configured in a mode yet";
1695 return false;
1696 }
1697 const auto combinations = getCurrentModeIfaceCombinations();
1698 for (const auto& combination : combinations) {
1699 const auto expanded_combos = expandIfaceCombinations(combination);
1700 for (const auto& expanded_combo : expanded_combos) {
1701 if (canExpandedIfaceComboSupportIfaceCombo(expanded_combo,
1702 req_combo)) {
1703 return true;
1704 }
1705 }
1706 }
1707 return false;
1708}
1709
1710// This method does the following:
1711// a) Enumerate all possible iface combos by expanding the current
1712// ChipIfaceCombination.
1713// b) Check if the requested iface type can be added to the current mode.
1714bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType requested_type) {
1715 // Check if we can support atleast 1 iface of type.
1716 std::map<IfaceType, size_t> req_iface_combo;
1717 req_iface_combo[requested_type] = 1;
1718 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1719}
1720
Roshan Piuscc338202017-11-02 13:54:09 -07001721bool WifiChip::isValidModeId(ChipModeId mode_id) {
1722 for (const auto& mode : modes_) {
1723 if (mode.id == mode_id) {
1724 return true;
1725 }
1726 }
1727 return false;
1728}
1729
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001730bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() {
1731 // Check if we can support atleast 1 STA & 1 AP concurrently.
1732 std::map<IfaceType, size_t> req_iface_combo;
1733 req_iface_combo[IfaceType::AP] = 1;
1734 req_iface_combo[IfaceType::STA] = 1;
1735 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1736}
1737
James Mattisd2e4c072019-05-22 16:14:48 -07001738bool WifiChip::isDualApAllowedInCurrentMode() {
1739 // Check if we can support atleast 1 STA & 1 AP concurrently.
1740 std::map<IfaceType, size_t> req_iface_combo;
1741 req_iface_combo[IfaceType::AP] = 2;
1742 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1743}
1744
Roshan Pius6036c022019-03-27 10:41:58 -07001745std::string WifiChip::getFirstActiveWlanIfaceName() {
Roshan Pius444473f2019-04-19 08:41:20 -07001746 if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName();
1747 if (ap_ifaces_.size() > 0) return ap_ifaces_[0]->getName();
Roshan Pius6036c022019-03-27 10:41:58 -07001748 // This could happen if the chip call is made before any STA/AP
1749 // iface is created. Default to wlan0 for such cases.
Roshan Pius444473f2019-04-19 08:41:20 -07001750 LOG(WARNING) << "No active wlan interfaces in use! Using default";
Jimmy Chen2dddd792019-12-23 17:50:39 +02001751 return getWlanIfaceNameWithType(IfaceType::STA, 0);
Roshan Pius6036c022019-03-27 10:41:58 -07001752}
1753
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001754// Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx|
1755// not already in use.
1756// Note: This doesn't check the actual presence of these interfaces.
Jimmy Chen2dddd792019-12-23 17:50:39 +02001757std::string WifiChip::allocateApOrStaIfaceName(IfaceType type,
1758 uint32_t start_idx) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001759 for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001760 const auto ifname = getWlanIfaceNameWithType(type, idx);
lesl94d28242020-11-18 22:17:37 +08001761 if (findUsingNameFromBridgedApInstances(ifname)) continue;
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001762 if (findUsingName(ap_ifaces_, ifname)) continue;
1763 if (findUsingName(sta_ifaces_, ifname)) continue;
1764 return ifname;
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001765 }
1766 // This should never happen. We screwed up somewhere if it did.
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001767 CHECK(false) << "All wlan interfaces in use already!";
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001768 return {};
1769}
1770
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001771// AP iface names start with idx 1 for modes supporting
James Mattisd2e4c072019-05-22 16:14:48 -07001772// concurrent STA and not dual AP, else start with idx 0.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001773std::string WifiChip::allocateApIfaceName() {
Roshan Pius78cb5992020-04-30 12:39:21 -07001774 // Check if we have a dedicated iface for AP.
1775 std::string ifname = getApIfaceName();
1776 if (!ifname.empty()) {
1777 return ifname;
1778 }
Jimmy Chen2dddd792019-12-23 17:50:39 +02001779 return allocateApOrStaIfaceName(IfaceType::AP,
1780 (isStaApConcurrencyAllowedInCurrentMode() &&
James Mattisd2e4c072019-05-22 16:14:48 -07001781 !isDualApAllowedInCurrentMode())
1782 ? 1
1783 : 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001784}
1785
1786// STA iface names start with idx 0.
1787// Primary STA iface will always be 0.
1788std::string WifiChip::allocateStaIfaceName() {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001789 return allocateApOrStaIfaceName(IfaceType::STA, 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001790}
1791
xshu5899e8e2018-01-09 15:36:03 -08001792bool WifiChip::writeRingbufferFilesInternal() {
1793 if (!removeOldFilesInternal()) {
1794 LOG(ERROR) << "Error occurred while deleting old tombstone files";
1795 return false;
1796 }
1797 // write ringbuffers to file
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301798 {
1799 std::unique_lock<std::mutex> lk(lock_t);
1800 for (const auto& item : ringbuffer_map_) {
1801 const Ringbuffer& cur_buffer = item.second;
1802 if (cur_buffer.getData().empty()) {
1803 continue;
1804 }
1805 const std::string file_path_raw =
1806 kTombstoneFolderPath + item.first + "XXXXXXXXXX";
1807 const int dump_fd = mkstemp(makeCharVec(file_path_raw).data());
1808 if (dump_fd == -1) {
1809 PLOG(ERROR) << "create file failed";
1810 return false;
1811 }
1812 unique_fd file_auto_closer(dump_fd);
1813 for (const auto& cur_block : cur_buffer.getData()) {
1814 if (write(dump_fd, cur_block.data(),
1815 sizeof(cur_block[0]) * cur_block.size()) == -1) {
1816 PLOG(ERROR) << "Error writing to file";
1817 }
xshu5899e8e2018-01-09 15:36:03 -08001818 }
1819 }
xshu0a0fe512020-07-22 17:53:37 -07001820 // unique_lock unlocked here
xshu5899e8e2018-01-09 15:36:03 -08001821 }
1822 return true;
1823}
1824
Jimmy Chen2dddd792019-12-23 17:50:39 +02001825std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) {
1826 std::string ifname;
1827
1828 // let the legacy hal override the interface name
1829 legacy_hal::wifi_error err =
1830 legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname);
1831 if (err == legacy_hal::WIFI_SUCCESS) return ifname;
1832
1833 return getWlanIfaceName(idx);
1834}
1835
lesl94d28242020-11-18 22:17:37 +08001836void WifiChip::invalidateAndClearBridgedApAll() {
1837 for (auto const& it : br_ifaces_ap_instances_) {
1838 for (auto const& iface : it.second) {
1839 iface_util_.lock()->removeIfaceFromBridge(it.first, iface);
1840 legacy_hal_.lock()->deleteVirtualInterface(iface);
1841 }
1842 iface_util_.lock()->deleteBridge(it.first);
1843 }
1844 br_ifaces_ap_instances_.clear();
1845}
1846
1847void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) {
1848 if (br_name.empty()) return;
1849 // delete managed interfaces
1850 for (auto const& it : br_ifaces_ap_instances_) {
1851 if (it.first == br_name) {
1852 for (auto const& iface : it.second) {
1853 iface_util_.lock()->removeIfaceFromBridge(br_name, iface);
1854 legacy_hal_.lock()->deleteVirtualInterface(iface);
1855 }
1856 iface_util_.lock()->deleteBridge(br_name);
1857 br_ifaces_ap_instances_.erase(br_name);
1858 break;
1859 }
1860 }
1861 return;
1862}
1863
1864bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) {
1865 for (auto const& it : br_ifaces_ap_instances_) {
1866 if (it.first == name) {
1867 return true;
1868 }
1869 for (auto const& iface : it.second) {
1870 if (iface == name) {
1871 return true;
1872 }
1873 }
1874 }
1875 return false;
1876}
1877
Roshan Pius79a99752016-10-04 13:03:58 -07001878} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +02001879} // namespace V1_5
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001880} // namespace wifi
1881} // namespace hardware
1882} // namespace android