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 HT if driver supports it;
82 * drop to 11b if driver does not support 11g */
85 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
86 /* Remove 802.11b rates from supported and basic rate sets */
87 int *list = os_malloc(4 * sizeof(int));
94 conf->basic_rates = list;
96 list = os_malloc(9 * sizeof(int));
108 conf->supported_rates = list;
110 #endif /* CONFIG_P2P */
112 if (ssid->ssid_len == 0) {
113 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
116 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
117 bss->ssid.ssid[ssid->ssid_len] = '\0';
118 bss->ssid.ssid_len = ssid->ssid_len;
119 bss->ssid.ssid_set = 1;
121 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
122 bss->wpa = ssid->proto;
123 bss->wpa_key_mgmt = ssid->key_mgmt;
124 bss->wpa_pairwise = ssid->pairwise_cipher;
125 if (ssid->passphrase) {
126 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
127 } else if (ssid->psk_set) {
128 os_free(bss->ssid.wpa_psk);
129 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
130 if (bss->ssid.wpa_psk == NULL)
132 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
133 bss->ssid.wpa_psk->group = 1;
136 /* Select group cipher based on the enabled pairwise cipher suites */
139 pairwise |= bss->wpa_pairwise;
141 if (bss->rsn_pairwise == 0)
142 bss->rsn_pairwise = bss->wpa_pairwise;
143 pairwise |= bss->rsn_pairwise;
145 if (pairwise & WPA_CIPHER_TKIP)
146 bss->wpa_group = WPA_CIPHER_TKIP;
148 bss->wpa_group = WPA_CIPHER_CCMP;
150 if (bss->wpa && bss->ieee802_1x)
151 bss->ssid.security_policy = SECURITY_WPA;
153 bss->ssid.security_policy = SECURITY_WPA_PSK;
154 else if (bss->ieee802_1x) {
155 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
156 bss->ssid.wep.default_len = bss->default_wep_key_len;
157 } else if (bss->ssid.wep.keys_set)
158 bss->ssid.security_policy = SECURITY_STATIC_WEP;
160 bss->ssid.security_policy = SECURITY_PLAINTEXT;
164 * Enable WPS by default, but require user interaction to actually use
165 * it. Only the internal Registrar is supported.
169 bss->ap_setup_locked = 2;
170 if (wpa_s->conf->config_methods)
171 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
172 if (wpa_s->conf->device_type)
173 bss->device_type = os_strdup(wpa_s->conf->device_type);
174 if (wpa_s->conf->device_name) {
175 bss->device_name = os_strdup(wpa_s->conf->device_name);
176 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
178 if (wpa_s->conf->manufacturer)
179 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
180 if (wpa_s->conf->model_name)
181 bss->model_name = os_strdup(wpa_s->conf->model_name);
182 if (wpa_s->conf->model_number)
183 bss->model_number = os_strdup(wpa_s->conf->model_number);
184 if (wpa_s->conf->serial_number)
185 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
186 if (is_nil_uuid(wpa_s->conf->uuid))
187 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
189 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
190 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
191 #endif /* CONFIG_WPS */
193 if (wpa_s->max_stations &&
194 wpa_s->max_stations < wpa_s->conf->max_num_sta)
195 bss->max_num_sta = wpa_s->max_stations;
197 bss->max_num_sta = wpa_s->conf->max_num_sta;
199 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
205 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
208 struct wpa_supplicant *wpa_s = ctx;
209 const struct ieee80211_mgmt *mgmt;
212 mgmt = (const struct ieee80211_mgmt *) buf;
213 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
216 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
217 mgmt->u.action.category,
218 &mgmt->u.action.u.vs_public_action.action,
219 len - hdr_len, freq);
220 #endif /* CONFIG_P2P */
224 static void ap_wps_event_cb(void *ctx, enum wps_event event,
225 union wps_event_data *data)
228 struct wpa_supplicant *wpa_s = ctx;
230 if (event == WPS_EV_FAIL && wpa_s->parent && wpa_s->parent != wpa_s &&
231 wpa_s == wpa_s->global->p2p_group_formation) {
232 struct wps_event_fail *fail = &data->fail;
235 * src/ap/wps_hostapd.c has already sent this on the main
236 * interface, so only send on the parent interface here if
239 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
240 "msg=%d config_error=%d",
241 fail->msg, fail->config_error);
243 #endif /* CONFIG_P2P */
247 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
250 wpas_notify_sta_authorized(ctx, mac_addr, authorized);
254 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
257 struct wpa_supplicant *wpa_s = ctx;
258 const struct ieee80211_mgmt *mgmt;
261 mgmt = (const struct ieee80211_mgmt *) buf;
262 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
265 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
266 mgmt->u.action.category,
267 &mgmt->u.action.u.vs_public_action.action,
268 len - hdr_len, freq);
269 #endif /* CONFIG_P2P */
274 static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
278 struct wpa_supplicant *wpa_s = ctx;
279 return wpas_p2p_probe_req_rx(wpa_s, addr, ie, ie_len);
280 #else /* CONFIG_P2P */
282 #endif /* CONFIG_P2P */
286 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
290 struct wpa_supplicant *wpa_s = ctx;
291 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
292 #endif /* CONFIG_P2P */
296 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
297 struct wpa_ssid *ssid)
299 struct wpa_driver_associate_params params;
300 struct hostapd_iface *hapd_iface;
301 struct hostapd_config *conf;
304 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
305 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
309 wpa_supplicant_ap_deinit(wpa_s);
311 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
312 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
314 os_memset(¶ms, 0, sizeof(params));
315 params.ssid = ssid->ssid;
316 params.ssid_len = ssid->ssid_len;
317 switch (ssid->mode) {
318 case WPAS_MODE_INFRA:
319 params.mode = IEEE80211_MODE_INFRA;
322 params.mode = IEEE80211_MODE_IBSS;
325 case WPAS_MODE_P2P_GO:
326 case WPAS_MODE_P2P_GROUP_FORMATION:
327 params.mode = IEEE80211_MODE_AP;
330 params.freq = ssid->frequency;
332 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
333 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
335 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
336 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
338 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
339 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
340 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
341 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
342 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
343 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
345 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
349 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
350 params.group_suite = params.pairwise_suite;
353 if (ssid->mode == WPAS_MODE_P2P_GO ||
354 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
356 wpa_drv_set_intra_bss(wpa_s, wpa_s->conf->p2p_intra_bss);
357 #endif /* CONFIG_P2P */
359 if (wpa_s->parent->set_ap_uapsd)
360 params.uapsd = wpa_s->parent->ap_uapsd;
364 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
365 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
369 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
370 if (hapd_iface == NULL)
372 hapd_iface->owner = wpa_s;
374 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
376 wpa_supplicant_ap_deinit(wpa_s);
380 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
381 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
382 wpa_supplicant_ap_deinit(wpa_s);
387 if (ssid->mode == WPAS_MODE_P2P_GO)
388 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
389 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
390 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
392 #endif /* CONFIG_P2P */
394 hapd_iface->num_bss = conf->num_bss;
395 hapd_iface->bss = os_zalloc(conf->num_bss *
396 sizeof(struct hostapd_data *));
397 if (hapd_iface->bss == NULL) {
398 wpa_supplicant_ap_deinit(wpa_s);
402 for (i = 0; i < conf->num_bss; i++) {
404 hostapd_alloc_bss_data(hapd_iface, conf,
406 if (hapd_iface->bss[i] == NULL) {
407 wpa_supplicant_ap_deinit(wpa_s);
411 hapd_iface->bss[i]->msg_ctx = wpa_s;
412 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
413 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
414 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
415 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
416 hostapd_register_probereq_cb(hapd_iface->bss[i],
417 ap_probe_req_rx, wpa_s);
418 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
419 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
420 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
421 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
422 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
423 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
425 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
426 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
427 wpa_s, ssid->p2p_persistent_group,
428 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
429 #endif /* CONFIG_P2P */
432 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
433 hapd_iface->bss[0]->driver = wpa_s->driver;
434 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
436 if (hostapd_setup_interface(wpa_s->ap_iface)) {
437 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
438 wpa_supplicant_ap_deinit(wpa_s);
442 wpa_s->current_ssid = ssid;
443 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
444 wpa_s->assoc_freq = ssid->frequency;
445 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
447 if (wpa_s->ap_configured_cb)
448 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
449 wpa_s->ap_configured_cb_data);
455 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
458 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
459 #endif /* CONFIG_WPS */
461 if (wpa_s->ap_iface == NULL)
464 wpa_s->current_ssid = NULL;
465 wpa_s->assoc_freq = 0;
467 if (wpa_s->ap_iface->bss)
468 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
469 wpas_p2p_group_deinit(wpa_s);
470 #endif /* CONFIG_P2P */
471 hostapd_interface_deinit(wpa_s->ap_iface);
472 hostapd_interface_free(wpa_s->ap_iface);
473 wpa_s->ap_iface = NULL;
474 wpa_drv_deinit_ap(wpa_s);
478 void ap_tx_status(void *ctx, const u8 *addr,
479 const u8 *buf, size_t len, int ack)
482 struct wpa_supplicant *wpa_s = ctx;
483 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
484 #endif /* NEED_AP_MLME */
488 void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
491 struct wpa_supplicant *wpa_s = ctx;
492 const struct ieee80211_hdr *hdr =
493 (const struct ieee80211_hdr *) frame;
494 u16 fc = le_to_host16(hdr->frame_control);
495 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
496 (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
497 (WLAN_FC_TODS | WLAN_FC_FROMDS));
498 #endif /* NEED_AP_MLME */
502 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
505 struct wpa_supplicant *wpa_s = ctx;
506 struct hostapd_frame_info fi;
507 os_memset(&fi, 0, sizeof(fi));
508 fi.datarate = rx_mgmt->datarate;
509 fi.ssi_signal = rx_mgmt->ssi_signal;
510 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
511 rx_mgmt->frame_len, &fi);
512 #endif /* NEED_AP_MLME */
516 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
519 struct wpa_supplicant *wpa_s = ctx;
520 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
521 #endif /* NEED_AP_MLME */
525 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
526 const u8 *src_addr, const u8 *buf, size_t len)
528 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
534 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
535 const u8 *p2p_dev_addr)
537 if (!wpa_s->ap_iface)
539 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
544 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
545 struct sta_info *sta, void *ctx)
547 if (sta && (sta->flags & WLAN_STA_WPS)) {
548 ap_sta_deauthenticate(hapd, sta,
549 WLAN_REASON_PREV_AUTH_NOT_VALID);
550 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
551 __func__, MAC2STR(sta->addr));
559 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
561 struct wps_registrar *reg;
562 int reg_sel = 0, wps_sta = 0;
564 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
567 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
568 reg_sel = wps_registrar_wps_cancel(reg);
569 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
570 wpa_supplicant_ap_wps_sta_cancel, NULL);
572 if (!reg_sel && !wps_sta) {
573 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
579 * There are 2 cases to return wps cancel as success:
580 * 1. When wps cancel was initiated but no connection has been
581 * established with client yet.
582 * 2. Client is in the middle of exchanging WPS messages.
589 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
590 const char *pin, char *buf, size_t buflen)
592 int ret, ret_len = 0;
594 if (!wpa_s->ap_iface)
598 unsigned int rpin = wps_generate_pin();
599 ret_len = os_snprintf(buf, buflen, "%d", rpin);
602 ret_len = os_snprintf(buf, buflen, "%s", pin);
604 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
612 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
614 struct wpa_supplicant *wpa_s = eloop_data;
615 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
616 wpas_wps_ap_pin_disable(wpa_s);
620 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
622 struct hostapd_data *hapd;
624 if (wpa_s->ap_iface == NULL)
626 hapd = wpa_s->ap_iface->bss[0];
627 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
628 hapd->ap_pin_failures = 0;
629 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
631 eloop_register_timeout(timeout, 0,
632 wpas_wps_ap_pin_timeout, wpa_s, NULL);
636 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
638 struct hostapd_data *hapd;
640 if (wpa_s->ap_iface == NULL)
642 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
643 hapd = wpa_s->ap_iface->bss[0];
644 os_free(hapd->conf->ap_pin);
645 hapd->conf->ap_pin = NULL;
646 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
650 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
652 struct hostapd_data *hapd;
656 if (wpa_s->ap_iface == NULL)
658 hapd = wpa_s->ap_iface->bss[0];
659 pin = wps_generate_pin();
660 os_snprintf(pin_txt, sizeof(pin_txt), "%u", pin);
661 os_free(hapd->conf->ap_pin);
662 hapd->conf->ap_pin = os_strdup(pin_txt);
663 if (hapd->conf->ap_pin == NULL)
665 wpas_wps_ap_pin_enable(wpa_s, timeout);
667 return hapd->conf->ap_pin;
671 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
673 struct hostapd_data *hapd;
674 if (wpa_s->ap_iface == NULL)
676 hapd = wpa_s->ap_iface->bss[0];
677 return hapd->conf->ap_pin;
681 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
684 struct hostapd_data *hapd;
688 if (wpa_s->ap_iface == NULL)
690 hapd = wpa_s->ap_iface->bss[0];
691 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
692 if (ret < 0 || ret >= (int) sizeof(pin_txt))
694 os_free(hapd->conf->ap_pin);
695 hapd->conf->ap_pin = os_strdup(pin_txt);
696 if (hapd->conf->ap_pin == NULL)
698 wpas_wps_ap_pin_enable(wpa_s, timeout);
704 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
706 struct hostapd_data *hapd;
708 if (wpa_s->ap_iface == NULL)
710 hapd = wpa_s->ap_iface->bss[0];
713 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
714 * PIN if this happens multiple times to slow down brute force attacks.
716 hapd->ap_pin_failures++;
717 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
718 hapd->ap_pin_failures);
719 if (hapd->ap_pin_failures < 3)
722 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
723 hapd->ap_pin_failures = 0;
724 os_free(hapd->conf->ap_pin);
725 hapd->conf->ap_pin = NULL;
728 #endif /* CONFIG_WPS */
731 #ifdef CONFIG_CTRL_IFACE
733 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
734 char *buf, size_t buflen)
736 if (wpa_s->ap_iface == NULL)
738 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
743 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
744 char *buf, size_t buflen)
746 if (wpa_s->ap_iface == NULL)
748 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
753 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
754 char *buf, size_t buflen)
756 if (wpa_s->ap_iface == NULL)
758 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
763 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
764 size_t buflen, int verbose)
766 char *pos = buf, *end = buf + buflen;
768 struct hostapd_bss_config *conf;
770 if (wpa_s->ap_iface == NULL)
773 conf = wpa_s->ap_iface->bss[0]->conf;
777 ret = os_snprintf(pos, end - pos,
778 "pairwise_cipher=%s\n"
781 wpa_cipher_txt(conf->rsn_pairwise),
782 wpa_cipher_txt(conf->wpa_group),
783 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
785 if (ret < 0 || ret >= end - pos)
791 #endif /* CONFIG_CTRL_IFACE */
794 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
796 struct hostapd_iface *iface = wpa_s->ap_iface;
797 struct wpa_ssid *ssid = wpa_s->current_ssid;
798 struct hostapd_data *hapd;
800 if (ssid == NULL || wpa_s->ap_iface == NULL)
804 if (ssid->mode == WPAS_MODE_P2P_GO)
805 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
806 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
807 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
809 #endif /* CONFIG_P2P */
811 ieee802_11_set_beacons(iface);
812 hapd = iface->bss[0];
813 hostapd_set_ap_wps_ie(hapd);
819 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
822 struct hostapd_data *hapd;
823 struct hostapd_bss_config *conf;
825 if (!wpa_s->ap_iface)
829 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
832 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
834 hapd = wpa_s->ap_iface->bss[0];
837 os_free(conf->accept_mac);
838 conf->accept_mac = NULL;
839 conf->num_accept_mac = 0;
840 os_free(conf->deny_mac);
841 conf->deny_mac = NULL;
842 conf->num_deny_mac = 0;
845 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
849 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
850 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
851 if (conf->accept_mac == NULL)
853 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
854 conf->num_accept_mac = 1;