blob: 5d9d315e40aaf683c91e655a874dd83fd3c1d027 [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) {
lesl420c4fc2020-11-23 19:33:04 +0800897 std::vector<std::string> ap_instances;
898 for (auto const& it : br_ifaces_ap_instances_) {
899 if (it.first == ifname) {
900 ap_instances = it.second;
901 }
902 }
903 sp<WifiApIface> iface =
904 new WifiApIface(ifname, ap_instances, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -0700905 ap_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700906 for (const auto& callback : event_cb_handler_.getCallbacks()) {
907 if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) {
908 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
909 }
910 }
Roshan Pius8574e7f2019-04-01 13:30:40 -0700911 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
lesl94d28242020-11-18 22:17:37 +0800912 return iface;
913}
914
lesl420c4fc2020-11-23 19:33:04 +0800915std::pair<WifiStatus, sp<V1_5::IWifiApIface>>
916WifiChip::createApIfaceInternal() {
lesl94d28242020-11-18 22:17:37 +0800917 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
918 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
919 }
920 std::string ifname = allocateApIfaceName();
921 WifiStatus status = createVirtualApInterface(ifname);
922 if (status.code != WifiStatusCode::SUCCESS) {
923 return {status, {}};
924 }
925 sp<WifiApIface> iface = newWifiApIface(ifname);
926 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
927}
928
lesl420c4fc2020-11-23 19:33:04 +0800929std::pair<WifiStatus, sp<V1_5::IWifiApIface>>
lesl94d28242020-11-18 22:17:37 +0800930WifiChip::createBridgedApIfaceInternal() {
931 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::AP)) {
932 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
933 }
934 std::string br_ifname = kApBridgeIfacePrefix + allocateApIfaceName();
935 std::vector<std::string> ap_instances;
936 for (int i = 0; i < 2; i++) {
937 // TODO: b/173999527, it should use idx from 2 when STA+STA support, but
938 // need to check vendor support or not.
939 std::string ifaceInstanceName = allocateApOrStaIfaceName(
940 IfaceType::AP, isStaApConcurrencyAllowedInCurrentMode() ? 1 : 0);
941 WifiStatus status = createVirtualApInterface(ifaceInstanceName);
942 if (status.code != WifiStatusCode::SUCCESS) {
943 if (ap_instances.size() != 0) {
944 legacy_hal_.lock()->deleteVirtualInterface(
945 ap_instances.front());
946 }
947 return {status, {}};
948 }
949 ap_instances.push_back(ifaceInstanceName);
950 }
951 br_ifaces_ap_instances_[br_ifname] = ap_instances;
952 if (!iface_util_.lock()->createBridge(br_ifname)) {
953 LOG(ERROR) << "Failed createBridge - br_name=" << br_ifname.c_str();
954 invalidateAndClearBridgedAp(br_ifname);
955 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
956 }
957 for (auto const& instance : ap_instances) {
958 // Bind ap instance interface to AP bridge
959 if (!iface_util_.lock()->addIfaceToBridge(br_ifname, instance)) {
960 LOG(ERROR) << "Failed add if to Bridge - if_name="
961 << instance.c_str();
962 invalidateAndClearBridgedAp(br_ifname);
963 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
964 }
965 }
966 sp<WifiApIface> iface = newWifiApIface(br_ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700967 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700968}
969
970std::pair<WifiStatus, std::vector<hidl_string>>
971WifiChip::getApIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -0700972 if (ap_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700973 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
974 }
Roshan Pius675609b2017-10-31 14:24:58 -0700975 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(ap_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -0700976}
977
lesl420c4fc2020-11-23 19:33:04 +0800978std::pair<WifiStatus, sp<V1_5::IWifiApIface>> WifiChip::getApIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800979 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), nullptr};
983 }
Roshan Pius675609b2017-10-31 14:24:58 -0700984 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -0700985}
986
Roshan Pius8b55e6f2016-12-09 12:05:12 -0800987WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -0700988 const auto iface = findUsingName(ap_ifaces_, ifname);
989 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -0700990 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -0800991 }
Roshan Pius82368502019-05-16 12:53:02 -0700992 // Invalidate & remove any dependent objects first.
993 // Note: This is probably not required because we never create
994 // nan/rtt objects over AP iface. But, there is no harm to do it
995 // here and not make that assumption all over the place.
996 invalidateAndRemoveDependencies(ifname);
lesl94d28242020-11-18 22:17:37 +0800997 // Clear the bridge interface and the iface instance.
998 invalidateAndClearBridgedAp(ifname);
Roshan Pius675609b2017-10-31 14:24:58 -0700999 invalidateAndClear(ap_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001000 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1001 if (!callback->onIfaceRemoved(IfaceType::AP, ifname).isOk()) {
1002 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1003 }
1004 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001005 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001006 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001007}
1008
lesl94d28242020-11-18 22:17:37 +08001009WifiStatus WifiChip::removeIfaceInstanceFromBridgedApIfaceInternal(
1010 const std::string& ifname, const std::string& ifInstanceName) {
1011 legacy_hal::wifi_error legacy_status;
1012 const auto iface = findUsingName(ap_ifaces_, ifname);
1013 if (!iface.get() || !ifInstanceName.empty()) {
1014 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
1015 }
1016 // Requires to remove one of the instance in bridge mode
1017 for (auto const& it : br_ifaces_ap_instances_) {
1018 if (it.first == ifname) {
1019 for (auto const& iface : it.second) {
1020 if (iface == ifInstanceName) {
1021 if (!iface_util_.lock()->removeIfaceFromBridge(it.first,
1022 iface)) {
1023 LOG(ERROR) << "Failed to remove interface: " << iface
1024 << " from " << ifname << ", error: "
1025 << legacyErrorToString(legacy_status);
1026 return createWifiStatus(
1027 WifiStatusCode::ERROR_NOT_AVAILABLE);
1028 }
1029 legacy_status =
1030 legacy_hal_.lock()->deleteVirtualInterface(iface);
1031 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1032 LOG(ERROR) << "Failed to del interface: " << iface
1033 << " " << legacyErrorToString(legacy_status);
1034 return createWifiStatusFromLegacyError(legacy_status);
1035 }
1036 }
1037 }
1038 break;
1039 }
1040 }
1041 br_ifaces_ap_instances_.erase(ifInstanceName);
1042 return createWifiStatus(WifiStatusCode::SUCCESS);
1043}
1044
Jimmy Chend460df32019-11-29 17:31:22 +02001045std::pair<WifiStatus, sp<V1_4::IWifiNanIface>>
1046WifiChip::createNanIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001047 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::NAN)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001048 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Etan Cohenc5700402017-03-08 16:43:38 -08001049 }
Roshan Pius5ba0a902020-04-14 11:55:42 -07001050 bool is_dedicated_iface = true;
1051 std::string ifname = getNanIfaceName();
Nate Jiang63f34ed2020-05-20 23:22:51 -07001052 if (ifname.empty() || !iface_util_.lock()->ifNameToIndex(ifname)) {
Roshan Pius5ba0a902020-04-14 11:55:42 -07001053 // Use the first shared STA iface (wlan0) if a dedicated aware iface is
1054 // not defined.
1055 ifname = getFirstActiveWlanIfaceName();
1056 is_dedicated_iface = false;
1057 }
1058 sp<WifiNanIface> iface =
1059 new WifiNanIface(ifname, is_dedicated_iface, legacy_hal_, iface_util_);
Roshan Piuscc338202017-11-02 13:54:09 -07001060 nan_ifaces_.push_back(iface);
1061 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1062 if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
1063 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1064 }
1065 }
1066 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001067}
1068
1069std::pair<WifiStatus, std::vector<hidl_string>>
1070WifiChip::getNanIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001071 if (nan_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001072 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1073 }
Roshan Pius675609b2017-10-31 14:24:58 -07001074 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(nan_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001075}
1076
Jimmy Chend460df32019-11-29 17:31:22 +02001077std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> WifiChip::getNanIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001078 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), nullptr};
1082 }
Roshan Pius675609b2017-10-31 14:24:58 -07001083 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001084}
1085
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001086WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001087 const auto iface = findUsingName(nan_ifaces_, ifname);
1088 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001089 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001090 }
Roshan Pius675609b2017-10-31 14:24:58 -07001091 invalidateAndClear(nan_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001092 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1093 if (!callback->onIfaceRemoved(IfaceType::NAN, ifname).isOk()) {
1094 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1095 }
1096 }
1097 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001098}
1099
Roshan Pius3c868522016-10-27 12:43:49 -07001100std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::createP2pIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001101 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::P2P)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001102 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001103 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001104 std::string ifname = getP2pIfaceName();
Roshan Pius675609b2017-10-31 14:24:58 -07001105 sp<WifiP2pIface> iface = new WifiP2pIface(ifname, legacy_hal_);
1106 p2p_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001107 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1108 if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) {
1109 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1110 }
1111 }
Roshan Pius675609b2017-10-31 14:24:58 -07001112 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001113}
1114
1115std::pair<WifiStatus, std::vector<hidl_string>>
1116WifiChip::getP2pIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001117 if (p2p_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001118 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1119 }
Roshan Pius675609b2017-10-31 14:24:58 -07001120 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(p2p_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001121}
1122
1123std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001124 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), nullptr};
1128 }
Roshan Pius675609b2017-10-31 14:24:58 -07001129 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001130}
1131
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001132WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001133 const auto iface = findUsingName(p2p_ifaces_, ifname);
1134 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001135 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001136 }
Roshan Pius675609b2017-10-31 14:24:58 -07001137 invalidateAndClear(p2p_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001138 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1139 if (!callback->onIfaceRemoved(IfaceType::P2P, ifname).isOk()) {
1140 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1141 }
1142 }
1143 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001144}
1145
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001146std::pair<WifiStatus, sp<V1_5::IWifiStaIface>>
Ahmed ElArabawyb23485d2019-12-09 15:24:16 -08001147WifiChip::createStaIfaceInternal() {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001148 if (!canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType::STA)) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001149 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
Roshan Piusbc662202017-01-30 17:07:42 -08001150 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001151 std::string ifname = allocateStaIfaceName();
Sunil Raviddab4bb2020-02-03 22:45:19 -08001152 legacy_hal::wifi_error legacy_status =
1153 legacy_hal_.lock()->createVirtualInterface(
1154 ifname,
1155 hidl_struct_util::convertHidlIfaceTypeToLegacy(IfaceType::STA));
1156 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1157 LOG(ERROR) << "Failed to add interface: " << ifname << " "
1158 << legacyErrorToString(legacy_status);
1159 return {createWifiStatusFromLegacyError(legacy_status), {}};
1160 }
Roshan Pius99dab382019-02-14 07:57:10 -08001161 sp<WifiStaIface> iface = new WifiStaIface(ifname, legacy_hal_, iface_util_);
Roshan Pius675609b2017-10-31 14:24:58 -07001162 sta_ifaces_.push_back(iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001163 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1164 if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
1165 LOG(ERROR) << "Failed to invoke onIfaceAdded callback";
1166 }
1167 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001168 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Pius675609b2017-10-31 14:24:58 -07001169 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001170}
1171
1172std::pair<WifiStatus, std::vector<hidl_string>>
1173WifiChip::getStaIfaceNamesInternal() {
Roshan Pius675609b2017-10-31 14:24:58 -07001174 if (sta_ifaces_.empty()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001175 return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
1176 }
Roshan Pius675609b2017-10-31 14:24:58 -07001177 return {createWifiStatus(WifiStatusCode::SUCCESS), getNames(sta_ifaces_)};
Roshan Pius3c868522016-10-27 12:43:49 -07001178}
1179
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001180std::pair<WifiStatus, sp<V1_5::IWifiStaIface>> WifiChip::getStaIfaceInternal(
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001181 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), nullptr};
1185 }
Roshan Pius675609b2017-10-31 14:24:58 -07001186 return {createWifiStatus(WifiStatusCode::SUCCESS), iface};
Roshan Pius3c868522016-10-27 12:43:49 -07001187}
1188
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001189WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) {
Roshan Pius675609b2017-10-31 14:24:58 -07001190 const auto iface = findUsingName(sta_ifaces_, ifname);
1191 if (!iface.get()) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001192 return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
Roshan Piusbc662202017-01-30 17:07:42 -08001193 }
Roshan Pius82368502019-05-16 12:53:02 -07001194 // Invalidate & remove any dependent objects first.
1195 invalidateAndRemoveDependencies(ifname);
Sunil Raviddab4bb2020-02-03 22:45:19 -08001196 legacy_hal::wifi_error legacy_status =
1197 legacy_hal_.lock()->deleteVirtualInterface(ifname);
1198 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1199 LOG(ERROR) << "Failed to remove interface: " << ifname << " "
1200 << legacyErrorToString(legacy_status);
1201 }
Roshan Pius675609b2017-10-31 14:24:58 -07001202 invalidateAndClear(sta_ifaces_, iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001203 for (const auto& callback : event_cb_handler_.getCallbacks()) {
1204 if (!callback->onIfaceRemoved(IfaceType::STA, ifname).isOk()) {
1205 LOG(ERROR) << "Failed to invoke onIfaceRemoved callback";
1206 }
1207 }
Roshan Pius8574e7f2019-04-01 13:30:40 -07001208 setActiveWlanIfaceNameProperty(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001209 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius8b55e6f2016-12-09 12:05:12 -08001210}
1211
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001212std::pair<WifiStatus, sp<V1_0::IWifiRttController>>
1213WifiChip::createRttControllerInternal(const sp<IWifiIface>& /*bound_iface*/) {
1214 LOG(ERROR) << "createRttController is not supported on this HAL";
Ahmed ElArabawy36defb32019-12-29 21:24:27 -08001215 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), {}};
Roshan Pius3c868522016-10-27 12:43:49 -07001216}
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001217
1218std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
1219WifiChip::getDebugRingBuffersStatusInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001220 legacy_hal::wifi_error legacy_status;
1221 std::vector<legacy_hal::wifi_ring_buffer_status>
1222 legacy_ring_buffer_status_vec;
1223 std::tie(legacy_status, legacy_ring_buffer_status_vec) =
Roshan Pius6036c022019-03-27 10:41:58 -07001224 legacy_hal_.lock()->getRingBuffersStatus(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001225 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1226 return {createWifiStatusFromLegacyError(legacy_status), {}};
1227 }
1228 std::vector<WifiDebugRingBufferStatus> hidl_ring_buffer_status_vec;
1229 if (!hidl_struct_util::convertLegacyVectorOfDebugRingBufferStatusToHidl(
1230 legacy_ring_buffer_status_vec, &hidl_ring_buffer_status_vec)) {
1231 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1232 }
1233 return {createWifiStatus(WifiStatusCode::SUCCESS),
1234 hidl_ring_buffer_status_vec};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001235}
1236
1237WifiStatus WifiChip::startLoggingToDebugRingBufferInternal(
Roshan Piusabcf78f2017-10-06 16:30:38 -07001238 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
1239 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes) {
1240 WifiStatus status = registerDebugRingBufferCallback();
1241 if (status.code != WifiStatusCode::SUCCESS) {
1242 return status;
1243 }
1244 legacy_hal::wifi_error legacy_status =
1245 legacy_hal_.lock()->startRingBufferLogging(
Roshan Pius6036c022019-03-27 10:41:58 -07001246 getFirstActiveWlanIfaceName(), ring_name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001247 static_cast<
1248 std::underlying_type<WifiDebugRingBufferVerboseLevel>::type>(
1249 verbose_level),
1250 max_interval_in_sec, min_data_size_in_bytes);
xshu5899e8e2018-01-09 15:36:03 -08001251 ringbuffer_map_.insert(std::pair<std::string, Ringbuffer>(
1252 ring_name, Ringbuffer(kMaxBufferSizeBytes)));
Roshan Piusa63b53f2019-11-18 11:03:13 -08001253 // if verbose logging enabled, turn up HAL daemon logging as well.
1254 if (verbose_level < WifiDebugRingBufferVerboseLevel::VERBOSE) {
1255 android::base::SetMinimumLogSeverity(android::base::DEBUG);
1256 } else {
1257 android::base::SetMinimumLogSeverity(android::base::VERBOSE);
1258 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001259 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001260}
1261
1262WifiStatus WifiChip::forceDumpToDebugRingBufferInternal(
Roshan Piuse2d0ab52016-12-05 15:24:20 -08001263 const hidl_string& ring_name) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001264 WifiStatus status = registerDebugRingBufferCallback();
1265 if (status.code != WifiStatusCode::SUCCESS) {
1266 return status;
1267 }
1268 legacy_hal::wifi_error legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001269 legacy_hal_.lock()->getRingBufferData(getFirstActiveWlanIfaceName(),
1270 ring_name);
xshu5899e8e2018-01-09 15:36:03 -08001271
Roshan Piusabcf78f2017-10-06 16:30:38 -07001272 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001273}
1274
Roger Wangb294c762018-11-02 15:34:39 +08001275WifiStatus WifiChip::flushRingBufferToFileInternal() {
1276 if (!writeRingbufferFilesInternal()) {
1277 LOG(ERROR) << "Error writing files to flash";
1278 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1279 }
1280 return createWifiStatus(WifiStatusCode::SUCCESS);
1281}
1282
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001283WifiStatus WifiChip::stopLoggingToDebugRingBufferInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001284 legacy_hal::wifi_error legacy_status =
1285 legacy_hal_.lock()->deregisterRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001286 getFirstActiveWlanIfaceName());
xshu0a0fe512020-07-22 17:53:37 -07001287 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1288 debug_ring_buffer_cb_registered_ = false;
1289 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001290 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius8c0c8e92017-02-24 08:07:42 -08001291}
1292
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001293std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
1294WifiChip::getDebugHostWakeReasonStatsInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001295 legacy_hal::wifi_error legacy_status;
1296 legacy_hal::WakeReasonStats legacy_stats;
1297 std::tie(legacy_status, legacy_stats) =
Roshan Pius6036c022019-03-27 10:41:58 -07001298 legacy_hal_.lock()->getWakeReasonStats(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001299 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1300 return {createWifiStatusFromLegacyError(legacy_status), {}};
1301 }
1302 WifiDebugHostWakeReasonStats hidl_stats;
1303 if (!hidl_struct_util::convertLegacyWakeReasonStatsToHidl(legacy_stats,
1304 &hidl_stats)) {
1305 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), {}};
1306 }
1307 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_stats};
Roshan Pius7d08d7a2016-10-27 14:35:05 -07001308}
1309
Roshan Pius203cb032016-12-14 17:41:20 -08001310WifiStatus WifiChip::enableDebugErrorAlertsInternal(bool enable) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001311 legacy_hal::wifi_error legacy_status;
1312 if (enable) {
1313 android::wp<WifiChip> weak_ptr_this(this);
1314 const auto& on_alert_callback = [weak_ptr_this](
1315 int32_t error_code,
1316 std::vector<uint8_t> debug_data) {
1317 const auto shared_ptr_this = weak_ptr_this.promote();
1318 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1319 LOG(ERROR) << "Callback invoked on an invalid object";
1320 return;
1321 }
1322 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
1323 if (!callback->onDebugErrorAlert(error_code, debug_data)
1324 .isOk()) {
1325 LOG(ERROR) << "Failed to invoke onDebugErrorAlert callback";
1326 }
1327 }
1328 };
1329 legacy_status = legacy_hal_.lock()->registerErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001330 getFirstActiveWlanIfaceName(), on_alert_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -07001331 } else {
1332 legacy_status = legacy_hal_.lock()->deregisterErrorAlertCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001333 getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001334 }
1335 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius203cb032016-12-14 17:41:20 -08001336}
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001337
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001338WifiStatus WifiChip::selectTxPowerScenarioInternal(
Jong Wook Kimda830c92018-07-23 15:29:38 -07001339 V1_1::IWifiChip::TxPowerScenario scenario) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001340 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001341 getFirstActiveWlanIfaceName(),
Roshan Piusabcf78f2017-10-06 16:30:38 -07001342 hidl_struct_util::convertHidlTxPowerScenarioToLegacy(scenario));
1343 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001344}
1345
Roshan Pius735ff432017-07-25 08:48:08 -07001346WifiStatus WifiChip::resetTxPowerScenarioInternal() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001347 auto legacy_status =
Roshan Pius6036c022019-03-27 10:41:58 -07001348 legacy_hal_.lock()->resetTxPowerScenario(getFirstActiveWlanIfaceName());
Roshan Piusabcf78f2017-10-06 16:30:38 -07001349 return createWifiStatusFromLegacyError(legacy_status);
Roshan Piusdbd83ef2017-06-20 12:05:40 -07001350}
1351
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001352WifiStatus WifiChip::setLatencyModeInternal(LatencyMode mode) {
1353 auto legacy_status = legacy_hal_.lock()->setLatencyMode(
Roshan Pius6036c022019-03-27 10:41:58 -07001354 getFirstActiveWlanIfaceName(),
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -07001355 hidl_struct_util::convertHidlLatencyModeToLegacy(mode));
1356 return createWifiStatusFromLegacyError(legacy_status);
1357}
1358
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001359WifiStatus WifiChip::registerEventCallbackInternal_1_2(
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001360 const sp<V1_2::IWifiChipEventCallback>& /* event_callback */) {
1361 // Deprecated support for this callback.
1362 return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
Roshan Pius1ce92cf2018-01-22 16:12:19 -08001363}
1364
Jong Wook Kimda830c92018-07-23 15:29:38 -07001365WifiStatus WifiChip::selectTxPowerScenarioInternal_1_2(
1366 TxPowerScenario scenario) {
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001367 auto legacy_status = legacy_hal_.lock()->selectTxPowerScenario(
Roshan Pius6036c022019-03-27 10:41:58 -07001368 getFirstActiveWlanIfaceName(),
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -08001369 hidl_struct_util::convertHidlTxPowerScenarioToLegacy_1_2(scenario));
1370 return createWifiStatusFromLegacyError(legacy_status);
1371}
1372
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001373std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_3() {
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001374 // Deprecated support for this callback.
1375 return {createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED), 0};
1376}
1377
1378std::pair<WifiStatus, uint32_t> WifiChip::getCapabilitiesInternal_1_5() {
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001379 legacy_hal::wifi_error legacy_status;
Jimmy Chen1bdf1a72019-12-23 17:53:40 +02001380 uint64_t legacy_feature_set;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001381 uint32_t legacy_logger_feature_set;
1382 const auto ifname = getFirstActiveWlanIfaceName();
1383 std::tie(legacy_status, legacy_feature_set) =
1384 legacy_hal_.lock()->getSupportedFeatureSet(ifname);
1385 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1386 return {createWifiStatusFromLegacyError(legacy_status), 0};
1387 }
1388 std::tie(legacy_status, legacy_logger_feature_set) =
1389 legacy_hal_.lock()->getLoggerSupportedFeatureSet(ifname);
1390 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1391 // some devices don't support querying logger feature set
1392 legacy_logger_feature_set = 0;
1393 }
1394 uint32_t hidl_caps;
1395 if (!hidl_struct_util::convertLegacyFeaturesToHidlChipCapabilities(
1396 legacy_feature_set, legacy_logger_feature_set, &hidl_caps)) {
1397 return {createWifiStatus(WifiStatusCode::ERROR_UNKNOWN), 0};
1398 }
1399 return {createWifiStatus(WifiStatusCode::SUCCESS), hidl_caps};
1400}
1401
Jimmy Chend460df32019-11-29 17:31:22 +02001402std::pair<WifiStatus, sp<V1_4::IWifiRttController>>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -07001403WifiChip::createRttControllerInternal_1_4(const sp<IWifiIface>& bound_iface) {
1404 if (sta_ifaces_.size() == 0 &&
1405 !canCurrentModeSupportIfaceOfType(IfaceType::STA)) {
1406 LOG(ERROR)
1407 << "createRttControllerInternal_1_4: Chip cannot support STAs "
1408 "(and RTT by extension)";
1409 return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
1410 }
1411 sp<WifiRttController> rtt = new WifiRttController(
1412 getFirstActiveWlanIfaceName(), bound_iface, legacy_hal_);
1413 rtt_controllers_.emplace_back(rtt);
1414 return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
1415}
1416
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001417WifiStatus WifiChip::registerEventCallbackInternal_1_4(
Jimmy Chend460df32019-11-29 17:31:22 +02001418 const sp<V1_4::IWifiChipEventCallback>& event_callback) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001419 if (!event_cb_handler_.addCallback(event_callback)) {
1420 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1421 }
1422 return createWifiStatus(WifiStatusCode::SUCCESS);
1423}
1424
Roshan Piuse9d1e7d2020-11-04 11:44:16 -08001425WifiStatus WifiChip::setMultiStaPrimaryConnectionInternal(
1426 const std::string& ifname) {
1427 auto legacy_status =
1428 legacy_hal_.lock()->multiStaSetPrimaryConnection(ifname);
1429 return createWifiStatusFromLegacyError(legacy_status);
1430}
1431
1432WifiStatus WifiChip::setMultiStaUseCaseInternal(MultiStaUseCase use_case) {
1433 auto legacy_status = legacy_hal_.lock()->multiStaSetUseCase(
1434 hidl_struct_util::convertHidlMultiStaUseCaseToLegacy(use_case));
1435 return createWifiStatusFromLegacyError(legacy_status);
1436}
1437
Roshan Piusba38d9c2017-12-08 07:32:08 -08001438WifiStatus WifiChip::handleChipConfiguration(
1439 /* NONNULL */ std::unique_lock<std::recursive_mutex>* lock,
1440 ChipModeId mode_id) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001441 // If the chip is already configured in a different mode, stop
1442 // the legacy HAL and then start it after firmware mode change.
Roshan Piuscc338202017-11-02 13:54:09 -07001443 if (isValidModeId(current_mode_id_)) {
Roshan Piusba38d9c2017-12-08 07:32:08 -08001444 LOG(INFO) << "Reconfiguring chip from mode " << current_mode_id_
1445 << " to mode " << mode_id;
1446 invalidateAndRemoveAllIfaces();
1447 legacy_hal::wifi_error legacy_status =
1448 legacy_hal_.lock()->stop(lock, []() {});
1449 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1450 LOG(ERROR) << "Failed to stop legacy HAL: "
1451 << legacyErrorToString(legacy_status);
1452 return createWifiStatusFromLegacyError(legacy_status);
1453 }
Roshan Piusabcf78f2017-10-06 16:30:38 -07001454 }
Roshan Piuscc338202017-11-02 13:54:09 -07001455 // Firmware mode change not needed for V2 devices.
1456 bool success = true;
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001457 if (mode_id == feature_flags::chip_mode_ids::kV1Sta) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001458 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::STA);
Tomasz Wasilczykb424da72018-11-15 11:52:57 -08001459 } else if (mode_id == feature_flags::chip_mode_ids::kV1Ap) {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001460 success = mode_controller_.lock()->changeFirmwareMode(IfaceType::AP);
1461 }
1462 if (!success) {
1463 return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
1464 }
1465 legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->start();
1466 if (legacy_status != legacy_hal::WIFI_SUCCESS) {
1467 LOG(ERROR) << "Failed to start legacy HAL: "
1468 << legacyErrorToString(legacy_status);
1469 return createWifiStatusFromLegacyError(legacy_status);
1470 }
Roshan Pius85c64412018-01-22 17:58:40 -08001471 // Every time the HAL is restarted, we need to register the
1472 // radio mode change callback.
1473 WifiStatus status = registerRadioModeChangeCallback();
1474 if (status.code != WifiStatusCode::SUCCESS) {
1475 // This probably is not a critical failure?
1476 LOG(ERROR) << "Failed to register radio mode change callback";
1477 }
chenpaulf5eca292019-03-14 11:08:03 +08001478 // Extract and save the version information into property.
Jimmy Chend460df32019-11-29 17:31:22 +02001479 std::pair<WifiStatus, V1_4::IWifiChip::ChipDebugInfo> version_info;
chenpaulf5eca292019-03-14 11:08:03 +08001480 version_info = WifiChip::requestChipDebugInfoInternal();
1481 if (WifiStatusCode::SUCCESS == version_info.first.code) {
1482 property_set("vendor.wlan.firmware.version",
1483 version_info.second.firmwareDescription.c_str());
1484 property_set("vendor.wlan.driver.version",
1485 version_info.second.driverDescription.c_str());
1486 }
1487
Roshan Piusabcf78f2017-10-06 16:30:38 -07001488 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius2c06a3f2016-12-15 17:51:40 -08001489}
Roshan Pius48185b22016-12-15 19:10:30 -08001490
1491WifiStatus WifiChip::registerDebugRingBufferCallback() {
Roshan Piusabcf78f2017-10-06 16:30:38 -07001492 if (debug_ring_buffer_cb_registered_) {
1493 return createWifiStatus(WifiStatusCode::SUCCESS);
Roshan Pius48185b22016-12-15 19:10:30 -08001494 }
Roshan Pius3797e182017-03-30 18:01:54 -07001495
Roshan Piusabcf78f2017-10-06 16:30:38 -07001496 android::wp<WifiChip> weak_ptr_this(this);
1497 const auto& on_ring_buffer_data_callback =
xshu5899e8e2018-01-09 15:36:03 -08001498 [weak_ptr_this](const std::string& name,
Roshan Piusabcf78f2017-10-06 16:30:38 -07001499 const std::vector<uint8_t>& data,
1500 const legacy_hal::wifi_ring_buffer_status& status) {
1501 const auto shared_ptr_this = weak_ptr_this.promote();
1502 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1503 LOG(ERROR) << "Callback invoked on an invalid object";
1504 return;
1505 }
1506 WifiDebugRingBufferStatus hidl_status;
1507 if (!hidl_struct_util::convertLegacyDebugRingBufferStatusToHidl(
1508 status, &hidl_status)) {
1509 LOG(ERROR) << "Error converting ring buffer status";
1510 return;
1511 }
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301512 {
1513 std::unique_lock<std::mutex> lk(shared_ptr_this->lock_t);
1514 const auto& target =
1515 shared_ptr_this->ringbuffer_map_.find(name);
1516 if (target != shared_ptr_this->ringbuffer_map_.end()) {
1517 Ringbuffer& cur_buffer = target->second;
1518 cur_buffer.append(data);
1519 } else {
1520 LOG(ERROR) << "Ringname " << name << " not found";
1521 return;
1522 }
xshu0a0fe512020-07-22 17:53:37 -07001523 // unique_lock unlocked here
Roshan Piusabcf78f2017-10-06 16:30:38 -07001524 }
1525 };
1526 legacy_hal::wifi_error legacy_status =
1527 legacy_hal_.lock()->registerRingBufferCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001528 getFirstActiveWlanIfaceName(), on_ring_buffer_data_callback);
Roshan Pius48185b22016-12-15 19:10:30 -08001529
Roshan Piusabcf78f2017-10-06 16:30:38 -07001530 if (legacy_status == legacy_hal::WIFI_SUCCESS) {
1531 debug_ring_buffer_cb_registered_ = true;
1532 }
1533 return createWifiStatusFromLegacyError(legacy_status);
Roshan Pius48185b22016-12-15 19:10:30 -08001534}
1535
Roshan Pius85c64412018-01-22 17:58:40 -08001536WifiStatus WifiChip::registerRadioModeChangeCallback() {
1537 android::wp<WifiChip> weak_ptr_this(this);
1538 const auto& on_radio_mode_change_callback =
1539 [weak_ptr_this](const std::vector<legacy_hal::WifiMacInfo>& mac_infos) {
1540 const auto shared_ptr_this = weak_ptr_this.promote();
1541 if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
1542 LOG(ERROR) << "Callback invoked on an invalid object";
1543 return;
1544 }
Jimmy Chend460df32019-11-29 17:31:22 +02001545 std::vector<V1_4::IWifiChipEventCallback::RadioModeInfo>
Roshan Pius85c64412018-01-22 17:58:40 -08001546 hidl_radio_mode_infos;
1547 if (!hidl_struct_util::convertLegacyWifiMacInfosToHidl(
1548 mac_infos, &hidl_radio_mode_infos)) {
1549 LOG(ERROR) << "Error converting wifi mac info";
1550 return;
1551 }
1552 for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001553 if (!callback->onRadioModeChange_1_4(hidl_radio_mode_infos)
Roshan Pius85c64412018-01-22 17:58:40 -08001554 .isOk()) {
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -08001555 LOG(ERROR) << "Failed to invoke onRadioModeChange_1_4"
Roshan Pius85c64412018-01-22 17:58:40 -08001556 << " callback on: " << toString(callback);
1557 }
1558 }
1559 };
1560 legacy_hal::wifi_error legacy_status =
1561 legacy_hal_.lock()->registerRadioModeChangeCallbackHandler(
Roshan Pius6036c022019-03-27 10:41:58 -07001562 getFirstActiveWlanIfaceName(), on_radio_mode_change_callback);
Roshan Pius85c64412018-01-22 17:58:40 -08001563 return createWifiStatusFromLegacyError(legacy_status);
1564}
1565
Jimmy Chend460df32019-11-29 17:31:22 +02001566std::vector<V1_4::IWifiChip::ChipIfaceCombination>
Roshan Piuscc338202017-11-02 13:54:09 -07001567WifiChip::getCurrentModeIfaceCombinations() {
1568 if (!isValidModeId(current_mode_id_)) {
1569 LOG(ERROR) << "Chip not configured in a mode yet";
1570 return {};
1571 }
1572 for (const auto& mode : modes_) {
1573 if (mode.id == current_mode_id_) {
1574 return mode.availableCombinations;
1575 }
1576 }
1577 CHECK(0) << "Expected to find iface combinations for current mode!";
1578 return {};
1579}
1580
1581// Returns a map indexed by IfaceType with the number of ifaces currently
1582// created of the corresponding type.
1583std::map<IfaceType, size_t> WifiChip::getCurrentIfaceCombination() {
1584 std::map<IfaceType, size_t> iface_counts;
1585 iface_counts[IfaceType::AP] = ap_ifaces_.size();
1586 iface_counts[IfaceType::NAN] = nan_ifaces_.size();
1587 iface_counts[IfaceType::P2P] = p2p_ifaces_.size();
1588 iface_counts[IfaceType::STA] = sta_ifaces_.size();
1589 return iface_counts;
1590}
1591
1592// This expands the provided iface combinations to a more parseable
1593// form. Returns a vector of available combinations possible with the number
1594// of ifaces of each type in the combination.
1595// This method is a port of HalDeviceManager.expandIfaceCombos() from framework.
1596std::vector<std::map<IfaceType, size_t>> WifiChip::expandIfaceCombinations(
Jimmy Chend460df32019-11-29 17:31:22 +02001597 const V1_4::IWifiChip::ChipIfaceCombination& combination) {
Roshan Piuscc338202017-11-02 13:54:09 -07001598 uint32_t num_expanded_combos = 1;
1599 for (const auto& limit : combination.limits) {
1600 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1601 num_expanded_combos *= limit.types.size();
1602 }
1603 }
1604
1605 // Allocate the vector of expanded combos and reset all iface counts to 0
1606 // in each combo.
1607 std::vector<std::map<IfaceType, size_t>> expanded_combos;
1608 expanded_combos.resize(num_expanded_combos);
1609 for (auto& expanded_combo : expanded_combos) {
1610 for (const auto type :
1611 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1612 expanded_combo[type] = 0;
1613 }
1614 }
1615 uint32_t span = num_expanded_combos;
1616 for (const auto& limit : combination.limits) {
1617 for (uint32_t i = 0; i < limit.maxIfaces; i++) {
1618 span /= limit.types.size();
1619 for (uint32_t k = 0; k < num_expanded_combos; ++k) {
1620 const auto iface_type =
1621 limit.types[(k / span) % limit.types.size()];
1622 expanded_combos[k][iface_type]++;
1623 }
1624 }
1625 }
1626 return expanded_combos;
1627}
1628
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001629bool WifiChip::canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1630 const std::map<IfaceType, size_t>& expanded_combo,
1631 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001632 const auto current_combo = getCurrentIfaceCombination();
1633
1634 // Check if we have space for 1 more iface of |type| in this combo
1635 for (const auto type :
1636 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1637 size_t num_ifaces_needed = current_combo.at(type);
1638 if (type == requested_type) {
1639 num_ifaces_needed++;
1640 }
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001641 size_t num_ifaces_allowed = expanded_combo.at(type);
Roshan Piuscc338202017-11-02 13:54:09 -07001642 if (num_ifaces_needed > num_ifaces_allowed) {
1643 return false;
1644 }
1645 }
1646 return true;
1647}
1648
1649// This method does the following:
1650// a) Enumerate all possible iface combos by expanding the current
1651// ChipIfaceCombination.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001652// b) Check if the requested iface type can be added to the current mode
1653// with the iface combination that is already active.
1654bool WifiChip::canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(
1655 IfaceType requested_type) {
Roshan Piuscc338202017-11-02 13:54:09 -07001656 if (!isValidModeId(current_mode_id_)) {
1657 LOG(ERROR) << "Chip not configured in a mode yet";
1658 return false;
1659 }
1660 const auto combinations = getCurrentModeIfaceCombinations();
1661 for (const auto& combination : combinations) {
1662 const auto expanded_combos = expandIfaceCombinations(combination);
1663 for (const auto& expanded_combo : expanded_combos) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001664 if (canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
1665 expanded_combo, requested_type)) {
Roshan Piuscc338202017-11-02 13:54:09 -07001666 return true;
1667 }
1668 }
1669 }
1670 return false;
1671}
1672
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001673// Note: This does not consider ifaces already active. It only checks if the
1674// provided expanded iface combination can support the requested combo.
1675bool WifiChip::canExpandedIfaceComboSupportIfaceCombo(
1676 const std::map<IfaceType, size_t>& expanded_combo,
1677 const std::map<IfaceType, size_t>& req_combo) {
1678 // Check if we have space for 1 more iface of |type| in this combo
1679 for (const auto type :
1680 {IfaceType::AP, IfaceType::NAN, IfaceType::P2P, IfaceType::STA}) {
1681 if (req_combo.count(type) == 0) {
1682 // Iface of "type" not in the req_combo.
1683 continue;
1684 }
1685 size_t num_ifaces_needed = req_combo.at(type);
1686 size_t num_ifaces_allowed = expanded_combo.at(type);
1687 if (num_ifaces_needed > num_ifaces_allowed) {
1688 return false;
1689 }
1690 }
1691 return true;
1692}
1693// This method does the following:
1694// a) Enumerate all possible iface combos by expanding the current
1695// ChipIfaceCombination.
1696// b) Check if the requested iface combo can be added to the current mode.
1697// Note: This does not consider ifaces already active. It only checks if the
1698// current mode can support the requested combo.
1699bool WifiChip::canCurrentModeSupportIfaceCombo(
1700 const std::map<IfaceType, size_t>& req_combo) {
1701 if (!isValidModeId(current_mode_id_)) {
1702 LOG(ERROR) << "Chip not configured in a mode yet";
1703 return false;
1704 }
1705 const auto combinations = getCurrentModeIfaceCombinations();
1706 for (const auto& combination : combinations) {
1707 const auto expanded_combos = expandIfaceCombinations(combination);
1708 for (const auto& expanded_combo : expanded_combos) {
1709 if (canExpandedIfaceComboSupportIfaceCombo(expanded_combo,
1710 req_combo)) {
1711 return true;
1712 }
1713 }
1714 }
1715 return false;
1716}
1717
1718// This method does the following:
1719// a) Enumerate all possible iface combos by expanding the current
1720// ChipIfaceCombination.
1721// b) Check if the requested iface type can be added to the current mode.
1722bool WifiChip::canCurrentModeSupportIfaceOfType(IfaceType requested_type) {
1723 // Check if we can support atleast 1 iface of type.
1724 std::map<IfaceType, size_t> req_iface_combo;
1725 req_iface_combo[requested_type] = 1;
1726 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1727}
1728
Roshan Piuscc338202017-11-02 13:54:09 -07001729bool WifiChip::isValidModeId(ChipModeId mode_id) {
1730 for (const auto& mode : modes_) {
1731 if (mode.id == mode_id) {
1732 return true;
1733 }
1734 }
1735 return false;
1736}
1737
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001738bool WifiChip::isStaApConcurrencyAllowedInCurrentMode() {
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] = 1;
1742 req_iface_combo[IfaceType::STA] = 1;
1743 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1744}
1745
James Mattisd2e4c072019-05-22 16:14:48 -07001746bool WifiChip::isDualApAllowedInCurrentMode() {
1747 // Check if we can support atleast 1 STA & 1 AP concurrently.
1748 std::map<IfaceType, size_t> req_iface_combo;
1749 req_iface_combo[IfaceType::AP] = 2;
1750 return canCurrentModeSupportIfaceCombo(req_iface_combo);
1751}
1752
Roshan Pius6036c022019-03-27 10:41:58 -07001753std::string WifiChip::getFirstActiveWlanIfaceName() {
Roshan Pius444473f2019-04-19 08:41:20 -07001754 if (sta_ifaces_.size() > 0) return sta_ifaces_[0]->getName();
1755 if (ap_ifaces_.size() > 0) return ap_ifaces_[0]->getName();
Roshan Pius6036c022019-03-27 10:41:58 -07001756 // This could happen if the chip call is made before any STA/AP
1757 // iface is created. Default to wlan0 for such cases.
Roshan Pius444473f2019-04-19 08:41:20 -07001758 LOG(WARNING) << "No active wlan interfaces in use! Using default";
Jimmy Chen2dddd792019-12-23 17:50:39 +02001759 return getWlanIfaceNameWithType(IfaceType::STA, 0);
Roshan Pius6036c022019-03-27 10:41:58 -07001760}
1761
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001762// Return the first wlan (wlan0, wlan1 etc.) starting from |start_idx|
1763// not already in use.
1764// Note: This doesn't check the actual presence of these interfaces.
Jimmy Chen2dddd792019-12-23 17:50:39 +02001765std::string WifiChip::allocateApOrStaIfaceName(IfaceType type,
1766 uint32_t start_idx) {
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001767 for (unsigned idx = start_idx; idx < kMaxWlanIfaces; idx++) {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001768 const auto ifname = getWlanIfaceNameWithType(type, idx);
lesl94d28242020-11-18 22:17:37 +08001769 if (findUsingNameFromBridgedApInstances(ifname)) continue;
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001770 if (findUsingName(ap_ifaces_, ifname)) continue;
1771 if (findUsingName(sta_ifaces_, ifname)) continue;
1772 return ifname;
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001773 }
1774 // This should never happen. We screwed up somewhere if it did.
Tomasz Wasilczyk77401d32018-12-20 12:42:54 -08001775 CHECK(false) << "All wlan interfaces in use already!";
Roshan Pius8e3c7ef2017-11-03 09:43:08 -07001776 return {};
1777}
1778
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001779// AP iface names start with idx 1 for modes supporting
James Mattisd2e4c072019-05-22 16:14:48 -07001780// concurrent STA and not dual AP, else start with idx 0.
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001781std::string WifiChip::allocateApIfaceName() {
Roshan Pius78cb5992020-04-30 12:39:21 -07001782 // Check if we have a dedicated iface for AP.
1783 std::string ifname = getApIfaceName();
1784 if (!ifname.empty()) {
1785 return ifname;
1786 }
Jimmy Chen2dddd792019-12-23 17:50:39 +02001787 return allocateApOrStaIfaceName(IfaceType::AP,
1788 (isStaApConcurrencyAllowedInCurrentMode() &&
James Mattisd2e4c072019-05-22 16:14:48 -07001789 !isDualApAllowedInCurrentMode())
1790 ? 1
1791 : 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001792}
1793
1794// STA iface names start with idx 0.
1795// Primary STA iface will always be 0.
1796std::string WifiChip::allocateStaIfaceName() {
Jimmy Chen2dddd792019-12-23 17:50:39 +02001797 return allocateApOrStaIfaceName(IfaceType::STA, 0);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -07001798}
1799
xshu5899e8e2018-01-09 15:36:03 -08001800bool WifiChip::writeRingbufferFilesInternal() {
1801 if (!removeOldFilesInternal()) {
1802 LOG(ERROR) << "Error occurred while deleting old tombstone files";
1803 return false;
1804 }
1805 // write ringbuffers to file
Veerendranath Jakkam25b3a6f2020-04-14 22:04:39 +05301806 {
1807 std::unique_lock<std::mutex> lk(lock_t);
1808 for (const auto& item : ringbuffer_map_) {
1809 const Ringbuffer& cur_buffer = item.second;
1810 if (cur_buffer.getData().empty()) {
1811 continue;
1812 }
1813 const std::string file_path_raw =
1814 kTombstoneFolderPath + item.first + "XXXXXXXXXX";
1815 const int dump_fd = mkstemp(makeCharVec(file_path_raw).data());
1816 if (dump_fd == -1) {
1817 PLOG(ERROR) << "create file failed";
1818 return false;
1819 }
1820 unique_fd file_auto_closer(dump_fd);
1821 for (const auto& cur_block : cur_buffer.getData()) {
1822 if (write(dump_fd, cur_block.data(),
1823 sizeof(cur_block[0]) * cur_block.size()) == -1) {
1824 PLOG(ERROR) << "Error writing to file";
1825 }
xshu5899e8e2018-01-09 15:36:03 -08001826 }
1827 }
xshu0a0fe512020-07-22 17:53:37 -07001828 // unique_lock unlocked here
xshu5899e8e2018-01-09 15:36:03 -08001829 }
1830 return true;
1831}
1832
Jimmy Chen2dddd792019-12-23 17:50:39 +02001833std::string WifiChip::getWlanIfaceNameWithType(IfaceType type, unsigned idx) {
1834 std::string ifname;
1835
1836 // let the legacy hal override the interface name
1837 legacy_hal::wifi_error err =
1838 legacy_hal_.lock()->getSupportedIfaceName((uint32_t)type, ifname);
1839 if (err == legacy_hal::WIFI_SUCCESS) return ifname;
1840
1841 return getWlanIfaceName(idx);
1842}
1843
lesl94d28242020-11-18 22:17:37 +08001844void WifiChip::invalidateAndClearBridgedApAll() {
1845 for (auto const& it : br_ifaces_ap_instances_) {
1846 for (auto const& iface : it.second) {
1847 iface_util_.lock()->removeIfaceFromBridge(it.first, iface);
1848 legacy_hal_.lock()->deleteVirtualInterface(iface);
1849 }
1850 iface_util_.lock()->deleteBridge(it.first);
1851 }
1852 br_ifaces_ap_instances_.clear();
1853}
1854
1855void WifiChip::invalidateAndClearBridgedAp(const std::string& br_name) {
1856 if (br_name.empty()) return;
1857 // delete managed interfaces
1858 for (auto const& it : br_ifaces_ap_instances_) {
1859 if (it.first == br_name) {
1860 for (auto const& iface : it.second) {
1861 iface_util_.lock()->removeIfaceFromBridge(br_name, iface);
1862 legacy_hal_.lock()->deleteVirtualInterface(iface);
1863 }
1864 iface_util_.lock()->deleteBridge(br_name);
1865 br_ifaces_ap_instances_.erase(br_name);
1866 break;
1867 }
1868 }
1869 return;
1870}
1871
1872bool WifiChip::findUsingNameFromBridgedApInstances(const std::string& name) {
1873 for (auto const& it : br_ifaces_ap_instances_) {
1874 if (it.first == name) {
1875 return true;
1876 }
1877 for (auto const& iface : it.second) {
1878 if (iface == name) {
1879 return true;
1880 }
1881 }
1882 }
1883 return false;
1884}
1885
Roshan Pius79a99752016-10-04 13:03:58 -07001886} // namespace implementation
Jimmy Chend460df32019-11-29 17:31:22 +02001887} // namespace V1_5
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001888} // namespace wifi
1889} // namespace hardware
1890} // namespace android