blob: a3d4e28d3e17a56e4377683b597ad47f0b914465 [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
Chris Weir808564b2024-08-07 10:12:16 -0700858std::optional<struct sta_info*> getStaInfoByMacAddr(const struct hostapd_data* iface_hapd,
859 const u8 *mac_addr) {
860 if (iface_hapd == nullptr || mac_addr == nullptr){
861 wpa_printf(MSG_ERROR, "nullptr passsed to getStaInfoByMacAddr!");
862 return std::nullopt;
863 }
864
865 for (struct sta_info* sta_ptr = iface_hapd->sta_list; sta_ptr; sta_ptr = sta_ptr->next) {
866 int res;
867 res = memcmp(sta_ptr->addr, mac_addr, ETH_ALEN);
868 if (res == 0) {
869 return sta_ptr;
870 }
871 }
872 return std::nullopt;
873}
874
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000875bool forceStaDisconnection(struct hostapd_data* hapd,
876 const std::vector<uint8_t>& client_address,
877 const uint16_t reason_code) {
Sunil Ravi1a360892022-11-29 20:16:01 +0000878 if (client_address.size() != ETH_ALEN) {
879 return false;
880 }
Chris Weir808564b2024-08-07 10:12:16 -0700881
882 auto sta_ptr_optional = getStaInfoByMacAddr(hapd, client_address.data());
883 if (sta_ptr_optional.has_value()) {
884 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
885 MAC2STR(client_address.data()), reason_code);
886 ap_sta_disconnect(hapd, sta_ptr_optional.value(), sta_ptr_optional.value()->addr,
887 reason_code);
888 return true;
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000889 }
Chris Weir808564b2024-08-07 10:12:16 -0700890
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000891 return false;
892}
893
894// hostapd core functions accept "C" style function pointers, so use global
895// functions to pass to the hostapd core function and store the corresponding
896// std::function methods to be invoked.
897//
898// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
899//
900// Callback to be invoked once setup is complete
901std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
902void onAsyncSetupCompleteCb(void* ctx)
903{
904 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
905 if (on_setup_complete_internal_callback) {
906 on_setup_complete_internal_callback(iface_hapd);
907 // Invalidate this callback since we don't want this firing
908 // again in single AP mode.
909 if (strlen(iface_hapd->conf->bridge) > 0) {
910 on_setup_complete_internal_callback = nullptr;
911 }
912 }
913}
914
915// Callback to be invoked on hotspot client connection/disconnection
916std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized,
917 const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback;
918void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized,
Sunil Ravid8128a22023-11-06 23:53:58 +0000919 const u8 *p2p_dev_addr, const u8 *ip)
Gabriel Biren72cf9a52021-06-25 23:29:26 +0000920{
921 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
922 if (on_sta_authorized_internal_callback) {
923 on_sta_authorized_internal_callback(iface_hapd, mac_addr,
924 authorized, p2p_dev_addr);
925 }
926}
927
928std::function<void(struct hostapd_data*, int level,
929 enum wpa_msg_type type, const char *txt,
930 size_t len)> on_wpa_msg_internal_callback;
931
932void onAsyncWpaEventCb(void *ctx, int level,
933 enum wpa_msg_type type, const char *txt,
934 size_t len)
935{
936 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
937 if (on_wpa_msg_internal_callback) {
938 on_wpa_msg_internal_callback(iface_hapd, level,
939 type, txt, len);
940 }
941}
942
943inline ndk::ScopedAStatus createStatus(HostapdStatusCode status_code) {
944 return ndk::ScopedAStatus::fromServiceSpecificError(
945 static_cast<int32_t>(status_code));
946}
947
948inline ndk::ScopedAStatus createStatusWithMsg(
949 HostapdStatusCode status_code, std::string msg)
950{
951 return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage(
952 static_cast<int32_t>(status_code), msg.c_str());
953}
954
955// Method called by death_notifier_ on client death.
956void onDeath(void* cookie) {
957 wpa_printf(MSG_ERROR, "Client died. Terminating...");
958 eloop_terminate();
959}
960
961} // namespace
962
963namespace aidl {
964namespace android {
965namespace hardware {
966namespace wifi {
967namespace hostapd {
968
969Hostapd::Hostapd(struct hapd_interfaces* interfaces)
970 : interfaces_(interfaces)
971{
972 death_notifier_ = AIBinder_DeathRecipient_new(onDeath);
973}
974
975::ndk::ScopedAStatus Hostapd::addAccessPoint(
976 const IfaceParams& iface_params, const NetworkParams& nw_params)
977{
978 return addAccessPointInternal(iface_params, nw_params);
979}
980
981::ndk::ScopedAStatus Hostapd::removeAccessPoint(const std::string& iface_name)
982{
983 return removeAccessPointInternal(iface_name);
984}
985
986::ndk::ScopedAStatus Hostapd::terminate()
987{
988 wpa_printf(MSG_INFO, "Terminating...");
989 // Clear the callback to avoid IPCThreadState shutdown during the
990 // callback event.
991 callbacks_.clear();
992 eloop_terminate();
993 return ndk::ScopedAStatus::ok();
994}
995
996::ndk::ScopedAStatus Hostapd::registerCallback(
997 const std::shared_ptr<IHostapdCallback>& callback)
998{
999 return registerCallbackInternal(callback);
1000}
1001
1002::ndk::ScopedAStatus Hostapd::forceClientDisconnect(
1003 const std::string& iface_name, const std::vector<uint8_t>& client_address,
1004 Ieee80211ReasonCode reason_code)
1005{
1006 return forceClientDisconnectInternal(iface_name, client_address, reason_code);
1007}
1008
1009::ndk::ScopedAStatus Hostapd::setDebugParams(DebugLevel level)
1010{
1011 return setDebugParamsInternal(level);
1012}
1013
1014::ndk::ScopedAStatus Hostapd::addAccessPointInternal(
1015 const IfaceParams& iface_params,
1016 const NetworkParams& nw_params)
1017{
1018 int channelParamsSize = iface_params.channelParams.size();
1019 if (channelParamsSize == 1) {
1020 // Single AP
1021 wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s",
1022 iface_params.name.c_str());
1023 return addSingleAccessPoint(iface_params, iface_params.channelParams[0],
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301024 nw_params, "", "");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001025 } else if (channelParamsSize == 2) {
1026 // Concurrent APs
1027 wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s",
1028 iface_params.name.c_str());
1029 return addConcurrentAccessPoints(iface_params, nw_params);
1030 }
1031 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1032}
1033
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301034std::vector<uint8_t> generateRandomOweSsid()
1035{
1036 u8 random[8] = {0};
1037 os_get_random(random, 8);
1038
1039 std::string ssid = StringPrintf("Owe-%s", random);
1040 wpa_printf(MSG_INFO, "Generated OWE SSID: %s", ssid.c_str());
1041 std::vector<uint8_t> vssid(ssid.begin(), ssid.end());
1042
1043 return vssid;
1044}
1045
Les Lee399c6302024-09-12 03:03:38 +00001046
1047// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1048// -----------------------------------------
1049// | br_name | instance#1 | instance#2 |
1050// ___________________________________________________________
1051// bridged dual APs | ap_br_wlanX | wlan X | wlanY |
1052// ___________________________________________________________
1053// MLO AP | wlanX | 0 | 1 |
1054// ___________________________________________________________
1055// Both will be added in br_interfaces_[$br_name] and use instance's name
1056// to be iface_params_new.name to create single Access point.
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001057::ndk::ScopedAStatus Hostapd::addConcurrentAccessPoints(
1058 const IfaceParams& iface_params, const NetworkParams& nw_params)
1059{
1060 int channelParamsListSize = iface_params.channelParams.size();
1061 // Get available interfaces in bridge
Les Lee399c6302024-09-12 03:03:38 +00001062 std::vector<std::string> managed_instances;
1063 std::string br_name = StringPrintf("%s", iface_params.name.c_str());
1064 if (iface_params.usesMlo) {
1065 // MLO AP is using link id as instance.
1066 for (std::size_t i = 0; i < iface_params.instanceIdentities->size(); i++) {
1067 managed_instances.push_back(iface_params.instanceIdentities->at(i)->c_str());
1068 }
1069 } else {
1070 if (!GetInterfacesInBridge(br_name, &managed_instances)) {
1071 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1072 "Get interfaces in bridge failed.");
1073 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001074 }
Les Lee399c6302024-09-12 03:03:38 +00001075 // Either bridged AP or MLO AP should have two instances.
1076 if (managed_instances.size() < channelParamsListSize) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001077 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
Les Lee399c6302024-09-12 03:03:38 +00001078 "Available interfaces less than requested bands");
1079 }
1080
1081 if (iface_params.usesMlo
1082 && nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
1083 return createStatusWithMsg(HostapdStatusCode::FAILURE_UNKNOWN,
1084 "Invalid encryptionType (OWE transition) for MLO SAP.");
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001085 }
1086 // start BSS on specified bands
1087 for (std::size_t i = 0; i < channelParamsListSize; i ++) {
1088 IfaceParams iface_params_new = iface_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301089 NetworkParams nw_params_new = nw_params;
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301090 std::string owe_transition_ifname = "";
Les Lee399c6302024-09-12 03:03:38 +00001091 iface_params_new.name = managed_instances[i];
Ahmed ElArabawy1aaf1802022-02-04 15:58:55 -08001092 if (nw_params.encryptionType == EncryptionType::WPA3_OWE_TRANSITION) {
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301093 if (i == 0 && i+1 < channelParamsListSize) {
Les Lee399c6302024-09-12 03:03:38 +00001094 owe_transition_ifname = managed_instances[i+1];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301095 nw_params_new.encryptionType = EncryptionType::NONE;
1096 } else {
Les Lee399c6302024-09-12 03:03:38 +00001097 owe_transition_ifname = managed_instances[0];
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301098 nw_params_new.isHidden = true;
1099 nw_params_new.ssid = generateRandomOweSsid();
1100 }
1101 }
1102
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001103 ndk::ScopedAStatus status = addSingleAccessPoint(
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301104 iface_params_new, iface_params.channelParams[i], nw_params_new,
1105 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001106 if (!status.isOk()) {
1107 wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s",
Les Lee399c6302024-09-12 03:03:38 +00001108 managed_instances[i].c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001109 return status;
1110 }
1111 }
Les Lee399c6302024-09-12 03:03:38 +00001112
1113 if (iface_params.usesMlo) {
1114 std::size_t i = 0;
1115 std::size_t j = 0;
1116 for (i = 0; i < interfaces_->count; i++) {
1117 struct hostapd_iface *iface = interfaces_->iface[i];
1118
1119 for (j = 0; j < iface->num_bss; j++) {
1120 struct hostapd_data *iface_hapd = iface->bss[j];
1121 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
1122 wpa_printf(
1123 MSG_ERROR, "Enabling interface %s failed on %zu",
1124 iface_params.name.c_str(), i);
1125 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1126 }
1127 }
1128 }
1129 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001130 // Save bridge interface info
Les Lee399c6302024-09-12 03:03:38 +00001131 br_interfaces_[br_name] = managed_instances;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001132 return ndk::ScopedAStatus::ok();
1133}
1134
Les Lee399c6302024-09-12 03:03:38 +00001135struct hostapd_data * hostapd_get_iface_by_link_id(struct hapd_interfaces *interfaces,
1136 const size_t link_id)
1137{
1138#ifdef CONFIG_IEEE80211BE
1139 size_t i, j;
1140
1141 for (i = 0; i < interfaces->count; i++) {
1142 struct hostapd_iface *iface = interfaces->iface[i];
1143
1144 for (j = 0; j < iface->num_bss; j++) {
1145 struct hostapd_data *hapd = iface->bss[j];
1146
1147 if (link_id == hapd->mld_link_id)
1148 return hapd;
1149 }
1150 }
1151#endif
1152 return NULL;
1153}
1154
1155// Both of bridged dual APs and MLO AP will be treated as concurrenct APs.
1156// -----------------------------------------
1157// | br_name | iface_params.name
1158// _______________________________________________________________
1159// bridged dual APs | bridged interface name | interface name
1160// _______________________________________________________________
1161// MLO AP | AP interface name | mld link id as instance name
1162// _______________________________________________________________
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001163::ndk::ScopedAStatus Hostapd::addSingleAccessPoint(
1164 const IfaceParams& iface_params,
1165 const ChannelParams& channelParams,
1166 const NetworkParams& nw_params,
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301167 const std::string br_name,
1168 const std::string owe_transition_ifname)
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001169{
Les Lee399c6302024-09-12 03:03:38 +00001170 if (iface_params.usesMlo) { // the mlo case, iface name is instance name which is mld_link_id
1171 if (hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str())) {
1172 wpa_printf(
1173 MSG_ERROR, "Instance link id %s already present",
1174 iface_params.name.c_str());
1175 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1176 }
1177 }
1178 if (hostapd_get_iface(interfaces_,
1179 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str())) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001180 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001181 MSG_ERROR, "Instance interface %s already present",
1182 iface_params.usesMlo ? br_name.c_str() : iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001183 return createStatus(HostapdStatusCode::FAILURE_IFACE_EXISTS);
1184 }
Purushottam Kushwaha0316c882021-12-20 15:07:44 +05301185 const auto conf_params = CreateHostapdConfig(iface_params, channelParams, nw_params,
1186 br_name, owe_transition_ifname);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001187 if (conf_params.empty()) {
1188 wpa_printf(MSG_ERROR, "Failed to create config params");
1189 return createStatus(HostapdStatusCode::FAILURE_ARGS_INVALID);
1190 }
1191 const auto conf_file_path =
Les Lee399c6302024-09-12 03:03:38 +00001192 WriteHostapdConfig(iface_params.name, conf_params, br_name, iface_params.usesMlo);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001193 if (conf_file_path.empty()) {
1194 wpa_printf(MSG_ERROR, "Failed to write config file");
1195 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1196 }
1197 std::string add_iface_param_str = StringPrintf(
Les Lee399c6302024-09-12 03:03:38 +00001198 "%s config=%s", iface_params.usesMlo ? br_name.c_str(): iface_params.name.c_str(),
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001199 conf_file_path.c_str());
1200 std::vector<char> add_iface_param_vec(
1201 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
1202 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
1203 wpa_printf(
Les Lee399c6302024-09-12 03:03:38 +00001204 MSG_ERROR, "Adding hostapd iface %s failed",
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001205 add_iface_param_str.c_str());
1206 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1207 }
Les Lee399c6302024-09-12 03:03:38 +00001208
1209 // find the iface and set up callback.
1210 struct hostapd_data* iface_hapd = iface_params.usesMlo ?
1211 hostapd_get_iface_by_link_id(interfaces_, (size_t) iface_params.name.c_str()) :
1212 hostapd_get_iface(interfaces_, iface_params.name.c_str());
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001213 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Les Lee399c6302024-09-12 03:03:38 +00001214 if (iface_params.usesMlo) {
1215 memcmp(iface_hapd->conf->iface, br_name.c_str(), br_name.size());
1216 }
1217
1218 // Callback discrepancy between bridged dual APs and MLO AP
1219 // Note: Only bridged dual APs will have "iface_hapd->conf->bridge" and
1220 // Only MLO AP will have "iface_hapd->mld_link_id"
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001221 // Register the setup complete callbacks
Les Lee399c6302024-09-12 03:03:38 +00001222 // -----------------------------------------
1223 // | bridged dual APs | bridged single link MLO | MLO SAP
1224 // _________________________________________________________________________________________
1225 // hapd->conf->bridge | bridged interface name | bridged interface nam | N/A
1226 // _________________________________________________________________________________________
1227 // hapd->conf->iface | AP interface name | AP interface name | AP interface name
1228 // _________________________________________________________________________________________
1229 // hapd->mld_link_id | 0 (default value) | link id (0) | link id (0 or 1)
1230 // _________________________________________________________________________________________
1231 // hapd->mld_ap | 0 | 1 | 1
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001232 on_setup_complete_internal_callback =
1233 [this](struct hostapd_data* iface_hapd) {
1234 wpa_printf(
1235 MSG_INFO, "AP interface setup completed - state %s",
1236 hostapd_state_text(iface_hapd->iface->state));
1237 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
1238 // Invoke the failure callback on all registered
1239 // clients.
Les Lee399c6302024-09-12 03:03:38 +00001240 std::string instanceName = iface_hapd->conf->iface;
1241#ifdef CONFIG_IEEE80211BE
1242 if (iface_hapd->conf->mld_ap
1243 && strlen(iface_hapd->conf->bridge) == 0) {
1244 instanceName = std::to_string(iface_hapd->mld_link_id);
1245 }
1246#endif
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001247 for (const auto& callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301248 auto status = callback->onFailure(
1249 strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001250 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001251 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301252 if (!status.isOk()) {
1253 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1254 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001255 }
1256 }
1257 };
1258
1259 // Register for new client connect/disconnect indication.
1260 on_sta_authorized_internal_callback =
1261 [this](struct hostapd_data* iface_hapd, const u8 *mac_addr,
1262 int authorized, const u8 *p2p_dev_addr) {
1263 wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s",
1264 MAC2STR(mac_addr),
1265 (authorized) ? "Connected" : "Disconnected");
1266 ClientInfo info;
1267 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1268 iface_hapd->conf->bridge : iface_hapd->conf->iface;
Les Lee399c6302024-09-12 03:03:38 +00001269 std::string instanceName = iface_hapd->conf->iface;
1270#ifdef CONFIG_IEEE80211BE
1271 if (iface_hapd->conf->mld_ap
1272 && strlen(iface_hapd->conf->bridge) == 0) {
1273 instanceName = std::to_string(iface_hapd->mld_link_id);
1274 }
1275#endif
1276 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001277 info.clientAddress.assign(mac_addr, mac_addr + ETH_ALEN);
1278 info.isConnected = authorized;
Chris Weir808564b2024-08-07 10:12:16 -07001279 if(isAidlServiceVersionAtLeast(3) && !authorized) {
1280 u16 disconnect_reason_code = WLAN_REASON_UNSPECIFIED;
1281 auto sta_ptr_optional = getStaInfoByMacAddr(iface_hapd, mac_addr);
1282 if (sta_ptr_optional.has_value()){
1283 disconnect_reason_code = sta_ptr_optional.value()->deauth_reason;
1284 }
1285 info.disconnectReasonCode =
1286 static_cast<common::DeauthenticationReasonCode>(disconnect_reason_code);
1287 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001288 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301289 auto status = callback->onConnectedClientsChanged(info);
1290 if (!status.isOk()) {
1291 wpa_printf(MSG_ERROR, "Failed to invoke onConnectedClientsChanged");
1292 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001293 }
1294 };
1295
1296 // Register for wpa_event which used to get channel switch event
1297 on_wpa_msg_internal_callback =
1298 [this](struct hostapd_data* iface_hapd, int level,
1299 enum wpa_msg_type type, const char *txt,
1300 size_t len) {
1301 wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt);
1302 if (os_strncmp(txt, AP_EVENT_ENABLED,
1303 strlen(AP_EVENT_ENABLED)) == 0 ||
1304 os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH,
1305 strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) {
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
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001312 ApInfo info;
1313 info.ifaceName = strlen(iface_hapd->conf->bridge) > 0 ?
1314 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001315 info.apIfaceInstance = instanceName;
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001316 info.freqMhz = iface_hapd->iface->freq;
Ahmed ElArabawyb4115792022-02-08 09:33:01 -08001317 info.channelBandwidth = getChannelBandwidth(iface_hapd->iconf);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001318 info.generation = getGeneration(iface_hapd->iface->current_mode);
1319 info.apIfaceInstanceMacAddress.assign(iface_hapd->own_addr,
1320 iface_hapd->own_addr + ETH_ALEN);
1321 for (const auto &callback : callbacks_) {
Chenming Huangbaa5e582024-04-02 08:21:10 +05301322 auto status = callback->onApInstanceInfoChanged(info);
1323 if (!status.isOk()) {
1324 wpa_printf(MSG_ERROR,
1325 "Failed to invoke onApInstanceInfoChanged");
1326 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001327 }
Les Leea0c90cb2022-04-19 17:39:23 +08001328 } else if (os_strncmp(txt, AP_EVENT_DISABLED, strlen(AP_EVENT_DISABLED)) == 0
1329 || os_strncmp(txt, INTERFACE_DISABLED, strlen(INTERFACE_DISABLED)) == 0)
1330 {
Les Lee399c6302024-09-12 03:03:38 +00001331 std::string instanceName = iface_hapd->conf->iface;
1332#ifdef CONFIG_IEEE80211BE
1333 if (iface_hapd->conf->mld_ap && strlen(iface_hapd->conf->bridge) == 0) {
1334 instanceName = std::to_string(iface_hapd->mld_link_id);
1335 }
1336#endif
Yu Ouyang378d3c42021-08-20 17:31:08 +08001337 // Invoke the failure callback on all registered clients.
1338 for (const auto& callback : callbacks_) {
Les Lee399c6302024-09-12 03:03:38 +00001339 auto status =
1340 callback->onFailure(strlen(iface_hapd->conf->bridge) > 0 ?
Les Leee08c2862021-10-29 16:36:41 +08001341 iface_hapd->conf->bridge : iface_hapd->conf->iface,
Les Lee399c6302024-09-12 03:03:38 +00001342 instanceName);
Chenming Huangbaa5e582024-04-02 08:21:10 +05301343 if (!status.isOk()) {
1344 wpa_printf(MSG_ERROR, "Failed to invoke onFailure");
1345 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001346 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001347 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001348 };
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001349
1350 // Setup callback
1351 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
1352 iface_hapd->setup_complete_cb_ctx = iface_hapd;
1353 iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb;
1354 iface_hapd->sta_authorized_cb_ctx = iface_hapd;
Hu Wang7c5a4322021-06-24 17:24:59 +08001355 wpa_msg_register_aidl_cb(onAsyncWpaEventCb);
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001356
Les Lee399c6302024-09-12 03:03:38 +00001357 // Multi-link MLO should enable iface after both links have been set.
1358 if (!iface_params.usesMlo && hostapd_enable_iface(iface_hapd->iface) < 0) {
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001359 wpa_printf(
1360 MSG_ERROR, "Enabling interface %s failed",
1361 iface_params.name.c_str());
1362 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1363 }
1364 return ndk::ScopedAStatus::ok();
1365}
1366
1367::ndk::ScopedAStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
1368{
1369 // interfaces to be removed
1370 std::vector<std::string> interfaces;
1371 bool is_error = false;
1372
1373 const auto it = br_interfaces_.find(iface_name);
1374 if (it != br_interfaces_.end()) {
1375 // In case bridge, remove managed interfaces
1376 interfaces = it->second;
1377 br_interfaces_.erase(iface_name);
1378 } else {
1379 // else remove current interface
1380 interfaces.push_back(iface_name);
1381 }
1382
1383 for (auto& iface : interfaces) {
1384 std::vector<char> remove_iface_param_vec(
1385 iface.begin(), iface.end() + 1);
1386 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) < 0) {
1387 wpa_printf(MSG_INFO, "Remove interface %s failed", iface.c_str());
1388 is_error = true;
1389 }
1390 }
1391 if (is_error) {
1392 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1393 }
1394 return ndk::ScopedAStatus::ok();
1395}
1396
1397::ndk::ScopedAStatus Hostapd::registerCallbackInternal(
1398 const std::shared_ptr<IHostapdCallback>& callback)
1399{
1400 binder_status_t status = AIBinder_linkToDeath(callback->asBinder().get(),
1401 death_notifier_, this /* cookie */);
1402 if (status != STATUS_OK) {
1403 wpa_printf(
1404 MSG_ERROR,
1405 "Error registering for death notification for "
1406 "hostapd callback object");
1407 return createStatus(HostapdStatusCode::FAILURE_UNKNOWN);
1408 }
1409 callbacks_.push_back(callback);
Manaswini Paluri76ae6982024-02-29 14:49:20 +05301410 if (aidl_service_version == 0) {
1411 aidl_service_version = Hostapd::version;
1412 wpa_printf(MSG_INFO, "AIDL service version: %d", aidl_service_version);
1413 }
1414 if (aidl_client_version == 0) {
1415 callback->getInterfaceVersion(&aidl_client_version);
1416 wpa_printf(MSG_INFO, "AIDL client version: %d", aidl_client_version);
1417 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001418 return ndk::ScopedAStatus::ok();
1419}
1420
1421::ndk::ScopedAStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
1422 const std::vector<uint8_t>& client_address, Ieee80211ReasonCode reason_code)
1423{
1424 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
1425 bool result;
1426 if (!hapd) {
1427 for (auto const& iface : br_interfaces_) {
1428 if (iface.first == iface_name) {
1429 for (auto const& instance : iface.second) {
1430 hapd = hostapd_get_iface(interfaces_, instance.c_str());
1431 if (hapd) {
1432 result = forceStaDisconnection(hapd, client_address,
1433 (uint16_t) reason_code);
1434 if (result) break;
1435 }
1436 }
1437 }
1438 }
1439 } else {
1440 result = forceStaDisconnection(hapd, client_address, (uint16_t) reason_code);
1441 }
1442 if (!hapd) {
1443 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
1444 return createStatus(HostapdStatusCode::FAILURE_IFACE_UNKNOWN);
1445 }
1446 if (result) {
1447 return ndk::ScopedAStatus::ok();
1448 }
1449 return createStatus(HostapdStatusCode::FAILURE_CLIENT_UNKNOWN);
1450}
1451
1452::ndk::ScopedAStatus Hostapd::setDebugParamsInternal(DebugLevel level)
1453{
1454 wpa_debug_level = static_cast<uint32_t>(level);
1455 return ndk::ScopedAStatus::ok();
1456}
1457
1458} // namespace hostapd
1459} // namespace wifi
1460} // namespace hardware
1461} // namespace android
Les Leee08c2862021-10-29 16:36:41 +08001462} // namespace aidl