blob: 9c485e77a498ea3e4a6ff8e11eec4c39ea097b86 [file] [log] [blame]
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001/*
2 * aidl interface for wpa_hostapd daemon
3 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2004-2018, Roshan Pius <rpius@google.com>
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9#include <iomanip>
10#include <sstream>
11#include <string>
12#include <vector>
13#include <net/if.h>
14#include <sys/socket.h>
15#include <linux/if_bridge.h>
16
17#include <android-base/file.h>
18#include <android-base/stringprintf.h>
19#include <android-base/unique_fd.h>
20
21#include "hostapd.h"
22#include <aidl/android/hardware/wifi/hostapd/ApInfo.h>
23#include <aidl/android/hardware/wifi/hostapd/BandMask.h>
24#include <aidl/android/hardware/wifi/hostapd/ChannelParams.h>
25#include <aidl/android/hardware/wifi/hostapd/ClientInfo.h>
26#include <aidl/android/hardware/wifi/hostapd/EncryptionType.h>
27#include <aidl/android/hardware/wifi/hostapd/HostapdStatusCode.h>
28#include <aidl/android/hardware/wifi/hostapd/IfaceParams.h>
29#include <aidl/android/hardware/wifi/hostapd/NetworkParams.h>
30#include <aidl/android/hardware/wifi/hostapd/ParamSizeLimits.h>
31
32extern "C"
33{
34#include "common/wpa_ctrl.h"
35#include "drivers/linux_ioctl.h"
36}
37
38// The AIDL implementation for hostapd creates a hostapd.conf dynamically for
39// each interface. This file can then be used to hook onto the normal config
40// file parsing logic in hostapd code. Helps us to avoid duplication of code
41// in the AIDL interface.
42// TOOD(b/71872409): Add unit tests for this.
43namespace {
44constexpr char kConfFileNameFmt[] = "/data/vendor/wifi/hostapd/hostapd_%s.conf";
45
46using android::base::RemoveFileIfExists;
47using android::base::StringPrintf;
48using android::base::WriteStringToFile;
49using aidl::android::hardware::wifi::hostapd::BandMask;
Ahmed ElArabawyb4115792022-02-08 09:33:01 -080050using aidl::android::hardware::wifi::hostapd::ChannelBandwidth;
Gabriel Biren72cf9a52021-06-25 23:29:26 +000051using aidl::android::hardware::wifi::hostapd::ChannelParams;
52using aidl::android::hardware::wifi::hostapd::EncryptionType;
53using aidl::android::hardware::wifi::hostapd::Generation;
54using aidl::android::hardware::wifi::hostapd::HostapdStatusCode;
55using aidl::android::hardware::wifi::hostapd::IfaceParams;
56using aidl::android::hardware::wifi::hostapd::NetworkParams;
57using aidl::android::hardware::wifi::hostapd::ParamSizeLimits;
58
59int band2Ghz = (int)BandMask::BAND_2_GHZ;
60int band5Ghz = (int)BandMask::BAND_5_GHZ;
61int band6Ghz = (int)BandMask::BAND_6_GHZ;
62int band60Ghz = (int)BandMask::BAND_60_GHZ;
63
Manaswini Paluri76ae6982024-02-29 14:49:20 +053064int32_t aidl_client_version = 0;
65int32_t aidl_service_version = 0;
66
67/**
68 * Check that the AIDL service is running at least the expected version.
69 * Use to avoid the case where the AIDL interface version
70 * is greater than the version implemented by the service.
71 */
72inline int32_t isAidlServiceVersionAtLeast(int32_t expected_version)
73{
74 return expected_version <= aidl_service_version;
75}
76
77inline int32_t isAidlClientVersionAtLeast(int32_t expected_version)
78{
79 return expected_version <= aidl_client_version;
80}
81
Gabriel Biren72cf9a52021-06-25 23:29:26 +000082#define MAX_PORTS 1024
83bool GetInterfacesInBridge(std::string br_name,
84 std::vector<std::string>* interfaces) {
85 android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
86 if (sock.get() < 0) {
87 wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s",
88 strerror(errno), __FUNCTION__);
89 return false;
90 }
91
92 struct ifreq request;
93 int i, ifindices[MAX_PORTS];
94 char if_name[IFNAMSIZ];
95 unsigned long args[3];
96
97 memset(ifindices, 0, MAX_PORTS * sizeof(int));
98
99 args[0] = BRCTL_GET_PORT_LIST;
100 args[1] = (unsigned long) ifindices;
101 args[2] = MAX_PORTS;
102
103 strlcpy(request.ifr_name, br_name.c_str(), IFNAMSIZ);
104 request.ifr_data = (char *)args;
105
106 if (ioctl(sock.get(), SIOCDEVPRIVATE, &request) < 0) {
107 wpa_printf(MSG_ERROR, "Failed to ioctl SIOCDEVPRIVATE in %s",
108 __FUNCTION__);
109 return false;
110 }
111
112 for (i = 0; i < MAX_PORTS; i ++) {
113 memset(if_name, 0, IFNAMSIZ);
114 if (ifindices[i] == 0 || !if_indextoname(ifindices[i], if_name)) {
115 continue;
116 }
117 interfaces->push_back(if_name);
118 }
119 return true;
120}
121
122std::string WriteHostapdConfig(
Les Lee399c6302024-09-12 03:03:38 +0000123 const std::string& instance_name, const std::string& config,
124 const std::string br_name, const bool usesMlo)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000125{
Les Lee399c6302024-09-12 03:03:38 +0000126 std::string conf_name_as_string = instance_name;
127 if (usesMlo) {
128 conf_name_as_string = StringPrintf(
129 "%s-%s", br_name.c_str(), instance_name.c_str());
130 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000131 const std::string file_path =
Les Lee399c6302024-09-12 03:03:38 +0000132 StringPrintf(kConfFileNameFmt, conf_name_as_string.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000133 if (WriteStringToFile(
134 config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
135 getuid(), getgid())) {
136 return file_path;
137 }
138 // Diagnose failure
139 int error = errno;
140 wpa_printf(
141 MSG_ERROR, "Cannot write hostapd config to %s, error: %s",
142 file_path.c_str(), strerror(error));
143 struct stat st;
144 int result = stat(file_path.c_str(), &st);
145 if (result == 0) {
146 wpa_printf(
147 MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d",
148 st.st_uid, st.st_gid, st.st_mode);
149 } else {
150 wpa_printf(
151 MSG_ERROR,
152 "Error calling stat() on hostapd config file: %s",
153 strerror(errno));
154 }
155 return "";
156}
157
158/*
159 * Get the op_class for a channel/band
160 * The logic here is based on Table E-4 in the 802.11 Specification
161 */
162int getOpClassForChannel(int channel, int band, bool support11n, bool support11ac) {
163 // 2GHz Band
164 if ((band & band2Ghz) != 0) {
165 if (channel == 14) {
166 return 82;
167 }
168 if (channel >= 1 && channel <= 13) {
169 if (!support11n) {
170 //20MHz channel
171 return 81;
172 }
173 if (channel <= 9) {
174 // HT40 with secondary channel above primary
175 return 83;
176 }
177 // HT40 with secondary channel below primary
178 return 84;
179 }
180 // Error
181 return 0;
182 }
183
184 // 5GHz Band
185 if ((band & band5Ghz) != 0) {
186 if (support11ac) {
187 switch (channel) {
188 case 42:
189 case 58:
190 case 106:
191 case 122:
192 case 138:
193 case 155:
194 // 80MHz channel
195 return 128;
196 case 50:
197 case 114:
198 // 160MHz channel
199 return 129;
200 }
201 }
202
203 if (!support11n) {
204 if (channel >= 36 && channel <= 48) {
205 return 115;
206 }
207 if (channel >= 52 && channel <= 64) {
208 return 118;
209 }
210 if (channel >= 100 && channel <= 144) {
211 return 121;
212 }
213 if (channel >= 149 && channel <= 161) {
214 return 124;
215 }
216 if (channel >= 165 && channel <= 169) {
217 return 125;
218 }
219 } else {
220 switch (channel) {
221 case 36:
222 case 44:
223 // HT40 with secondary channel above primary
224 return 116;
225 case 40:
226 case 48:
227 // HT40 with secondary channel below primary
228 return 117;
229 case 52:
230 case 60:
231 // HT40 with secondary channel above primary
232 return 119;
233 case 56:
234 case 64:
235 // HT40 with secondary channel below primary
236 return 120;
237 case 100:
238 case 108:
239 case 116:
240 case 124:
241 case 132:
242 case 140:
243 // HT40 with secondary channel above primary
244 return 122;
245 case 104:
246 case 112:
247 case 120:
248 case 128:
249 case 136:
250 case 144:
251 // HT40 with secondary channel below primary
252 return 123;
253 case 149:
254 case 157:
255 // HT40 with secondary channel above primary
256 return 126;
257 case 153:
258 case 161:
259 // HT40 with secondary channel below primary
260 return 127;
261 }
262 }
263 // Error
264 return 0;
265 }
266
267 // 6GHz Band
268 if ((band & band6Ghz) != 0) {
269 // Channels 1, 5. 9, 13, ...
270 if ((channel & 0x03) == 0x01) {
271 // 20MHz channel
272 return 131;
273 }
274 // Channels 3, 11, 19, 27, ...
275 if ((channel & 0x07) == 0x03) {
276 // 40MHz channel
277 return 132;
278 }
279 // Channels 7, 23, 39, 55, ...
280 if ((channel & 0x0F) == 0x07) {
281 // 80MHz channel
282 return 133;
283 }
284 // Channels 15, 47, 69, ...
285 if ((channel & 0x1F) == 0x0F) {
286 // 160MHz channel
287 return 134;
288 }
289 if (channel == 2) {
290 // 20MHz channel
291 return 136;
292 }
293 // Error
294 return 0;
295 }
296
297 if ((band & band60Ghz) != 0) {
298 if (1 <= channel && channel <= 8) {
299 return 180;
300 } else if (9 <= channel && channel <= 15) {
301 return 181;
302 } else if (17 <= channel && channel <= 22) {
303 return 182;
304 } else if (25 <= channel && channel <= 29) {
305 return 183;
306 }
307 // Error
308 return 0;
309 }
310
311 return 0;
312}
313
314bool validatePassphrase(int passphrase_len, int min_len, int max_len)
315{
316 if (min_len != -1 && passphrase_len < min_len) return false;
317 if (max_len != -1 && passphrase_len > max_len) return false;
318 return true;
319}
320
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530321std::string getInterfaceMacAddress(const std::string& if_name)
322{
323 u8 addr[ETH_ALEN] = {};
324 struct ifreq ifr;
325 std::string mac_addr;
326
327 android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
328 if (sock.get() < 0) {
329 wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s",
330 strerror(errno), __FUNCTION__);
331 return "";
332 }
333
334 memset(&ifr, 0, sizeof(ifr));
335 strlcpy(ifr.ifr_name, if_name.c_str(), IFNAMSIZ);
336 if (ioctl(sock.get(), SIOCGIFHWADDR, &ifr) < 0) {
337 wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
338 if_name.c_str(), strerror(errno));
339 return "";
340 }
341
342 memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
343 mac_addr = StringPrintf("" MACSTR, MAC2STR(addr));
344
345 return mac_addr;
346}
347
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000348std::string CreateHostapdConfig(
349 const IfaceParams& iface_params,
350 const ChannelParams& channelParams,
351 const NetworkParams& nw_params,
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530352 const std::string br_name,
353 const std::string owe_transition_ifname)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000354{
355 if (nw_params.ssid.size() >
356 static_cast<uint32_t>(
357 ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) {
358 wpa_printf(
359 MSG_ERROR, "Invalid SSID size: %zu", nw_params.ssid.size());
360 return "";
361 }
362
363 // SSID string
364 std::stringstream ss;
365 ss << std::hex;
366 ss << std::setfill('0');
367 for (uint8_t b : nw_params.ssid) {
368 ss << std::setw(2) << static_cast<unsigned int>(b);
369 }
370 const std::string ssid_as_string = ss.str();
371
372 // Encryption config string
373 uint32_t band = 0;
374 band |= static_cast<uint32_t>(channelParams.bandMask);
Sunil Ravi4fc918f2022-04-17 09:26:48 -0700375 bool is_2Ghz_band_only = band == static_cast<uint32_t>(band2Ghz);
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000376 bool is_6Ghz_band_only = band == static_cast<uint32_t>(band6Ghz);
377 bool is_60Ghz_band_only = band == static_cast<uint32_t>(band60Ghz);
378 std::string encryption_config_as_string;
379 switch (nw_params.encryptionType) {
380 case EncryptionType::NONE:
381 // no security params
382 break;
383 case EncryptionType::WPA:
384 if (!validatePassphrase(
385 nw_params.passphrase.size(),
386 static_cast<uint32_t>(ParamSizeLimits::
387 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
388 static_cast<uint32_t>(ParamSizeLimits::
389 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
390 return "";
391 }
392 encryption_config_as_string = StringPrintf(
393 "wpa=3\n"
394 "wpa_pairwise=%s\n"
395 "wpa_passphrase=%s",
396 is_60Ghz_band_only ? "GCMP" : "TKIP CCMP",
397 nw_params.passphrase.c_str());
398 break;
399 case EncryptionType::WPA2:
400 if (!validatePassphrase(
401 nw_params.passphrase.size(),
402 static_cast<uint32_t>(ParamSizeLimits::
403 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
404 static_cast<uint32_t>(ParamSizeLimits::
405 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
406 return "";
407 }
408 encryption_config_as_string = StringPrintf(
409 "wpa=2\n"
410 "rsn_pairwise=%s\n"
Sunil Ravib3580db2022-01-28 12:25:46 -0800411#ifdef ENABLE_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL
412 "ieee80211w=1\n"
413#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000414 "wpa_passphrase=%s",
415 is_60Ghz_band_only ? "GCMP" : "CCMP",
416 nw_params.passphrase.c_str());
417 break;
418 case EncryptionType::WPA3_SAE_TRANSITION:
419 if (!validatePassphrase(
420 nw_params.passphrase.size(),
421 static_cast<uint32_t>(ParamSizeLimits::
422 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
423 static_cast<uint32_t>(ParamSizeLimits::
424 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
425 return "";
426 }
Sunil Ravid917c832023-07-07 17:30:33 +0000427 // WPA3 transition mode or SAE+WPA_PSK key management(AKM) is not allowed in 6GHz.
428 // Auto-convert any such configurations to SAE.
429 if ((band & band6Ghz) != 0) {
430 wpa_printf(MSG_INFO, "WPA3_SAE_TRANSITION configured in 6GHz band."
431 "Enable only SAE in key_mgmt");
432 encryption_config_as_string = StringPrintf(
433 "wpa=2\n"
434 "rsn_pairwise=CCMP\n"
435 "wpa_key_mgmt=%s\n"
436 "ieee80211w=2\n"
437 "sae_require_mfp=2\n"
438 "sae_pwe=%d\n"
439 "sae_password=%s",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000440#ifdef CONFIG_IEEE80211BE
Sunil Ravid917c832023-07-07 17:30:33 +0000441 iface_params.hwModeParams.enable80211BE ?
442 "SAE SAE-EXT-KEY" : "SAE",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000443#else
Sunil Ravid917c832023-07-07 17:30:33 +0000444 "SAE",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000445#endif
Sunil Ravid917c832023-07-07 17:30:33 +0000446 is_6Ghz_band_only ? 1 : 2,
447 nw_params.passphrase.c_str());
448 } else {
449 encryption_config_as_string = StringPrintf(
450 "wpa=2\n"
451 "rsn_pairwise=%s\n"
452 "wpa_key_mgmt=%s\n"
453 "ieee80211w=1\n"
454 "sae_require_mfp=1\n"
455 "wpa_passphrase=%s\n"
456 "sae_password=%s",
457 is_60Ghz_band_only ? "GCMP" : "CCMP",
458#ifdef CONFIG_IEEE80211BE
459 iface_params.hwModeParams.enable80211BE ?
460 "WPA-PSK SAE SAE-EXT-KEY" : "WPA-PSK SAE",
461#else
462 "WPA-PSK SAE",
463#endif
464 nw_params.passphrase.c_str(),
465 nw_params.passphrase.c_str());
466 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000467 break;
468 case EncryptionType::WPA3_SAE:
469 if (!validatePassphrase(nw_params.passphrase.size(), 1, -1)) {
470 return "";
471 }
472 encryption_config_as_string = StringPrintf(
473 "wpa=2\n"
474 "rsn_pairwise=%s\n"
Sunil Ravi65251732023-01-24 05:03:35 +0000475 "wpa_key_mgmt=%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000476 "ieee80211w=2\n"
477 "sae_require_mfp=2\n"
478 "sae_pwe=%d\n"
479 "sae_password=%s",
480 is_60Ghz_band_only ? "GCMP" : "CCMP",
Sunil Ravi65251732023-01-24 05:03:35 +0000481#ifdef CONFIG_IEEE80211BE
482 iface_params.hwModeParams.enable80211BE ? "SAE SAE-EXT-KEY" : "SAE",
483#else
484 "SAE",
485#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000486 is_6Ghz_band_only ? 1 : 2,
487 nw_params.passphrase.c_str());
488 break;
Ahmed ElArabawy1aaf1802022-02-04 15:58:55 -0800489 case EncryptionType::WPA3_OWE_TRANSITION:
490 encryption_config_as_string = StringPrintf(
491 "wpa=2\n"
492 "rsn_pairwise=%s\n"
493 "wpa_key_mgmt=OWE\n"
494 "ieee80211w=2",
495 is_60Ghz_band_only ? "GCMP" : "CCMP");
496 break;
497 case EncryptionType::WPA3_OWE:
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530498 encryption_config_as_string = StringPrintf(
499 "wpa=2\n"
500 "rsn_pairwise=%s\n"
501 "wpa_key_mgmt=OWE\n"
502 "ieee80211w=2",
503 is_60Ghz_band_only ? "GCMP" : "CCMP");
504 break;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000505 default:
506 wpa_printf(MSG_ERROR, "Unknown encryption type");
507 return "";
508 }
509
510 std::string channel_config_as_string;
511 bool isFirst = true;
512 if (channelParams.enableAcs) {
513 std::string freqList_as_string;
514 for (const auto &range :
515 channelParams.acsChannelFreqRangesMhz) {
516 if (!isFirst) {
517 freqList_as_string += ",";
518 }
519 isFirst = false;
520
521 if (range.startMhz != range.endMhz) {
522 freqList_as_string +=
523 StringPrintf("%d-%d", range.startMhz, range.endMhz);
524 } else {
525 freqList_as_string += StringPrintf("%d", range.startMhz);
526 }
527 }
528 channel_config_as_string = StringPrintf(
529 "channel=0\n"
530 "acs_exclude_dfs=%d\n"
531 "freqlist=%s",
532 channelParams.acsShouldExcludeDfs,
533 freqList_as_string.c_str());
534 } else {
535 int op_class = getOpClassForChannel(
536 channelParams.channel,
537 band,
538 iface_params.hwModeParams.enable80211N,
539 iface_params.hwModeParams.enable80211AC);
540 channel_config_as_string = StringPrintf(
541 "channel=%d\n"
542 "op_class=%d",
543 channelParams.channel, op_class);
544 }
545
546 std::string hw_mode_as_string;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000547 std::string enable_edmg_as_string;
548 std::string edmg_channel_as_string;
549 bool is_60Ghz_used = false;
550
551 if (((band & band60Ghz) != 0)) {
552 hw_mode_as_string = "hw_mode=ad";
553 if (iface_params.hwModeParams.enableEdmg) {
554 enable_edmg_as_string = "enable_edmg=1";
555 edmg_channel_as_string = StringPrintf(
556 "edmg_channel=%d",
557 channelParams.channel);
558 }
559 is_60Ghz_used = true;
560 } else if ((band & band2Ghz) != 0) {
561 if (((band & band5Ghz) != 0)
562 || ((band & band6Ghz) != 0)) {
563 hw_mode_as_string = "hw_mode=any";
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000564 } else {
565 hw_mode_as_string = "hw_mode=g";
566 }
567 } else if (((band & band5Ghz) != 0)
568 || ((band & band6Ghz) != 0)) {
569 hw_mode_as_string = "hw_mode=a";
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000570 } else {
571 wpa_printf(MSG_ERROR, "Invalid band");
572 return "";
573 }
574
575 std::string he_params_as_string;
576#ifdef CONFIG_IEEE80211AX
577 if (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) {
578 he_params_as_string = StringPrintf(
579 "ieee80211ax=1\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000580 "he_su_beamformer=%d\n"
581 "he_su_beamformee=%d\n"
582 "he_mu_beamformer=%d\n"
583 "he_twt_required=%d\n",
584 iface_params.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0,
585 iface_params.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0,
586 iface_params.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0,
587 iface_params.hwModeParams.enableHeTargetWakeTime ? 1 : 0);
588 } else {
589 he_params_as_string = "ieee80211ax=0";
590 }
591#endif /* CONFIG_IEEE80211AX */
Sunil Ravi65251732023-01-24 05:03:35 +0000592 std::string eht_params_as_string;
593#ifdef CONFIG_IEEE80211BE
594 if (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) {
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530595 eht_params_as_string = "ieee80211be=1\n";
596 if (isAidlServiceVersionAtLeast(2) && isAidlClientVersionAtLeast(2)) {
Les Lee399c6302024-09-12 03:03:38 +0000597 std::string interface_mac_addr = getInterfaceMacAddress(
598 iface_params.usesMlo ? br_name : iface_params.name);
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530599 if (interface_mac_addr.empty()) {
600 wpa_printf(MSG_ERROR,
601 "Unable to set interface mac address as bssid for 11BE SAP");
602 return "";
603 }
Les Lee399c6302024-09-12 03:03:38 +0000604 if (iface_params.usesMlo) {
605 eht_params_as_string += StringPrintf(
606 "mld_addr=%s\n"
607 "mld_ap=1",
608 interface_mac_addr.c_str());
609 } else {
610 eht_params_as_string += StringPrintf(
611 "bssid=%s\n"
612 "mld_ap=1",
613 interface_mac_addr.c_str());
614 }
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530615 }
Sunil Ravi65251732023-01-24 05:03:35 +0000616 /* TODO set eht_su_beamformer, eht_su_beamformee, eht_mu_beamformer */
617 } else {
618 eht_params_as_string = "ieee80211be=0";
619 }
620#endif /* CONFIG_IEEE80211BE */
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000621
Xin Dengfec682f2024-02-06 22:59:39 -0800622 std::string ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string;
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530623 switch (iface_params.hwModeParams.maximumChannelBandwidth) {
624 case ChannelBandwidth::BANDWIDTH_20:
Xin Dengfec682f2024-02-06 22:59:39 -0800625 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
626#ifdef CONFIG_IEEE80211BE
627 "eht_oper_chwidth=0\n"
628#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530629#ifdef CONFIG_IEEE80211AX
630 "he_oper_chwidth=0\n"
631#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800632 "vht_oper_chwidth=0\n"
633 "%s", (band & band6Ghz) ? "op_class=131" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530634 break;
635 case ChannelBandwidth::BANDWIDTH_40:
Xin Dengfec682f2024-02-06 22:59:39 -0800636 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530637 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800638#ifdef CONFIG_IEEE80211BE
639 "eht_oper_chwidth=0\n"
640#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530641#ifdef CONFIG_IEEE80211AX
642 "he_oper_chwidth=0\n"
643#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800644 "vht_oper_chwidth=0\n"
645 "%s", (band & band6Ghz) ? "op_class=132" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530646 break;
647 case ChannelBandwidth::BANDWIDTH_80:
Xin Dengfec682f2024-02-06 22:59:39 -0800648 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530649 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800650#ifdef CONFIG_IEEE80211BE
651 "eht_oper_chwidth=%d\n"
652#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530653#ifdef CONFIG_IEEE80211AX
654 "he_oper_chwidth=%d\n"
655#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800656 "vht_oper_chwidth=%d\n"
657 "%s",
Xin Dengfec682f2024-02-06 22:59:39 -0800658#ifdef CONFIG_IEEE80211BE
659 (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) ? 1 : 0,
660#endif
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530661#ifdef CONFIG_IEEE80211AX
662 (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) ? 1 : 0,
663#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800664 iface_params.hwModeParams.enable80211AC ? 1 : 0,
665 (band & band6Ghz) ? "op_class=133" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530666 break;
667 case ChannelBandwidth::BANDWIDTH_160:
Xin Dengfec682f2024-02-06 22:59:39 -0800668 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530669 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800670#ifdef CONFIG_IEEE80211BE
671 "eht_oper_chwidth=%d\n"
672#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530673#ifdef CONFIG_IEEE80211AX
674 "he_oper_chwidth=%d\n"
675#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800676 "vht_oper_chwidth=%d\n"
677 "%s",
Xin Dengfec682f2024-02-06 22:59:39 -0800678#ifdef CONFIG_IEEE80211BE
679 (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) ? 2 : 0,
680#endif
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530681#ifdef CONFIG_IEEE80211AX
682 (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) ? 2 : 0,
683#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800684 iface_params.hwModeParams.enable80211AC ? 2 : 0,
685 (band & band6Ghz) ? "op_class=134" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530686 break;
687 default:
Sunil Raviffa5cce2022-08-22 23:37:16 +0000688 if (!is_2Ghz_band_only && !is_60Ghz_used) {
689 if (iface_params.hwModeParams.enable80211AC) {
Xin Dengfec682f2024-02-06 22:59:39 -0800690 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string =
Sunil Ravi4fc918f2022-04-17 09:26:48 -0700691 "ht_capab=[HT40+]\n"
692 "vht_oper_chwidth=1\n";
Sunil Raviffa5cce2022-08-22 23:37:16 +0000693 }
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800694 if (band & band6Ghz) {
Xin Deng3ee3fe12024-02-20 23:24:37 -0800695#ifdef CONFIG_IEEE80211BE
696 if (iface_params.hwModeParams.enable80211BE)
697 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=137\n";
698 else
699 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=134\n";
700#else /* CONFIG_IEEE80211BE */
Xin Dengfec682f2024-02-06 22:59:39 -0800701 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=134\n";
Xin Deng3ee3fe12024-02-20 23:24:37 -0800702#endif /* CONFIG_IEEE80211BE */
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800703 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530704#ifdef CONFIG_IEEE80211AX
Sunil Raviffa5cce2022-08-22 23:37:16 +0000705 if (iface_params.hwModeParams.enable80211AX) {
Xin Dengfec682f2024-02-06 22:59:39 -0800706 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "he_oper_chwidth=1\n";
707 }
708#endif
709#ifdef CONFIG_IEEE80211BE
710 if (iface_params.hwModeParams.enable80211BE) {
711 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "eht_oper_chwidth=1";
Sunil Raviffa5cce2022-08-22 23:37:16 +0000712 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530713#endif
Sunil Raviffa5cce2022-08-22 23:37:16 +0000714 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530715 break;
716 }
717
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000718#ifdef CONFIG_INTERWORKING
719 std::string access_network_params_as_string;
720 if (nw_params.isMetered) {
721 access_network_params_as_string = StringPrintf(
722 "interworking=1\n"
723 "access_network_type=2\n"); // CHARGEABLE_PUBLIC_NETWORK
724 } else {
725 access_network_params_as_string = StringPrintf(
726 "interworking=0\n");
727 }
728#endif /* CONFIG_INTERWORKING */
729
730 std::string bridge_as_string;
Les Lee399c6302024-09-12 03:03:38 +0000731 if (!br_name.empty() && !iface_params.usesMlo) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000732 bridge_as_string = StringPrintf("bridge=%s", br_name.c_str());
733 }
734
Serik Beketayev8af7a722021-12-23 12:25:36 -0800735 // vendor_elements string
736 std::string vendor_elements_as_string;
737 if (nw_params.vendorElements.size() > 0) {
738 std::stringstream ss;
739 ss << std::hex;
740 ss << std::setfill('0');
741 for (uint8_t b : nw_params.vendorElements) {
742 ss << std::setw(2) << static_cast<unsigned int>(b);
743 }
744 vendor_elements_as_string = StringPrintf("vendor_elements=%s", ss.str().c_str());
745 }
746
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530747 std::string owe_transition_ifname_as_string;
748 if (!owe_transition_ifname.empty()) {
749 owe_transition_ifname_as_string = StringPrintf(
750 "owe_transition_ifname=%s", owe_transition_ifname.c_str());
751 }
752
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000753 return StringPrintf(
754 "interface=%s\n"
755 "driver=nl80211\n"
Les Lee399c6302024-09-12 03:03:38 +0000756 "ctrl_interface=/data/vendor/wifi/hostapd/ctrl_%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000757 // ssid2 signals to hostapd that the value is not a literal value
758 // for use as a SSID. In this case, we're giving it a hex
759 // std::string and hostapd needs to expect that.
760 "ssid2=%s\n"
761 "%s\n"
762 "ieee80211n=%d\n"
763 "ieee80211ac=%d\n"
764 "%s\n"
765 "%s\n"
766 "%s\n"
Sunil Ravi65251732023-01-24 05:03:35 +0000767 "%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000768 "ignore_broadcast_ssid=%d\n"
769 "wowlan_triggers=any\n"
770#ifdef CONFIG_INTERWORKING
771 "%s\n"
772#endif /* CONFIG_INTERWORKING */
773 "%s\n"
774 "%s\n"
775 "%s\n"
Serik Beketayev8af7a722021-12-23 12:25:36 -0800776 "%s\n"
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530777 "%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000778 "%s\n",
Les Lee399c6302024-09-12 03:03:38 +0000779 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str(),
780 iface_params.name.c_str(),
781 ssid_as_string.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000782 channel_config_as_string.c_str(),
783 iface_params.hwModeParams.enable80211N ? 1 : 0,
784 iface_params.hwModeParams.enable80211AC ? 1 : 0,
785 he_params_as_string.c_str(),
Sunil Ravi65251732023-01-24 05:03:35 +0000786 eht_params_as_string.c_str(),
Xin Dengfec682f2024-02-06 22:59:39 -0800787 hw_mode_as_string.c_str(), ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000788 nw_params.isHidden ? 1 : 0,
789#ifdef CONFIG_INTERWORKING
790 access_network_params_as_string.c_str(),
791#endif /* CONFIG_INTERWORKING */
792 encryption_config_as_string.c_str(),
793 bridge_as_string.c_str(),
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530794 owe_transition_ifname_as_string.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000795 enable_edmg_as_string.c_str(),
Serik Beketayev8af7a722021-12-23 12:25:36 -0800796 edmg_channel_as_string.c_str(),
797 vendor_elements_as_string.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000798}
799
800Generation getGeneration(hostapd_hw_modes *current_mode)
801{
802 wpa_printf(MSG_DEBUG, "getGeneration hwmode=%d, ht_enabled=%d,"
803 " vht_enabled=%d, he_supported=%d",
804 current_mode->mode, current_mode->ht_capab != 0,
805 current_mode->vht_capab != 0, current_mode->he_capab->he_supported);
806 switch (current_mode->mode) {
807 case HOSTAPD_MODE_IEEE80211B:
808 return Generation::WIFI_STANDARD_LEGACY;
809 case HOSTAPD_MODE_IEEE80211G:
810 return current_mode->ht_capab == 0 ?
811 Generation::WIFI_STANDARD_LEGACY : Generation::WIFI_STANDARD_11N;
812 case HOSTAPD_MODE_IEEE80211A:
813 if (current_mode->he_capab->he_supported) {
814 return Generation::WIFI_STANDARD_11AX;
815 }
816 return current_mode->vht_capab == 0 ?
817 Generation::WIFI_STANDARD_11N : Generation::WIFI_STANDARD_11AC;
818 case HOSTAPD_MODE_IEEE80211AD:
819 return Generation::WIFI_STANDARD_11AD;
820 default:
821 return Generation::WIFI_STANDARD_UNKNOWN;
822 }
823}
824
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800825ChannelBandwidth getChannelBandwidth(struct hostapd_config *iconf)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000826{
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800827 wpa_printf(MSG_DEBUG, "getChannelBandwidth %d, isHT=%d, isHT40=%d",
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000828 iconf->vht_oper_chwidth, iconf->ieee80211n,
829 iconf->secondary_channel);
830 switch (iconf->vht_oper_chwidth) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000831 case CONF_OPER_CHWIDTH_80MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800832 return ChannelBandwidth::BANDWIDTH_80;
Sunil8cd6f4d2022-06-28 18:40:46 +0000833 case CONF_OPER_CHWIDTH_80P80MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800834 return ChannelBandwidth::BANDWIDTH_80P80;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000835 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000836 case CONF_OPER_CHWIDTH_160MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800837 return ChannelBandwidth::BANDWIDTH_160;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000838 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000839 case CONF_OPER_CHWIDTH_USE_HT:
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000840 if (iconf->ieee80211n) {
841 return iconf->secondary_channel != 0 ?
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800842 ChannelBandwidth::BANDWIDTH_40 : ChannelBandwidth::BANDWIDTH_20;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000843 }
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800844 return ChannelBandwidth::BANDWIDTH_20_NOHT;
Sunil8cd6f4d2022-06-28 18:40:46 +0000845 case CONF_OPER_CHWIDTH_2160MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800846 return ChannelBandwidth::BANDWIDTH_2160;
Sunil8cd6f4d2022-06-28 18:40:46 +0000847 case CONF_OPER_CHWIDTH_4320MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800848 return ChannelBandwidth::BANDWIDTH_4320;
Sunil8cd6f4d2022-06-28 18:40:46 +0000849 case CONF_OPER_CHWIDTH_6480MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800850 return ChannelBandwidth::BANDWIDTH_6480;
Sunil8cd6f4d2022-06-28 18:40:46 +0000851 case CONF_OPER_CHWIDTH_8640MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800852 return ChannelBandwidth::BANDWIDTH_8640;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000853 default:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800854 return ChannelBandwidth::BANDWIDTH_INVALID;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000855 }
856}
857
858bool forceStaDisconnection(struct hostapd_data* hapd,
859 const std::vector<uint8_t>& client_address,
860 const uint16_t reason_code) {
861 struct sta_info *sta;
Sunil Ravi1a360892022-11-29 20:16:01 +0000862 if (client_address.size() != ETH_ALEN) {
863 return false;
864 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000865 for (sta = hapd->sta_list; sta; sta = sta->next) {
866 int res;
867 res = memcmp(sta->addr, client_address.data(), ETH_ALEN);
868 if (res == 0) {
869 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
870 MAC2STR(client_address.data()), reason_code);
871 ap_sta_disconnect(hapd, sta, sta->addr, reason_code);
872 return true;
873 }
874 }
875 return false;
876}
877
878// hostapd core functions accept "C" style function pointers, so use global
879// functions to pass to the hostapd core function and store the corresponding
880// std::function methods to be invoked.
881//
882// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
883//
884// Callback to be invoked once setup is complete
885std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
886void onAsyncSetupCompleteCb(void* ctx)
887{
888 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
889 if (on_setup_complete_internal_callback) {
890 on_setup_complete_internal_callback(iface_hapd);
891 // Invalidate this callback since we don't want this firing
892 // again in single AP mode.
893 if (strlen(iface_hapd->conf->bridge) > 0) {
894 on_setup_complete_internal_callback = nullptr;
895 }
896 }
897}
898
899// Callback to be invoked on hotspot client connection/disconnection
900std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized,
901 const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback;
902void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized,
Sunil Ravid8128a22023-11-06 23:53:58 +0000903 const u8 *p2p_dev_addr, const u8 *ip)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000904{
905 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
906 if (on_sta_authorized_internal_callback) {
907 on_sta_authorized_internal_callback(iface_hapd, mac_addr,
908 authorized, p2p_dev_addr);
909 }
910}
911
912std::function<void(struct hostapd_data*, int level,
913 enum wpa_msg_type type, const char *txt,
914 size_t len)> on_wpa_msg_internal_callback;
915
916void onAsyncWpaEventCb(void *ctx, int level,
917 enum wpa_msg_type type, const char *txt,
918 size_t len)
919{
920 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
921 if (on_wpa_msg_internal_callback) {
922 on_wpa_msg_internal_callback(iface_hapd, level,
923 type, txt, len);
924 }
925}
926
927inline ndk::ScopedAStatus createStatus(HostapdStatusCode status_code) {
928 return ndk::ScopedAStatus::fromServiceSpecificError(
929 static_cast<int32_t>(status_code));
930}
931
932inline ndk::ScopedAStatus createStatusWithMsg(
933 HostapdStatusCode status_code, std::string msg)
934{
935 return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
936 static_cast<int32_t>(status_code), msg.c_str());
937}
938
939// Method called by death_notifier_ on client death.
940void onDeath(void* cookie) {
941 wpa_printf(MSG_ERROR, "Client died. Terminating...");
942 eloop_terminate();
943}
944
945} // namespace
946
947namespace aidl {
948namespace android {
949namespace hardware {
950namespace wifi {
951namespace hostapd {
952
953Hostapd::Hostapd(struct hapd_interfaces* interfaces)
954 : interfaces_(interfaces)
955{
956 death_notifier_ = AIBinder_DeathRecipient_new(onDeath);
957}
958
959::ndk::ScopedAStatus Hostapd::addAccessPoint(
960 const IfaceParams& iface_params, const NetworkParams& nw_params)
961{
962 return addAccessPointInternal(iface_params, nw_params);
963}
964
965::ndk::ScopedAStatus Hostapd::removeAccessPoint(const std::string& iface_name)
966{
967 return removeAccessPointInternal(iface_name);
968}
969
970::ndk::ScopedAStatus Hostapd::terminate()
971{
972 wpa_printf(MSG_INFO, "Terminating...");
973 // Clear the callback to avoid IPCThreadState shutdown during the
974 // callback event.
975 callbacks_.clear();
976 eloop_terminate();
977 return ndk::ScopedAStatus::ok();
978}
979
980::ndk::ScopedAStatus Hostapd::registerCallback(
981 const std::shared_ptr<IHostapdCallback>& callback)
982{
983 return registerCallbackInternal(callback);
984}
985
986::ndk::ScopedAStatus Hostapd::forceClientDisconnect(
987 const std::string& iface_name, const std::vector<uint8_t>& client_address,
988 Ieee80211ReasonCode reason_code)
989{
990 return forceClientDisconnectInternal(iface_name, client_address, reason_code);
991}
992
993::ndk::ScopedAStatus Hostapd::setDebugParams(DebugLevel level)
994{
995 return setDebugParamsInternal(level);
996}
997
998::ndk::ScopedAStatus Hostapd::addAccessPointInternal(
999 const IfaceParams& iface_params,
1000 const NetworkParams& nw_params)
1001{
1002 int channelParamsSize = iface_params.channelParams.size();
1003 if (channelParamsSize == 1) {
1004 // Single AP
1005 wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s",
1006 iface_params.name.c_str());
1007 return addSingleAccessPoint(iface_params, iface_params.channelParams[0],
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301008 nw_params, "", "");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001009 } else if (channelParamsSize == 2) {
1010 // Concurrent APs
1011 wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s",
1012 iface_params.name.c_str());
1013 return addConcurrentAccessPoints(iface_params, nw_params);
1014 }
1015 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1016}
1017
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301018std::vector<uint8_t> generateRandomOweSsid()
1019{
1020 u8 random[8] = {0};
1021 os_get_random(random, 8);
1022
1023 std::string ssid = StringPrintf("Owe-%s", random);
1024 wpa_printf(MSG_INFO, "Generated OWE SSID: %s", ssid.c_str());
1025 std::vector<uint8_t> vssid(ssid.begin(), ssid.end());
1026
1027 return vssid;
1028}
1029
Les Lee399c6302024-09-12 03:03:38 +00001030
1031// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1032// -----------------------------------------
1033// | br_name | instance#1 | instance#2 |
1034// ___________________________________________________________
1035// bridged dual APs | ap_br_wlanX | wlan X | wlanY |
1036// ___________________________________________________________
1037// MLO AP | wlanX | 0 | 1 |
1038// ___________________________________________________________
1039// Both will be added in br_interfaces_[$br_name] and use instance's name
1040// to be iface_params_new.name to create single Access point.
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001041::ndk::ScopedAStatus Hostapd::addConcurrentAccessPoints(
1042 const IfaceParams& iface_params, const NetworkParams& nw_params)
1043{
1044 int channelParamsListSize = iface_params.channelParams.size();
1045 // Get available interfaces in bridge
Les Lee399c6302024-09-12 03:03:38 +00001046 std::vector<std::string> managed_instances;
1047 std::string br_name = StringPrintf("%s", iface_params.name.c_str());
1048 if (iface_params.usesMlo) {
1049 // MLO AP is using link id as instance.
1050 for (std::size_t i = 0; i < iface_params.instanceIdentities->size(); i++) {
1051 managed_instances.push_back(iface_params.instanceIdentities->at(i)->c_str());
1052 }
1053 } else {
1054 if (!GetInterfacesInBridge(br_name, &managed_instances)) {
1055 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1056 "Get interfaces in bridge failed.");
1057 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001058 }
Les Lee399c6302024-09-12 03:03:38 +00001059 // Either bridged AP or MLO AP should have two instances.
1060 if (managed_instances.size() < channelParamsListSize) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001061 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
Les Lee399c6302024-09-12 03:03:38 +00001062 "Available interfaces less than requested bands");
1063 }
1064
1065 if (iface_params.usesMlo
1066 && nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
1067 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1068 "Invalid encryptionType (OWE transition) for MLO SAP.");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001069 }
1070 // start BSS on specified bands
1071 for (std::size_t i = 0; i < channelParamsListSize; i ++) {
1072 IfaceParams iface_params_new = iface_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301073 NetworkParams nw_params_new = nw_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301074 std::string owe_transition_ifname = "";
Les Lee399c6302024-09-12 03:03:38 +00001075 iface_params_new.name = managed_instances[i];
Ahmed ElArabawy1aaf1802022-02-04 15:58:55 -08001076 if (nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301077 if (i == 0 && i+1 < channelParamsListSize) {
Les Lee399c6302024-09-12 03:03:38 +00001078 owe_transition_ifname = managed_instances[i+1];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301079 nw_params_new.encryptionType = EncryptionType::NONE;
1080 } else {
Les Lee399c6302024-09-12 03:03:38 +00001081 owe_transition_ifname = managed_instances[0];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301082 nw_params_new.isHidden = true;
1083 nw_params_new.ssid = generateRandomOweSsid();
1084 }
1085 }
1086
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001087 ndk::ScopedAStatus status = addSingleAccessPoint(
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301088 iface_params_new, iface_params.channelParams[i], nw_params_new,
1089 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001090 if (!status.isOk()) {
1091 wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s",
Les Lee399c6302024-09-12 03:03:38 +00001092 managed_instances[i].c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001093 return status;
1094 }
1095 }
Les Lee399c6302024-09-12 03:03:38 +00001096
1097 if (iface_params.usesMlo) {
1098 std::size_t i = 0;
1099 std::size_t j = 0;
1100 for (i = 0; i < interfaces_->count; i++) {
1101 struct hostapd_iface *iface = interfaces_->iface[i];
1102
1103 for (j = 0; j < iface->num_bss; j++) {
1104 struct hostapd_data *iface_hapd = iface->bss[j];
1105 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
1106 wpa_printf(
1107 MSG_ERROR, "Enabling interface %s failed on %zu",
1108 iface_params.name.c_str(), i);
1109 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1110 }
1111 }
1112 }
1113 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001114 // Save bridge interface info
Les Lee399c6302024-09-12 03:03:38 +00001115 br_interfaces_[br_name] = managed_instances;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001116 return ndk::ScopedAStatus::ok();
1117}
1118
Les Lee399c6302024-09-12 03:03:38 +00001119struct hostapd_data * hostapd_get_iface_by_link_id(struct hapd_interfaces *interfaces,
1120 const size_t link_id)
1121{
1122#ifdef CONFIG_IEEE80211BE
1123 size_t i, j;
1124
1125 for (i = 0; i < interfaces->count; i++) {
1126 struct hostapd_iface *iface = interfaces->iface[i];
1127
1128 for (j = 0; j < iface->num_bss; j++) {
1129 struct hostapd_data *hapd = iface->bss[j];
1130
1131 if (link_id == hapd->mld_link_id)
1132 return hapd;
1133 }
1134 }
1135#endif
1136 return NULL;
1137}
1138
1139// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1140// -----------------------------------------
1141// | br_name | iface_params.name
1142// _______________________________________________________________
1143// bridged dual APs | bridged interface name | interface name
1144// _______________________________________________________________
1145// MLO AP | AP interface name | mld link id as instance name
1146// _______________________________________________________________
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001147::ndk::ScopedAStatus Hostapd::addSingleAccessPoint(
1148 const IfaceParams& iface_params,
1149 const ChannelParams& channelParams,
1150 const NetworkParams& nw_params,
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301151 const std::string br_name,
1152 const std::string owe_transition_ifname)
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001153{
Les Lee399c6302024-09-12 03:03:38 +00001154 if (iface_params.usesMlo) { // the mlo case, iface name is instance name which is mld_link_id
1155 if (hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str())) {
1156 wpa_printf(
1157 MSG_ERROR, "Instance link id %s already present",
1158 iface_params.name.c_str());
1159 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1160 }
1161 }
1162 if (hostapd_get_iface(interfaces_,
1163 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str())) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001164 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001165 MSG_ERROR, "Instance interface %s already present",
1166 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001167 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1168 }
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301169 const auto conf_params = CreateHostapdConfig(iface_params, channelParams, nw_params,
1170 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001171 if (conf_params.empty()) {
1172 wpa_printf(MSG_ERROR, "Failed to create config params");
1173 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1174 }
1175 const auto conf_file_path =
Les Lee399c6302024-09-12 03:03:38 +00001176 WriteHostapdConfig(iface_params.name, conf_params, br_name, iface_params.usesMlo);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001177 if (conf_file_path.empty()) {
1178 wpa_printf(MSG_ERROR, "Failed to write config file");
1179 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1180 }
1181 std::string add_iface_param_str = StringPrintf(
Les Lee399c6302024-09-12 03:03:38 +00001182 "%s config=%s", iface_params.usesMlo ? br_name.c_str(): iface_params.name.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001183 conf_file_path.c_str());
1184 std::vector<char> add_iface_param_vec(
1185 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
1186 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
1187 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001188 MSG_ERROR, "Adding hostapd iface %s failed",
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001189 add_iface_param_str.c_str());
1190 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1191 }
Les Lee399c6302024-09-12 03:03:38 +00001192
1193 // find the iface and set up callback.
1194 struct hostapd_data* iface_hapd = iface_params.usesMlo ?
1195 hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str()) :
1196 hostapd_get_iface(interfaces_, iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001197 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Les Lee399c6302024-09-12 03:03:38 +00001198 if (iface_params.usesMlo) {
1199 memcmp(iface_hapd->conf->iface, br_name.c_str(), br_name.size());
1200 }
1201
1202 // Callback discrepancy between bridged dual APs and MLO AP
1203 // Note: Only bridged dual APs will have "iface_hapd->conf->bridge" and
1204 // Only MLO AP will have "iface_hapd->mld_link_id"
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001205 // Register the setup complete callbacks
Les Lee399c6302024-09-12 03:03:38 +00001206 // -----------------------------------------
1207 // | bridged dual APs | bridged single link MLO | MLO SAP
1208 // _________________________________________________________________________________________
1209 // hapd->conf->bridge | bridged interface name | bridged interface nam | N/A
1210 // _________________________________________________________________________________________
1211 // hapd->conf->iface | AP interface name | AP interface name | AP interface name
1212 // _________________________________________________________________________________________
1213 // hapd->mld_link_id | 0 (default value) | link id (0) | link id (0 or 1)
1214 // _________________________________________________________________________________________
1215 // hapd->mld_ap | 0 | 1 | 1
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001216 on_setup_complete_internal_callback =
1217 [this](struct hostapd_data* iface_hapd) {
1218 wpa_printf(
1219 MSG_INFO, "AP interface setup completed - state %s",
1220 hostapd_state_text(iface_hapd->iface->state));
1221 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
1222 // Invoke the failure callback on all registered
1223 // clients.
Les Lee399c6302024-09-12 03:03:38 +00001224 std::string instanceName = iface_hapd->conf->iface;
1225#ifdef CONFIG_IEEE80211BE
1226 if (iface_hapd->conf->mld_ap
1227 && strlen(iface_hapd->conf->bridge) == 0) {
1228 instanceName = std::to_string(iface_hapd->mld_link_id);
1229 }
1230#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001231 for (const auto& callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301232 auto status = callback->onFailure(
1233 strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001234 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001235 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301236 if (!status.isOk()) {
1237 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1238 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001239 }
1240 }
1241 };
1242
1243 // Register for new client connect/disconnect indication.
1244 on_sta_authorized_internal_callback =
1245 [this](struct hostapd_data* iface_hapd, const u8 *mac_addr,
1246 int authorized, const u8 *p2p_dev_addr) {
1247 wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s",
1248 MAC2STR(mac_addr),
1249 (authorized) ? "Connected" : "Disconnected");
1250 ClientInfo info;
1251 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1252 iface_hapd->conf->bridge : iface_hapd->conf->iface;
Les Lee399c6302024-09-12 03:03:38 +00001253 std::string instanceName = iface_hapd->conf->iface;
1254#ifdef CONFIG_IEEE80211BE
1255 if (iface_hapd->conf->mld_ap
1256 && strlen(iface_hapd->conf->bridge) == 0) {
1257 instanceName = std::to_string(iface_hapd->mld_link_id);
1258 }
1259#endif
1260 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001261 info.clientAddress.assign(mac_addr, mac_addr + ETH_ALEN);
1262 info.isConnected = authorized;
1263 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301264 auto status = callback->onConnectedClientsChanged(info);
1265 if (!status.isOk()) {
1266 wpa_printf(MSG_ERROR, "Failed to invoke onConnectedClientsChanged");
1267 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001268 }
1269 };
1270
1271 // Register for wpa_event which used to get channel switch event
1272 on_wpa_msg_internal_callback =
1273 [this](struct hostapd_data* iface_hapd, int level,
1274 enum wpa_msg_type type, const char *txt,
1275 size_t len) {
1276 wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt);
1277 if (os_strncmp(txt, AP_EVENT_ENABLED,
1278 strlen(AP_EVENT_ENABLED)) == 0 ||
1279 os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH,
1280 strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) {
Les Lee399c6302024-09-12 03:03:38 +00001281 std::string instanceName = iface_hapd->conf->iface;
1282#ifdef CONFIG_IEEE80211BE
1283 if (iface_hapd->conf->mld_ap && strlen(iface_hapd->conf->bridge) == 0) {
1284 instanceName = std::to_string(iface_hapd->mld_link_id);
1285 }
1286#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001287 ApInfo info;
1288 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1289 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001290 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001291 info.freqMhz = iface_hapd->iface->freq;
Ahmed ElArabawyb4115792022-02-08 09:33:01 -08001292 info.channelBandwidth = getChannelBandwidth(iface_hapd->iconf);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001293 info.generation = getGeneration(iface_hapd->iface->current_mode);
1294 info.apIfaceInstanceMacAddress.assign(iface_hapd->own_addr,
1295 iface_hapd->own_addr + ETH_ALEN);
1296 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301297 auto status = callback->onApInstanceInfoChanged(info);
1298 if (!status.isOk()) {
1299 wpa_printf(MSG_ERROR,
1300 "Failed to invoke onApInstanceInfoChanged");
1301 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001302 }
Les Leea0c90cb2022-04-19 17:39:23 +08001303 } else if (os_strncmp(txt, AP_EVENT_DISABLED, strlen(AP_EVENT_DISABLED)) == 0
1304 || os_strncmp(txt, INTERFACE_DISABLED, strlen(INTERFACE_DISABLED)) == 0)
1305 {
Les Lee399c6302024-09-12 03:03:38 +00001306 std::string instanceName = iface_hapd->conf->iface;
1307#ifdef CONFIG_IEEE80211BE
1308 if (iface_hapd->conf->mld_ap && strlen(iface_hapd->conf->bridge) == 0) {
1309 instanceName = std::to_string(iface_hapd->mld_link_id);
1310 }
1311#endif
Yu Ouyang378d3c42021-08-20 17:31:08 +08001312 // Invoke the failure callback on all registered clients.
1313 for (const auto& callback : callbacks_) {
Les Lee399c6302024-09-12 03:03:38 +00001314 auto status =
1315 callback->onFailure(strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001316 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001317 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301318 if (!status.isOk()) {
1319 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1320 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001321 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001322 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001323 };
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001324
1325 // Setup callback
1326 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
1327 iface_hapd->setup_complete_cb_ctx = iface_hapd;
1328 iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb;
1329 iface_hapd->sta_authorized_cb_ctx = iface_hapd;
Hu Wang7c5a4322021-06-24 17:24:59 +08001330 wpa_msg_register_aidl_cb(onAsyncWpaEventCb);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001331
Les Lee399c6302024-09-12 03:03:38 +00001332 // Multi-link MLO should enable iface after both links have been set.
1333 if (!iface_params.usesMlo && hostapd_enable_iface(iface_hapd->iface) < 0) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001334 wpa_printf(
1335 MSG_ERROR, "Enabling interface %s failed",
1336 iface_params.name.c_str());
1337 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1338 }
1339 return ndk::ScopedAStatus::ok();
1340}
1341
1342::ndk::ScopedAStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
1343{
1344 // interfaces to be removed
1345 std::vector<std::string> interfaces;
1346 bool is_error = false;
1347
1348 const auto it = br_interfaces_.find(iface_name);
1349 if (it != br_interfaces_.end()) {
1350 // In case bridge, remove managed interfaces
1351 interfaces = it->second;
1352 br_interfaces_.erase(iface_name);
1353 } else {
1354 // else remove current interface
1355 interfaces.push_back(iface_name);
1356 }
1357
1358 for (auto& iface : interfaces) {
1359 std::vector<char> remove_iface_param_vec(
1360 iface.begin(), iface.end() + 1);
1361 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) < 0) {
1362 wpa_printf(MSG_INFO, "Remove interface %s failed", iface.c_str());
1363 is_error = true;
1364 }
1365 }
1366 if (is_error) {
1367 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1368 }
1369 return ndk::ScopedAStatus::ok();
1370}
1371
1372::ndk::ScopedAStatus Hostapd::registerCallbackInternal(
1373 const std::shared_ptr<IHostapdCallback>& callback)
1374{
1375 binder_status_t status = AIBinder_linkToDeath(callback->asBinder().get(),
1376 death_notifier_, this /* cookie */);
1377 if (status != STATUS_OK) {
1378 wpa_printf(
1379 MSG_ERROR,
1380 "Error registering for death notification for "
1381 "hostapd callback object");
1382 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1383 }
1384 callbacks_.push_back(callback);
Manaswini Paluri76ae6982024-02-29 14:49:20 +05301385 if (aidl_service_version == 0) {
1386 aidl_service_version = Hostapd::version;
1387 wpa_printf(MSG_INFO, "AIDL service version: %d", aidl_service_version);
1388 }
1389 if (aidl_client_version == 0) {
1390 callback->getInterfaceVersion(&aidl_client_version);
1391 wpa_printf(MSG_INFO, "AIDL client version: %d", aidl_client_version);
1392 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001393 return ndk::ScopedAStatus::ok();
1394}
1395
1396::ndk::ScopedAStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
1397 const std::vector<uint8_t>& client_address, Ieee80211ReasonCode reason_code)
1398{
1399 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
1400 bool result;
1401 if (!hapd) {
1402 for (auto const& iface : br_interfaces_) {
1403 if (iface.first == iface_name) {
1404 for (auto const& instance : iface.second) {
1405 hapd = hostapd_get_iface(interfaces_, instance.c_str());
1406 if (hapd) {
1407 result = forceStaDisconnection(hapd, client_address,
1408 (uint16_t) reason_code);
1409 if (result) break;
1410 }
1411 }
1412 }
1413 }
1414 } else {
1415 result = forceStaDisconnection(hapd, client_address, (uint16_t) reason_code);
1416 }
1417 if (!hapd) {
1418 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
1419 return createStatus(HostapdStatusCode::FAILURE_IFACE_UNKNOWN);
1420 }
1421 if (result) {
1422 return ndk::ScopedAStatus::ok();
1423 }
1424 return createStatus(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN);
1425}
1426
1427::ndk::ScopedAStatus Hostapd::setDebugParamsInternal(DebugLevel level)
1428{
1429 wpa_debug_level = static_cast<uint32_t>(level);
1430 return ndk::ScopedAStatus::ok();
1431}
1432
1433} // namespace hostapd
1434} // namespace wifi
1435} // namespace hardware
1436} // namespace android
Les Leee08c2862021-10-29 16:36:41 +08001437} // namespace aidl