2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
16 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "utils/eloop.h"
20 #include "utils/uuid.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/wpa_ctrl.h"
23 #include "ap/hostapd.h"
24 #include "ap/ap_config.h"
25 #include "ap/ap_drv_ops.h"
27 #include "ap/ieee802_11.h"
28 #endif /* NEED_AP_MLME */
29 #include "ap/beacon.h"
30 #include "ap/ieee802_1x.h"
31 #include "ap/wps_hostapd.h"
32 #include "ap/ctrl_iface_ap.h"
33 #include "eap_common/eap_defs.h"
34 #include "eap_server/eap_methods.h"
35 #include "eap_common/eap_wsc_common.h"
37 #include "common/ieee802_11_defs.h"
38 #include "config_ssid.h"
40 #include "wpa_supplicant_i.h"
42 #include "p2p_supplicant.h"
44 #include "ap/sta_info.h"
49 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
50 #endif /* CONFIG_WPS */
53 static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid,
55 struct hostapd_config *conf)
57 struct hostapd_bss_config *bss = &conf->bss[0];
60 conf->driver = wpa_s->driver;
62 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
64 if (ssid->frequency == 0) {
65 /* default channel 11 */
66 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
68 } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
69 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
70 conf->channel = (ssid->frequency - 2407) / 5;
71 } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
72 (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
73 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
74 conf->channel = (ssid->frequency - 5000) / 5;
76 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
81 /* TODO: enable HT40 if driver supports it;
82 * drop to 11b if driver does not support 11g */
84 #ifdef CONFIG_IEEE80211N
86 * Enable HT20 if the driver supports it, by setting conf->ieee80211n.
87 * Using default config settings for: conf->ht_op_mode_fixed,
88 * conf->ht_capab, conf->secondary_channel, conf->require_ht
90 if (wpa_s->hw.modes) {
91 struct hostapd_hw_modes *mode = NULL;
93 for (i = 0; i < wpa_s->hw.num_modes; i++) {
94 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
95 mode = &wpa_s->hw.modes[i];
99 if (mode && mode->ht_capab)
100 conf->ieee80211n = 1;
102 #endif /* CONFIG_IEEE80211N */
105 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
106 /* Remove 802.11b rates from supported and basic rate sets */
107 int *list = os_malloc(4 * sizeof(int));
114 conf->basic_rates = list;
116 list = os_malloc(9 * sizeof(int));
128 conf->supported_rates = list;
131 bss->isolate = !wpa_s->conf->p2p_intra_bss;
132 #endif /* CONFIG_P2P */
134 if (ssid->ssid_len == 0) {
135 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
138 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
139 bss->ssid.ssid[ssid->ssid_len] = '\0';
140 bss->ssid.ssid_len = ssid->ssid_len;
141 bss->ssid.ssid_set = 1;
143 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
144 bss->wpa = ssid->proto;
145 bss->wpa_key_mgmt = ssid->key_mgmt;
146 bss->wpa_pairwise = ssid->pairwise_cipher;
147 if (ssid->passphrase) {
148 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
149 } else if (ssid->psk_set) {
150 os_free(bss->ssid.wpa_psk);
151 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
152 if (bss->ssid.wpa_psk == NULL)
154 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
155 bss->ssid.wpa_psk->group = 1;
156 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
157 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
158 struct hostapd_wep_keys *wep = &bss->ssid.wep;
160 for (i = 0; i < NUM_WEP_KEYS; i++) {
161 if (ssid->wep_key_len[i] == 0)
163 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
164 if (wep->key[i] == NULL)
166 os_memcpy(wep->key[i], ssid->wep_key[i],
167 ssid->wep_key_len[i]);
168 wep->len[i] = ssid->wep_key_len[i];
170 wep->idx = ssid->wep_tx_keyidx;
174 /* Select group cipher based on the enabled pairwise cipher suites */
177 pairwise |= bss->wpa_pairwise;
179 if (bss->rsn_pairwise == 0)
180 bss->rsn_pairwise = bss->wpa_pairwise;
181 pairwise |= bss->rsn_pairwise;
183 if (pairwise & WPA_CIPHER_TKIP)
184 bss->wpa_group = WPA_CIPHER_TKIP;
186 bss->wpa_group = WPA_CIPHER_CCMP;
188 if (bss->wpa && bss->ieee802_1x)
189 bss->ssid.security_policy = SECURITY_WPA;
191 bss->ssid.security_policy = SECURITY_WPA_PSK;
192 else if (bss->ieee802_1x) {
193 int cipher = WPA_CIPHER_NONE;
194 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
195 bss->ssid.wep.default_len = bss->default_wep_key_len;
196 if (bss->default_wep_key_len)
197 cipher = bss->default_wep_key_len >= 13 ?
198 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
199 bss->wpa_group = cipher;
200 bss->wpa_pairwise = cipher;
201 bss->rsn_pairwise = cipher;
202 } else if (bss->ssid.wep.keys_set) {
203 int cipher = WPA_CIPHER_WEP40;
204 if (bss->ssid.wep.len[0] >= 13)
205 cipher = WPA_CIPHER_WEP104;
206 bss->ssid.security_policy = SECURITY_STATIC_WEP;
207 bss->wpa_group = cipher;
208 bss->wpa_pairwise = cipher;
209 bss->rsn_pairwise = cipher;
211 bss->ssid.security_policy = SECURITY_PLAINTEXT;
212 bss->wpa_group = WPA_CIPHER_NONE;
213 bss->wpa_pairwise = WPA_CIPHER_NONE;
214 bss->rsn_pairwise = WPA_CIPHER_NONE;
219 * Enable WPS by default, but require user interaction to actually use
220 * it. Only the internal Registrar is supported.
224 bss->ap_setup_locked = 2;
225 if (wpa_s->conf->config_methods)
226 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
227 os_memcpy(bss->device_type, wpa_s->conf->device_type,
229 if (wpa_s->conf->device_name) {
230 bss->device_name = os_strdup(wpa_s->conf->device_name);
231 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
233 if (wpa_s->conf->manufacturer)
234 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
235 if (wpa_s->conf->model_name)
236 bss->model_name = os_strdup(wpa_s->conf->model_name);
237 if (wpa_s->conf->model_number)
238 bss->model_number = os_strdup(wpa_s->conf->model_number);
239 if (wpa_s->conf->serial_number)
240 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
241 if (is_nil_uuid(wpa_s->conf->uuid))
242 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
244 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
245 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
246 #endif /* CONFIG_WPS */
248 if (wpa_s->max_stations &&
249 wpa_s->max_stations < wpa_s->conf->max_num_sta)
250 bss->max_num_sta = wpa_s->max_stations;
252 bss->max_num_sta = wpa_s->conf->max_num_sta;
254 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
260 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
263 struct wpa_supplicant *wpa_s = ctx;
264 const struct ieee80211_mgmt *mgmt;
267 mgmt = (const struct ieee80211_mgmt *) buf;
268 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
271 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
272 mgmt->u.action.category,
273 &mgmt->u.action.u.vs_public_action.action,
274 len - hdr_len, freq);
275 #endif /* CONFIG_P2P */
279 static void ap_wps_event_cb(void *ctx, enum wps_event event,
280 union wps_event_data *data)
283 struct wpa_supplicant *wpa_s = ctx;
285 if (event == WPS_EV_FAIL) {
286 struct wps_event_fail *fail = &data->fail;
288 if (wpa_s->parent && wpa_s->parent != wpa_s &&
289 wpa_s == wpa_s->global->p2p_group_formation) {
291 * src/ap/wps_hostapd.c has already sent this on the
292 * main interface, so only send on the parent interface
295 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
296 "msg=%d config_error=%d",
297 fail->msg, fail->config_error);
299 wpas_p2p_wps_failed(wpa_s, fail);
301 #endif /* CONFIG_P2P */
305 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
308 wpas_notify_sta_authorized(ctx, mac_addr, authorized);
312 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
315 struct wpa_supplicant *wpa_s = ctx;
316 const struct ieee80211_mgmt *mgmt;
319 mgmt = (const struct ieee80211_mgmt *) buf;
320 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
323 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
324 mgmt->u.action.category,
325 &mgmt->u.action.u.vs_public_action.action,
326 len - hdr_len, freq);
327 #endif /* CONFIG_P2P */
332 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
333 const u8 *bssid, const u8 *ie, size_t ie_len)
336 struct wpa_supplicant *wpa_s = ctx;
337 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len);
338 #else /* CONFIG_P2P */
340 #endif /* CONFIG_P2P */
344 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
348 struct wpa_supplicant *wpa_s = ctx;
349 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
350 #endif /* CONFIG_P2P */
354 static void wpas_ap_configured_cb(void *ctx)
356 struct wpa_supplicant *wpa_s = ctx;
358 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
360 if (wpa_s->ap_configured_cb)
361 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
362 wpa_s->ap_configured_cb_data);
366 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
367 struct wpa_ssid *ssid)
369 struct wpa_driver_associate_params params;
370 struct hostapd_iface *hapd_iface;
371 struct hostapd_config *conf;
374 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
375 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
379 wpa_supplicant_ap_deinit(wpa_s);
381 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
382 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
384 os_memset(¶ms, 0, sizeof(params));
385 params.ssid = ssid->ssid;
386 params.ssid_len = ssid->ssid_len;
387 switch (ssid->mode) {
388 case WPAS_MODE_INFRA:
389 params.mode = IEEE80211_MODE_INFRA;
392 params.mode = IEEE80211_MODE_IBSS;
395 case WPAS_MODE_P2P_GO:
396 case WPAS_MODE_P2P_GROUP_FORMATION:
397 params.mode = IEEE80211_MODE_AP;
400 params.freq = ssid->frequency;
402 params.wpa_proto = ssid->proto;
403 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
404 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
406 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
407 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
409 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
410 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
411 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
412 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
413 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
414 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
416 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
420 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
421 params.group_suite = params.pairwise_suite;
424 if (ssid->mode == WPAS_MODE_P2P_GO ||
425 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
427 #endif /* CONFIG_P2P */
429 if (wpa_s->parent->set_ap_uapsd)
430 params.uapsd = wpa_s->parent->ap_uapsd;
434 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
435 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
439 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
440 if (hapd_iface == NULL)
442 hapd_iface->owner = wpa_s;
443 hapd_iface->drv_flags = wpa_s->drv_flags;
445 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
447 wpa_supplicant_ap_deinit(wpa_s);
451 if (params.uapsd > 0) {
452 conf->bss->wmm_enabled = 1;
453 conf->bss->wmm_uapsd = 1;
456 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
457 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
458 wpa_supplicant_ap_deinit(wpa_s);
463 if (ssid->mode == WPAS_MODE_P2P_GO)
464 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
465 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
466 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
468 #endif /* CONFIG_P2P */
470 hapd_iface->num_bss = conf->num_bss;
471 hapd_iface->bss = os_zalloc(conf->num_bss *
472 sizeof(struct hostapd_data *));
473 if (hapd_iface->bss == NULL) {
474 wpa_supplicant_ap_deinit(wpa_s);
478 for (i = 0; i < conf->num_bss; i++) {
480 hostapd_alloc_bss_data(hapd_iface, conf,
482 if (hapd_iface->bss[i] == NULL) {
483 wpa_supplicant_ap_deinit(wpa_s);
487 hapd_iface->bss[i]->msg_ctx = wpa_s;
488 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
489 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
490 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
491 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
492 hostapd_register_probereq_cb(hapd_iface->bss[i],
493 ap_probe_req_rx, wpa_s);
494 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
495 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
496 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
497 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
498 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
499 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
501 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
502 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
503 wpa_s, ssid->p2p_persistent_group,
504 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
505 #endif /* CONFIG_P2P */
506 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
507 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
510 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
511 hapd_iface->bss[0]->driver = wpa_s->driver;
512 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
514 wpa_s->current_ssid = ssid;
515 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
516 wpa_s->assoc_freq = ssid->frequency;
518 if (hostapd_setup_interface(wpa_s->ap_iface)) {
519 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
520 wpa_supplicant_ap_deinit(wpa_s);
528 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
531 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
532 #endif /* CONFIG_WPS */
534 if (wpa_s->ap_iface == NULL)
537 wpa_s->current_ssid = NULL;
538 wpa_s->assoc_freq = 0;
539 wpa_s->reassociated_connection = 0;
541 if (wpa_s->ap_iface->bss)
542 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
543 wpas_p2p_group_deinit(wpa_s);
544 #endif /* CONFIG_P2P */
545 hostapd_interface_deinit(wpa_s->ap_iface);
546 hostapd_interface_free(wpa_s->ap_iface);
547 wpa_s->ap_iface = NULL;
548 wpa_drv_deinit_ap(wpa_s);
552 void ap_tx_status(void *ctx, const u8 *addr,
553 const u8 *buf, size_t len, int ack)
556 struct wpa_supplicant *wpa_s = ctx;
557 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
558 #endif /* NEED_AP_MLME */
562 void ap_client_poll_ok(void *ctx, const u8 *addr)
565 struct wpa_supplicant *wpa_s = ctx;
567 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
568 #endif /* NEED_AP_MLME */
572 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
575 struct wpa_supplicant *wpa_s = ctx;
576 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
577 #endif /* NEED_AP_MLME */
581 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
584 struct wpa_supplicant *wpa_s = ctx;
585 struct hostapd_frame_info fi;
586 os_memset(&fi, 0, sizeof(fi));
587 fi.datarate = rx_mgmt->datarate;
588 fi.ssi_signal = rx_mgmt->ssi_signal;
589 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
590 rx_mgmt->frame_len, &fi);
591 #endif /* NEED_AP_MLME */
595 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
598 struct wpa_supplicant *wpa_s = ctx;
599 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
600 #endif /* NEED_AP_MLME */
604 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
605 const u8 *src_addr, const u8 *buf, size_t len)
607 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
613 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
614 const u8 *p2p_dev_addr)
616 if (!wpa_s->ap_iface)
618 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
623 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
624 struct sta_info *sta, void *ctx)
626 if (sta && (sta->flags & WLAN_STA_WPS)) {
627 ap_sta_deauthenticate(hapd, sta,
628 WLAN_REASON_PREV_AUTH_NOT_VALID);
629 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
630 __func__, MAC2STR(sta->addr));
638 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
640 struct wps_registrar *reg;
641 int reg_sel = 0, wps_sta = 0;
643 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
646 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
647 reg_sel = wps_registrar_wps_cancel(reg);
648 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
649 wpa_supplicant_ap_wps_sta_cancel, NULL);
651 if (!reg_sel && !wps_sta) {
652 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
658 * There are 2 cases to return wps cancel as success:
659 * 1. When wps cancel was initiated but no connection has been
660 * established with client yet.
661 * 2. Client is in the middle of exchanging WPS messages.
668 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
669 const char *pin, char *buf, size_t buflen)
671 int ret, ret_len = 0;
673 if (!wpa_s->ap_iface)
677 unsigned int rpin = wps_generate_pin();
678 ret_len = os_snprintf(buf, buflen, "%d", rpin);
681 ret_len = os_snprintf(buf, buflen, "%s", pin);
683 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
691 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
693 struct wpa_supplicant *wpa_s = eloop_data;
694 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
695 wpas_wps_ap_pin_disable(wpa_s);
699 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
701 struct hostapd_data *hapd;
703 if (wpa_s->ap_iface == NULL)
705 hapd = wpa_s->ap_iface->bss[0];
706 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
707 hapd->ap_pin_failures = 0;
708 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
710 eloop_register_timeout(timeout, 0,
711 wpas_wps_ap_pin_timeout, wpa_s, NULL);
715 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
717 struct hostapd_data *hapd;
719 if (wpa_s->ap_iface == NULL)
721 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
722 hapd = wpa_s->ap_iface->bss[0];
723 os_free(hapd->conf->ap_pin);
724 hapd->conf->ap_pin = NULL;
725 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
729 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
731 struct hostapd_data *hapd;
735 if (wpa_s->ap_iface == NULL)
737 hapd = wpa_s->ap_iface->bss[0];
738 pin = wps_generate_pin();
739 os_snprintf(pin_txt, sizeof(pin_txt), "%u", pin);
740 os_free(hapd->conf->ap_pin);
741 hapd->conf->ap_pin = os_strdup(pin_txt);
742 if (hapd->conf->ap_pin == NULL)
744 wpas_wps_ap_pin_enable(wpa_s, timeout);
746 return hapd->conf->ap_pin;
750 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
752 struct hostapd_data *hapd;
753 if (wpa_s->ap_iface == NULL)
755 hapd = wpa_s->ap_iface->bss[0];
756 return hapd->conf->ap_pin;
760 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
763 struct hostapd_data *hapd;
767 if (wpa_s->ap_iface == NULL)
769 hapd = wpa_s->ap_iface->bss[0];
770 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
771 if (ret < 0 || ret >= (int) sizeof(pin_txt))
773 os_free(hapd->conf->ap_pin);
774 hapd->conf->ap_pin = os_strdup(pin_txt);
775 if (hapd->conf->ap_pin == NULL)
777 wpas_wps_ap_pin_enable(wpa_s, timeout);
783 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
785 struct hostapd_data *hapd;
787 if (wpa_s->ap_iface == NULL)
789 hapd = wpa_s->ap_iface->bss[0];
792 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
793 * PIN if this happens multiple times to slow down brute force attacks.
795 hapd->ap_pin_failures++;
796 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
797 hapd->ap_pin_failures);
798 if (hapd->ap_pin_failures < 3)
801 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
802 hapd->ap_pin_failures = 0;
803 os_free(hapd->conf->ap_pin);
804 hapd->conf->ap_pin = NULL;
807 #endif /* CONFIG_WPS */
810 #ifdef CONFIG_CTRL_IFACE
812 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
813 char *buf, size_t buflen)
815 if (wpa_s->ap_iface == NULL)
817 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
822 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
823 char *buf, size_t buflen)
825 if (wpa_s->ap_iface == NULL)
827 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
832 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
833 char *buf, size_t buflen)
835 if (wpa_s->ap_iface == NULL)
837 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
842 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
843 size_t buflen, int verbose)
845 char *pos = buf, *end = buf + buflen;
847 struct hostapd_bss_config *conf;
849 if (wpa_s->ap_iface == NULL)
852 conf = wpa_s->ap_iface->bss[0]->conf;
856 ret = os_snprintf(pos, end - pos,
857 "pairwise_cipher=%s\n"
860 wpa_cipher_txt(conf->rsn_pairwise),
861 wpa_cipher_txt(conf->wpa_group),
862 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
864 if (ret < 0 || ret >= end - pos)
870 #endif /* CONFIG_CTRL_IFACE */
873 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
875 struct hostapd_iface *iface = wpa_s->ap_iface;
876 struct wpa_ssid *ssid = wpa_s->current_ssid;
877 struct hostapd_data *hapd;
879 if (ssid == NULL || wpa_s->ap_iface == NULL)
883 if (ssid->mode == WPAS_MODE_P2P_GO)
884 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
885 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
886 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
888 #endif /* CONFIG_P2P */
890 ieee802_11_set_beacons(iface);
891 hapd = iface->bss[0];
892 hostapd_set_ap_wps_ie(hapd);
898 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
901 struct hostapd_data *hapd;
902 struct hostapd_bss_config *conf;
904 if (!wpa_s->ap_iface)
908 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
911 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
913 hapd = wpa_s->ap_iface->bss[0];
916 os_free(conf->accept_mac);
917 conf->accept_mac = NULL;
918 conf->num_accept_mac = 0;
919 os_free(conf->deny_mac);
920 conf->deny_mac = NULL;
921 conf->num_deny_mac = 0;
924 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
928 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
929 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
930 if (conf->accept_mac == NULL)
932 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
933 conf->num_accept_mac = 1;