blob: 6bbf3d91aec938a35282f59d6b573f9cbda86213 [file] [log] [blame]
Roshan Piuscc817562017-12-22 14:45:05 -08001/*
2 * hidl 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 */
Roshan Pius30b452e2017-12-27 13:36:21 -08009#include <iomanip>
10#include <sstream>
11#include <string>
12#include <vector>
lesl0cb0e272020-10-30 16:58:08 +080013#include <net/if.h>
14#include <sys/socket.h>
15#include <linux/if_bridge.h>
16
Roshan Pius30b452e2017-12-27 13:36:21 -080017
18#include <android-base/file.h>
19#include <android-base/stringprintf.h>
lesl0cb0e272020-10-30 16:58:08 +080020#include <android-base/unique_fd.h>
Roshan Piuscc817562017-12-22 14:45:05 -080021
22#include "hostapd.h"
23#include "hidl_return_util.h"
24
Roshan Pius3455af42018-02-01 09:19:49 -080025extern "C"
26{
lesldab91502020-08-17 18:29:47 +080027#include "common/wpa_ctrl.h"
lesl0cb0e272020-10-30 16:58:08 +080028#include "drivers/linux_ioctl.h"
Roshan Pius3455af42018-02-01 09:19:49 -080029}
30
Roshan Pius30b452e2017-12-27 13:36:21 -080031// The HIDL implementation for hostapd creates a hostapd.conf dynamically for
32// each interface. This file can then be used to hook onto the normal config
33// file parsing logic in hostapd code. Helps us to avoid duplication of code
34// in the HIDL interface.
35// TOOD(b/71872409): Add unit tests for this.
36namespace {
37constexpr char kConfFileNameFmt[] = "/data/vendor/wifi/hostapd/hostapd_%s.conf";
38
39using android::base::RemoveFileIfExists;
40using android::base::StringPrintf;
41using android::base::WriteStringToFile;
leslb0f4d542020-09-16 23:06:03 +080042using android::hardware::wifi::hostapd::V1_3::IHostapd;
lesldab91502020-08-17 18:29:47 +080043using android::hardware::wifi::hostapd::V1_3::Generation;
44using android::hardware::wifi::hostapd::V1_3::Bandwidth;
Roshan Pius30b452e2017-12-27 13:36:21 -080045
lesl0cb0e272020-10-30 16:58:08 +080046#define MAX_PORTS 1024
47bool GetInterfacesInBridge(std::string br_name,
48 std::vector<std::string>* interfaces) {
49 android::base::unique_fd sock(socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0));
50 if (sock.get() < 0) {
51 wpa_printf(MSG_ERROR, "Failed to create sock (%s) in %s",
52 strerror(errno), __FUNCTION__);
53 return false;
54 }
55
56 struct ifreq request;
57 int i, ifindices[MAX_PORTS];
58 char if_name[IFNAMSIZ];
59 unsigned long args[3];
60
61 memset(ifindices, 0, MAX_PORTS * sizeof(int));
62
63 args[0] = BRCTL_GET_PORT_LIST;
64 args[1] = (unsigned long) ifindices;
65 args[2] = MAX_PORTS;
66
67 strlcpy(request.ifr_name, br_name.c_str(), IFNAMSIZ);
68 request.ifr_data = (char *)args;
69
70 if (ioctl(sock.get(), SIOCDEVPRIVATE, &request) < 0) {
71 wpa_printf(MSG_ERROR, "Failed to ioctl SIOCDEVPRIVATE in %s",
72 __FUNCTION__);
73 return false;
74 }
75
76 for (i = 0; i < MAX_PORTS; i ++) {
77 memset(if_name, 0, IFNAMSIZ);
78 if (ifindices[i] == 0 || !if_indextoname(ifindices[i], if_name)) {
79 continue;
80 }
81 interfaces->push_back(if_name);
82 }
83 return true;
84}
85
Roshan Pius30b452e2017-12-27 13:36:21 -080086std::string WriteHostapdConfig(
87 const std::string& interface_name, const std::string& config)
88{
89 const std::string file_path =
90 StringPrintf(kConfFileNameFmt, interface_name.c_str());
91 if (WriteStringToFile(
92 config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
93 getuid(), getgid())) {
94 return file_path;
95 }
96 // Diagnose failure
97 int error = errno;
98 wpa_printf(
99 MSG_ERROR, "Cannot write hostapd config to %s, error: %s",
100 file_path.c_str(), strerror(error));
101 struct stat st;
102 int result = stat(file_path.c_str(), &st);
103 if (result == 0) {
104 wpa_printf(
105 MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d",
106 st.st_uid, st.st_gid, st.st_mode);
107 } else {
108 wpa_printf(
109 MSG_ERROR,
110 "Error calling stat() on hostapd config file: %s",
111 strerror(errno));
112 }
113 return "";
114}
115
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800116/*
117 * Get the op_class for a channel/band
118 * The logic here is based on Table E-4 in the 802.11 Specification
119 */
120int getOpClassForChannel(int channel, int band, bool support11n, bool support11ac) {
121 // 2GHz Band
122 if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) {
123 if (channel == 14) {
124 return 82;
125 }
126 if (channel >= 1 && channel <= 13) {
127 if (!support11n) {
128 //20MHz channel
129 return 81;
130 }
131 if (channel <= 9) {
132 // HT40 with secondary channel above primary
133 return 83;
134 }
135 // HT40 with secondary channel below primary
136 return 84;
137 }
138 // Error
139 return 0;
140 }
141
142 // 5GHz Band
143 if ((band & IHostapd::BandMask::BAND_5_GHZ) != 0) {
144 if (support11ac) {
145 switch (channel) {
146 case 42:
147 case 58:
148 case 106:
149 case 122:
150 case 138:
151 case 155:
152 // 80MHz channel
153 return 128;
154 case 50:
155 case 114:
156 // 160MHz channel
157 return 129;
158 }
159 }
160
161 if (!support11n) {
162 if (channel >= 36 && channel <= 48) {
163 return 115;
164 }
165 if (channel >= 52 && channel <= 64) {
166 return 118;
167 }
168 if (channel >= 100 && channel <= 144) {
169 return 121;
170 }
171 if (channel >= 149 && channel <= 161) {
172 return 124;
173 }
174 if (channel >= 165 && channel <= 169) {
175 return 125;
176 }
177 } else {
178 switch (channel) {
179 case 36:
180 case 44:
181 // HT40 with secondary channel above primary
182 return 116;
183 case 40:
184 case 48:
185 // HT40 with secondary channel below primary
186 return 117;
187 case 52:
188 case 60:
189 // HT40 with secondary channel above primary
190 return 119;
191 case 56:
192 case 64:
193 // HT40 with secondary channel below primary
194 return 120;
195 case 100:
196 case 108:
197 case 116:
198 case 124:
199 case 132:
200 case 140:
201 // HT40 with secondary channel above primary
202 return 122;
203 case 104:
204 case 112:
205 case 120:
206 case 128:
207 case 136:
208 case 144:
209 // HT40 with secondary channel below primary
210 return 123;
211 case 149:
212 case 157:
213 // HT40 with secondary channel above primary
214 return 126;
215 case 153:
216 case 161:
217 // HT40 with secondary channel below primary
218 return 127;
219 }
220 }
221 // Error
222 return 0;
223 }
224
225 // 6GHz Band
226 if ((band & IHostapd::BandMask::BAND_6_GHZ) != 0) {
227 // Channels 1, 5. 9, 13, ...
228 if ((channel & 0x03) == 0x01) {
229 // 20MHz channel
230 return 131;
231 }
232 // Channels 3, 11, 19, 27, ...
233 if ((channel & 0x07) == 0x03) {
234 // 40MHz channel
235 return 132;
236 }
237 // Channels 7, 23, 39, 55, ...
238 if ((channel & 0x0F) == 0x07) {
239 // 80MHz channel
240 return 133;
241 }
242 // Channels 15, 47, 69, ...
243 if ((channel & 0x1F) == 0x0F) {
244 // 160MHz channel
245 return 134;
246 }
Kai Shia0cfc142020-09-16 20:05:13 -0700247 if (channel == 2) {
248 // 20MHz channel
249 return 136;
250 }
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800251 // Error
252 return 0;
253 }
254
255 return 0;
256}
257
lesldd48efd2019-12-26 15:13:51 +0800258bool validatePassphrase(int passphrase_len, int min_len, int max_len)
259{
260 if (min_len != -1 && passphrase_len < min_len) return false;
261 if (max_len != -1 && passphrase_len > max_len) return false;
262 return true;
263}
264
Roshan Pius30b452e2017-12-27 13:36:21 -0800265std::string CreateHostapdConfig(
lesl0cb0e272020-10-30 16:58:08 +0800266 const android::hardware::wifi::hostapd::V1_2::IHostapd::IfaceParams& iface_params,
267 const IHostapd::NetworkParams& nw_params,
268 const std::string br_name)
Roshan Pius30b452e2017-12-27 13:36:21 -0800269{
leslb0f4d542020-09-16 23:06:03 +0800270 if (nw_params.V1_2.V1_0.ssid.size() >
Roshan Pius30b452e2017-12-27 13:36:21 -0800271 static_cast<uint32_t>(
272 IHostapd::ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) {
273 wpa_printf(
leslb0f4d542020-09-16 23:06:03 +0800274 MSG_ERROR, "Invalid SSID size: %zu", nw_params.V1_2.V1_0.ssid.size());
Roshan Pius30b452e2017-12-27 13:36:21 -0800275 return "";
276 }
277
278 // SSID string
279 std::stringstream ss;
280 ss << std::hex;
281 ss << std::setfill('0');
leslb0f4d542020-09-16 23:06:03 +0800282 for (uint8_t b : nw_params.V1_2.V1_0.ssid) {
Roshan Pius30b452e2017-12-27 13:36:21 -0800283 ss << std::setw(2) << static_cast<unsigned int>(b);
284 }
285 const std::string ssid_as_string = ss.str();
286
287 // Encryption config string
Kai Shi35d8ea42020-10-07 15:24:01 -0700288 uint32_t band = 0;
289 band |= iface_params.channelParams.bandMask;
290 bool is_6Ghz_band_only = band == static_cast<uint32_t>(IHostapd::BandMask::BAND_6_GHZ);
Roshan Pius30b452e2017-12-27 13:36:21 -0800291 std::string encryption_config_as_string;
leslb0f4d542020-09-16 23:06:03 +0800292 switch (nw_params.V1_2.encryptionType) {
Roshan Pius30b452e2017-12-27 13:36:21 -0800293 case IHostapd::EncryptionType::NONE:
294 // no security params
295 break;
296 case IHostapd::EncryptionType::WPA:
lesldd48efd2019-12-26 15:13:51 +0800297 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800298 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800299 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
300 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
301 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
302 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
303 return "";
304 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800305 encryption_config_as_string = StringPrintf(
306 "wpa=3\n"
307 "wpa_pairwise=TKIP CCMP\n"
308 "wpa_passphrase=%s",
leslb0f4d542020-09-16 23:06:03 +0800309 nw_params.V1_2.passphrase.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800310 break;
311 case IHostapd::EncryptionType::WPA2:
lesldd48efd2019-12-26 15:13:51 +0800312 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800313 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800314 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
315 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
316 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
317 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
318 return "";
319 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800320 encryption_config_as_string = StringPrintf(
321 "wpa=2\n"
322 "rsn_pairwise=CCMP\n"
323 "wpa_passphrase=%s",
leslb0f4d542020-09-16 23:06:03 +0800324 nw_params.V1_2.passphrase.c_str());
lesldd48efd2019-12-26 15:13:51 +0800325 break;
326 case IHostapd::EncryptionType::WPA3_SAE_TRANSITION:
327 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800328 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800329 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
330 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
331 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
332 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
333 return "";
334 }
335 encryption_config_as_string = StringPrintf(
336 "wpa=2\n"
337 "rsn_pairwise=CCMP\n"
338 "wpa_key_mgmt=WPA-PSK SAE\n"
339 "ieee80211w=1\n"
340 "sae_require_mfp=1\n"
341 "wpa_passphrase=%s\n"
342 "sae_password=%s",
leslb0f4d542020-09-16 23:06:03 +0800343 nw_params.V1_2.passphrase.c_str(),
344 nw_params.V1_2.passphrase.c_str());
lesldd48efd2019-12-26 15:13:51 +0800345 break;
346 case IHostapd::EncryptionType::WPA3_SAE:
leslb0f4d542020-09-16 23:06:03 +0800347 if (!validatePassphrase(nw_params.V1_2.passphrase.size(), 1, -1)) {
lesldd48efd2019-12-26 15:13:51 +0800348 return "";
349 }
350 encryption_config_as_string = StringPrintf(
351 "wpa=2\n"
352 "rsn_pairwise=CCMP\n"
353 "wpa_key_mgmt=SAE\n"
354 "ieee80211w=2\n"
355 "sae_require_mfp=2\n"
Kai Shi35d8ea42020-10-07 15:24:01 -0700356 "sae_pwe=%d\n"
lesldd48efd2019-12-26 15:13:51 +0800357 "sae_password=%s",
Kai Shi35d8ea42020-10-07 15:24:01 -0700358 is_6Ghz_band_only ? 1 : 2,
leslb0f4d542020-09-16 23:06:03 +0800359 nw_params.V1_2.passphrase.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800360 break;
361 default:
362 wpa_printf(MSG_ERROR, "Unknown encryption type");
363 return "";
364 }
365
366 std::string channel_config_as_string;
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800367 bool isFirst = true;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800368 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800369 std::string freqList_as_string;
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900370 for (const auto &range :
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800371 iface_params.channelParams.acsChannelFreqRangesMhz) {
372 if (!isFirst) {
373 freqList_as_string += ",";
374 }
375 isFirst = false;
376
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900377 if (range.start != range.end) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800378 freqList_as_string +=
379 StringPrintf("%d-%d", range.start, range.end);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900380 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800381 freqList_as_string += StringPrintf("%d", range.start);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900382 }
383 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800384 channel_config_as_string = StringPrintf(
385 "channel=0\n"
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900386 "acs_exclude_dfs=%d\n"
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800387 "freqlist=%s",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800388 iface_params.V1_1.V1_0.channelParams.acsShouldExcludeDfs,
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800389 freqList_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800390 } else {
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800391 int op_class = getOpClassForChannel(
392 iface_params.V1_1.V1_0.channelParams.channel,
393 band,
394 iface_params.V1_1.V1_0.hwModeParams.enable80211N,
395 iface_params.V1_1.V1_0.hwModeParams.enable80211AC);
Roshan Pius30b452e2017-12-27 13:36:21 -0800396 channel_config_as_string = StringPrintf(
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800397 "channel=%d\n"
398 "op_class=%d",
399 iface_params.V1_1.V1_0.channelParams.channel, op_class);
Roshan Pius30b452e2017-12-27 13:36:21 -0800400 }
401
Roshan Pius30b452e2017-12-27 13:36:21 -0800402 std::string hw_mode_as_string;
Roshan Pius49446472018-03-07 10:23:46 -0800403 std::string ht_cap_vht_oper_chwidth_as_string;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800404
405 if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800406 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
407 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800408 hw_mode_as_string = "hw_mode=any";
409 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
410 ht_cap_vht_oper_chwidth_as_string =
411 "ht_capab=[HT40+]\n"
412 "vht_oper_chwidth=1";
413 }
414 } else {
415 hw_mode_as_string = "hw_mode=g";
Roshan Pius49446472018-03-07 10:23:46 -0800416 }
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800417 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800418 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
419 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800420 hw_mode_as_string = "hw_mode=a";
421 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
422 ht_cap_vht_oper_chwidth_as_string =
423 "ht_capab=[HT40+]\n"
424 "vht_oper_chwidth=1";
425 }
426 } else {
427 wpa_printf(MSG_ERROR, "Invalid band");
428 return "";
Roshan Pius49446472018-03-07 10:23:46 -0800429 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800430 }
431
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800432 std::string he_params_as_string;
Roshan Pius36510302020-05-09 21:01:01 -0700433#ifdef CONFIG_IEEE80211AX
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800434 if (iface_params.hwModeParams.enable80211AX) {
435 he_params_as_string = StringPrintf(
436 "ieee80211ax=1\n"
437 "he_su_beamformer=%d\n"
438 "he_su_beamformee=%d\n"
439 "he_mu_beamformer=%d\n"
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800440 "he_twt_required=%d\n",
441 iface_params.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0,
442 iface_params.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0,
443 iface_params.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0,
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800444 iface_params.hwModeParams.enableHeTargetWakeTime ? 1 : 0);
445 } else {
446 he_params_as_string = "ieee80211ax=0";
447 }
Roshan Pius36510302020-05-09 21:01:01 -0700448#endif /* CONFIG_IEEE80211AX */
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800449
leslb0f4d542020-09-16 23:06:03 +0800450#ifdef CONFIG_INTERWORKING
451 std::string access_network_params_as_string;
452 if (nw_params.isMetered) {
453 access_network_params_as_string = StringPrintf(
454 "interworking=1\n"
455 "access_network_type=2\n"); // CHARGEABLE_PUBLIC_NETWORK
456 } else {
457 access_network_params_as_string = StringPrintf(
458 "interworking=0\n");
459 }
460#endif /* CONFIG_INTERWORKING */
461
lesl0cb0e272020-10-30 16:58:08 +0800462 std::string bridge_as_string;
463 if (!br_name.empty()) {
464 bridge_as_string = StringPrintf("bridge=%s", br_name.c_str());
465 }
466
Roshan Pius30b452e2017-12-27 13:36:21 -0800467 return StringPrintf(
468 "interface=%s\n"
469 "driver=nl80211\n"
Daichi Ueuracaa74a82018-02-14 22:25:39 +0900470 "ctrl_interface=/data/vendor/wifi/hostapd/ctrl\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800471 // ssid2 signals to hostapd that the value is not a literal value
472 // for use as a SSID. In this case, we're giving it a hex
473 // std::string and hostapd needs to expect that.
474 "ssid2=%s\n"
475 "%s\n"
476 "ieee80211n=%d\n"
477 "ieee80211ac=%d\n"
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800478 "%s\n"
Roshan Piuse453f712018-02-09 15:49:57 -0800479 "%s\n"
Roshan Pius49446472018-03-07 10:23:46 -0800480 "%s\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800481 "ignore_broadcast_ssid=%d\n"
482 "wowlan_triggers=any\n"
leslb0f4d542020-09-16 23:06:03 +0800483#ifdef CONFIG_INTERWORKING
484 "%s\n"
485#endif /* CONFIG_INTERWORKING */
lesl0cb0e272020-10-30 16:58:08 +0800486 "%s\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800487 "%s\n",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800488 iface_params.V1_1.V1_0.ifaceName.c_str(), ssid_as_string.c_str(),
Roshan Pius30b452e2017-12-27 13:36:21 -0800489 channel_config_as_string.c_str(),
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800490 iface_params.V1_1.V1_0.hwModeParams.enable80211N ? 1 : 0,
491 iface_params.V1_1.V1_0.hwModeParams.enable80211AC ? 1 : 0,
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800492 he_params_as_string.c_str(),
Roshan Pius49446472018-03-07 10:23:46 -0800493 hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(),
leslb0f4d542020-09-16 23:06:03 +0800494 nw_params.V1_2.V1_0.isHidden ? 1 : 0,
495#ifdef CONFIG_INTERWORKING
lesl0cb0e272020-10-30 16:58:08 +0800496 access_network_params_as_string.c_str(),
leslb0f4d542020-09-16 23:06:03 +0800497#endif /* CONFIG_INTERWORKING */
lesl0cb0e272020-10-30 16:58:08 +0800498 encryption_config_as_string.c_str(),
499 bridge_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800500}
Roshan Piuse2d21012018-08-17 11:22:06 -0700501
lesldab91502020-08-17 18:29:47 +0800502Generation getGeneration(hostapd_hw_modes *current_mode)
503{
504 wpa_printf(MSG_DEBUG, "getGeneration hwmode=%d, ht_enabled=%d, vht_enabled=%d",
505 current_mode->mode, current_mode->ht_capab != 0,
506 current_mode->vht_capab != 0);
507 switch (current_mode->mode) {
508 case HOSTAPD_MODE_IEEE80211B:
509 return Generation::WIFI_STANDARD_LEGACY;
510 case HOSTAPD_MODE_IEEE80211G:
511 return current_mode->ht_capab == 0 ?
512 Generation::WIFI_STANDARD_LEGACY : Generation::WIFI_STANDARD_11N;
513 case HOSTAPD_MODE_IEEE80211A:
514 return current_mode->vht_capab == 0 ?
515 Generation::WIFI_STANDARD_11N : Generation::WIFI_STANDARD_11AC;
516 // TODO: b/162484222 miss HOSTAPD_MODE_IEEE80211AX definition.
517 default:
518 return Generation::WIFI_STANDARD_UNKNOWN;
519 }
520}
521
522Bandwidth getBandwidth(struct hostapd_config *iconf)
523{
524 wpa_printf(MSG_DEBUG, "getBandwidth %d, isHT=%d, isHT40=%d",
525 iconf->vht_oper_chwidth, iconf->ieee80211n,
526 iconf->secondary_channel);
527 switch (iconf->vht_oper_chwidth) {
528 case CHANWIDTH_80MHZ:
529 return Bandwidth::WIFI_BANDWIDTH_80;
530 case CHANWIDTH_80P80MHZ:
531 return Bandwidth::WIFI_BANDWIDTH_80P80;
532 break;
533 case CHANWIDTH_160MHZ:
534 return Bandwidth::WIFI_BANDWIDTH_160;
535 break;
536 case CHANWIDTH_USE_HT:
537 if (iconf->ieee80211n) {
538 return iconf->secondary_channel != 0 ?
539 Bandwidth::WIFI_BANDWIDTH_40 : Bandwidth::WIFI_BANDWIDTH_20;
540 }
541 return Bandwidth::WIFI_BANDWIDTH_20_NOHT;
542 default:
543 return Bandwidth::WIFI_BANDWIDTH_INVALID;
544 }
545}
546
Roshan Piuse2d21012018-08-17 11:22:06 -0700547// hostapd core functions accept "C" style function pointers, so use global
548// functions to pass to the hostapd core function and store the corresponding
549// std::function methods to be invoked.
550//
551// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
552//
553// Callback to be invoked once setup is complete
554std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
555void onAsyncSetupCompleteCb(void* ctx)
556{
557 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
558 if (on_setup_complete_internal_callback) {
559 on_setup_complete_internal_callback(iface_hapd);
560 // Invalidate this callback since we don't want this firing
lesl0cb0e272020-10-30 16:58:08 +0800561 // again in single AP mode.
562 if (strlen(iface_hapd->conf->bridge) > 0) {
563 on_setup_complete_internal_callback = nullptr;
564 }
Roshan Piuse2d21012018-08-17 11:22:06 -0700565 }
566}
lesld0621052020-08-10 13:54:28 +0800567
568// Callback to be invoked on hotspot client connection/disconnection
569std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized,
570 const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback;
571void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized,
572 const u8 *p2p_dev_addr)
573{
574 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
575 if (on_sta_authorized_internal_callback) {
576 on_sta_authorized_internal_callback(iface_hapd, mac_addr,
577 authorized, p2p_dev_addr);
578 }
579}
580
lesldab91502020-08-17 18:29:47 +0800581std::function<void(struct hostapd_data*, int level,
582 enum wpa_msg_type type, const char *txt,
583 size_t len)> on_wpa_msg_internal_callback;
584
585void onAsyncWpaEventCb(void *ctx, int level,
586 enum wpa_msg_type type, const char *txt,
587 size_t len)
588{
589 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
590 if (on_wpa_msg_internal_callback) {
591 on_wpa_msg_internal_callback(iface_hapd, level,
592 type, txt, len);
593 }
594}
595
596
Roshan Pius30b452e2017-12-27 13:36:21 -0800597} // namespace
598
Roshan Piuscc817562017-12-22 14:45:05 -0800599namespace android {
600namespace hardware {
601namespace wifi {
602namespace hostapd {
leslf8b1b402020-08-04 17:09:39 +0800603namespace V1_3 {
Roshan Piuscc817562017-12-22 14:45:05 -0800604namespace implementation {
605using hidl_return_util::call;
Roshan Piuse2d21012018-08-17 11:22:06 -0700606using namespace android::hardware::wifi::hostapd::V1_0;
Roshan Piuscc817562017-12-22 14:45:05 -0800607
Roshan Pius80e5a0f2020-10-19 13:48:22 -0700608Hostapd::Hostapd(struct hapd_interfaces* interfaces)
609 : interfaces_(interfaces), death_notifier_(sp<DeathNotifier>::make())
Roshan Piuscc817562017-12-22 14:45:05 -0800610{}
611
612Return<void> Hostapd::addAccessPoint(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900613 const V1_0::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800614 const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900615{
616 return call(
617 this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params,
618 nw_params);
619}
620
621Return<void> Hostapd::addAccessPoint_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800622 const V1_1::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800623 const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
Roshan Piuscc817562017-12-22 14:45:05 -0800624{
625 return call(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900626 this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params,
Roshan Piuscc817562017-12-22 14:45:05 -0800627 nw_params);
628}
629
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800630Return<void> Hostapd::addAccessPoint_1_2(
leslb0f4d542020-09-16 23:06:03 +0800631 const V1_2::IHostapd::IfaceParams& iface_params,
632 const V1_2::IHostapd::NetworkParams& nw_params,
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800633 addAccessPoint_1_2_cb _hidl_cb)
634{
635 return call(
636 this, &Hostapd::addAccessPointInternal_1_2, _hidl_cb, iface_params,
637 nw_params);
638}
639
leslb0f4d542020-09-16 23:06:03 +0800640Return<void> Hostapd::addAccessPoint_1_3(
641 const V1_3::IHostapd::IfaceParams& iface_params,
642 const V1_3::IHostapd::NetworkParams& nw_params,
643 addAccessPoint_1_3_cb _hidl_cb)
644{
645 return call(
646 this, &Hostapd::addAccessPointInternal_1_3, _hidl_cb, iface_params,
647 nw_params);
648}
649
Roshan Piuscc817562017-12-22 14:45:05 -0800650Return<void> Hostapd::removeAccessPoint(
651 const hidl_string& iface_name, removeAccessPoint_cb _hidl_cb)
652{
653 return call(
654 this, &Hostapd::removeAccessPointInternal, _hidl_cb, iface_name);
655}
656
Roshan Piuse2d21012018-08-17 11:22:06 -0700657Return<void> Hostapd::terminate()
658{
Roshan Pius3455af42018-02-01 09:19:49 -0800659 wpa_printf(MSG_INFO, "Terminating...");
660 eloop_terminate();
661 return Void();
662}
663
Roshan Piuse2d21012018-08-17 11:22:06 -0700664Return<void> Hostapd::registerCallback(
lesl1a842e62019-12-02 19:00:37 +0800665 const sp<V1_1::IHostapdCallback>& callback, registerCallback_cb _hidl_cb)
Roshan Piuse2d21012018-08-17 11:22:06 -0700666{
667 return call(
668 this, &Hostapd::registerCallbackInternal, _hidl_cb, callback);
669}
670
leslf8b1b402020-08-04 17:09:39 +0800671Return<void> Hostapd::registerCallback_1_3(
672 const sp<V1_3::IHostapdCallback>& callback, registerCallback_1_3_cb _hidl_cb)
673{
674 return call(
675 this, &Hostapd::registerCallbackInternal_1_3, _hidl_cb, callback);
676}
677
lesl1a842e62019-12-02 19:00:37 +0800678Return<void> Hostapd::forceClientDisconnect(
679 const hidl_string& iface_name, const hidl_array<uint8_t, 6>& client_address,
680 V1_2::Ieee80211ReasonCode reason_code, forceClientDisconnect_cb _hidl_cb)
681{
682 return call(
683 this, &Hostapd::forceClientDisconnectInternal, _hidl_cb, iface_name,
684 client_address, reason_code);
685}
686
Roger Wangcede5062019-12-30 12:56:28 +0800687Return<void> Hostapd::setDebugParams(
leslf8b1b402020-08-04 17:09:39 +0800688 V1_2::DebugLevel level, setDebugParams_cb _hidl_cb)
Roger Wangcede5062019-12-30 12:56:28 +0800689{
690 return call(
691 this, &Hostapd::setDebugParamsInternal, _hidl_cb, level);
692}
lesl1a842e62019-12-02 19:00:37 +0800693
694V1_0::HostapdStatus Hostapd::addAccessPointInternal(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900695 const V1_0::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800696 const V1_0::IHostapd::NetworkParams& nw_params)
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900697{
lesl1a842e62019-12-02 19:00:37 +0800698 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900699}
700
lesl1a842e62019-12-02 19:00:37 +0800701V1_0::HostapdStatus Hostapd::addAccessPointInternal_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800702 const V1_1::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800703 const V1_1::IHostapd::NetworkParams& nw_params)
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800704{
705 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
706}
707
leslf8b1b402020-08-04 17:09:39 +0800708V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_2(
leslb0f4d542020-09-16 23:06:03 +0800709 const V1_2::IHostapd::IfaceParams& iface_params,
710 const V1_2::IHostapd::NetworkParams& nw_params) {
711 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
712}
713
lesl0cb0e272020-10-30 16:58:08 +0800714V1_2::IHostapd::IfaceParams prepareIfaceParams1_2From1_3(const std::string interfaceName,
715 const V1_3::IHostapd::IfaceParams iface_1_3,
716 const V1_3::IHostapd::ChannelParams channelParams_1_3)
717{
718 // Using HIDL 1.2 iface_params to enable the AP
719 V1_2::IHostapd::IfaceParams iface_params_1_2 = iface_1_3.V1_2;
720 iface_params_1_2.V1_1.V1_0.ifaceName = interfaceName;
721 // Prepare bandMask & acsChannelFreqRangesMhz
722 iface_params_1_2.channelParams = channelParams_1_3.V1_2;
723 // Prepare channel
724 iface_params_1_2.V1_1.V1_0.channelParams.channel = channelParams_1_3.channel;
725 // Prepare enableAcs
726 iface_params_1_2.V1_1.V1_0.channelParams.enableAcs = channelParams_1_3.enableAcs;
727 return iface_params_1_2;
728}
729
leslb0f4d542020-09-16 23:06:03 +0800730V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_3(
lesl0cb0e272020-10-30 16:58:08 +0800731 const V1_3::IHostapd::IfaceParams& iface_params,
leslb0f4d542020-09-16 23:06:03 +0800732 const V1_3::IHostapd::NetworkParams& nw_params)
Roshan Piuscc817562017-12-22 14:45:05 -0800733{
lesl0cb0e272020-10-30 16:58:08 +0800734 int channelParamsListSize = iface_params.channelParamsList.size();
735 if (channelParamsListSize == 1) {
736 // Single AP
737 wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s",
738 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
739 return addSingleAccessPoint(
740 prepareIfaceParams1_2From1_3(iface_params.V1_2.V1_1.V1_0.ifaceName,
741 iface_params, iface_params.channelParamsList[0]),
742 nw_params, "");
743 } else if (channelParamsListSize == 2) {
744 // Concurrent APs
745 wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s",
746 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
747 return addConcurrentAccessPoints(iface_params, nw_params);
748 }
749 return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
750}
751
752V1_2::HostapdStatus Hostapd::addConcurrentAccessPoints(
753 const V1_3::IHostapd::IfaceParams& iface_params, const V1_3::IHostapd::NetworkParams& nw_params)
754{
755 int channelParamsListSize = iface_params.channelParamsList.size();
756 // Get available interfaces in bridge
757 std::vector<std::string> managed_interfaces;
758 std::string br_name = StringPrintf(
759 "%s", iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
760 if (!GetInterfacesInBridge(br_name, &managed_interfaces)) {
761 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN,
762 "Get interfaces in bridge failed."};
763 }
764 if (managed_interfaces.size() < channelParamsListSize) {
765 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN,
766 "Available interfaces less than requested bands"};
767 }
768 // start BSS on specified bands
769 for (std::size_t i = 0; i < channelParamsListSize; i ++) {
770 V1_2::HostapdStatus status = addSingleAccessPoint(
771 prepareIfaceParams1_2From1_3(managed_interfaces[i], iface_params,
772 iface_params.channelParamsList[i]),
773 nw_params, br_name);
774 if (status.code != V1_2::HostapdStatusCode::SUCCESS) {
775 wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s",
776 managed_interfaces[i].c_str());
777 return status;
778 }
779 }
780 // Save bridge interface info
781 br_interfaces_[br_name] = managed_interfaces;
782 return {V1_2::HostapdStatusCode::SUCCESS, ""};
783}
784
785V1_2::HostapdStatus Hostapd::addSingleAccessPoint(
786 const V1_2::IHostapd::IfaceParams& iface_params,
787 const V1_3::IHostapd::NetworkParams& nw_params,
788 const std::string br_name)
789{
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800790 if (hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str())) {
Roshan Pius087d8692017-12-27 14:11:44 -0800791 wpa_printf(
792 MSG_ERROR, "Interface %s already present",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800793 iface_params.V1_1.V1_0.ifaceName.c_str());
leslf8b1b402020-08-04 17:09:39 +0800794 return {V1_2::HostapdStatusCode::FAILURE_IFACE_EXISTS, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800795 }
lesl0cb0e272020-10-30 16:58:08 +0800796 const auto conf_params = CreateHostapdConfig(iface_params, nw_params, br_name);
Roshan Pius087d8692017-12-27 14:11:44 -0800797 if (conf_params.empty()) {
798 wpa_printf(MSG_ERROR, "Failed to create config params");
leslf8b1b402020-08-04 17:09:39 +0800799 return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800800 }
801 const auto conf_file_path =
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800802 WriteHostapdConfig(iface_params.V1_1.V1_0.ifaceName, conf_params);
Roshan Pius087d8692017-12-27 14:11:44 -0800803 if (conf_file_path.empty()) {
804 wpa_printf(MSG_ERROR, "Failed to write config file");
leslf8b1b402020-08-04 17:09:39 +0800805 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800806 }
807 std::string add_iface_param_str = StringPrintf(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800808 "%s config=%s", iface_params.V1_1.V1_0.ifaceName.c_str(),
Roshan Pius087d8692017-12-27 14:11:44 -0800809 conf_file_path.c_str());
810 std::vector<char> add_iface_param_vec(
811 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
812 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
813 wpa_printf(
814 MSG_ERROR, "Adding interface %s failed",
815 add_iface_param_str.c_str());
leslf8b1b402020-08-04 17:09:39 +0800816 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800817 }
818 struct hostapd_data* iface_hapd =
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800819 hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str());
Roshan Pius087d8692017-12-27 14:11:44 -0800820 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Roshan Piuse2d21012018-08-17 11:22:06 -0700821 // Register the setup complete callbacks
822 on_setup_complete_internal_callback =
823 [this](struct hostapd_data* iface_hapd) {
824 wpa_printf(
lesl0cb0e272020-10-30 16:58:08 +0800825 MSG_INFO, "AP interface setup completed - state %s",
Roshan Piuse2d21012018-08-17 11:22:06 -0700826 hostapd_state_text(iface_hapd->iface->state));
827 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
828 // Invoke the failure callback on all registered
829 // clients.
830 for (const auto& callback : callbacks_) {
831 callback->onFailure(
832 iface_hapd->conf->iface);
833 }
834 }
835 };
lesld0621052020-08-10 13:54:28 +0800836
837 // Rgegister for new client connect/disconnect indication.
838 on_sta_authorized_internal_callback =
839 [this](struct hostapd_data* iface_hapd, const u8 *mac_addr,
840 int authorized, const u8 *p2p_dev_addr) {
841 wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s",
842 MAC2STR(mac_addr),
843 (authorized) ? "Connected" : "Disconnected");
lesld0621052020-08-10 13:54:28 +0800844 for (const auto &callback : callbacks_) {
lesl0cb0e272020-10-30 16:58:08 +0800845 callback->onConnectedClientsChanged(strlen(iface_hapd->conf->bridge) > 0 ?
846 iface_hapd->conf->bridge : iface_hapd->conf->iface,
lesld0621052020-08-10 13:54:28 +0800847 iface_hapd->conf->iface, mac_addr, authorized);
848 }
849 };
850
lesldab91502020-08-17 18:29:47 +0800851 // Register for wpa_event which used to get channel switch event
852 on_wpa_msg_internal_callback =
853 [this](struct hostapd_data* iface_hapd, int level,
854 enum wpa_msg_type type, const char *txt,
855 size_t len) {
856 wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt);
857 if (os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH,
858 strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) {
859 for (const auto &callback : callbacks_) {
860 callback->onApInstanceInfoChanged(
lesl0cb0e272020-10-30 16:58:08 +0800861 strlen(iface_hapd->conf->bridge) > 0 ?
862 iface_hapd->conf->bridge : iface_hapd->conf->iface,
863 iface_hapd->conf->iface, iface_hapd->iface->freq,
864 getBandwidth(iface_hapd->iconf),
lesl29973f82020-09-10 22:40:06 +0800865 getGeneration(iface_hapd->iface->current_mode),
866 iface_hapd->own_addr);
lesldab91502020-08-17 18:29:47 +0800867 }
868 }
869 };
lesld0621052020-08-10 13:54:28 +0800870
871 // Setup callback
Roshan Piuse2d21012018-08-17 11:22:06 -0700872 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
873 iface_hapd->setup_complete_cb_ctx = iface_hapd;
lesld0621052020-08-10 13:54:28 +0800874 iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb;
875 iface_hapd->sta_authorized_cb_ctx = iface_hapd;
lesldab91502020-08-17 18:29:47 +0800876 wpa_msg_register_cb(onAsyncWpaEventCb);
lesld0621052020-08-10 13:54:28 +0800877
Roshan Pius087d8692017-12-27 14:11:44 -0800878 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
879 wpa_printf(
880 MSG_ERROR, "Enabling interface %s failed",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800881 iface_params.V1_1.V1_0.ifaceName.c_str());
leslf8b1b402020-08-04 17:09:39 +0800882 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800883 }
leslf8b1b402020-08-04 17:09:39 +0800884 return {V1_2::HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800885}
886
lesl1a842e62019-12-02 19:00:37 +0800887V1_0::HostapdStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
Roshan Piuscc817562017-12-22 14:45:05 -0800888{
Roshan Pius087d8692017-12-27 14:11:44 -0800889 std::vector<char> remove_iface_param_vec(
890 iface_name.begin(), iface_name.end() + 1);
891 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) <
892 0) {
893 wpa_printf(
894 MSG_ERROR, "Removing interface %s failed",
895 iface_name.c_str());
lesl1a842e62019-12-02 19:00:37 +0800896 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800897 }
lesl1a842e62019-12-02 19:00:37 +0800898 return {V1_0::HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800899}
Roshan Piuse2d21012018-08-17 11:22:06 -0700900
lesl1a842e62019-12-02 19:00:37 +0800901V1_0::HostapdStatus Hostapd::registerCallbackInternal(
902 const sp<V1_1::IHostapdCallback>& callback)
Roshan Piuse2d21012018-08-17 11:22:06 -0700903{
leslf8b1b402020-08-04 17:09:39 +0800904 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
905}
906
907V1_2::HostapdStatus Hostapd::registerCallbackInternal_1_3(
908 const sp<V1_3::IHostapdCallback>& callback)
909{
Roshan Pius80e5a0f2020-10-19 13:48:22 -0700910 if (!callback->linkToDeath(death_notifier_, 0)) {
911 wpa_printf(
912 MSG_ERROR,
913 "Error registering for death notification for "
914 "hostapd callback object");
915 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
916 }
Roshan Piuse2d21012018-08-17 11:22:06 -0700917 callbacks_.push_back(callback);
leslf8b1b402020-08-04 17:09:39 +0800918 return {V1_2::HostapdStatusCode::SUCCESS, ""};
lesl1a842e62019-12-02 19:00:37 +0800919}
920
921V1_2::HostapdStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
922 const std::array<uint8_t, 6>& client_address, V1_2::Ieee80211ReasonCode reason_code)
923{
924 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
925 struct sta_info *sta;
926 if (!hapd) {
927 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
928 return {V1_2::HostapdStatusCode::FAILURE_IFACE_UNKNOWN, ""};
929 }
930 for (sta = hapd->sta_list; sta; sta = sta->next) {
931 int res;
932 res = memcmp(sta->addr, client_address.data(), ETH_ALEN);
933 if (res == 0) {
934 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
935 MAC2STR(client_address.data()), (uint16_t) reason_code);
936 ap_sta_disconnect(hapd, sta, sta->addr, (uint16_t) reason_code);
937 return {V1_2::HostapdStatusCode::SUCCESS, ""};
938 }
939 }
940 return {V1_2::HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, ""};
Roshan Piuse2d21012018-08-17 11:22:06 -0700941}
942
leslf8b1b402020-08-04 17:09:39 +0800943V1_2::HostapdStatus Hostapd::setDebugParamsInternal(V1_2::DebugLevel level)
Roger Wangcede5062019-12-30 12:56:28 +0800944{
945 wpa_debug_level = static_cast<uint32_t>(level);
946 return {V1_2::HostapdStatusCode::SUCCESS, ""};
947}
948
Roshan Piuscc817562017-12-22 14:45:05 -0800949} // namespace implementation
leslf8b1b402020-08-04 17:09:39 +0800950} // namespace V1_3
Roshan Piuscc817562017-12-22 14:45:05 -0800951} // namespace hostapd
952} // namespace wifi
953} // namespace hardware
954} // namespace android