blob: ce3256427cec2429b6e3e5c64980ff9458b64ca8 [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
Sunil Ravide0e6bf2024-10-14 04:58:16 +000082inline int32_t areAidlServiceAndClientAtLeastVersion(int32_t expected_version)
83{
84 return isAidlServiceVersionAtLeast(expected_version)
85 && isAidlClientVersionAtLeast(expected_version);
86}
87
Gabriel Biren72cf9a52021-06-25 23:29:26 +000088#define MAX_PORTS 1024
89bool GetInterfacesInBridge(std::string br_name,
90 std::vector<std::string>* interfaces) {
91 android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
92 if (sock.get() < 0) {
93 wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s",
94 strerror(errno), __FUNCTION__);
95 return false;
96 }
97
98 struct ifreq request;
99 int i, ifindices[MAX_PORTS];
100 char if_name[IFNAMSIZ];
101 unsigned long args[3];
102
103 memset(ifindices, 0, MAX_PORTS * sizeof(int));
104
105 args[0] = BRCTL_GET_PORT_LIST;
106 args[1] = (unsigned long) ifindices;
107 args[2] = MAX_PORTS;
108
109 strlcpy(request.ifr_name, br_name.c_str(), IFNAMSIZ);
110 request.ifr_data = (char *)args;
111
112 if (ioctl(sock.get(), SIOCDEVPRIVATE, &request) < 0) {
113 wpa_printf(MSG_ERROR, "Failed to ioctl SIOCDEVPRIVATE in %s",
114 __FUNCTION__);
115 return false;
116 }
117
118 for (i = 0; i < MAX_PORTS; i ++) {
119 memset(if_name, 0, IFNAMSIZ);
120 if (ifindices[i] == 0 || !if_indextoname(ifindices[i], if_name)) {
121 continue;
122 }
123 interfaces->push_back(if_name);
124 }
125 return true;
126}
127
128std::string WriteHostapdConfig(
Les Lee399c6302024-09-12 03:03:38 +0000129 const std::string& instance_name, const std::string& config,
130 const std::string br_name, const bool usesMlo)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000131{
Les Lee399c6302024-09-12 03:03:38 +0000132 std::string conf_name_as_string = instance_name;
133 if (usesMlo) {
134 conf_name_as_string = StringPrintf(
135 "%s-%s", br_name.c_str(), instance_name.c_str());
136 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000137 const std::string file_path =
Les Lee399c6302024-09-12 03:03:38 +0000138 StringPrintf(kConfFileNameFmt, conf_name_as_string.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000139 if (WriteStringToFile(
140 config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
141 getuid(), getgid())) {
142 return file_path;
143 }
144 // Diagnose failure
145 int error = errno;
146 wpa_printf(
147 MSG_ERROR, "Cannot write hostapd config to %s, error: %s",
148 file_path.c_str(), strerror(error));
149 struct stat st;
150 int result = stat(file_path.c_str(), &st);
151 if (result == 0) {
152 wpa_printf(
153 MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d",
154 st.st_uid, st.st_gid, st.st_mode);
155 } else {
156 wpa_printf(
157 MSG_ERROR,
158 "Error calling stat() on hostapd config file: %s",
159 strerror(errno));
160 }
161 return "";
162}
163
164/*
165 * Get the op_class for a channel/band
166 * The logic here is based on Table E-4 in the 802.11 Specification
167 */
168int getOpClassForChannel(int channel, int band, bool support11n, bool support11ac) {
169 // 2GHz Band
170 if ((band & band2Ghz) != 0) {
171 if (channel == 14) {
172 return 82;
173 }
174 if (channel >= 1 && channel <= 13) {
175 if (!support11n) {
176 //20MHz channel
177 return 81;
178 }
179 if (channel <= 9) {
180 // HT40 with secondary channel above primary
181 return 83;
182 }
183 // HT40 with secondary channel below primary
184 return 84;
185 }
186 // Error
187 return 0;
188 }
189
190 // 5GHz Band
191 if ((band & band5Ghz) != 0) {
192 if (support11ac) {
193 switch (channel) {
194 case 42:
195 case 58:
196 case 106:
197 case 122:
198 case 138:
199 case 155:
200 // 80MHz channel
201 return 128;
202 case 50:
203 case 114:
204 // 160MHz channel
205 return 129;
206 }
207 }
208
209 if (!support11n) {
210 if (channel >= 36 && channel <= 48) {
211 return 115;
212 }
213 if (channel >= 52 && channel <= 64) {
214 return 118;
215 }
216 if (channel >= 100 && channel <= 144) {
217 return 121;
218 }
219 if (channel >= 149 && channel <= 161) {
220 return 124;
221 }
222 if (channel >= 165 && channel <= 169) {
223 return 125;
224 }
225 } else {
226 switch (channel) {
227 case 36:
228 case 44:
229 // HT40 with secondary channel above primary
230 return 116;
231 case 40:
232 case 48:
233 // HT40 with secondary channel below primary
234 return 117;
235 case 52:
236 case 60:
237 // HT40 with secondary channel above primary
238 return 119;
239 case 56:
240 case 64:
241 // HT40 with secondary channel below primary
242 return 120;
243 case 100:
244 case 108:
245 case 116:
246 case 124:
247 case 132:
248 case 140:
249 // HT40 with secondary channel above primary
250 return 122;
251 case 104:
252 case 112:
253 case 120:
254 case 128:
255 case 136:
256 case 144:
257 // HT40 with secondary channel below primary
258 return 123;
259 case 149:
260 case 157:
261 // HT40 with secondary channel above primary
262 return 126;
263 case 153:
264 case 161:
265 // HT40 with secondary channel below primary
266 return 127;
267 }
268 }
269 // Error
270 return 0;
271 }
272
273 // 6GHz Band
274 if ((band & band6Ghz) != 0) {
275 // Channels 1, 5. 9, 13, ...
276 if ((channel & 0x03) == 0x01) {
277 // 20MHz channel
278 return 131;
279 }
280 // Channels 3, 11, 19, 27, ...
281 if ((channel & 0x07) == 0x03) {
282 // 40MHz channel
283 return 132;
284 }
285 // Channels 7, 23, 39, 55, ...
286 if ((channel & 0x0F) == 0x07) {
287 // 80MHz channel
288 return 133;
289 }
290 // Channels 15, 47, 69, ...
291 if ((channel & 0x1F) == 0x0F) {
292 // 160MHz channel
293 return 134;
294 }
295 if (channel == 2) {
296 // 20MHz channel
297 return 136;
298 }
299 // Error
300 return 0;
301 }
302
303 if ((band & band60Ghz) != 0) {
304 if (1 <= channel && channel <= 8) {
305 return 180;
306 } else if (9 <= channel && channel <= 15) {
307 return 181;
308 } else if (17 <= channel && channel <= 22) {
309 return 182;
310 } else if (25 <= channel && channel <= 29) {
311 return 183;
312 }
313 // Error
314 return 0;
315 }
316
317 return 0;
318}
319
320bool validatePassphrase(int passphrase_len, int min_len, int max_len)
321{
322 if (min_len != -1 && passphrase_len < min_len) return false;
323 if (max_len != -1 && passphrase_len > max_len) return false;
324 return true;
325}
326
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530327std::string getInterfaceMacAddress(const std::string& if_name)
328{
329 u8 addr[ETH_ALEN] = {};
330 struct ifreq ifr;
331 std::string mac_addr;
332
333 android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
334 if (sock.get() < 0) {
335 wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s",
336 strerror(errno), __FUNCTION__);
337 return "";
338 }
339
340 memset(&ifr, 0, sizeof(ifr));
341 strlcpy(ifr.ifr_name, if_name.c_str(), IFNAMSIZ);
342 if (ioctl(sock.get(), SIOCGIFHWADDR, &ifr) < 0) {
343 wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
344 if_name.c_str(), strerror(errno));
345 return "";
346 }
347
348 memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
349 mac_addr = StringPrintf("" MACSTR, MAC2STR(addr));
350
351 return mac_addr;
352}
353
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000354std::string CreateHostapdConfig(
355 const IfaceParams& iface_params,
356 const ChannelParams& channelParams,
357 const NetworkParams& nw_params,
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530358 const std::string br_name,
359 const std::string owe_transition_ifname)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000360{
361 if (nw_params.ssid.size() >
362 static_cast<uint32_t>(
363 ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) {
364 wpa_printf(
365 MSG_ERROR, "Invalid SSID size: %zu", nw_params.ssid.size());
366 return "";
367 }
368
369 // SSID string
370 std::stringstream ss;
371 ss << std::hex;
372 ss << std::setfill('0');
373 for (uint8_t b : nw_params.ssid) {
374 ss << std::setw(2) << static_cast<unsigned int>(b);
375 }
376 const std::string ssid_as_string = ss.str();
377
378 // Encryption config string
379 uint32_t band = 0;
380 band |= static_cast<uint32_t>(channelParams.bandMask);
Sunil Ravi4fc918f2022-04-17 09:26:48 -0700381 bool is_2Ghz_band_only = band == static_cast<uint32_t>(band2Ghz);
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000382 bool is_6Ghz_band_only = band == static_cast<uint32_t>(band6Ghz);
383 bool is_60Ghz_band_only = band == static_cast<uint32_t>(band60Ghz);
384 std::string encryption_config_as_string;
385 switch (nw_params.encryptionType) {
386 case EncryptionType::NONE:
387 // no security params
388 break;
389 case EncryptionType::WPA:
390 if (!validatePassphrase(
391 nw_params.passphrase.size(),
392 static_cast<uint32_t>(ParamSizeLimits::
393 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
394 static_cast<uint32_t>(ParamSizeLimits::
395 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
396 return "";
397 }
398 encryption_config_as_string = StringPrintf(
399 "wpa=3\n"
400 "wpa_pairwise=%s\n"
401 "wpa_passphrase=%s",
402 is_60Ghz_band_only ? "GCMP" : "TKIP CCMP",
403 nw_params.passphrase.c_str());
404 break;
405 case EncryptionType::WPA2:
406 if (!validatePassphrase(
407 nw_params.passphrase.size(),
408 static_cast<uint32_t>(ParamSizeLimits::
409 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
410 static_cast<uint32_t>(ParamSizeLimits::
411 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
412 return "";
413 }
414 encryption_config_as_string = StringPrintf(
415 "wpa=2\n"
416 "rsn_pairwise=%s\n"
Sunil Ravib3580db2022-01-28 12:25:46 -0800417#ifdef ENABLE_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL
418 "ieee80211w=1\n"
419#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000420 "wpa_passphrase=%s",
421 is_60Ghz_band_only ? "GCMP" : "CCMP",
422 nw_params.passphrase.c_str());
423 break;
424 case EncryptionType::WPA3_SAE_TRANSITION:
425 if (!validatePassphrase(
426 nw_params.passphrase.size(),
427 static_cast<uint32_t>(ParamSizeLimits::
428 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
429 static_cast<uint32_t>(ParamSizeLimits::
430 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
431 return "";
432 }
Sunil Ravid917c832023-07-07 17:30:33 +0000433 // WPA3 transition mode or SAE+WPA_PSK key management(AKM) is not allowed in 6GHz.
434 // Auto-convert any such configurations to SAE.
435 if ((band & band6Ghz) != 0) {
436 wpa_printf(MSG_INFO, "WPA3_SAE_TRANSITION configured in 6GHz band."
437 "Enable only SAE in key_mgmt");
438 encryption_config_as_string = StringPrintf(
439 "wpa=2\n"
440 "rsn_pairwise=CCMP\n"
441 "wpa_key_mgmt=%s\n"
442 "ieee80211w=2\n"
443 "sae_require_mfp=2\n"
444 "sae_pwe=%d\n"
445 "sae_password=%s",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000446#ifdef CONFIG_IEEE80211BE
Sunil Ravid917c832023-07-07 17:30:33 +0000447 iface_params.hwModeParams.enable80211BE ?
448 "SAE SAE-EXT-KEY" : "SAE",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000449#else
Sunil Ravid917c832023-07-07 17:30:33 +0000450 "SAE",
Sunil Ravic1edd3e2023-02-06 18:52:51 +0000451#endif
Sunil Ravid917c832023-07-07 17:30:33 +0000452 is_6Ghz_band_only ? 1 : 2,
453 nw_params.passphrase.c_str());
454 } else {
455 encryption_config_as_string = StringPrintf(
456 "wpa=2\n"
457 "rsn_pairwise=%s\n"
458 "wpa_key_mgmt=%s\n"
459 "ieee80211w=1\n"
460 "sae_require_mfp=1\n"
461 "wpa_passphrase=%s\n"
462 "sae_password=%s",
463 is_60Ghz_band_only ? "GCMP" : "CCMP",
464#ifdef CONFIG_IEEE80211BE
465 iface_params.hwModeParams.enable80211BE ?
466 "WPA-PSK SAE SAE-EXT-KEY" : "WPA-PSK SAE",
467#else
468 "WPA-PSK SAE",
469#endif
470 nw_params.passphrase.c_str(),
471 nw_params.passphrase.c_str());
472 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000473 break;
474 case EncryptionType::WPA3_SAE:
475 if (!validatePassphrase(nw_params.passphrase.size(), 1, -1)) {
476 return "";
477 }
478 encryption_config_as_string = StringPrintf(
479 "wpa=2\n"
480 "rsn_pairwise=%s\n"
Sunil Ravi65251732023-01-24 05:03:35 +0000481 "wpa_key_mgmt=%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000482 "ieee80211w=2\n"
483 "sae_require_mfp=2\n"
484 "sae_pwe=%d\n"
485 "sae_password=%s",
486 is_60Ghz_band_only ? "GCMP" : "CCMP",
Sunil Ravi65251732023-01-24 05:03:35 +0000487#ifdef CONFIG_IEEE80211BE
488 iface_params.hwModeParams.enable80211BE ? "SAE SAE-EXT-KEY" : "SAE",
489#else
490 "SAE",
491#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000492 is_6Ghz_band_only ? 1 : 2,
493 nw_params.passphrase.c_str());
494 break;
Ahmed ElArabawy1aaf1802022-02-04 15:58:55 -0800495 case EncryptionType::WPA3_OWE_TRANSITION:
496 encryption_config_as_string = StringPrintf(
497 "wpa=2\n"
498 "rsn_pairwise=%s\n"
499 "wpa_key_mgmt=OWE\n"
500 "ieee80211w=2",
501 is_60Ghz_band_only ? "GCMP" : "CCMP");
502 break;
503 case EncryptionType::WPA3_OWE:
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530504 encryption_config_as_string = StringPrintf(
505 "wpa=2\n"
506 "rsn_pairwise=%s\n"
507 "wpa_key_mgmt=OWE\n"
508 "ieee80211w=2",
509 is_60Ghz_band_only ? "GCMP" : "CCMP");
510 break;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000511 default:
512 wpa_printf(MSG_ERROR, "Unknown encryption type");
513 return "";
514 }
515
516 std::string channel_config_as_string;
517 bool isFirst = true;
518 if (channelParams.enableAcs) {
519 std::string freqList_as_string;
520 for (const auto &range :
521 channelParams.acsChannelFreqRangesMhz) {
522 if (!isFirst) {
523 freqList_as_string += ",";
524 }
525 isFirst = false;
526
527 if (range.startMhz != range.endMhz) {
528 freqList_as_string +=
529 StringPrintf("%d-%d", range.startMhz, range.endMhz);
530 } else {
531 freqList_as_string += StringPrintf("%d", range.startMhz);
532 }
533 }
534 channel_config_as_string = StringPrintf(
535 "channel=0\n"
536 "acs_exclude_dfs=%d\n"
537 "freqlist=%s",
538 channelParams.acsShouldExcludeDfs,
539 freqList_as_string.c_str());
540 } else {
541 int op_class = getOpClassForChannel(
542 channelParams.channel,
543 band,
544 iface_params.hwModeParams.enable80211N,
545 iface_params.hwModeParams.enable80211AC);
546 channel_config_as_string = StringPrintf(
547 "channel=%d\n"
548 "op_class=%d",
549 channelParams.channel, op_class);
550 }
551
552 std::string hw_mode_as_string;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000553 std::string enable_edmg_as_string;
554 std::string edmg_channel_as_string;
555 bool is_60Ghz_used = false;
556
557 if (((band & band60Ghz) != 0)) {
558 hw_mode_as_string = "hw_mode=ad";
559 if (iface_params.hwModeParams.enableEdmg) {
560 enable_edmg_as_string = "enable_edmg=1";
561 edmg_channel_as_string = StringPrintf(
562 "edmg_channel=%d",
563 channelParams.channel);
564 }
565 is_60Ghz_used = true;
566 } else if ((band & band2Ghz) != 0) {
567 if (((band & band5Ghz) != 0)
568 || ((band & band6Ghz) != 0)) {
569 hw_mode_as_string = "hw_mode=any";
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000570 } else {
571 hw_mode_as_string = "hw_mode=g";
572 }
573 } else if (((band & band5Ghz) != 0)
574 || ((band & band6Ghz) != 0)) {
575 hw_mode_as_string = "hw_mode=a";
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000576 } else {
577 wpa_printf(MSG_ERROR, "Invalid band");
578 return "";
579 }
580
581 std::string he_params_as_string;
582#ifdef CONFIG_IEEE80211AX
583 if (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) {
584 he_params_as_string = StringPrintf(
585 "ieee80211ax=1\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000586 "he_su_beamformer=%d\n"
587 "he_su_beamformee=%d\n"
588 "he_mu_beamformer=%d\n"
589 "he_twt_required=%d\n",
590 iface_params.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0,
591 iface_params.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0,
592 iface_params.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0,
593 iface_params.hwModeParams.enableHeTargetWakeTime ? 1 : 0);
594 } else {
595 he_params_as_string = "ieee80211ax=0";
596 }
597#endif /* CONFIG_IEEE80211AX */
Sunil Ravi65251732023-01-24 05:03:35 +0000598 std::string eht_params_as_string;
599#ifdef CONFIG_IEEE80211BE
600 if (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) {
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530601 eht_params_as_string = "ieee80211be=1\n";
Sunil Ravide0e6bf2024-10-14 04:58:16 +0000602 if (areAidlServiceAndClientAtLeastVersion(2)) {
Les Lee399c6302024-09-12 03:03:38 +0000603 std::string interface_mac_addr = getInterfaceMacAddress(
604 iface_params.usesMlo ? br_name : iface_params.name);
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530605 if (interface_mac_addr.empty()) {
606 wpa_printf(MSG_ERROR,
607 "Unable to set interface mac address as bssid for 11BE SAP");
608 return "";
609 }
Les Lee399c6302024-09-12 03:03:38 +0000610 if (iface_params.usesMlo) {
611 eht_params_as_string += StringPrintf(
612 "mld_addr=%s\n"
613 "mld_ap=1",
614 interface_mac_addr.c_str());
615 } else {
616 eht_params_as_string += StringPrintf(
617 "bssid=%s\n"
618 "mld_ap=1",
619 interface_mac_addr.c_str());
620 }
Manaswini Paluri76ae6982024-02-29 14:49:20 +0530621 }
Sunil Ravi65251732023-01-24 05:03:35 +0000622 /* TODO set eht_su_beamformer, eht_su_beamformee, eht_mu_beamformer */
623 } else {
624 eht_params_as_string = "ieee80211be=0";
625 }
626#endif /* CONFIG_IEEE80211BE */
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000627
Xin Dengfec682f2024-02-06 22:59:39 -0800628 std::string ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string;
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530629 switch (iface_params.hwModeParams.maximumChannelBandwidth) {
630 case ChannelBandwidth::BANDWIDTH_20:
Xin Dengfec682f2024-02-06 22:59:39 -0800631 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
632#ifdef CONFIG_IEEE80211BE
633 "eht_oper_chwidth=0\n"
634#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530635#ifdef CONFIG_IEEE80211AX
636 "he_oper_chwidth=0\n"
637#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800638 "vht_oper_chwidth=0\n"
639 "%s", (band & band6Ghz) ? "op_class=131" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530640 break;
641 case ChannelBandwidth::BANDWIDTH_40:
Xin Dengfec682f2024-02-06 22:59:39 -0800642 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530643 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800644#ifdef CONFIG_IEEE80211BE
645 "eht_oper_chwidth=0\n"
646#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530647#ifdef CONFIG_IEEE80211AX
648 "he_oper_chwidth=0\n"
649#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800650 "vht_oper_chwidth=0\n"
651 "%s", (band & band6Ghz) ? "op_class=132" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530652 break;
653 case ChannelBandwidth::BANDWIDTH_80:
Xin Dengfec682f2024-02-06 22:59:39 -0800654 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530655 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800656#ifdef CONFIG_IEEE80211BE
657 "eht_oper_chwidth=%d\n"
658#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530659#ifdef CONFIG_IEEE80211AX
660 "he_oper_chwidth=%d\n"
661#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800662 "vht_oper_chwidth=%d\n"
663 "%s",
Xin Dengfec682f2024-02-06 22:59:39 -0800664#ifdef CONFIG_IEEE80211BE
665 (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) ? 1 : 0,
666#endif
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530667#ifdef CONFIG_IEEE80211AX
668 (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) ? 1 : 0,
669#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800670 iface_params.hwModeParams.enable80211AC ? 1 : 0,
671 (band & band6Ghz) ? "op_class=133" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530672 break;
673 case ChannelBandwidth::BANDWIDTH_160:
Xin Dengfec682f2024-02-06 22:59:39 -0800674 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string = StringPrintf(
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530675 "ht_capab=[HT40+]\n"
Xin Dengfec682f2024-02-06 22:59:39 -0800676#ifdef CONFIG_IEEE80211BE
677 "eht_oper_chwidth=%d\n"
678#endif /* CONFIG_IEEE80211BE */
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530679#ifdef CONFIG_IEEE80211AX
680 "he_oper_chwidth=%d\n"
681#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800682 "vht_oper_chwidth=%d\n"
683 "%s",
Xin Dengfec682f2024-02-06 22:59:39 -0800684#ifdef CONFIG_IEEE80211BE
685 (iface_params.hwModeParams.enable80211BE && !is_60Ghz_used) ? 2 : 0,
686#endif
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530687#ifdef CONFIG_IEEE80211AX
688 (iface_params.hwModeParams.enable80211AX && !is_60Ghz_used) ? 2 : 0,
689#endif
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800690 iface_params.hwModeParams.enable80211AC ? 2 : 0,
691 (band & band6Ghz) ? "op_class=134" : "");
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530692 break;
693 default:
Sunil Raviffa5cce2022-08-22 23:37:16 +0000694 if (!is_2Ghz_band_only && !is_60Ghz_used) {
695 if (iface_params.hwModeParams.enable80211AC) {
Xin Dengfec682f2024-02-06 22:59:39 -0800696 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string =
Sunil Ravi4fc918f2022-04-17 09:26:48 -0700697 "ht_capab=[HT40+]\n"
698 "vht_oper_chwidth=1\n";
Sunil Raviffa5cce2022-08-22 23:37:16 +0000699 }
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800700 if (band & band6Ghz) {
Xin Deng3ee3fe12024-02-20 23:24:37 -0800701#ifdef CONFIG_IEEE80211BE
702 if (iface_params.hwModeParams.enable80211BE)
703 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=137\n";
704 else
705 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=134\n";
706#else /* CONFIG_IEEE80211BE */
Xin Dengfec682f2024-02-06 22:59:39 -0800707 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "op_class=134\n";
Xin Deng3ee3fe12024-02-20 23:24:37 -0800708#endif /* CONFIG_IEEE80211BE */
Kiran Kumar Lokereb6445122024-02-06 20:06:27 -0800709 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530710#ifdef CONFIG_IEEE80211AX
Sunil Raviffa5cce2022-08-22 23:37:16 +0000711 if (iface_params.hwModeParams.enable80211AX) {
Xin Dengfec682f2024-02-06 22:59:39 -0800712 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "he_oper_chwidth=1\n";
713 }
714#endif
715#ifdef CONFIG_IEEE80211BE
716 if (iface_params.hwModeParams.enable80211BE) {
717 ht_cap_vht_oper_he_oper_eht_oper_chwidth_as_string += "eht_oper_chwidth=1";
Sunil Raviffa5cce2022-08-22 23:37:16 +0000718 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530719#endif
Sunil Raviffa5cce2022-08-22 23:37:16 +0000720 }
Purushottam Kushwaha90c710b2022-02-04 19:00:34 +0530721 break;
722 }
723
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000724#ifdef CONFIG_INTERWORKING
725 std::string access_network_params_as_string;
726 if (nw_params.isMetered) {
727 access_network_params_as_string = StringPrintf(
728 "interworking=1\n"
729 "access_network_type=2\n"); // CHARGEABLE_PUBLIC_NETWORK
730 } else {
731 access_network_params_as_string = StringPrintf(
732 "interworking=0\n");
733 }
734#endif /* CONFIG_INTERWORKING */
735
736 std::string bridge_as_string;
Les Lee399c6302024-09-12 03:03:38 +0000737 if (!br_name.empty() && !iface_params.usesMlo) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000738 bridge_as_string = StringPrintf("bridge=%s", br_name.c_str());
739 }
740
Serik Beketayev8af7a722021-12-23 12:25:36 -0800741 // vendor_elements string
742 std::string vendor_elements_as_string;
743 if (nw_params.vendorElements.size() > 0) {
744 std::stringstream ss;
745 ss << std::hex;
746 ss << std::setfill('0');
747 for (uint8_t b : nw_params.vendorElements) {
748 ss << std::setw(2) << static_cast<unsigned int>(b);
749 }
750 vendor_elements_as_string = StringPrintf("vendor_elements=%s", ss.str().c_str());
751 }
752
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530753 std::string owe_transition_ifname_as_string;
754 if (!owe_transition_ifname.empty()) {
755 owe_transition_ifname_as_string = StringPrintf(
756 "owe_transition_ifname=%s", owe_transition_ifname.c_str());
757 }
758
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000759 return StringPrintf(
760 "interface=%s\n"
761 "driver=nl80211\n"
Les Lee399c6302024-09-12 03:03:38 +0000762 "ctrl_interface=/data/vendor/wifi/hostapd/ctrl_%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000763 // ssid2 signals to hostapd that the value is not a literal value
764 // for use as a SSID. In this case, we're giving it a hex
765 // std::string and hostapd needs to expect that.
766 "ssid2=%s\n"
767 "%s\n"
768 "ieee80211n=%d\n"
769 "ieee80211ac=%d\n"
770 "%s\n"
771 "%s\n"
772 "%s\n"
Sunil Ravi65251732023-01-24 05:03:35 +0000773 "%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000774 "ignore_broadcast_ssid=%d\n"
775 "wowlan_triggers=any\n"
776#ifdef CONFIG_INTERWORKING
777 "%s\n"
778#endif /* CONFIG_INTERWORKING */
779 "%s\n"
780 "%s\n"
781 "%s\n"
Serik Beketayev8af7a722021-12-23 12:25:36 -0800782 "%s\n"
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530783 "%s\n"
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000784 "%s\n",
Les Lee399c6302024-09-12 03:03:38 +0000785 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str(),
786 iface_params.name.c_str(),
787 ssid_as_string.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000788 channel_config_as_string.c_str(),
789 iface_params.hwModeParams.enable80211N ? 1 : 0,
790 iface_params.hwModeParams.enable80211AC ? 1 : 0,
791 he_params_as_string.c_str(),
Sunil Ravi65251732023-01-24 05:03:35 +0000792 eht_params_as_string.c_str(),
Xin Dengfec682f2024-02-06 22:59:39 -0800793 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 +0000794 nw_params.isHidden ? 1 : 0,
795#ifdef CONFIG_INTERWORKING
796 access_network_params_as_string.c_str(),
797#endif /* CONFIG_INTERWORKING */
798 encryption_config_as_string.c_str(),
799 bridge_as_string.c_str(),
Purushottam Kushwaha0316c882021-12-20 15:07:44 +0530800 owe_transition_ifname_as_string.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000801 enable_edmg_as_string.c_str(),
Serik Beketayev8af7a722021-12-23 12:25:36 -0800802 edmg_channel_as_string.c_str(),
803 vendor_elements_as_string.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000804}
805
806Generation getGeneration(hostapd_hw_modes *current_mode)
807{
808 wpa_printf(MSG_DEBUG, "getGeneration hwmode=%d, ht_enabled=%d,"
809 " vht_enabled=%d, he_supported=%d",
810 current_mode->mode, current_mode->ht_capab != 0,
811 current_mode->vht_capab != 0, current_mode->he_capab->he_supported);
812 switch (current_mode->mode) {
813 case HOSTAPD_MODE_IEEE80211B:
814 return Generation::WIFI_STANDARD_LEGACY;
815 case HOSTAPD_MODE_IEEE80211G:
816 return current_mode->ht_capab == 0 ?
817 Generation::WIFI_STANDARD_LEGACY : Generation::WIFI_STANDARD_11N;
818 case HOSTAPD_MODE_IEEE80211A:
819 if (current_mode->he_capab->he_supported) {
820 return Generation::WIFI_STANDARD_11AX;
821 }
822 return current_mode->vht_capab == 0 ?
823 Generation::WIFI_STANDARD_11N : Generation::WIFI_STANDARD_11AC;
824 case HOSTAPD_MODE_IEEE80211AD:
825 return Generation::WIFI_STANDARD_11AD;
826 default:
827 return Generation::WIFI_STANDARD_UNKNOWN;
828 }
829}
830
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800831ChannelBandwidth getChannelBandwidth(struct hostapd_config *iconf)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000832{
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800833 wpa_printf(MSG_DEBUG, "getChannelBandwidth %d, isHT=%d, isHT40=%d",
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000834 iconf->vht_oper_chwidth, iconf->ieee80211n,
835 iconf->secondary_channel);
836 switch (iconf->vht_oper_chwidth) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000837 case CONF_OPER_CHWIDTH_80MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800838 return ChannelBandwidth::BANDWIDTH_80;
Sunil8cd6f4d2022-06-28 18:40:46 +0000839 case CONF_OPER_CHWIDTH_80P80MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800840 return ChannelBandwidth::BANDWIDTH_80P80;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000841 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000842 case CONF_OPER_CHWIDTH_160MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800843 return ChannelBandwidth::BANDWIDTH_160;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000844 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000845 case CONF_OPER_CHWIDTH_USE_HT:
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000846 if (iconf->ieee80211n) {
847 return iconf->secondary_channel != 0 ?
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800848 ChannelBandwidth::BANDWIDTH_40 : ChannelBandwidth::BANDWIDTH_20;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000849 }
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800850 return ChannelBandwidth::BANDWIDTH_20_NOHT;
Sunil8cd6f4d2022-06-28 18:40:46 +0000851 case CONF_OPER_CHWIDTH_2160MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800852 return ChannelBandwidth::BANDWIDTH_2160;
Sunil8cd6f4d2022-06-28 18:40:46 +0000853 case CONF_OPER_CHWIDTH_4320MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800854 return ChannelBandwidth::BANDWIDTH_4320;
Sunil8cd6f4d2022-06-28 18:40:46 +0000855 case CONF_OPER_CHWIDTH_6480MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800856 return ChannelBandwidth::BANDWIDTH_6480;
Sunil8cd6f4d2022-06-28 18:40:46 +0000857 case CONF_OPER_CHWIDTH_8640MHZ:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800858 return ChannelBandwidth::BANDWIDTH_8640;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000859 default:
Ahmed ElArabawyb4115792022-02-08 09:33:01 -0800860 return ChannelBandwidth::BANDWIDTH_INVALID;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000861 }
862}
863
864bool forceStaDisconnection(struct hostapd_data* hapd,
865 const std::vector<uint8_t>& client_address,
866 const uint16_t reason_code) {
867 struct sta_info *sta;
Sunil Ravi1a360892022-11-29 20:16:01 +0000868 if (client_address.size() != ETH_ALEN) {
869 return false;
870 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000871 for (sta = hapd->sta_list; sta; sta = sta->next) {
872 int res;
873 res = memcmp(sta->addr, client_address.data(), ETH_ALEN);
874 if (res == 0) {
875 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
876 MAC2STR(client_address.data()), reason_code);
877 ap_sta_disconnect(hapd, sta, sta->addr, reason_code);
878 return true;
879 }
880 }
881 return false;
882}
883
884// hostapd core functions accept "C" style function pointers, so use global
885// functions to pass to the hostapd core function and store the corresponding
886// std::function methods to be invoked.
887//
888// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
889//
890// Callback to be invoked once setup is complete
891std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
892void onAsyncSetupCompleteCb(void* ctx)
893{
894 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
895 if (on_setup_complete_internal_callback) {
896 on_setup_complete_internal_callback(iface_hapd);
897 // Invalidate this callback since we don't want this firing
898 // again in single AP mode.
899 if (strlen(iface_hapd->conf->bridge) > 0) {
900 on_setup_complete_internal_callback = nullptr;
901 }
902 }
903}
904
905// Callback to be invoked on hotspot client connection/disconnection
906std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized,
907 const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback;
908void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized,
Sunil Ravid8128a22023-11-06 23:53:58 +0000909 const u8 *p2p_dev_addr, const u8 *ip)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000910{
911 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
912 if (on_sta_authorized_internal_callback) {
913 on_sta_authorized_internal_callback(iface_hapd, mac_addr,
914 authorized, p2p_dev_addr);
915 }
916}
917
918std::function<void(struct hostapd_data*, int level,
919 enum wpa_msg_type type, const char *txt,
920 size_t len)> on_wpa_msg_internal_callback;
921
922void onAsyncWpaEventCb(void *ctx, int level,
923 enum wpa_msg_type type, const char *txt,
924 size_t len)
925{
926 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
927 if (on_wpa_msg_internal_callback) {
928 on_wpa_msg_internal_callback(iface_hapd, level,
929 type, txt, len);
930 }
931}
932
933inline ndk::ScopedAStatus createStatus(HostapdStatusCode status_code) {
934 return ndk::ScopedAStatus::fromServiceSpecificError(
935 static_cast<int32_t>(status_code));
936}
937
938inline ndk::ScopedAStatus createStatusWithMsg(
939 HostapdStatusCode status_code, std::string msg)
940{
941 return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
942 static_cast<int32_t>(status_code), msg.c_str());
943}
944
945// Method called by death_notifier_ on client death.
946void onDeath(void* cookie) {
947 wpa_printf(MSG_ERROR, "Client died. Terminating...");
948 eloop_terminate();
949}
950
951} // namespace
952
953namespace aidl {
954namespace android {
955namespace hardware {
956namespace wifi {
957namespace hostapd {
958
959Hostapd::Hostapd(struct hapd_interfaces* interfaces)
960 : interfaces_(interfaces)
961{
962 death_notifier_ = AIBinder_DeathRecipient_new(onDeath);
963}
964
965::ndk::ScopedAStatus Hostapd::addAccessPoint(
966 const IfaceParams& iface_params, const NetworkParams& nw_params)
967{
968 return addAccessPointInternal(iface_params, nw_params);
969}
970
971::ndk::ScopedAStatus Hostapd::removeAccessPoint(const std::string& iface_name)
972{
973 return removeAccessPointInternal(iface_name);
974}
975
976::ndk::ScopedAStatus Hostapd::terminate()
977{
978 wpa_printf(MSG_INFO, "Terminating...");
979 // Clear the callback to avoid IPCThreadState shutdown during the
980 // callback event.
981 callbacks_.clear();
982 eloop_terminate();
983 return ndk::ScopedAStatus::ok();
984}
985
986::ndk::ScopedAStatus Hostapd::registerCallback(
987 const std::shared_ptr<IHostapdCallback>& callback)
988{
989 return registerCallbackInternal(callback);
990}
991
992::ndk::ScopedAStatus Hostapd::forceClientDisconnect(
993 const std::string& iface_name, const std::vector<uint8_t>& client_address,
994 Ieee80211ReasonCode reason_code)
995{
996 return forceClientDisconnectInternal(iface_name, client_address, reason_code);
997}
998
999::ndk::ScopedAStatus Hostapd::setDebugParams(DebugLevel level)
1000{
1001 return setDebugParamsInternal(level);
1002}
1003
1004::ndk::ScopedAStatus Hostapd::addAccessPointInternal(
1005 const IfaceParams& iface_params,
1006 const NetworkParams& nw_params)
1007{
1008 int channelParamsSize = iface_params.channelParams.size();
1009 if (channelParamsSize == 1) {
1010 // Single AP
1011 wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s",
1012 iface_params.name.c_str());
1013 return addSingleAccessPoint(iface_params, iface_params.channelParams[0],
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301014 nw_params, "", "");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001015 } else if (channelParamsSize == 2) {
1016 // Concurrent APs
1017 wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s",
1018 iface_params.name.c_str());
1019 return addConcurrentAccessPoints(iface_params, nw_params);
1020 }
1021 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1022}
1023
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301024std::vector<uint8_t> generateRandomOweSsid()
1025{
1026 u8 random[8] = {0};
1027 os_get_random(random, 8);
1028
1029 std::string ssid = StringPrintf("Owe-%s", random);
1030 wpa_printf(MSG_INFO, "Generated OWE SSID: %s", ssid.c_str());
1031 std::vector<uint8_t> vssid(ssid.begin(), ssid.end());
1032
1033 return vssid;
1034}
1035
Les Lee399c6302024-09-12 03:03:38 +00001036
1037// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1038// -----------------------------------------
1039// | br_name | instance#1 | instance#2 |
1040// ___________________________________________________________
1041// bridged dual APs | ap_br_wlanX | wlan X | wlanY |
1042// ___________________________________________________________
1043// MLO AP | wlanX | 0 | 1 |
1044// ___________________________________________________________
1045// Both will be added in br_interfaces_[$br_name] and use instance's name
1046// to be iface_params_new.name to create single Access point.
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001047::ndk::ScopedAStatus Hostapd::addConcurrentAccessPoints(
1048 const IfaceParams& iface_params, const NetworkParams& nw_params)
1049{
1050 int channelParamsListSize = iface_params.channelParams.size();
1051 // Get available interfaces in bridge
Les Lee399c6302024-09-12 03:03:38 +00001052 std::vector<std::string> managed_instances;
1053 std::string br_name = StringPrintf("%s", iface_params.name.c_str());
1054 if (iface_params.usesMlo) {
1055 // MLO AP is using link id as instance.
1056 for (std::size_t i = 0; i < iface_params.instanceIdentities->size(); i++) {
1057 managed_instances.push_back(iface_params.instanceIdentities->at(i)->c_str());
1058 }
1059 } else {
1060 if (!GetInterfacesInBridge(br_name, &managed_instances)) {
1061 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1062 "Get interfaces in bridge failed.");
1063 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001064 }
Les Lee399c6302024-09-12 03:03:38 +00001065 // Either bridged AP or MLO AP should have two instances.
1066 if (managed_instances.size() < channelParamsListSize) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001067 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
Les Lee399c6302024-09-12 03:03:38 +00001068 "Available interfaces less than requested bands");
1069 }
1070
1071 if (iface_params.usesMlo
1072 && nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
1073 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1074 "Invalid encryptionType (OWE transition) for MLO SAP.");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001075 }
1076 // start BSS on specified bands
1077 for (std::size_t i = 0; i < channelParamsListSize; i ++) {
1078 IfaceParams iface_params_new = iface_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301079 NetworkParams nw_params_new = nw_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301080 std::string owe_transition_ifname = "";
Les Lee399c6302024-09-12 03:03:38 +00001081 iface_params_new.name = managed_instances[i];
Ahmed ElArabawy1aaf1802022-02-04 15:58:55 -08001082 if (nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301083 if (i == 0 && i+1 < channelParamsListSize) {
Les Lee399c6302024-09-12 03:03:38 +00001084 owe_transition_ifname = managed_instances[i+1];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301085 nw_params_new.encryptionType = EncryptionType::NONE;
1086 } else {
Les Lee399c6302024-09-12 03:03:38 +00001087 owe_transition_ifname = managed_instances[0];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301088 nw_params_new.isHidden = true;
1089 nw_params_new.ssid = generateRandomOweSsid();
1090 }
1091 }
1092
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001093 ndk::ScopedAStatus status = addSingleAccessPoint(
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301094 iface_params_new, iface_params.channelParams[i], nw_params_new,
1095 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001096 if (!status.isOk()) {
1097 wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s",
Les Lee399c6302024-09-12 03:03:38 +00001098 managed_instances[i].c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001099 return status;
1100 }
1101 }
Les Lee399c6302024-09-12 03:03:38 +00001102
1103 if (iface_params.usesMlo) {
1104 std::size_t i = 0;
1105 std::size_t j = 0;
1106 for (i = 0; i < interfaces_->count; i++) {
1107 struct hostapd_iface *iface = interfaces_->iface[i];
1108
1109 for (j = 0; j < iface->num_bss; j++) {
1110 struct hostapd_data *iface_hapd = iface->bss[j];
1111 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
1112 wpa_printf(
1113 MSG_ERROR, "Enabling interface %s failed on %zu",
1114 iface_params.name.c_str(), i);
1115 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1116 }
1117 }
1118 }
1119 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001120 // Save bridge interface info
Les Lee399c6302024-09-12 03:03:38 +00001121 br_interfaces_[br_name] = managed_instances;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001122 return ndk::ScopedAStatus::ok();
1123}
1124
Les Lee399c6302024-09-12 03:03:38 +00001125struct hostapd_data * hostapd_get_iface_by_link_id(struct hapd_interfaces *interfaces,
1126 const size_t link_id)
1127{
1128#ifdef CONFIG_IEEE80211BE
1129 size_t i, j;
1130
1131 for (i = 0; i < interfaces->count; i++) {
1132 struct hostapd_iface *iface = interfaces->iface[i];
1133
1134 for (j = 0; j < iface->num_bss; j++) {
1135 struct hostapd_data *hapd = iface->bss[j];
1136
1137 if (link_id == hapd->mld_link_id)
1138 return hapd;
1139 }
1140 }
1141#endif
1142 return NULL;
1143}
1144
1145// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1146// -----------------------------------------
1147// | br_name | iface_params.name
1148// _______________________________________________________________
1149// bridged dual APs | bridged interface name | interface name
1150// _______________________________________________________________
1151// MLO AP | AP interface name | mld link id as instance name
1152// _______________________________________________________________
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001153::ndk::ScopedAStatus Hostapd::addSingleAccessPoint(
1154 const IfaceParams& iface_params,
1155 const ChannelParams& channelParams,
1156 const NetworkParams& nw_params,
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301157 const std::string br_name,
1158 const std::string owe_transition_ifname)
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001159{
Les Lee399c6302024-09-12 03:03:38 +00001160 if (iface_params.usesMlo) { // the mlo case, iface name is instance name which is mld_link_id
1161 if (hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str())) {
1162 wpa_printf(
1163 MSG_ERROR, "Instance link id %s already present",
1164 iface_params.name.c_str());
1165 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1166 }
1167 }
1168 if (hostapd_get_iface(interfaces_,
1169 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str())) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001170 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001171 MSG_ERROR, "Instance interface %s already present",
1172 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001173 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1174 }
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301175 const auto conf_params = CreateHostapdConfig(iface_params, channelParams, nw_params,
1176 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001177 if (conf_params.empty()) {
1178 wpa_printf(MSG_ERROR, "Failed to create config params");
1179 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1180 }
1181 const auto conf_file_path =
Les Lee399c6302024-09-12 03:03:38 +00001182 WriteHostapdConfig(iface_params.name, conf_params, br_name, iface_params.usesMlo);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001183 if (conf_file_path.empty()) {
1184 wpa_printf(MSG_ERROR, "Failed to write config file");
1185 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1186 }
1187 std::string add_iface_param_str = StringPrintf(
Les Lee399c6302024-09-12 03:03:38 +00001188 "%s config=%s", iface_params.usesMlo ? br_name.c_str(): iface_params.name.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001189 conf_file_path.c_str());
1190 std::vector<char> add_iface_param_vec(
1191 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
1192 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
1193 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001194 MSG_ERROR, "Adding hostapd iface %s failed",
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001195 add_iface_param_str.c_str());
1196 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1197 }
Les Lee399c6302024-09-12 03:03:38 +00001198
1199 // find the iface and set up callback.
1200 struct hostapd_data* iface_hapd = iface_params.usesMlo ?
1201 hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str()) :
1202 hostapd_get_iface(interfaces_, iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001203 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Les Lee399c6302024-09-12 03:03:38 +00001204 if (iface_params.usesMlo) {
1205 memcmp(iface_hapd->conf->iface, br_name.c_str(), br_name.size());
1206 }
1207
1208 // Callback discrepancy between bridged dual APs and MLO AP
1209 // Note: Only bridged dual APs will have "iface_hapd->conf->bridge" and
1210 // Only MLO AP will have "iface_hapd->mld_link_id"
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001211 // Register the setup complete callbacks
Les Lee399c6302024-09-12 03:03:38 +00001212 // -----------------------------------------
1213 // | bridged dual APs | bridged single link MLO | MLO SAP
1214 // _________________________________________________________________________________________
1215 // hapd->conf->bridge | bridged interface name | bridged interface nam | N/A
1216 // _________________________________________________________________________________________
1217 // hapd->conf->iface | AP interface name | AP interface name | AP interface name
1218 // _________________________________________________________________________________________
1219 // hapd->mld_link_id | 0 (default value) | link id (0) | link id (0 or 1)
1220 // _________________________________________________________________________________________
1221 // hapd->mld_ap | 0 | 1 | 1
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001222 on_setup_complete_internal_callback =
1223 [this](struct hostapd_data* iface_hapd) {
1224 wpa_printf(
1225 MSG_INFO, "AP interface setup completed - state %s",
1226 hostapd_state_text(iface_hapd->iface->state));
1227 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
1228 // Invoke the failure callback on all registered
1229 // clients.
Les Lee399c6302024-09-12 03:03:38 +00001230 std::string instanceName = iface_hapd->conf->iface;
1231#ifdef CONFIG_IEEE80211BE
1232 if (iface_hapd->conf->mld_ap
1233 && strlen(iface_hapd->conf->bridge) == 0) {
1234 instanceName = std::to_string(iface_hapd->mld_link_id);
1235 }
1236#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001237 for (const auto& callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301238 auto status = callback->onFailure(
1239 strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001240 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001241 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301242 if (!status.isOk()) {
1243 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1244 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001245 }
1246 }
1247 };
1248
1249 // Register for new client connect/disconnect indication.
1250 on_sta_authorized_internal_callback =
1251 [this](struct hostapd_data* iface_hapd, const u8 *mac_addr,
1252 int authorized, const u8 *p2p_dev_addr) {
1253 wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s",
1254 MAC2STR(mac_addr),
1255 (authorized) ? "Connected" : "Disconnected");
1256 ClientInfo info;
1257 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1258 iface_hapd->conf->bridge : iface_hapd->conf->iface;
Les Lee399c6302024-09-12 03:03:38 +00001259 std::string instanceName = iface_hapd->conf->iface;
1260#ifdef CONFIG_IEEE80211BE
1261 if (iface_hapd->conf->mld_ap
1262 && strlen(iface_hapd->conf->bridge) == 0) {
1263 instanceName = std::to_string(iface_hapd->mld_link_id);
1264 }
1265#endif
1266 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001267 info.clientAddress.assign(mac_addr, mac_addr + ETH_ALEN);
1268 info.isConnected = authorized;
1269 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301270 auto status = callback->onConnectedClientsChanged(info);
1271 if (!status.isOk()) {
1272 wpa_printf(MSG_ERROR, "Failed to invoke onConnectedClientsChanged");
1273 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001274 }
1275 };
1276
1277 // Register for wpa_event which used to get channel switch event
1278 on_wpa_msg_internal_callback =
1279 [this](struct hostapd_data* iface_hapd, int level,
1280 enum wpa_msg_type type, const char *txt,
1281 size_t len) {
1282 wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt);
1283 if (os_strncmp(txt, AP_EVENT_ENABLED,
1284 strlen(AP_EVENT_ENABLED)) == 0 ||
1285 os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH,
1286 strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) {
Les Lee399c6302024-09-12 03:03:38 +00001287 std::string instanceName = iface_hapd->conf->iface;
1288#ifdef CONFIG_IEEE80211BE
1289 if (iface_hapd->conf->mld_ap && strlen(iface_hapd->conf->bridge) == 0) {
1290 instanceName = std::to_string(iface_hapd->mld_link_id);
1291 }
1292#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001293 ApInfo info;
1294 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1295 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001296 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001297 info.freqMhz = iface_hapd->iface->freq;
Ahmed ElArabawyb4115792022-02-08 09:33:01 -08001298 info.channelBandwidth = getChannelBandwidth(iface_hapd->iconf);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001299 info.generation = getGeneration(iface_hapd->iface->current_mode);
1300 info.apIfaceInstanceMacAddress.assign(iface_hapd->own_addr,
1301 iface_hapd->own_addr + ETH_ALEN);
1302 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301303 auto status = callback->onApInstanceInfoChanged(info);
1304 if (!status.isOk()) {
1305 wpa_printf(MSG_ERROR,
1306 "Failed to invoke onApInstanceInfoChanged");
1307 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001308 }
Les Leea0c90cb2022-04-19 17:39:23 +08001309 } else if (os_strncmp(txt, AP_EVENT_DISABLED, strlen(AP_EVENT_DISABLED)) == 0
1310 || os_strncmp(txt, INTERFACE_DISABLED, strlen(INTERFACE_DISABLED)) == 0)
1311 {
Les Lee399c6302024-09-12 03:03:38 +00001312 std::string instanceName = iface_hapd->conf->iface;
1313#ifdef CONFIG_IEEE80211BE
1314 if (iface_hapd->conf->mld_ap && strlen(iface_hapd->conf->bridge) == 0) {
1315 instanceName = std::to_string(iface_hapd->mld_link_id);
1316 }
1317#endif
Yu Ouyang378d3c42021-08-20 17:31:08 +08001318 // Invoke the failure callback on all registered clients.
1319 for (const auto& callback : callbacks_) {
Les Lee399c6302024-09-12 03:03:38 +00001320 auto status =
1321 callback->onFailure(strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001322 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001323 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301324 if (!status.isOk()) {
1325 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1326 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001327 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001328 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001329 };
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001330
1331 // Setup callback
1332 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
1333 iface_hapd->setup_complete_cb_ctx = iface_hapd;
1334 iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb;
1335 iface_hapd->sta_authorized_cb_ctx = iface_hapd;
Hu Wang7c5a4322021-06-24 17:24:59 +08001336 wpa_msg_register_aidl_cb(onAsyncWpaEventCb);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001337
Les Lee399c6302024-09-12 03:03:38 +00001338 // Multi-link MLO should enable iface after both links have been set.
1339 if (!iface_params.usesMlo && hostapd_enable_iface(iface_hapd->iface) < 0) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001340 wpa_printf(
1341 MSG_ERROR, "Enabling interface %s failed",
1342 iface_params.name.c_str());
1343 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1344 }
1345 return ndk::ScopedAStatus::ok();
1346}
1347
1348::ndk::ScopedAStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
1349{
1350 // interfaces to be removed
1351 std::vector<std::string> interfaces;
1352 bool is_error = false;
1353
1354 const auto it = br_interfaces_.find(iface_name);
1355 if (it != br_interfaces_.end()) {
1356 // In case bridge, remove managed interfaces
1357 interfaces = it->second;
1358 br_interfaces_.erase(iface_name);
1359 } else {
1360 // else remove current interface
1361 interfaces.push_back(iface_name);
1362 }
1363
1364 for (auto& iface : interfaces) {
1365 std::vector<char> remove_iface_param_vec(
1366 iface.begin(), iface.end() + 1);
1367 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) < 0) {
1368 wpa_printf(MSG_INFO, "Remove interface %s failed", iface.c_str());
1369 is_error = true;
1370 }
1371 }
1372 if (is_error) {
1373 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1374 }
1375 return ndk::ScopedAStatus::ok();
1376}
1377
1378::ndk::ScopedAStatus Hostapd::registerCallbackInternal(
1379 const std::shared_ptr<IHostapdCallback>& callback)
1380{
1381 binder_status_t status = AIBinder_linkToDeath(callback->asBinder().get(),
1382 death_notifier_, this /* cookie */);
1383 if (status != STATUS_OK) {
1384 wpa_printf(
1385 MSG_ERROR,
1386 "Error registering for death notification for "
1387 "hostapd callback object");
1388 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1389 }
1390 callbacks_.push_back(callback);
Manaswini Paluri76ae6982024-02-29 14:49:20 +05301391 if (aidl_service_version == 0) {
1392 aidl_service_version = Hostapd::version;
1393 wpa_printf(MSG_INFO, "AIDL service version: %d", aidl_service_version);
1394 }
1395 if (aidl_client_version == 0) {
1396 callback->getInterfaceVersion(&aidl_client_version);
1397 wpa_printf(MSG_INFO, "AIDL client version: %d", aidl_client_version);
1398 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001399 return ndk::ScopedAStatus::ok();
1400}
1401
1402::ndk::ScopedAStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
1403 const std::vector<uint8_t>& client_address, Ieee80211ReasonCode reason_code)
1404{
1405 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
1406 bool result;
1407 if (!hapd) {
1408 for (auto const& iface : br_interfaces_) {
1409 if (iface.first == iface_name) {
1410 for (auto const& instance : iface.second) {
1411 hapd = hostapd_get_iface(interfaces_, instance.c_str());
1412 if (hapd) {
1413 result = forceStaDisconnection(hapd, client_address,
1414 (uint16_t) reason_code);
1415 if (result) break;
1416 }
1417 }
1418 }
1419 }
1420 } else {
1421 result = forceStaDisconnection(hapd, client_address, (uint16_t) reason_code);
1422 }
1423 if (!hapd) {
1424 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
1425 return createStatus(HostapdStatusCode::FAILURE_IFACE_UNKNOWN);
1426 }
1427 if (result) {
1428 return ndk::ScopedAStatus::ok();
1429 }
1430 return createStatus(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN);
1431}
1432
1433::ndk::ScopedAStatus Hostapd::setDebugParamsInternal(DebugLevel level)
1434{
1435 wpa_debug_level = static_cast<uint32_t>(level);
1436 return ndk::ScopedAStatus::ok();
1437}
1438
1439} // namespace hostapd
1440} // namespace wifi
1441} // namespace hardware
1442} // namespace android
Les Leee08c2862021-10-29 16:36:41 +08001443} // namespace aidl