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];
59 #ifdef CONFIG_IEEE80211N
60 struct hostapd_hw_modes *modes;
62 #endif /* CONFIG_IEEE80211N */
64 conf->driver = wpa_s->driver;
66 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
68 if (ssid->frequency == 0) {
69 /* default channel 11 */
70 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
72 } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
73 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
74 conf->channel = (ssid->frequency - 2407) / 5;
75 } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
76 (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
77 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
78 conf->channel = (ssid->frequency - 5000) / 5;
80 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
85 /* TODO: enable HT40 if driver supports it;
86 * drop to 11b if driver does not support 11g */
88 #ifdef CONFIG_IEEE80211N
90 * Enable HT20 if the driver supports it, by setting conf->ieee80211n.
91 * Using default config settings for: conf->ht_op_mode_fixed,
92 * conf->ht_capab, conf->secondary_channel, conf->require_ht
94 modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes, &flags);
96 struct hostapd_hw_modes *mode = NULL;
98 for (i = 0; i < num_modes; i++) {
99 if (modes[i].mode == conf->hw_mode) {
104 if (mode && mode->ht_capab)
105 conf->ieee80211n = 1;
106 ieee80211_sta_free_hw_features(modes, num_modes);
109 #endif /* CONFIG_IEEE80211N */
112 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
113 /* Remove 802.11b rates from supported and basic rate sets */
114 int *list = os_malloc(4 * sizeof(int));
121 conf->basic_rates = list;
123 list = os_malloc(9 * sizeof(int));
135 conf->supported_rates = list;
138 bss->isolate = !wpa_s->conf->p2p_intra_bss;
139 #endif /* CONFIG_P2P */
141 if (ssid->ssid_len == 0) {
142 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
145 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
146 bss->ssid.ssid[ssid->ssid_len] = '\0';
147 bss->ssid.ssid_len = ssid->ssid_len;
148 bss->ssid.ssid_set = 1;
150 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
151 bss->wpa = ssid->proto;
152 bss->wpa_key_mgmt = ssid->key_mgmt;
153 bss->wpa_pairwise = ssid->pairwise_cipher;
154 if (ssid->passphrase) {
155 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
156 } else if (ssid->psk_set) {
157 os_free(bss->ssid.wpa_psk);
158 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
159 if (bss->ssid.wpa_psk == NULL)
161 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
162 bss->ssid.wpa_psk->group = 1;
163 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
164 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
165 struct hostapd_wep_keys *wep = &bss->ssid.wep;
167 for (i = 0; i < NUM_WEP_KEYS; i++) {
168 if (ssid->wep_key_len[i] == 0)
170 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
171 if (wep->key[i] == NULL)
173 os_memcpy(wep->key[i], ssid->wep_key[i],
174 ssid->wep_key_len[i]);
175 wep->len[i] = ssid->wep_key_len[i];
177 wep->idx = ssid->wep_tx_keyidx;
181 /* Select group cipher based on the enabled pairwise cipher suites */
184 pairwise |= bss->wpa_pairwise;
186 if (bss->rsn_pairwise == 0)
187 bss->rsn_pairwise = bss->wpa_pairwise;
188 pairwise |= bss->rsn_pairwise;
190 if (pairwise & WPA_CIPHER_TKIP)
191 bss->wpa_group = WPA_CIPHER_TKIP;
193 bss->wpa_group = WPA_CIPHER_CCMP;
195 if (bss->wpa && bss->ieee802_1x)
196 bss->ssid.security_policy = SECURITY_WPA;
198 bss->ssid.security_policy = SECURITY_WPA_PSK;
199 else if (bss->ieee802_1x) {
200 int cipher = WPA_CIPHER_NONE;
201 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
202 bss->ssid.wep.default_len = bss->default_wep_key_len;
203 if (bss->default_wep_key_len)
204 cipher = bss->default_wep_key_len >= 13 ?
205 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
206 bss->wpa_group = cipher;
207 bss->wpa_pairwise = cipher;
208 bss->rsn_pairwise = cipher;
209 } else if (bss->ssid.wep.keys_set) {
210 int cipher = WPA_CIPHER_WEP40;
211 if (bss->ssid.wep.len[0] >= 13)
212 cipher = WPA_CIPHER_WEP104;
213 bss->ssid.security_policy = SECURITY_STATIC_WEP;
214 bss->wpa_group = cipher;
215 bss->wpa_pairwise = cipher;
216 bss->rsn_pairwise = cipher;
218 bss->ssid.security_policy = SECURITY_PLAINTEXT;
219 bss->wpa_group = WPA_CIPHER_NONE;
220 bss->wpa_pairwise = WPA_CIPHER_NONE;
221 bss->rsn_pairwise = WPA_CIPHER_NONE;
226 * Enable WPS by default, but require user interaction to actually use
227 * it. Only the internal Registrar is supported.
231 bss->ap_setup_locked = 2;
232 if (wpa_s->conf->config_methods)
233 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
234 os_memcpy(bss->device_type, wpa_s->conf->device_type,
236 if (wpa_s->conf->device_name) {
237 bss->device_name = os_strdup(wpa_s->conf->device_name);
238 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
240 if (wpa_s->conf->manufacturer)
241 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
242 if (wpa_s->conf->model_name)
243 bss->model_name = os_strdup(wpa_s->conf->model_name);
244 if (wpa_s->conf->model_number)
245 bss->model_number = os_strdup(wpa_s->conf->model_number);
246 if (wpa_s->conf->serial_number)
247 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
248 if (is_nil_uuid(wpa_s->conf->uuid))
249 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
251 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
252 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
253 #endif /* CONFIG_WPS */
255 if (wpa_s->max_stations &&
256 wpa_s->max_stations < wpa_s->conf->max_num_sta)
257 bss->max_num_sta = wpa_s->max_stations;
259 bss->max_num_sta = wpa_s->conf->max_num_sta;
261 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
267 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
270 struct wpa_supplicant *wpa_s = ctx;
271 const struct ieee80211_mgmt *mgmt;
274 mgmt = (const struct ieee80211_mgmt *) buf;
275 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
278 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
279 mgmt->u.action.category,
280 &mgmt->u.action.u.vs_public_action.action,
281 len - hdr_len, freq);
282 #endif /* CONFIG_P2P */
286 static void ap_wps_event_cb(void *ctx, enum wps_event event,
287 union wps_event_data *data)
290 struct wpa_supplicant *wpa_s = ctx;
292 if (event == WPS_EV_FAIL) {
293 struct wps_event_fail *fail = &data->fail;
295 if (wpa_s->parent && wpa_s->parent != wpa_s &&
296 wpa_s == wpa_s->global->p2p_group_formation) {
298 * src/ap/wps_hostapd.c has already sent this on the
299 * main interface, so only send on the parent interface
302 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
303 "msg=%d config_error=%d",
304 fail->msg, fail->config_error);
306 wpas_p2p_wps_failed(wpa_s, fail);
308 #endif /* CONFIG_P2P */
312 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
315 wpas_notify_sta_authorized(ctx, mac_addr, authorized);
319 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
322 struct wpa_supplicant *wpa_s = ctx;
323 const struct ieee80211_mgmt *mgmt;
326 mgmt = (const struct ieee80211_mgmt *) buf;
327 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
330 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
331 mgmt->u.action.category,
332 &mgmt->u.action.u.vs_public_action.action,
333 len - hdr_len, freq);
334 #endif /* CONFIG_P2P */
339 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
340 const u8 *bssid, const u8 *ie, size_t ie_len)
343 struct wpa_supplicant *wpa_s = ctx;
344 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len);
345 #else /* CONFIG_P2P */
347 #endif /* CONFIG_P2P */
351 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
355 struct wpa_supplicant *wpa_s = ctx;
356 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
357 #endif /* CONFIG_P2P */
361 static void wpas_ap_configured_cb(void *ctx)
363 struct wpa_supplicant *wpa_s = ctx;
365 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
367 if (wpa_s->ap_configured_cb)
368 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
369 wpa_s->ap_configured_cb_data);
373 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
374 struct wpa_ssid *ssid)
376 struct wpa_driver_associate_params params;
377 struct hostapd_iface *hapd_iface;
378 struct hostapd_config *conf;
381 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
382 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
386 wpa_supplicant_ap_deinit(wpa_s);
388 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
389 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
391 os_memset(¶ms, 0, sizeof(params));
392 params.ssid = ssid->ssid;
393 params.ssid_len = ssid->ssid_len;
394 switch (ssid->mode) {
395 case WPAS_MODE_INFRA:
396 params.mode = IEEE80211_MODE_INFRA;
399 params.mode = IEEE80211_MODE_IBSS;
402 case WPAS_MODE_P2P_GO:
403 case WPAS_MODE_P2P_GROUP_FORMATION:
404 params.mode = IEEE80211_MODE_AP;
407 params.freq = ssid->frequency;
409 params.wpa_proto = ssid->proto;
410 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
411 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
413 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
414 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
416 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
417 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
418 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
419 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
420 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
421 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
423 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
427 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
428 params.group_suite = params.pairwise_suite;
431 if (ssid->mode == WPAS_MODE_P2P_GO ||
432 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
434 #endif /* CONFIG_P2P */
436 if (wpa_s->parent->set_ap_uapsd)
437 params.uapsd = wpa_s->parent->ap_uapsd;
441 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
442 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
446 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
447 if (hapd_iface == NULL)
449 hapd_iface->owner = wpa_s;
450 hapd_iface->drv_flags = wpa_s->drv_flags;
452 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
454 wpa_supplicant_ap_deinit(wpa_s);
458 if (params.uapsd > 0) {
459 conf->bss->wmm_enabled = 1;
460 conf->bss->wmm_uapsd = 1;
463 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
464 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
465 wpa_supplicant_ap_deinit(wpa_s);
470 if (ssid->mode == WPAS_MODE_P2P_GO)
471 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
472 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
473 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
475 #endif /* CONFIG_P2P */
477 hapd_iface->num_bss = conf->num_bss;
478 hapd_iface->bss = os_zalloc(conf->num_bss *
479 sizeof(struct hostapd_data *));
480 if (hapd_iface->bss == NULL) {
481 wpa_supplicant_ap_deinit(wpa_s);
485 for (i = 0; i < conf->num_bss; i++) {
487 hostapd_alloc_bss_data(hapd_iface, conf,
489 if (hapd_iface->bss[i] == NULL) {
490 wpa_supplicant_ap_deinit(wpa_s);
494 hapd_iface->bss[i]->msg_ctx = wpa_s;
495 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
496 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
497 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
498 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
499 hostapd_register_probereq_cb(hapd_iface->bss[i],
500 ap_probe_req_rx, wpa_s);
501 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
502 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
503 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
504 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
505 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
506 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
508 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
509 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
510 wpa_s, ssid->p2p_persistent_group,
511 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
512 #endif /* CONFIG_P2P */
513 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
514 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
517 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
518 hapd_iface->bss[0]->driver = wpa_s->driver;
519 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
521 wpa_s->current_ssid = ssid;
522 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
523 wpa_s->assoc_freq = ssid->frequency;
525 if (hostapd_setup_interface(wpa_s->ap_iface)) {
526 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
527 wpa_supplicant_ap_deinit(wpa_s);
535 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
538 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
539 #endif /* CONFIG_WPS */
541 if (wpa_s->ap_iface == NULL)
544 wpa_s->current_ssid = NULL;
545 wpa_s->assoc_freq = 0;
546 wpa_s->reassociated_connection = 0;
548 if (wpa_s->ap_iface->bss)
549 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
550 wpas_p2p_group_deinit(wpa_s);
551 #endif /* CONFIG_P2P */
552 hostapd_interface_deinit(wpa_s->ap_iface);
553 hostapd_interface_free(wpa_s->ap_iface);
554 wpa_s->ap_iface = NULL;
555 wpa_drv_deinit_ap(wpa_s);
559 void ap_tx_status(void *ctx, const u8 *addr,
560 const u8 *buf, size_t len, int ack)
563 struct wpa_supplicant *wpa_s = ctx;
564 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
565 #endif /* NEED_AP_MLME */
569 void ap_client_poll_ok(void *ctx, const u8 *addr)
572 struct wpa_supplicant *wpa_s = ctx;
574 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
575 #endif /* NEED_AP_MLME */
579 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
582 struct wpa_supplicant *wpa_s = ctx;
583 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
584 #endif /* NEED_AP_MLME */
588 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
591 struct wpa_supplicant *wpa_s = ctx;
592 struct hostapd_frame_info fi;
593 os_memset(&fi, 0, sizeof(fi));
594 fi.datarate = rx_mgmt->datarate;
595 fi.ssi_signal = rx_mgmt->ssi_signal;
596 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
597 rx_mgmt->frame_len, &fi);
598 #endif /* NEED_AP_MLME */
602 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
605 struct wpa_supplicant *wpa_s = ctx;
606 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
607 #endif /* NEED_AP_MLME */
611 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
612 const u8 *src_addr, const u8 *buf, size_t len)
614 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
620 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
621 const u8 *p2p_dev_addr)
623 if (!wpa_s->ap_iface)
625 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
630 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
631 struct sta_info *sta, void *ctx)
633 if (sta && (sta->flags & WLAN_STA_WPS)) {
634 ap_sta_deauthenticate(hapd, sta,
635 WLAN_REASON_PREV_AUTH_NOT_VALID);
636 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
637 __func__, MAC2STR(sta->addr));
645 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
647 struct wps_registrar *reg;
648 int reg_sel = 0, wps_sta = 0;
650 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
653 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
654 reg_sel = wps_registrar_wps_cancel(reg);
655 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
656 wpa_supplicant_ap_wps_sta_cancel, NULL);
658 if (!reg_sel && !wps_sta) {
659 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
665 * There are 2 cases to return wps cancel as success:
666 * 1. When wps cancel was initiated but no connection has been
667 * established with client yet.
668 * 2. Client is in the middle of exchanging WPS messages.
675 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
676 const char *pin, char *buf, size_t buflen)
678 int ret, ret_len = 0;
680 if (!wpa_s->ap_iface)
684 unsigned int rpin = wps_generate_pin();
685 ret_len = os_snprintf(buf, buflen, "%d", rpin);
688 ret_len = os_snprintf(buf, buflen, "%s", pin);
690 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
698 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
700 struct wpa_supplicant *wpa_s = eloop_data;
701 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
702 wpas_wps_ap_pin_disable(wpa_s);
706 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
708 struct hostapd_data *hapd;
710 if (wpa_s->ap_iface == NULL)
712 hapd = wpa_s->ap_iface->bss[0];
713 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
714 hapd->ap_pin_failures = 0;
715 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
717 eloop_register_timeout(timeout, 0,
718 wpas_wps_ap_pin_timeout, wpa_s, NULL);
722 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
724 struct hostapd_data *hapd;
726 if (wpa_s->ap_iface == NULL)
728 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
729 hapd = wpa_s->ap_iface->bss[0];
730 os_free(hapd->conf->ap_pin);
731 hapd->conf->ap_pin = NULL;
732 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
736 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
738 struct hostapd_data *hapd;
742 if (wpa_s->ap_iface == NULL)
744 hapd = wpa_s->ap_iface->bss[0];
745 pin = wps_generate_pin();
746 os_snprintf(pin_txt, sizeof(pin_txt), "%u", pin);
747 os_free(hapd->conf->ap_pin);
748 hapd->conf->ap_pin = os_strdup(pin_txt);
749 if (hapd->conf->ap_pin == NULL)
751 wpas_wps_ap_pin_enable(wpa_s, timeout);
753 return hapd->conf->ap_pin;
757 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
759 struct hostapd_data *hapd;
760 if (wpa_s->ap_iface == NULL)
762 hapd = wpa_s->ap_iface->bss[0];
763 return hapd->conf->ap_pin;
767 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
770 struct hostapd_data *hapd;
774 if (wpa_s->ap_iface == NULL)
776 hapd = wpa_s->ap_iface->bss[0];
777 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
778 if (ret < 0 || ret >= (int) sizeof(pin_txt))
780 os_free(hapd->conf->ap_pin);
781 hapd->conf->ap_pin = os_strdup(pin_txt);
782 if (hapd->conf->ap_pin == NULL)
784 wpas_wps_ap_pin_enable(wpa_s, timeout);
790 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
792 struct hostapd_data *hapd;
794 if (wpa_s->ap_iface == NULL)
796 hapd = wpa_s->ap_iface->bss[0];
799 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
800 * PIN if this happens multiple times to slow down brute force attacks.
802 hapd->ap_pin_failures++;
803 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
804 hapd->ap_pin_failures);
805 if (hapd->ap_pin_failures < 3)
808 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
809 hapd->ap_pin_failures = 0;
810 os_free(hapd->conf->ap_pin);
811 hapd->conf->ap_pin = NULL;
814 #endif /* CONFIG_WPS */
817 #ifdef CONFIG_CTRL_IFACE
819 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
820 char *buf, size_t buflen)
822 if (wpa_s->ap_iface == NULL)
824 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
829 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
830 char *buf, size_t buflen)
832 if (wpa_s->ap_iface == NULL)
834 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
839 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
840 char *buf, size_t buflen)
842 if (wpa_s->ap_iface == NULL)
844 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
849 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
850 size_t buflen, int verbose)
852 char *pos = buf, *end = buf + buflen;
854 struct hostapd_bss_config *conf;
856 if (wpa_s->ap_iface == NULL)
859 conf = wpa_s->ap_iface->bss[0]->conf;
863 ret = os_snprintf(pos, end - pos,
864 "pairwise_cipher=%s\n"
867 wpa_cipher_txt(conf->rsn_pairwise),
868 wpa_cipher_txt(conf->wpa_group),
869 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
871 if (ret < 0 || ret >= end - pos)
877 #endif /* CONFIG_CTRL_IFACE */
880 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
882 struct hostapd_iface *iface = wpa_s->ap_iface;
883 struct wpa_ssid *ssid = wpa_s->current_ssid;
884 struct hostapd_data *hapd;
886 if (ssid == NULL || wpa_s->ap_iface == NULL)
890 if (ssid->mode == WPAS_MODE_P2P_GO)
891 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
892 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
893 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
895 #endif /* CONFIG_P2P */
897 ieee802_11_set_beacons(iface);
898 hapd = iface->bss[0];
899 hostapd_set_ap_wps_ie(hapd);
905 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
908 struct hostapd_data *hapd;
909 struct hostapd_bss_config *conf;
911 if (!wpa_s->ap_iface)
915 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
918 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
920 hapd = wpa_s->ap_iface->bss[0];
923 os_free(conf->accept_mac);
924 conf->accept_mac = NULL;
925 conf->num_accept_mac = 0;
926 os_free(conf->deny_mac);
927 conf->deny_mac = NULL;
928 conf->num_deny_mac = 0;
931 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
935 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
936 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
937 if (conf->accept_mac == NULL)
939 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
940 conf->num_accept_mac = 1;