blob: 274a079435018d2588a9a3a2952f830a1a74928e [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(
lesl31294252020-11-06 17:06:03 +0800266 const android::hardware::wifi::hostapd::V1_3::IHostapd::IfaceParams& iface_params,
267 const android::hardware::wifi::hostapd::V1_3::IHostapd::ChannelParams& channelParams,
lesl0cb0e272020-10-30 16:58:08 +0800268 const IHostapd::NetworkParams& nw_params,
269 const std::string br_name)
Roshan Pius30b452e2017-12-27 13:36:21 -0800270{
leslb0f4d542020-09-16 23:06:03 +0800271 if (nw_params.V1_2.V1_0.ssid.size() >
Roshan Pius30b452e2017-12-27 13:36:21 -0800272 static_cast<uint32_t>(
273 IHostapd::ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) {
274 wpa_printf(
leslb0f4d542020-09-16 23:06:03 +0800275 MSG_ERROR, "Invalid SSID size: %zu", nw_params.V1_2.V1_0.ssid.size());
Roshan Pius30b452e2017-12-27 13:36:21 -0800276 return "";
277 }
278
279 // SSID string
280 std::stringstream ss;
281 ss << std::hex;
282 ss << std::setfill('0');
leslb0f4d542020-09-16 23:06:03 +0800283 for (uint8_t b : nw_params.V1_2.V1_0.ssid) {
Roshan Pius30b452e2017-12-27 13:36:21 -0800284 ss << std::setw(2) << static_cast<unsigned int>(b);
285 }
286 const std::string ssid_as_string = ss.str();
287
288 // Encryption config string
Kai Shi35d8ea42020-10-07 15:24:01 -0700289 uint32_t band = 0;
lesl31294252020-11-06 17:06:03 +0800290 band |= channelParams.V1_2.bandMask;
Kai Shi35d8ea42020-10-07 15:24:01 -0700291 bool is_6Ghz_band_only = band == static_cast<uint32_t>(IHostapd::BandMask::BAND_6_GHZ);
Roshan Pius30b452e2017-12-27 13:36:21 -0800292 std::string encryption_config_as_string;
leslb0f4d542020-09-16 23:06:03 +0800293 switch (nw_params.V1_2.encryptionType) {
Roshan Pius30b452e2017-12-27 13:36:21 -0800294 case IHostapd::EncryptionType::NONE:
295 // no security params
296 break;
297 case IHostapd::EncryptionType::WPA:
lesldd48efd2019-12-26 15:13:51 +0800298 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800299 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800300 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
301 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
302 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
303 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
304 return "";
305 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800306 encryption_config_as_string = StringPrintf(
307 "wpa=3\n"
308 "wpa_pairwise=TKIP CCMP\n"
309 "wpa_passphrase=%s",
leslb0f4d542020-09-16 23:06:03 +0800310 nw_params.V1_2.passphrase.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800311 break;
312 case IHostapd::EncryptionType::WPA2:
lesldd48efd2019-12-26 15:13:51 +0800313 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800314 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800315 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
316 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
317 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
318 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
319 return "";
320 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800321 encryption_config_as_string = StringPrintf(
322 "wpa=2\n"
323 "rsn_pairwise=CCMP\n"
324 "wpa_passphrase=%s",
leslb0f4d542020-09-16 23:06:03 +0800325 nw_params.V1_2.passphrase.c_str());
lesldd48efd2019-12-26 15:13:51 +0800326 break;
327 case IHostapd::EncryptionType::WPA3_SAE_TRANSITION:
328 if (!validatePassphrase(
leslb0f4d542020-09-16 23:06:03 +0800329 nw_params.V1_2.passphrase.size(),
lesldd48efd2019-12-26 15:13:51 +0800330 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
331 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES),
332 static_cast<uint32_t>(IHostapd::ParamSizeLimits::
333 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
334 return "";
335 }
336 encryption_config_as_string = StringPrintf(
337 "wpa=2\n"
338 "rsn_pairwise=CCMP\n"
339 "wpa_key_mgmt=WPA-PSK SAE\n"
340 "ieee80211w=1\n"
341 "sae_require_mfp=1\n"
342 "wpa_passphrase=%s\n"
343 "sae_password=%s",
leslb0f4d542020-09-16 23:06:03 +0800344 nw_params.V1_2.passphrase.c_str(),
345 nw_params.V1_2.passphrase.c_str());
lesldd48efd2019-12-26 15:13:51 +0800346 break;
347 case IHostapd::EncryptionType::WPA3_SAE:
leslb0f4d542020-09-16 23:06:03 +0800348 if (!validatePassphrase(nw_params.V1_2.passphrase.size(), 1, -1)) {
lesldd48efd2019-12-26 15:13:51 +0800349 return "";
350 }
351 encryption_config_as_string = StringPrintf(
352 "wpa=2\n"
353 "rsn_pairwise=CCMP\n"
354 "wpa_key_mgmt=SAE\n"
355 "ieee80211w=2\n"
356 "sae_require_mfp=2\n"
Kai Shi35d8ea42020-10-07 15:24:01 -0700357 "sae_pwe=%d\n"
lesldd48efd2019-12-26 15:13:51 +0800358 "sae_password=%s",
Kai Shi35d8ea42020-10-07 15:24:01 -0700359 is_6Ghz_band_only ? 1 : 2,
leslb0f4d542020-09-16 23:06:03 +0800360 nw_params.V1_2.passphrase.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800361 break;
362 default:
363 wpa_printf(MSG_ERROR, "Unknown encryption type");
364 return "";
365 }
366
367 std::string channel_config_as_string;
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800368 bool isFirst = true;
lesl31294252020-11-06 17:06:03 +0800369 if (channelParams.enableAcs) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800370 std::string freqList_as_string;
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900371 for (const auto &range :
lesl31294252020-11-06 17:06:03 +0800372 channelParams.V1_2.acsChannelFreqRangesMhz) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800373 if (!isFirst) {
374 freqList_as_string += ",";
375 }
376 isFirst = false;
377
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900378 if (range.start != range.end) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800379 freqList_as_string +=
380 StringPrintf("%d-%d", range.start, range.end);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900381 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800382 freqList_as_string += StringPrintf("%d", range.start);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900383 }
384 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800385 channel_config_as_string = StringPrintf(
386 "channel=0\n"
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900387 "acs_exclude_dfs=%d\n"
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800388 "freqlist=%s",
lesl31294252020-11-06 17:06:03 +0800389 iface_params.V1_2.V1_1.V1_0.channelParams.acsShouldExcludeDfs,
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800390 freqList_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800391 } else {
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800392 int op_class = getOpClassForChannel(
lesl31294252020-11-06 17:06:03 +0800393 channelParams.channel,
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800394 band,
lesl31294252020-11-06 17:06:03 +0800395 iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211N,
396 iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC);
Roshan Pius30b452e2017-12-27 13:36:21 -0800397 channel_config_as_string = StringPrintf(
Ahmed ElArabawy7b4b40a2020-01-02 08:55:38 -0800398 "channel=%d\n"
399 "op_class=%d",
lesl31294252020-11-06 17:06:03 +0800400 channelParams.channel, op_class);
Roshan Pius30b452e2017-12-27 13:36:21 -0800401 }
402
Roshan Pius30b452e2017-12-27 13:36:21 -0800403 std::string hw_mode_as_string;
Roshan Pius49446472018-03-07 10:23:46 -0800404 std::string ht_cap_vht_oper_chwidth_as_string;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800405
406 if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800407 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
408 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800409 hw_mode_as_string = "hw_mode=any";
lesl31294252020-11-06 17:06:03 +0800410 if (iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800411 ht_cap_vht_oper_chwidth_as_string =
412 "ht_capab=[HT40+]\n"
413 "vht_oper_chwidth=1";
414 }
415 } else {
416 hw_mode_as_string = "hw_mode=g";
Roshan Pius49446472018-03-07 10:23:46 -0800417 }
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800418 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800419 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
420 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800421 hw_mode_as_string = "hw_mode=a";
lesl31294252020-11-06 17:06:03 +0800422 if (iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800423 ht_cap_vht_oper_chwidth_as_string =
424 "ht_capab=[HT40+]\n"
425 "vht_oper_chwidth=1";
426 }
427 } else {
428 wpa_printf(MSG_ERROR, "Invalid band");
429 return "";
Roshan Pius49446472018-03-07 10:23:46 -0800430 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800431 }
432
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800433 std::string he_params_as_string;
Roshan Pius36510302020-05-09 21:01:01 -0700434#ifdef CONFIG_IEEE80211AX
lesl31294252020-11-06 17:06:03 +0800435 if (iface_params.V1_2.hwModeParams.enable80211AX) {
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800436 he_params_as_string = StringPrintf(
437 "ieee80211ax=1\n"
438 "he_su_beamformer=%d\n"
439 "he_su_beamformee=%d\n"
440 "he_mu_beamformer=%d\n"
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800441 "he_twt_required=%d\n",
lesl31294252020-11-06 17:06:03 +0800442 iface_params.V1_2.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0,
443 iface_params.V1_2.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0,
444 iface_params.V1_2.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0,
445 iface_params.V1_2.hwModeParams.enableHeTargetWakeTime ? 1 : 0);
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800446 } else {
447 he_params_as_string = "ieee80211ax=0";
448 }
Roshan Pius36510302020-05-09 21:01:01 -0700449#endif /* CONFIG_IEEE80211AX */
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800450
leslb0f4d542020-09-16 23:06:03 +0800451#ifdef CONFIG_INTERWORKING
452 std::string access_network_params_as_string;
453 if (nw_params.isMetered) {
454 access_network_params_as_string = StringPrintf(
455 "interworking=1\n"
456 "access_network_type=2\n"); // CHARGEABLE_PUBLIC_NETWORK
457 } else {
458 access_network_params_as_string = StringPrintf(
459 "interworking=0\n");
460 }
461#endif /* CONFIG_INTERWORKING */
462
lesl0cb0e272020-10-30 16:58:08 +0800463 std::string bridge_as_string;
464 if (!br_name.empty()) {
465 bridge_as_string = StringPrintf("bridge=%s", br_name.c_str());
466 }
467
Roshan Pius30b452e2017-12-27 13:36:21 -0800468 return StringPrintf(
469 "interface=%s\n"
470 "driver=nl80211\n"
Daichi Ueuracaa74a82018-02-14 22:25:39 +0900471 "ctrl_interface=/data/vendor/wifi/hostapd/ctrl\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800472 // ssid2 signals to hostapd that the value is not a literal value
473 // for use as a SSID. In this case, we're giving it a hex
474 // std::string and hostapd needs to expect that.
475 "ssid2=%s\n"
476 "%s\n"
477 "ieee80211n=%d\n"
478 "ieee80211ac=%d\n"
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800479 "%s\n"
Roshan Piuse453f712018-02-09 15:49:57 -0800480 "%s\n"
Roshan Pius49446472018-03-07 10:23:46 -0800481 "%s\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800482 "ignore_broadcast_ssid=%d\n"
483 "wowlan_triggers=any\n"
leslb0f4d542020-09-16 23:06:03 +0800484#ifdef CONFIG_INTERWORKING
485 "%s\n"
486#endif /* CONFIG_INTERWORKING */
lesl0cb0e272020-10-30 16:58:08 +0800487 "%s\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800488 "%s\n",
lesl31294252020-11-06 17:06:03 +0800489 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str(), ssid_as_string.c_str(),
Roshan Pius30b452e2017-12-27 13:36:21 -0800490 channel_config_as_string.c_str(),
lesl31294252020-11-06 17:06:03 +0800491 iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211N ? 1 : 0,
492 iface_params.V1_2.V1_1.V1_0.hwModeParams.enable80211AC ? 1 : 0,
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800493 he_params_as_string.c_str(),
Roshan Pius49446472018-03-07 10:23:46 -0800494 hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(),
leslb0f4d542020-09-16 23:06:03 +0800495 nw_params.V1_2.V1_0.isHidden ? 1 : 0,
496#ifdef CONFIG_INTERWORKING
lesl0cb0e272020-10-30 16:58:08 +0800497 access_network_params_as_string.c_str(),
leslb0f4d542020-09-16 23:06:03 +0800498#endif /* CONFIG_INTERWORKING */
lesl0cb0e272020-10-30 16:58:08 +0800499 encryption_config_as_string.c_str(),
500 bridge_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800501}
Roshan Piuse2d21012018-08-17 11:22:06 -0700502
lesldab91502020-08-17 18:29:47 +0800503Generation getGeneration(hostapd_hw_modes *current_mode)
504{
505 wpa_printf(MSG_DEBUG, "getGeneration hwmode=%d, ht_enabled=%d, vht_enabled=%d",
506 current_mode->mode, current_mode->ht_capab != 0,
507 current_mode->vht_capab != 0);
508 switch (current_mode->mode) {
509 case HOSTAPD_MODE_IEEE80211B:
510 return Generation::WIFI_STANDARD_LEGACY;
511 case HOSTAPD_MODE_IEEE80211G:
512 return current_mode->ht_capab == 0 ?
513 Generation::WIFI_STANDARD_LEGACY : Generation::WIFI_STANDARD_11N;
514 case HOSTAPD_MODE_IEEE80211A:
515 return current_mode->vht_capab == 0 ?
516 Generation::WIFI_STANDARD_11N : Generation::WIFI_STANDARD_11AC;
517 // TODO: b/162484222 miss HOSTAPD_MODE_IEEE80211AX definition.
518 default:
519 return Generation::WIFI_STANDARD_UNKNOWN;
520 }
521}
522
523Bandwidth getBandwidth(struct hostapd_config *iconf)
524{
525 wpa_printf(MSG_DEBUG, "getBandwidth %d, isHT=%d, isHT40=%d",
526 iconf->vht_oper_chwidth, iconf->ieee80211n,
527 iconf->secondary_channel);
528 switch (iconf->vht_oper_chwidth) {
529 case CHANWIDTH_80MHZ:
530 return Bandwidth::WIFI_BANDWIDTH_80;
531 case CHANWIDTH_80P80MHZ:
532 return Bandwidth::WIFI_BANDWIDTH_80P80;
533 break;
534 case CHANWIDTH_160MHZ:
535 return Bandwidth::WIFI_BANDWIDTH_160;
536 break;
537 case CHANWIDTH_USE_HT:
538 if (iconf->ieee80211n) {
539 return iconf->secondary_channel != 0 ?
540 Bandwidth::WIFI_BANDWIDTH_40 : Bandwidth::WIFI_BANDWIDTH_20;
541 }
542 return Bandwidth::WIFI_BANDWIDTH_20_NOHT;
543 default:
544 return Bandwidth::WIFI_BANDWIDTH_INVALID;
545 }
546}
547
Roshan Piuse2d21012018-08-17 11:22:06 -0700548// hostapd core functions accept "C" style function pointers, so use global
549// functions to pass to the hostapd core function and store the corresponding
550// std::function methods to be invoked.
551//
552// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
553//
554// Callback to be invoked once setup is complete
555std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
556void onAsyncSetupCompleteCb(void* ctx)
557{
558 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
559 if (on_setup_complete_internal_callback) {
560 on_setup_complete_internal_callback(iface_hapd);
561 // Invalidate this callback since we don't want this firing
lesl0cb0e272020-10-30 16:58:08 +0800562 // again in single AP mode.
563 if (strlen(iface_hapd->conf->bridge) > 0) {
564 on_setup_complete_internal_callback = nullptr;
565 }
Roshan Piuse2d21012018-08-17 11:22:06 -0700566 }
567}
lesld0621052020-08-10 13:54:28 +0800568
569// Callback to be invoked on hotspot client connection/disconnection
570std::function<void(struct hostapd_data*, const u8 *mac_addr, int authorized,
571 const u8 *p2p_dev_addr)> on_sta_authorized_internal_callback;
572void onAsyncStaAuthorizedCb(void* ctx, const u8 *mac_addr, int authorized,
573 const u8 *p2p_dev_addr)
574{
575 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
576 if (on_sta_authorized_internal_callback) {
577 on_sta_authorized_internal_callback(iface_hapd, mac_addr,
578 authorized, p2p_dev_addr);
579 }
580}
581
lesldab91502020-08-17 18:29:47 +0800582std::function<void(struct hostapd_data*, int level,
583 enum wpa_msg_type type, const char *txt,
584 size_t len)> on_wpa_msg_internal_callback;
585
586void onAsyncWpaEventCb(void *ctx, int level,
587 enum wpa_msg_type type, const char *txt,
588 size_t len)
589{
590 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
591 if (on_wpa_msg_internal_callback) {
592 on_wpa_msg_internal_callback(iface_hapd, level,
593 type, txt, len);
594 }
595}
596
597
Roshan Pius30b452e2017-12-27 13:36:21 -0800598} // namespace
599
Roshan Piuscc817562017-12-22 14:45:05 -0800600namespace android {
601namespace hardware {
602namespace wifi {
603namespace hostapd {
leslf8b1b402020-08-04 17:09:39 +0800604namespace V1_3 {
Roshan Piuscc817562017-12-22 14:45:05 -0800605namespace implementation {
606using hidl_return_util::call;
Roshan Piuse2d21012018-08-17 11:22:06 -0700607using namespace android::hardware::wifi::hostapd::V1_0;
Roshan Piuscc817562017-12-22 14:45:05 -0800608
Roshan Pius80e5a0f2020-10-19 13:48:22 -0700609Hostapd::Hostapd(struct hapd_interfaces* interfaces)
610 : interfaces_(interfaces), death_notifier_(sp<DeathNotifier>::make())
Roshan Piuscc817562017-12-22 14:45:05 -0800611{}
612
613Return<void> Hostapd::addAccessPoint(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900614 const V1_0::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800615 const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900616{
617 return call(
618 this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params,
619 nw_params);
620}
621
622Return<void> Hostapd::addAccessPoint_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800623 const V1_1::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800624 const V1_0::IHostapd::NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
Roshan Piuscc817562017-12-22 14:45:05 -0800625{
626 return call(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900627 this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params,
Roshan Piuscc817562017-12-22 14:45:05 -0800628 nw_params);
629}
630
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800631Return<void> Hostapd::addAccessPoint_1_2(
leslb0f4d542020-09-16 23:06:03 +0800632 const V1_2::IHostapd::IfaceParams& iface_params,
633 const V1_2::IHostapd::NetworkParams& nw_params,
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800634 addAccessPoint_1_2_cb _hidl_cb)
635{
636 return call(
637 this, &Hostapd::addAccessPointInternal_1_2, _hidl_cb, iface_params,
638 nw_params);
639}
640
leslb0f4d542020-09-16 23:06:03 +0800641Return<void> Hostapd::addAccessPoint_1_3(
642 const V1_3::IHostapd::IfaceParams& iface_params,
643 const V1_3::IHostapd::NetworkParams& nw_params,
644 addAccessPoint_1_3_cb _hidl_cb)
645{
646 return call(
647 this, &Hostapd::addAccessPointInternal_1_3, _hidl_cb, iface_params,
648 nw_params);
649}
650
Roshan Piuscc817562017-12-22 14:45:05 -0800651Return<void> Hostapd::removeAccessPoint(
652 const hidl_string& iface_name, removeAccessPoint_cb _hidl_cb)
653{
654 return call(
655 this, &Hostapd::removeAccessPointInternal, _hidl_cb, iface_name);
656}
657
Roshan Piuse2d21012018-08-17 11:22:06 -0700658Return<void> Hostapd::terminate()
659{
Roshan Pius3455af42018-02-01 09:19:49 -0800660 wpa_printf(MSG_INFO, "Terminating...");
lesl3b8cc0c2020-11-20 23:44:32 +0800661 // Clear the callback to avoid IPCThreadState shutdown during the
662 // callback event.
663 callbacks_.clear();
Roshan Pius3455af42018-02-01 09:19:49 -0800664 eloop_terminate();
665 return Void();
666}
667
Roshan Piuse2d21012018-08-17 11:22:06 -0700668Return<void> Hostapd::registerCallback(
lesl1a842e62019-12-02 19:00:37 +0800669 const sp<V1_1::IHostapdCallback>& callback, registerCallback_cb _hidl_cb)
Roshan Piuse2d21012018-08-17 11:22:06 -0700670{
671 return call(
672 this, &Hostapd::registerCallbackInternal, _hidl_cb, callback);
673}
674
leslf8b1b402020-08-04 17:09:39 +0800675Return<void> Hostapd::registerCallback_1_3(
676 const sp<V1_3::IHostapdCallback>& callback, registerCallback_1_3_cb _hidl_cb)
677{
678 return call(
679 this, &Hostapd::registerCallbackInternal_1_3, _hidl_cb, callback);
680}
681
lesl1a842e62019-12-02 19:00:37 +0800682Return<void> Hostapd::forceClientDisconnect(
683 const hidl_string& iface_name, const hidl_array<uint8_t, 6>& client_address,
684 V1_2::Ieee80211ReasonCode reason_code, forceClientDisconnect_cb _hidl_cb)
685{
686 return call(
687 this, &Hostapd::forceClientDisconnectInternal, _hidl_cb, iface_name,
688 client_address, reason_code);
689}
690
Roger Wangcede5062019-12-30 12:56:28 +0800691Return<void> Hostapd::setDebugParams(
leslf8b1b402020-08-04 17:09:39 +0800692 V1_2::DebugLevel level, setDebugParams_cb _hidl_cb)
Roger Wangcede5062019-12-30 12:56:28 +0800693{
694 return call(
695 this, &Hostapd::setDebugParamsInternal, _hidl_cb, level);
696}
lesl1a842e62019-12-02 19:00:37 +0800697
698V1_0::HostapdStatus Hostapd::addAccessPointInternal(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900699 const V1_0::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800700 const V1_0::IHostapd::NetworkParams& nw_params)
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900701{
lesl1a842e62019-12-02 19:00:37 +0800702 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900703}
704
lesl1a842e62019-12-02 19:00:37 +0800705V1_0::HostapdStatus Hostapd::addAccessPointInternal_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800706 const V1_1::IHostapd::IfaceParams& iface_params,
lesldd48efd2019-12-26 15:13:51 +0800707 const V1_1::IHostapd::NetworkParams& nw_params)
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800708{
709 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
710}
711
leslf8b1b402020-08-04 17:09:39 +0800712V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_2(
leslb0f4d542020-09-16 23:06:03 +0800713 const V1_2::IHostapd::IfaceParams& iface_params,
714 const V1_2::IHostapd::NetworkParams& nw_params) {
715 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
716}
717
718V1_2::HostapdStatus Hostapd::addAccessPointInternal_1_3(
lesl0cb0e272020-10-30 16:58:08 +0800719 const V1_3::IHostapd::IfaceParams& iface_params,
leslb0f4d542020-09-16 23:06:03 +0800720 const V1_3::IHostapd::NetworkParams& nw_params)
Roshan Piuscc817562017-12-22 14:45:05 -0800721{
lesl0cb0e272020-10-30 16:58:08 +0800722 int channelParamsListSize = iface_params.channelParamsList.size();
723 if (channelParamsListSize == 1) {
724 // Single AP
725 wpa_printf(MSG_INFO, "AddSingleAccessPoint, iface=%s",
726 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
lesl31294252020-11-06 17:06:03 +0800727 return addSingleAccessPoint(iface_params, iface_params.channelParamsList[0],
lesl0cb0e272020-10-30 16:58:08 +0800728 nw_params, "");
729 } else if (channelParamsListSize == 2) {
730 // Concurrent APs
731 wpa_printf(MSG_INFO, "AddDualAccessPoint, iface=%s",
732 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
733 return addConcurrentAccessPoints(iface_params, nw_params);
734 }
735 return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
736}
737
738V1_2::HostapdStatus Hostapd::addConcurrentAccessPoints(
739 const V1_3::IHostapd::IfaceParams& iface_params, const V1_3::IHostapd::NetworkParams& nw_params)
740{
741 int channelParamsListSize = iface_params.channelParamsList.size();
742 // Get available interfaces in bridge
743 std::vector<std::string> managed_interfaces;
744 std::string br_name = StringPrintf(
745 "%s", iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
746 if (!GetInterfacesInBridge(br_name, &managed_interfaces)) {
747 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN,
748 "Get interfaces in bridge failed."};
749 }
750 if (managed_interfaces.size() < channelParamsListSize) {
751 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN,
752 "Available interfaces less than requested bands"};
753 }
754 // start BSS on specified bands
755 for (std::size_t i = 0; i < channelParamsListSize; i ++) {
lesl31294252020-11-06 17:06:03 +0800756 V1_3::IHostapd::IfaceParams iface_params_new = iface_params;
757 iface_params_new.V1_2.V1_1.V1_0.ifaceName = managed_interfaces[i];
lesl0cb0e272020-10-30 16:58:08 +0800758 V1_2::HostapdStatus status = addSingleAccessPoint(
lesl31294252020-11-06 17:06:03 +0800759 iface_params_new, iface_params.channelParamsList[i], nw_params, br_name);
lesl0cb0e272020-10-30 16:58:08 +0800760 if (status.code != V1_2::HostapdStatusCode::SUCCESS) {
761 wpa_printf(MSG_ERROR, "Failed to addAccessPoint %s",
762 managed_interfaces[i].c_str());
763 return status;
764 }
765 }
766 // Save bridge interface info
767 br_interfaces_[br_name] = managed_interfaces;
768 return {V1_2::HostapdStatusCode::SUCCESS, ""};
769}
770
771V1_2::HostapdStatus Hostapd::addSingleAccessPoint(
lesl31294252020-11-06 17:06:03 +0800772 const V1_3::IHostapd::IfaceParams& iface_params,
773 const V1_3::IHostapd::ChannelParams& channelParams,
lesl0cb0e272020-10-30 16:58:08 +0800774 const V1_3::IHostapd::NetworkParams& nw_params,
775 const std::string br_name)
776{
lesl31294252020-11-06 17:06:03 +0800777 if (hostapd_get_iface(interfaces_, iface_params.V1_2.V1_1.V1_0.ifaceName.c_str())) {
Roshan Pius087d8692017-12-27 14:11:44 -0800778 wpa_printf(
779 MSG_ERROR, "Interface %s already present",
lesl31294252020-11-06 17:06:03 +0800780 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
leslf8b1b402020-08-04 17:09:39 +0800781 return {V1_2::HostapdStatusCode::FAILURE_IFACE_EXISTS, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800782 }
lesl31294252020-11-06 17:06:03 +0800783 const auto conf_params = CreateHostapdConfig(iface_params, channelParams, nw_params, br_name);
Roshan Pius087d8692017-12-27 14:11:44 -0800784 if (conf_params.empty()) {
785 wpa_printf(MSG_ERROR, "Failed to create config params");
leslf8b1b402020-08-04 17:09:39 +0800786 return {V1_2::HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800787 }
788 const auto conf_file_path =
lesl31294252020-11-06 17:06:03 +0800789 WriteHostapdConfig(iface_params.V1_2.V1_1.V1_0.ifaceName, conf_params);
Roshan Pius087d8692017-12-27 14:11:44 -0800790 if (conf_file_path.empty()) {
791 wpa_printf(MSG_ERROR, "Failed to write config file");
leslf8b1b402020-08-04 17:09:39 +0800792 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800793 }
794 std::string add_iface_param_str = StringPrintf(
lesl31294252020-11-06 17:06:03 +0800795 "%s config=%s", iface_params.V1_2.V1_1.V1_0.ifaceName.c_str(),
Roshan Pius087d8692017-12-27 14:11:44 -0800796 conf_file_path.c_str());
797 std::vector<char> add_iface_param_vec(
798 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
799 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
800 wpa_printf(
801 MSG_ERROR, "Adding interface %s failed",
802 add_iface_param_str.c_str());
leslf8b1b402020-08-04 17:09:39 +0800803 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800804 }
805 struct hostapd_data* iface_hapd =
lesl31294252020-11-06 17:06:03 +0800806 hostapd_get_iface(interfaces_, iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
Roshan Pius087d8692017-12-27 14:11:44 -0800807 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Roshan Piuse2d21012018-08-17 11:22:06 -0700808 // Register the setup complete callbacks
809 on_setup_complete_internal_callback =
810 [this](struct hostapd_data* iface_hapd) {
811 wpa_printf(
lesl0cb0e272020-10-30 16:58:08 +0800812 MSG_INFO, "AP interface setup completed - state %s",
Roshan Piuse2d21012018-08-17 11:22:06 -0700813 hostapd_state_text(iface_hapd->iface->state));
814 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
815 // Invoke the failure callback on all registered
816 // clients.
817 for (const auto& callback : callbacks_) {
818 callback->onFailure(
819 iface_hapd->conf->iface);
820 }
821 }
822 };
lesld0621052020-08-10 13:54:28 +0800823
824 // Rgegister for new client connect/disconnect indication.
825 on_sta_authorized_internal_callback =
826 [this](struct hostapd_data* iface_hapd, const u8 *mac_addr,
827 int authorized, const u8 *p2p_dev_addr) {
828 wpa_printf(MSG_DEBUG, "notify client " MACSTR " %s",
829 MAC2STR(mac_addr),
830 (authorized) ? "Connected" : "Disconnected");
lesld0621052020-08-10 13:54:28 +0800831 for (const auto &callback : callbacks_) {
lesl0cb0e272020-10-30 16:58:08 +0800832 callback->onConnectedClientsChanged(strlen(iface_hapd->conf->bridge) > 0 ?
833 iface_hapd->conf->bridge : iface_hapd->conf->iface,
lesld0621052020-08-10 13:54:28 +0800834 iface_hapd->conf->iface, mac_addr, authorized);
835 }
836 };
837
lesldab91502020-08-17 18:29:47 +0800838 // Register for wpa_event which used to get channel switch event
839 on_wpa_msg_internal_callback =
840 [this](struct hostapd_data* iface_hapd, int level,
841 enum wpa_msg_type type, const char *txt,
842 size_t len) {
843 wpa_printf(MSG_DEBUG, "Receive wpa msg : %s", txt);
844 if (os_strncmp(txt, WPA_EVENT_CHANNEL_SWITCH,
845 strlen(WPA_EVENT_CHANNEL_SWITCH)) == 0) {
846 for (const auto &callback : callbacks_) {
847 callback->onApInstanceInfoChanged(
lesl0cb0e272020-10-30 16:58:08 +0800848 strlen(iface_hapd->conf->bridge) > 0 ?
849 iface_hapd->conf->bridge : iface_hapd->conf->iface,
850 iface_hapd->conf->iface, iface_hapd->iface->freq,
851 getBandwidth(iface_hapd->iconf),
lesl29973f82020-09-10 22:40:06 +0800852 getGeneration(iface_hapd->iface->current_mode),
853 iface_hapd->own_addr);
lesldab91502020-08-17 18:29:47 +0800854 }
855 }
856 };
lesld0621052020-08-10 13:54:28 +0800857
858 // Setup callback
Roshan Piuse2d21012018-08-17 11:22:06 -0700859 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
860 iface_hapd->setup_complete_cb_ctx = iface_hapd;
lesld0621052020-08-10 13:54:28 +0800861 iface_hapd->sta_authorized_cb = onAsyncStaAuthorizedCb;
862 iface_hapd->sta_authorized_cb_ctx = iface_hapd;
lesldab91502020-08-17 18:29:47 +0800863 wpa_msg_register_cb(onAsyncWpaEventCb);
lesld0621052020-08-10 13:54:28 +0800864
Roshan Pius087d8692017-12-27 14:11:44 -0800865 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
866 wpa_printf(
867 MSG_ERROR, "Enabling interface %s failed",
lesl31294252020-11-06 17:06:03 +0800868 iface_params.V1_2.V1_1.V1_0.ifaceName.c_str());
leslf8b1b402020-08-04 17:09:39 +0800869 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800870 }
leslf8b1b402020-08-04 17:09:39 +0800871 return {V1_2::HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800872}
873
lesl1a842e62019-12-02 19:00:37 +0800874V1_0::HostapdStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
Roshan Piuscc817562017-12-22 14:45:05 -0800875{
Roshan Pius087d8692017-12-27 14:11:44 -0800876 std::vector<char> remove_iface_param_vec(
877 iface_name.begin(), iface_name.end() + 1);
878 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) <
879 0) {
880 wpa_printf(
881 MSG_ERROR, "Removing interface %s failed",
882 iface_name.c_str());
lesl1a842e62019-12-02 19:00:37 +0800883 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800884 }
lesl1a842e62019-12-02 19:00:37 +0800885 return {V1_0::HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800886}
Roshan Piuse2d21012018-08-17 11:22:06 -0700887
lesl1a842e62019-12-02 19:00:37 +0800888V1_0::HostapdStatus Hostapd::registerCallbackInternal(
889 const sp<V1_1::IHostapdCallback>& callback)
Roshan Piuse2d21012018-08-17 11:22:06 -0700890{
leslf8b1b402020-08-04 17:09:39 +0800891 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
892}
893
894V1_2::HostapdStatus Hostapd::registerCallbackInternal_1_3(
895 const sp<V1_3::IHostapdCallback>& callback)
896{
Roshan Pius80e5a0f2020-10-19 13:48:22 -0700897 if (!callback->linkToDeath(death_notifier_, 0)) {
898 wpa_printf(
899 MSG_ERROR,
900 "Error registering for death notification for "
901 "hostapd callback object");
902 return {V1_2::HostapdStatusCode::FAILURE_UNKNOWN, ""};
903 }
Roshan Piuse2d21012018-08-17 11:22:06 -0700904 callbacks_.push_back(callback);
leslf8b1b402020-08-04 17:09:39 +0800905 return {V1_2::HostapdStatusCode::SUCCESS, ""};
lesl1a842e62019-12-02 19:00:37 +0800906}
907
908V1_2::HostapdStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
909 const std::array<uint8_t, 6>& client_address, V1_2::Ieee80211ReasonCode reason_code)
910{
911 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
912 struct sta_info *sta;
913 if (!hapd) {
914 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
915 return {V1_2::HostapdStatusCode::FAILURE_IFACE_UNKNOWN, ""};
916 }
917 for (sta = hapd->sta_list; sta; sta = sta->next) {
918 int res;
919 res = memcmp(sta->addr, client_address.data(), ETH_ALEN);
920 if (res == 0) {
921 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
922 MAC2STR(client_address.data()), (uint16_t) reason_code);
923 ap_sta_disconnect(hapd, sta, sta->addr, (uint16_t) reason_code);
924 return {V1_2::HostapdStatusCode::SUCCESS, ""};
925 }
926 }
927 return {V1_2::HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, ""};
Roshan Piuse2d21012018-08-17 11:22:06 -0700928}
929
leslf8b1b402020-08-04 17:09:39 +0800930V1_2::HostapdStatus Hostapd::setDebugParamsInternal(V1_2::DebugLevel level)
Roger Wangcede5062019-12-30 12:56:28 +0800931{
932 wpa_debug_level = static_cast<uint32_t>(level);
933 return {V1_2::HostapdStatusCode::SUCCESS, ""};
934}
935
Roshan Piuscc817562017-12-22 14:45:05 -0800936} // namespace implementation
leslf8b1b402020-08-04 17:09:39 +0800937} // namespace V1_3
Roshan Piuscc817562017-12-22 14:45:05 -0800938} // namespace hostapd
939} // namespace wifi
940} // namespace hardware
941} // namespace android