blob: d5dc80253f84004bba1f12b069b96b51fb32523a [file] [log] [blame]
Gabriel Biren57ededa2021-09-03 16:08:50 +00001/*
2 * WPA Supplicant - Supplicant Aidl interface
3 * Copyright (c) 2021, Google Inc. All rights reserved.
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "aidl_manager.h"
10#include "aidl_return_util.h"
11#include "misc_utils.h"
12#include "supplicant.h"
13#include "p2p_iface.h"
14
15#include <android-base/file.h>
16#include <fcntl.h>
17#include <sys/stat.h>
18
19namespace {
20
21// Pre-populated interface params for interfaces controlled by wpa_supplicant.
22// Note: This may differ for other OEM's. So, modify this accordingly.
23constexpr char kIfaceDriverName[] = "nl80211";
Jooyung Han40d8f1a2024-02-22 13:30:57 +090024
Gabriel Biren57ededa2021-09-03 16:08:50 +000025constexpr char kStaIfaceConfPath[] =
26 "/data/vendor/wifi/wpa/wpa_supplicant.conf";
Jooyung Han40d8f1a2024-02-22 13:30:57 +090027constexpr char kStaIfaceConfOverlayPath[] =
28 "/vendor/etc/wifi/wpa_supplicant_overlay.conf";
29
Gabriel Biren57ededa2021-09-03 16:08:50 +000030constexpr char kP2pIfaceConfPath[] =
31 "/data/vendor/wifi/wpa/p2p_supplicant.conf";
Jooyung Han40d8f1a2024-02-22 13:30:57 +090032constexpr char kP2pIfaceConfOverlayPath[] =
33 "/vendor/etc/wifi/p2p_supplicant_overlay.conf";
34
Gabriel Biren57ededa2021-09-03 16:08:50 +000035// Migrate conf files for existing devices.
Jooyung Han40d8f1a2024-02-22 13:30:57 +090036constexpr char kSystemTemplateConfPath[] =
37 "/system/etc/wifi/wpa_supplicant.conf";
38constexpr char kVendorTemplateConfPath[] =
39 "/vendor/etc/wifi/wpa_supplicant.conf";
40
Gabriel Biren57ededa2021-09-03 16:08:50 +000041constexpr char kOldStaIfaceConfPath[] = "/data/misc/wifi/wpa_supplicant.conf";
42constexpr char kOldP2pIfaceConfPath[] = "/data/misc/wifi/p2p_supplicant.conf";
43constexpr mode_t kConfigFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
44
Gabriel Biren57ededa2021-09-03 16:08:50 +000045int copyFile(
46 const std::string& src_file_path, const std::string& dest_file_path)
47{
48 std::string file_contents;
49 if (!android::base::ReadFileToString(src_file_path, &file_contents)) {
50 wpa_printf(
51 MSG_ERROR, "Failed to read from %s. Errno: %s",
52 src_file_path.c_str(), strerror(errno));
53 return -1;
54 }
55 if (!android::base::WriteStringToFile(
56 file_contents, dest_file_path, kConfigFileMode, getuid(),
57 getgid())) {
58 wpa_printf(
59 MSG_ERROR, "Failed to write to %s. Errno: %s",
60 dest_file_path.c_str(), strerror(errno));
61 return -1;
62 }
63 return 0;
64}
65
66/**
67 * Copy |src_file_path| to |dest_file_path| if it exists.
68 *
69 * Returns 1 if |src_file_path| does not exist or not accessible,
70 * Returns -1 if the copy fails.
71 * Returns 0 if the copy succeeds.
72 */
73int copyFileIfItExists(
74 const std::string& src_file_path, const std::string& dest_file_path)
75{
76 int ret = access(src_file_path.c_str(), R_OK);
77 // Sepolicy denial (2018+ device) will return EACCESS instead of ENOENT.
78 if ((ret != 0) && ((errno == ENOENT) || (errno == EACCES))) {
79 return 1;
80 }
81 ret = copyFile(src_file_path, dest_file_path);
82 if (ret != 0) {
83 wpa_printf(
84 MSG_ERROR, "Failed copying %s to %s.",
85 src_file_path.c_str(), dest_file_path.c_str());
86 return -1;
87 }
88 return 0;
89}
90
91/**
92 * Ensure that the specified config file pointed by |config_file_path| exists.
93 * a) If the |config_file_path| exists with the correct permissions, return.
94 * b) If the |config_file_path| does not exist, but |old_config_file_path|
95 * exists, copy over the contents of the |old_config_file_path| to
96 * |config_file_path|.
97 * c) If the |config_file_path| & |old_config_file_path|
98 * does not exists, copy over the contents of |template_config_file_path|.
99 */
100int ensureConfigFileExists(
101 const std::string& config_file_path,
102 const std::string& old_config_file_path)
103{
104 int ret = access(config_file_path.c_str(), R_OK | W_OK);
105 if (ret == 0) {
106 return 0;
107 }
108 if (errno == EACCES) {
109 ret = chmod(config_file_path.c_str(), kConfigFileMode);
110 if (ret == 0) {
111 return 0;
112 } else {
113 wpa_printf(
114 MSG_ERROR, "Cannot set RW to %s. Errno: %s",
115 config_file_path.c_str(), strerror(errno));
116 return -1;
117 }
118 } else if (errno != ENOENT) {
119 wpa_printf(
120 MSG_ERROR, "Cannot acces %s. Errno: %s",
121 config_file_path.c_str(), strerror(errno));
122 return -1;
123 }
124 ret = copyFileIfItExists(old_config_file_path, config_file_path);
125 if (ret == 0) {
126 wpa_printf(
127 MSG_INFO, "Migrated conf file from %s to %s",
128 old_config_file_path.c_str(), config_file_path.c_str());
129 unlink(old_config_file_path.c_str());
130 return 0;
131 } else if (ret == -1) {
132 unlink(config_file_path.c_str());
133 return -1;
134 }
Jooyung Han40d8f1a2024-02-22 13:30:57 +0900135 ret = copyFileIfItExists(kVendorTemplateConfPath, config_file_path);
136 if (ret == 0) {
137 wpa_printf(
138 MSG_INFO, "Copied template conf file from %s to %s",
139 kVendorTemplateConfPath, config_file_path.c_str());
140 return 0;
141 } else if (ret == -1) {
142 unlink(config_file_path.c_str());
143 return -1;
144 }
145 ret = copyFileIfItExists(kSystemTemplateConfPath, config_file_path);
146 if (ret == 0) {
147 wpa_printf(
148 MSG_INFO, "Copied template conf file from %s to %s",
149 kSystemTemplateConfPath, config_file_path.c_str());
150 return 0;
151 } else if (ret == -1) {
152 unlink(config_file_path.c_str());
153 return -1;
Gabriel Biren57ededa2021-09-03 16:08:50 +0000154 }
155 // Did not create the conf file.
156 return -1;
157}
158} // namespace
159
160namespace aidl {
161namespace android {
162namespace hardware {
163namespace wifi {
164namespace supplicant {
165using aidl_return_util::validateAndCall;
166using misc_utils::createStatus;
167using misc_utils::createStatusWithMsg;
168
169Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
170bool Supplicant::isValid()
171{
172 // This top level object cannot be invalidated.
173 return true;
174}
175
176::ndk::ScopedAStatus Supplicant::addP2pInterface(
177 const std::string& in_name,
178 std::shared_ptr<ISupplicantP2pIface>* _aidl_return)
179{
180 return validateAndCall(
181 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
182 &Supplicant::addP2pInterfaceInternal, _aidl_return, in_name);
183}
184
185::ndk::ScopedAStatus Supplicant::addStaInterface(
186 const std::string& in_name,
187 std::shared_ptr<ISupplicantStaIface>* _aidl_return)
188{
189 return validateAndCall(
190 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
191 &Supplicant::addStaInterfaceInternal, _aidl_return, in_name);
192}
193
194::ndk::ScopedAStatus Supplicant::removeInterface(
195 const IfaceInfo& in_ifaceInfo)
196{
197 return validateAndCall(
198 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
199 &Supplicant::removeInterfaceInternal, in_ifaceInfo);
200}
201
202::ndk::ScopedAStatus Supplicant::getP2pInterface(
203 const std::string& in_name,
204 std::shared_ptr<ISupplicantP2pIface>* _aidl_return)
205{
206 return validateAndCall(
207 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
208 &Supplicant::getP2pInterfaceInternal, _aidl_return, in_name);
209}
210
211::ndk::ScopedAStatus Supplicant::getStaInterface(
212 const std::string& in_name,
213 std::shared_ptr<ISupplicantStaIface>* _aidl_return)
214{
215 return validateAndCall(
216 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
217 &Supplicant::getStaInterfaceInternal, _aidl_return, in_name);
218}
219
220::ndk::ScopedAStatus Supplicant::listInterfaces(
221 std::vector<IfaceInfo>* _aidl_return)
222{
223 return validateAndCall(
224 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
225 &Supplicant::listInterfacesInternal, _aidl_return);
226}
227
228::ndk::ScopedAStatus Supplicant::registerCallback(
229 const std::shared_ptr<ISupplicantCallback>& in_callback)
230{
231 return validateAndCall(
232 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
233 &Supplicant::registerCallbackInternal, in_callback);
234}
235
Gabriel Birence222d72022-12-09 01:03:10 +0000236::ndk::ScopedAStatus Supplicant::registerNonStandardCertCallback(
237 const std::shared_ptr<INonStandardCertCallback>& in_callback)
238{
239 return validateAndCall(
240 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
241 &Supplicant::registerNonStandardCertCallbackInternal, in_callback);
242}
243
Gabriel Biren57ededa2021-09-03 16:08:50 +0000244::ndk::ScopedAStatus Supplicant::setDebugParams(
245 DebugLevel in_level, bool in_showTimestamp,
246 bool in_showKeys)
247{
248 return validateAndCall(
249 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
250 &Supplicant::setDebugParamsInternal, in_level,
251 in_showTimestamp, in_showKeys);
252}
253
254::ndk::ScopedAStatus Supplicant::setConcurrencyPriority(
255 IfaceType in_type)
256{
257 return validateAndCall(
258 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
259 &Supplicant::setConcurrencyPriorityInternal, in_type);
260}
261
262::ndk::ScopedAStatus Supplicant::getDebugLevel(DebugLevel* _aidl_return)
263{
264 *_aidl_return = static_cast<DebugLevel>(wpa_debug_level);
265 return ndk::ScopedAStatus::ok();
266}
267
268::ndk::ScopedAStatus Supplicant::isDebugShowTimestampEnabled(bool* _aidl_return)
269{
270 *_aidl_return = ((wpa_debug_timestamp != 0) ? true : false);
271 return ndk::ScopedAStatus::ok();
272}
273
274::ndk::ScopedAStatus Supplicant::isDebugShowKeysEnabled(bool* _aidl_return)
275{
276 *_aidl_return = ((wpa_debug_show_keys != 0) ? true : false);
277 return ndk::ScopedAStatus::ok();
278}
279
280::ndk::ScopedAStatus Supplicant::terminate()
281{
282 wpa_printf(MSG_INFO, "Terminating...");
283 wpa_supplicant_terminate_proc(wpa_global_);
284 return ndk::ScopedAStatus::ok();
285}
286
287ndk::ScopedAStatus Supplicant::addP2pDevInterface(struct wpa_interface iface_params)
288{
289 char primary_ifname[IFNAMSIZ];
290 u32 primary_ifname_len =
291 strlen(iface_params.ifname) - strlen(P2P_MGMT_DEVICE_PREFIX);
292
293 if(primary_ifname_len > IFNAMSIZ) {
294 wpa_printf(MSG_DEBUG, "%s, Invalid primary iface name ", __FUNCTION__);
295 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
296 }
297
298 strncpy(primary_ifname, iface_params.ifname +
299 strlen(P2P_MGMT_DEVICE_PREFIX), primary_ifname_len);
300 wpa_printf(MSG_DEBUG, "%s, Initialize p2p-dev-wlan0 iface with"
301 "primary_iface = %s", __FUNCTION__, primary_ifname);
302 struct wpa_supplicant* wpa_s =
303 wpa_supplicant_get_iface(wpa_global_, primary_ifname);
304 if (!wpa_s) {
305 wpa_printf(MSG_DEBUG, "%s,NULL wpa_s for wlan0", __FUNCTION__);
306 return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
307 }
Jimmy Chen44a0f2c2022-07-11 23:49:12 +0800308
309 const u8 *if_addr = NULL;
310 char force_name[100] = {'\0'};
311 wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE;
312 if (wpa_s->conf->p2p_device_random_mac_addr == 2 &&
313 !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr))
314 if_addr = wpa_s->conf->p2p_device_persistent_mac_addr;
315
316 int ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, iface_params.ifname, if_addr, NULL,
317 force_name, wpa_s->pending_interface_addr, NULL);
318 if (ret < 0) {
319 wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface");
320 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
321 }
322
323 os_strlcpy(wpa_s->pending_interface_name, iface_params.ifname,
324 sizeof(wpa_s->pending_interface_name));
325 iface_params.p2p_mgmt = 1;
326 iface_params.driver_param = wpa_s->conf->driver_param;
327 iface_params.ctrl_interface = NULL;
328
329 struct wpa_supplicant *p2pdev_wpa_s = wpa_supplicant_add_iface(
330 wpa_s->global, &iface_params, wpa_s);
331
332 if (!p2pdev_wpa_s) {
Gabriel Biren57ededa2021-09-03 16:08:50 +0000333 wpa_printf(MSG_INFO,
334 "Failed to enable P2P Device");
335 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
336 }
Jimmy Chen44a0f2c2022-07-11 23:49:12 +0800337 p2pdev_wpa_s->p2pdev = p2pdev_wpa_s;
338 wpa_s->pending_interface_name[0] = '\0';
339
Gabriel Biren57ededa2021-09-03 16:08:50 +0000340 return ndk::ScopedAStatus::ok();
341}
342
343std::pair<std::shared_ptr<ISupplicantP2pIface>, ndk::ScopedAStatus>
344Supplicant::addP2pInterfaceInternal(const std::string& name)
345{
346 std::shared_ptr<ISupplicantP2pIface> iface;
347
348 // Check if required |ifname| argument is empty.
349 if (name.empty()) {
350 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID)};
351 }
Jimmy Chen44a0f2c2022-07-11 23:49:12 +0800352 if (strncmp(name.c_str(), P2P_MGMT_DEVICE_PREFIX, strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
353 struct wpa_supplicant* wpa_s = wpa_supplicant_get_iface(wpa_global_, name.c_str());
354 if (wpa_s) {
355 wpa_printf(MSG_DEBUG, "Remove existing p2p dev interface");
356 wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0);
357 }
358 }
Gabriel Biren57ededa2021-09-03 16:08:50 +0000359 // Try to get the wpa_supplicant record for this iface, return
360 // the iface object with the appropriate status code if it exists.
361 ndk::ScopedAStatus status;
362 std::tie(iface, status) = getP2pInterfaceInternal(name);
363 if (status.isOk()) {
364 wpa_printf(MSG_INFO, "Iface already exists, return existing");
365 return {iface, ndk::ScopedAStatus::ok()};
366 }
367
368 struct wpa_interface iface_params = {};
369 iface_params.driver = kIfaceDriverName;
370 if (ensureConfigFileExists(
371 kP2pIfaceConfPath, kOldP2pIfaceConfPath) != 0) {
372 wpa_printf(
373 MSG_ERROR, "Conf file does not exists: %s",
374 kP2pIfaceConfPath);
375 return {nullptr, createStatusWithMsg(
376 SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")};
377 }
378 iface_params.confname = kP2pIfaceConfPath;
Jooyung Han40d8f1a2024-02-22 13:30:57 +0900379 int ret = access(kP2pIfaceConfOverlayPath, R_OK);
380 if (ret == 0) {
381 iface_params.confanother = kP2pIfaceConfOverlayPath;
Gabriel Biren57ededa2021-09-03 16:08:50 +0000382 }
383
384 iface_params.ifname = name.c_str();
385 if (strncmp(iface_params.ifname, P2P_MGMT_DEVICE_PREFIX,
386 strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
387 status = addP2pDevInterface(iface_params);
388 if (!status.isOk()) {
389 return {iface, createStatus(static_cast<SupplicantStatusCode>(
390 status.getServiceSpecificError()))};
391 }
392 } else {
393 struct wpa_supplicant* wpa_s =
394 wpa_supplicant_add_iface(wpa_global_, &iface_params, NULL);
395 if (!wpa_s) {
396 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
397 }
398 // Request the current scan results from the driver and update
399 // the local BSS list wpa_s->bss. This is to avoid a full scan
400 // while processing the connect request on newly created interface.
401 wpa_supplicant_update_scan_results(wpa_s);
402 }
403 // The supplicant core creates a corresponding aidl object via
404 // AidlManager when |wpa_supplicant_add_iface| is called.
405 return getP2pInterfaceInternal(name);
406}
407
408std::pair<std::shared_ptr<ISupplicantStaIface>, ndk::ScopedAStatus>
409Supplicant::addStaInterfaceInternal(const std::string& name)
410{
411 std::shared_ptr<ISupplicantStaIface> iface;
412
413 // Check if required |ifname| argument is empty.
414 if (name.empty()) {
415 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID)};
416 }
417 // Try to get the wpa_supplicant record for this iface, return
418 // the iface object with the appropriate status code if it exists.
419 ndk::ScopedAStatus status;
420 std::tie(iface, status) = getStaInterfaceInternal(name);
421 if (status.isOk()) {
422 wpa_printf(MSG_INFO, "Iface already exists, return existing");
423 return {iface, ndk::ScopedAStatus::ok()};
424 }
425
426 struct wpa_interface iface_params = {};
427 iface_params.driver = kIfaceDriverName;
428 if (ensureConfigFileExists(
429 kStaIfaceConfPath, kOldStaIfaceConfPath) != 0) {
430 wpa_printf(
431 MSG_ERROR, "Conf file does not exists: %s",
432 kStaIfaceConfPath);
433 return {nullptr, createStatusWithMsg(
434 SupplicantStatusCode::FAILURE_UNKNOWN, "Conf file does not exist")};
435 }
436 iface_params.confname = kStaIfaceConfPath;
Jooyung Han40d8f1a2024-02-22 13:30:57 +0900437 int ret = access(kStaIfaceConfOverlayPath, R_OK);
438 if (ret == 0) {
439 iface_params.confanother = kStaIfaceConfOverlayPath;
Gabriel Biren57ededa2021-09-03 16:08:50 +0000440 }
441
442 iface_params.ifname = name.c_str();
443 if (strncmp(iface_params.ifname, P2P_MGMT_DEVICE_PREFIX,
444 strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
445 status = addP2pDevInterface(iface_params);
446 if (!status.isOk()) {
447 return {iface, createStatus(static_cast<SupplicantStatusCode>(
448 status.getServiceSpecificError()))};
449 }
450 } else {
451 struct wpa_supplicant* wpa_s =
452 wpa_supplicant_add_iface(wpa_global_, &iface_params, NULL);
453 if (!wpa_s) {
454 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
455 }
456 // Request the current scan results from the driver and update
457 // the local BSS list wpa_s->bss. This is to avoid a full scan
458 // while processing the connect request on newly created interface.
459 wpa_supplicant_update_scan_results(wpa_s);
460 }
461 // The supplicant core creates a corresponding aidl object via
462 // AidlManager when |wpa_supplicant_add_iface| is called.
463 return getStaInterfaceInternal(name);
464}
465
466ndk::ScopedAStatus Supplicant::removeInterfaceInternal(
467 const IfaceInfo& iface_info)
468{
469 struct wpa_supplicant* wpa_s =
470 wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
471 if (!wpa_s) {
472 return createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
473 }
474 if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0)) {
475 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
476 }
477 return ndk::ScopedAStatus::ok();
478}
479
480std::pair<std::shared_ptr<ISupplicantP2pIface>, ndk::ScopedAStatus>
481Supplicant::getP2pInterfaceInternal(const std::string& name)
482{
483 struct wpa_supplicant* wpa_s =
484 wpa_supplicant_get_iface(wpa_global_, name.c_str());
485 if (!wpa_s) {
486 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN)};
487 }
488 AidlManager* aidl_manager = AidlManager::getInstance();
489 std::shared_ptr<ISupplicantP2pIface> iface;
490 if (!aidl_manager ||
491 aidl_manager->getP2pIfaceAidlObjectByIfname(
492 wpa_s->ifname, &iface)) {
493 return {iface, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
494 }
495 // Set this flag true here, since there is no AIDL initialize
496 // method for the p2p config, and the supplicant interface is
497 // not ready when the p2p iface is created.
498 wpa_s->conf->persistent_reconnect = true;
499 return {iface, ndk::ScopedAStatus::ok()};
500}
501
502std::pair<std::shared_ptr<ISupplicantStaIface>, ndk::ScopedAStatus>
503Supplicant::getStaInterfaceInternal(const std::string& name)
504{
505 struct wpa_supplicant* wpa_s =
506 wpa_supplicant_get_iface(wpa_global_, name.c_str());
507 if (!wpa_s) {
508 return {nullptr, createStatus(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN)};
509 }
510 AidlManager* aidl_manager = AidlManager::getInstance();
511 std::shared_ptr<ISupplicantStaIface> iface;
512 if (!aidl_manager ||
513 aidl_manager->getStaIfaceAidlObjectByIfname(
514 wpa_s->ifname, &iface)) {
515 return {iface, createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
516 }
517 return {iface, ndk::ScopedAStatus::ok()};
518}
519
520std::pair<std::vector<IfaceInfo>, ndk::ScopedAStatus>
521Supplicant::listInterfacesInternal()
522{
523 std::vector<IfaceInfo> ifaces;
524 for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
525 wpa_s = wpa_s->next) {
526 if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
527 ifaces.emplace_back(IfaceInfo{
528 IfaceType::P2P, wpa_s->ifname});
529 } else {
530 ifaces.emplace_back(IfaceInfo{
531 IfaceType::STA, wpa_s->ifname});
532 }
533 }
534 return {std::move(ifaces), ndk::ScopedAStatus::ok()};
535}
536
537ndk::ScopedAStatus Supplicant::registerCallbackInternal(
538 const std::shared_ptr<ISupplicantCallback>& callback)
539{
540 AidlManager* aidl_manager = AidlManager::getInstance();
541 if (!aidl_manager ||
542 aidl_manager->addSupplicantCallbackAidlObject(callback)) {
543 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
544 }
545 return ndk::ScopedAStatus::ok();
546}
547
Gabriel Birence222d72022-12-09 01:03:10 +0000548ndk::ScopedAStatus Supplicant::registerNonStandardCertCallbackInternal(
549 const std::shared_ptr<INonStandardCertCallback>& callback)
550{
551 AidlManager* aidl_manager = AidlManager::getInstance();
552 if (!aidl_manager ||
553 aidl_manager->registerNonStandardCertCallbackAidlObject(callback)) {
554 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
555 }
556 return ndk::ScopedAStatus::ok();
557}
558
Gabriel Biren57ededa2021-09-03 16:08:50 +0000559ndk::ScopedAStatus Supplicant::setDebugParamsInternal(
560 DebugLevel level, bool show_timestamp, bool show_keys)
561{
562 if (wpa_supplicant_set_debug_params(
563 wpa_global_, static_cast<uint32_t>(level), show_timestamp,
564 show_keys)) {
565 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
566 }
567 return ndk::ScopedAStatus::ok();
568}
569
570ndk::ScopedAStatus Supplicant::setConcurrencyPriorityInternal(IfaceType type)
571{
572 if (type == IfaceType::STA) {
573 wpa_global_->conc_pref =
574 wpa_global::wpa_conc_pref::WPA_CONC_PREF_STA;
575 } else if (type == IfaceType::P2P) {
576 wpa_global_->conc_pref =
577 wpa_global::wpa_conc_pref::WPA_CONC_PREF_P2P;
578 } else {
579 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
580 }
581 return ndk::ScopedAStatus::ok();
582}
583} // namespace supplicant
584} // namespace wifi
585} // namespace hardware
586} // namespace android
587} // namespace aidl