blob: b05e2f51645445e70edee443f1fee93f85e0480a [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>
13
14#include <android-base/file.h>
15#include <android-base/stringprintf.h>
Roshan Piuscc817562017-12-22 14:45:05 -080016
17#include "hostapd.h"
18#include "hidl_return_util.h"
19
Roshan Pius3455af42018-02-01 09:19:49 -080020extern "C"
21{
22#include "utils/eloop.h"
23}
24
Roshan Pius30b452e2017-12-27 13:36:21 -080025// The HIDL implementation for hostapd creates a hostapd.conf dynamically for
26// each interface. This file can then be used to hook onto the normal config
27// file parsing logic in hostapd code. Helps us to avoid duplication of code
28// in the HIDL interface.
29// TOOD(b/71872409): Add unit tests for this.
30namespace {
31constexpr char kConfFileNameFmt[] = "/data/vendor/wifi/hostapd/hostapd_%s.conf";
32
33using android::base::RemoveFileIfExists;
34using android::base::StringPrintf;
35using android::base::WriteStringToFile;
lesl1a842e62019-12-02 19:00:37 +080036using android::hardware::wifi::hostapd::V1_2::IHostapd;
Roshan Pius30b452e2017-12-27 13:36:21 -080037
38std::string WriteHostapdConfig(
39 const std::string& interface_name, const std::string& config)
40{
41 const std::string file_path =
42 StringPrintf(kConfFileNameFmt, interface_name.c_str());
43 if (WriteStringToFile(
44 config, file_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
45 getuid(), getgid())) {
46 return file_path;
47 }
48 // Diagnose failure
49 int error = errno;
50 wpa_printf(
51 MSG_ERROR, "Cannot write hostapd config to %s, error: %s",
52 file_path.c_str(), strerror(error));
53 struct stat st;
54 int result = stat(file_path.c_str(), &st);
55 if (result == 0) {
56 wpa_printf(
57 MSG_ERROR, "hostapd config file uid: %d, gid: %d, mode: %d",
58 st.st_uid, st.st_gid, st.st_mode);
59 } else {
60 wpa_printf(
61 MSG_ERROR,
62 "Error calling stat() on hostapd config file: %s",
63 strerror(errno));
64 }
65 return "";
66}
67
68std::string CreateHostapdConfig(
69 const IHostapd::IfaceParams& iface_params,
70 const IHostapd::NetworkParams& nw_params)
71{
72 if (nw_params.ssid.size() >
73 static_cast<uint32_t>(
74 IHostapd::ParamSizeLimits::SSID_MAX_LEN_IN_BYTES)) {
75 wpa_printf(
76 MSG_ERROR, "Invalid SSID size: %zu", nw_params.ssid.size());
77 return "";
78 }
Roshan Pius0b8a64f2018-01-23 11:42:34 -080079 if ((nw_params.encryptionType != IHostapd::EncryptionType::NONE) &&
80 (nw_params.pskPassphrase.size() <
81 static_cast<uint32_t>(
82 IHostapd::ParamSizeLimits::
83 WPA2_PSK_PASSPHRASE_MIN_LEN_IN_BYTES) ||
84 nw_params.pskPassphrase.size() >
85 static_cast<uint32_t>(
86 IHostapd::ParamSizeLimits::
87 WPA2_PSK_PASSPHRASE_MAX_LEN_IN_BYTES))) {
Roshan Pius30b452e2017-12-27 13:36:21 -080088 wpa_printf(
89 MSG_ERROR, "Invalid psk passphrase size: %zu",
90 nw_params.pskPassphrase.size());
91 return "";
92 }
93
94 // SSID string
95 std::stringstream ss;
96 ss << std::hex;
97 ss << std::setfill('0');
98 for (uint8_t b : nw_params.ssid) {
99 ss << std::setw(2) << static_cast<unsigned int>(b);
100 }
101 const std::string ssid_as_string = ss.str();
102
103 // Encryption config string
104 std::string encryption_config_as_string;
105 switch (nw_params.encryptionType) {
106 case IHostapd::EncryptionType::NONE:
107 // no security params
108 break;
109 case IHostapd::EncryptionType::WPA:
110 encryption_config_as_string = StringPrintf(
111 "wpa=3\n"
112 "wpa_pairwise=TKIP CCMP\n"
113 "wpa_passphrase=%s",
114 nw_params.pskPassphrase.c_str());
115 break;
116 case IHostapd::EncryptionType::WPA2:
117 encryption_config_as_string = StringPrintf(
118 "wpa=2\n"
119 "rsn_pairwise=CCMP\n"
120 "wpa_passphrase=%s",
121 nw_params.pskPassphrase.c_str());
122 break;
123 default:
124 wpa_printf(MSG_ERROR, "Unknown encryption type");
125 return "";
126 }
127
128 std::string channel_config_as_string;
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800129 bool isFirst = true;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800130 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800131 std::string freqList_as_string;
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900132 for (const auto &range :
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800133 iface_params.channelParams.acsChannelFreqRangesMhz) {
134 if (!isFirst) {
135 freqList_as_string += ",";
136 }
137 isFirst = false;
138
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900139 if (range.start != range.end) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800140 freqList_as_string +=
141 StringPrintf("%d-%d", range.start, range.end);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900142 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800143 freqList_as_string += StringPrintf("%d", range.start);
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900144 }
145 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800146 channel_config_as_string = StringPrintf(
147 "channel=0\n"
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900148 "acs_exclude_dfs=%d\n"
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800149 "freqlist=%s",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800150 iface_params.V1_1.V1_0.channelParams.acsShouldExcludeDfs,
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800151 freqList_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800152 } else {
153 channel_config_as_string = StringPrintf(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800154 "channel=%d", iface_params.V1_1.V1_0.channelParams.channel);
Roshan Pius30b452e2017-12-27 13:36:21 -0800155 }
156
Roshan Pius30b452e2017-12-27 13:36:21 -0800157 std::string hw_mode_as_string;
Roshan Pius49446472018-03-07 10:23:46 -0800158 std::string ht_cap_vht_oper_chwidth_as_string;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800159 unsigned int band = 0;
lesl00ac8a52020-01-08 15:54:51 +0800160 band |= iface_params.channelParams.bandMask;
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800161
162 if ((band & IHostapd::BandMask::BAND_2_GHZ) != 0) {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800163 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
164 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800165 hw_mode_as_string = "hw_mode=any";
166 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
167 ht_cap_vht_oper_chwidth_as_string =
168 "ht_capab=[HT40+]\n"
169 "vht_oper_chwidth=1";
170 }
171 } else {
172 hw_mode_as_string = "hw_mode=g";
Roshan Pius49446472018-03-07 10:23:46 -0800173 }
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800174 } else {
Ahmed ElArabawya390f292019-12-21 13:07:02 -0800175 if (((band & IHostapd::BandMask::BAND_5_GHZ) != 0)
176 || ((band & IHostapd::BandMask::BAND_6_GHZ) != 0)) {
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800177 hw_mode_as_string = "hw_mode=a";
178 if (iface_params.V1_1.V1_0.channelParams.enableAcs) {
179 ht_cap_vht_oper_chwidth_as_string =
180 "ht_capab=[HT40+]\n"
181 "vht_oper_chwidth=1";
182 }
183 } else {
184 wpa_printf(MSG_ERROR, "Invalid band");
185 return "";
Roshan Pius49446472018-03-07 10:23:46 -0800186 }
Roshan Pius30b452e2017-12-27 13:36:21 -0800187 }
188
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800189 std::string he_params_as_string;
190 if (iface_params.hwModeParams.enable80211AX) {
191 he_params_as_string = StringPrintf(
192 "ieee80211ax=1\n"
193 "he_su_beamformer=%d\n"
194 "he_su_beamformee=%d\n"
195 "he_mu_beamformer=%d\n"
196 "he_bss_color=%d\n"
197 "he_twt_required=%d\n",
198 iface_params.hwModeParams.enableHeSingleUserBeamformer ? 1 : 0,
199 iface_params.hwModeParams.enableHeSingleUserBeamformee ? 1 : 0,
200 iface_params.hwModeParams.enableHeMultiUserBeamformer ? 1 : 0,
201 iface_params.hwModeParams.heBssColor,
202 iface_params.hwModeParams.enableHeTargetWakeTime ? 1 : 0);
203 } else {
204 he_params_as_string = "ieee80211ax=0";
205 }
206
Roshan Pius30b452e2017-12-27 13:36:21 -0800207 return StringPrintf(
208 "interface=%s\n"
209 "driver=nl80211\n"
Daichi Ueuracaa74a82018-02-14 22:25:39 +0900210 "ctrl_interface=/data/vendor/wifi/hostapd/ctrl\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800211 // ssid2 signals to hostapd that the value is not a literal value
212 // for use as a SSID. In this case, we're giving it a hex
213 // std::string and hostapd needs to expect that.
214 "ssid2=%s\n"
215 "%s\n"
216 "ieee80211n=%d\n"
217 "ieee80211ac=%d\n"
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800218 "%s\n"
Roshan Piuse453f712018-02-09 15:49:57 -0800219 "%s\n"
Roshan Pius49446472018-03-07 10:23:46 -0800220 "%s\n"
Roshan Pius30b452e2017-12-27 13:36:21 -0800221 "ignore_broadcast_ssid=%d\n"
222 "wowlan_triggers=any\n"
223 "%s\n",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800224 iface_params.V1_1.V1_0.ifaceName.c_str(), ssid_as_string.c_str(),
Roshan Pius30b452e2017-12-27 13:36:21 -0800225 channel_config_as_string.c_str(),
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800226 iface_params.V1_1.V1_0.hwModeParams.enable80211N ? 1 : 0,
227 iface_params.V1_1.V1_0.hwModeParams.enable80211AC ? 1 : 0,
Ahmed ElArabawy5362fb12020-01-02 15:01:31 -0800228 he_params_as_string.c_str(),
Roshan Pius49446472018-03-07 10:23:46 -0800229 hw_mode_as_string.c_str(), ht_cap_vht_oper_chwidth_as_string.c_str(),
230 nw_params.isHidden ? 1 : 0, encryption_config_as_string.c_str());
Roshan Pius30b452e2017-12-27 13:36:21 -0800231}
Roshan Piuse2d21012018-08-17 11:22:06 -0700232
233// hostapd core functions accept "C" style function pointers, so use global
234// functions to pass to the hostapd core function and store the corresponding
235// std::function methods to be invoked.
236//
237// NOTE: Using the pattern from the vendor HAL (wifi_legacy_hal.cpp).
238//
239// Callback to be invoked once setup is complete
240std::function<void(struct hostapd_data*)> on_setup_complete_internal_callback;
241void onAsyncSetupCompleteCb(void* ctx)
242{
243 struct hostapd_data* iface_hapd = (struct hostapd_data*)ctx;
244 if (on_setup_complete_internal_callback) {
245 on_setup_complete_internal_callback(iface_hapd);
246 // Invalidate this callback since we don't want this firing
247 // again.
248 on_setup_complete_internal_callback = nullptr;
249 }
250}
Roshan Pius30b452e2017-12-27 13:36:21 -0800251} // namespace
252
Roshan Piuscc817562017-12-22 14:45:05 -0800253namespace android {
254namespace hardware {
255namespace wifi {
256namespace hostapd {
lesl1a842e62019-12-02 19:00:37 +0800257namespace V1_2 {
Roshan Piuscc817562017-12-22 14:45:05 -0800258namespace implementation {
259using hidl_return_util::call;
Roshan Piuse2d21012018-08-17 11:22:06 -0700260using namespace android::hardware::wifi::hostapd::V1_0;
Roshan Piuscc817562017-12-22 14:45:05 -0800261
262Hostapd::Hostapd(struct hapd_interfaces* interfaces) : interfaces_(interfaces)
263{}
264
265Return<void> Hostapd::addAccessPoint(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900266 const V1_0::IHostapd::IfaceParams& iface_params,
267 const NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
268{
269 return call(
270 this, &Hostapd::addAccessPointInternal, _hidl_cb, iface_params,
271 nw_params);
272}
273
274Return<void> Hostapd::addAccessPoint_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800275 const V1_1::IHostapd::IfaceParams& iface_params,
276 const NetworkParams& nw_params, addAccessPoint_cb _hidl_cb)
Roshan Piuscc817562017-12-22 14:45:05 -0800277{
278 return call(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900279 this, &Hostapd::addAccessPointInternal_1_1, _hidl_cb, iface_params,
Roshan Piuscc817562017-12-22 14:45:05 -0800280 nw_params);
281}
282
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800283Return<void> Hostapd::addAccessPoint_1_2(
284 const IfaceParams& iface_params, const NetworkParams& nw_params,
285 addAccessPoint_1_2_cb _hidl_cb)
286{
287 return call(
288 this, &Hostapd::addAccessPointInternal_1_2, _hidl_cb, iface_params,
289 nw_params);
290}
291
Roshan Piuscc817562017-12-22 14:45:05 -0800292Return<void> Hostapd::removeAccessPoint(
293 const hidl_string& iface_name, removeAccessPoint_cb _hidl_cb)
294{
295 return call(
296 this, &Hostapd::removeAccessPointInternal, _hidl_cb, iface_name);
297}
298
Roshan Piuse2d21012018-08-17 11:22:06 -0700299Return<void> Hostapd::terminate()
300{
Roshan Pius3455af42018-02-01 09:19:49 -0800301 wpa_printf(MSG_INFO, "Terminating...");
302 eloop_terminate();
303 return Void();
304}
305
Roshan Piuse2d21012018-08-17 11:22:06 -0700306Return<void> Hostapd::registerCallback(
lesl1a842e62019-12-02 19:00:37 +0800307 const sp<V1_1::IHostapdCallback>& callback, registerCallback_cb _hidl_cb)
Roshan Piuse2d21012018-08-17 11:22:06 -0700308{
309 return call(
310 this, &Hostapd::registerCallbackInternal, _hidl_cb, callback);
311}
312
lesl1a842e62019-12-02 19:00:37 +0800313Return<void> Hostapd::forceClientDisconnect(
314 const hidl_string& iface_name, const hidl_array<uint8_t, 6>& client_address,
315 V1_2::Ieee80211ReasonCode reason_code, forceClientDisconnect_cb _hidl_cb)
316{
317 return call(
318 this, &Hostapd::forceClientDisconnectInternal, _hidl_cb, iface_name,
319 client_address, reason_code);
320}
321
Roger Wangcede5062019-12-30 12:56:28 +0800322Return<void> Hostapd::setDebugParams(
323 DebugLevel level, setDebugParams_cb _hidl_cb)
324{
325 return call(
326 this, &Hostapd::setDebugParamsInternal, _hidl_cb, level);
327}
lesl1a842e62019-12-02 19:00:37 +0800328
329V1_0::HostapdStatus Hostapd::addAccessPointInternal(
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900330 const V1_0::IHostapd::IfaceParams& iface_params,
331 const NetworkParams& nw_params)
332{
lesl1a842e62019-12-02 19:00:37 +0800333 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Daisuke Niwac1bd20f2019-01-09 13:51:02 +0900334}
335
lesl1a842e62019-12-02 19:00:37 +0800336V1_0::HostapdStatus Hostapd::addAccessPointInternal_1_1(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800337 const V1_1::IHostapd::IfaceParams& iface_params,
338 const NetworkParams& nw_params)
339{
340 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
341}
342
343HostapdStatus Hostapd::addAccessPointInternal_1_2(
Roshan Piuscc817562017-12-22 14:45:05 -0800344 const IfaceParams& iface_params, const NetworkParams& nw_params)
345{
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800346 if (hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str())) {
Roshan Pius087d8692017-12-27 14:11:44 -0800347 wpa_printf(
348 MSG_ERROR, "Interface %s already present",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800349 iface_params.V1_1.V1_0.ifaceName.c_str());
350 return {HostapdStatusCode::FAILURE_IFACE_EXISTS, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800351 }
352 const auto conf_params = CreateHostapdConfig(iface_params, nw_params);
353 if (conf_params.empty()) {
354 wpa_printf(MSG_ERROR, "Failed to create config params");
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800355 return {HostapdStatusCode::FAILURE_ARGS_INVALID, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800356 }
357 const auto conf_file_path =
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800358 WriteHostapdConfig(iface_params.V1_1.V1_0.ifaceName, conf_params);
Roshan Pius087d8692017-12-27 14:11:44 -0800359 if (conf_file_path.empty()) {
360 wpa_printf(MSG_ERROR, "Failed to write config file");
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800361 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800362 }
363 std::string add_iface_param_str = StringPrintf(
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800364 "%s config=%s", iface_params.V1_1.V1_0.ifaceName.c_str(),
Roshan Pius087d8692017-12-27 14:11:44 -0800365 conf_file_path.c_str());
366 std::vector<char> add_iface_param_vec(
367 add_iface_param_str.begin(), add_iface_param_str.end() + 1);
368 if (hostapd_add_iface(interfaces_, add_iface_param_vec.data()) < 0) {
369 wpa_printf(
370 MSG_ERROR, "Adding interface %s failed",
371 add_iface_param_str.c_str());
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800372 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800373 }
374 struct hostapd_data* iface_hapd =
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800375 hostapd_get_iface(interfaces_, iface_params.V1_1.V1_0.ifaceName.c_str());
Roshan Pius087d8692017-12-27 14:11:44 -0800376 WPA_ASSERT(iface_hapd != nullptr && iface_hapd->iface != nullptr);
Roshan Piuse2d21012018-08-17 11:22:06 -0700377 // Register the setup complete callbacks
378 on_setup_complete_internal_callback =
379 [this](struct hostapd_data* iface_hapd) {
380 wpa_printf(
381 MSG_DEBUG, "AP interface setup completed - state %s",
382 hostapd_state_text(iface_hapd->iface->state));
383 if (iface_hapd->iface->state == HAPD_IFACE_DISABLED) {
384 // Invoke the failure callback on all registered
385 // clients.
386 for (const auto& callback : callbacks_) {
387 callback->onFailure(
388 iface_hapd->conf->iface);
389 }
390 }
391 };
392 iface_hapd->setup_complete_cb = onAsyncSetupCompleteCb;
393 iface_hapd->setup_complete_cb_ctx = iface_hapd;
Roshan Pius087d8692017-12-27 14:11:44 -0800394 if (hostapd_enable_iface(iface_hapd->iface) < 0) {
395 wpa_printf(
396 MSG_ERROR, "Enabling interface %s failed",
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800397 iface_params.V1_1.V1_0.ifaceName.c_str());
398 return {HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800399 }
Ahmed ElArabawy34982672019-12-06 10:10:17 -0800400 return {HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800401}
402
lesl1a842e62019-12-02 19:00:37 +0800403V1_0::HostapdStatus Hostapd::removeAccessPointInternal(const std::string& iface_name)
Roshan Piuscc817562017-12-22 14:45:05 -0800404{
Roshan Pius087d8692017-12-27 14:11:44 -0800405 std::vector<char> remove_iface_param_vec(
406 iface_name.begin(), iface_name.end() + 1);
407 if (hostapd_remove_iface(interfaces_, remove_iface_param_vec.data()) <
408 0) {
409 wpa_printf(
410 MSG_ERROR, "Removing interface %s failed",
411 iface_name.c_str());
lesl1a842e62019-12-02 19:00:37 +0800412 return {V1_0::HostapdStatusCode::FAILURE_UNKNOWN, ""};
Roshan Pius087d8692017-12-27 14:11:44 -0800413 }
lesl1a842e62019-12-02 19:00:37 +0800414 return {V1_0::HostapdStatusCode::SUCCESS, ""};
Roshan Piuscc817562017-12-22 14:45:05 -0800415}
Roshan Piuse2d21012018-08-17 11:22:06 -0700416
lesl1a842e62019-12-02 19:00:37 +0800417V1_0::HostapdStatus Hostapd::registerCallbackInternal(
418 const sp<V1_1::IHostapdCallback>& callback)
Roshan Piuse2d21012018-08-17 11:22:06 -0700419{
420 callbacks_.push_back(callback);
lesl1a842e62019-12-02 19:00:37 +0800421 return {V1_0::HostapdStatusCode::SUCCESS, ""};
422}
423
424V1_2::HostapdStatus Hostapd::forceClientDisconnectInternal(const std::string& iface_name,
425 const std::array<uint8_t, 6>& client_address, V1_2::Ieee80211ReasonCode reason_code)
426{
427 struct hostapd_data *hapd = hostapd_get_iface(interfaces_, iface_name.c_str());
428 struct sta_info *sta;
429 if (!hapd) {
430 wpa_printf(MSG_ERROR, "Interface %s doesn't exist", iface_name.c_str());
431 return {V1_2::HostapdStatusCode::FAILURE_IFACE_UNKNOWN, ""};
432 }
433 for (sta = hapd->sta_list; sta; sta = sta->next) {
434 int res;
435 res = memcmp(sta->addr, client_address.data(), ETH_ALEN);
436 if (res == 0) {
437 wpa_printf(MSG_INFO, "Force client:" MACSTR " disconnect with reason: %d",
438 MAC2STR(client_address.data()), (uint16_t) reason_code);
439 ap_sta_disconnect(hapd, sta, sta->addr, (uint16_t) reason_code);
440 return {V1_2::HostapdStatusCode::SUCCESS, ""};
441 }
442 }
443 return {V1_2::HostapdStatusCode::FAILURE_CLIENT_UNKNOWN, ""};
Roshan Piuse2d21012018-08-17 11:22:06 -0700444}
445
Roger Wangcede5062019-12-30 12:56:28 +0800446V1_2::HostapdStatus Hostapd::setDebugParamsInternal(DebugLevel level)
447{
448 wpa_debug_level = static_cast<uint32_t>(level);
449 return {V1_2::HostapdStatusCode::SUCCESS, ""};
450}
451
Roshan Piuscc817562017-12-22 14:45:05 -0800452} // namespace implementation
lesl1a842e62019-12-02 19:00:37 +0800453} // namespace V1_2
Roshan Piuscc817562017-12-22 14:45:05 -0800454} // namespace hostapd
455} // namespace wifi
456} // namespace hardware
457} // namespace android