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;
165 /* Select group cipher based on the enabled pairwise cipher suites */
168 pairwise |= bss->wpa_pairwise;
170 if (bss->rsn_pairwise == 0)
171 bss->rsn_pairwise = bss->wpa_pairwise;
172 pairwise |= bss->rsn_pairwise;
174 if (pairwise & WPA_CIPHER_TKIP)
175 bss->wpa_group = WPA_CIPHER_TKIP;
177 bss->wpa_group = WPA_CIPHER_CCMP;
179 if (bss->wpa && bss->ieee802_1x)
180 bss->ssid.security_policy = SECURITY_WPA;
182 bss->ssid.security_policy = SECURITY_WPA_PSK;
183 else if (bss->ieee802_1x) {
184 int cipher = WPA_CIPHER_NONE;
185 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
186 bss->ssid.wep.default_len = bss->default_wep_key_len;
187 if (bss->default_wep_key_len)
188 cipher = bss->default_wep_key_len >= 13 ?
189 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
190 bss->wpa_group = cipher;
191 bss->wpa_pairwise = cipher;
192 bss->rsn_pairwise = cipher;
193 } else if (bss->ssid.wep.keys_set) {
194 int cipher = WPA_CIPHER_WEP40;
195 if (bss->ssid.wep.len[0] >= 13)
196 cipher = WPA_CIPHER_WEP104;
197 bss->ssid.security_policy = SECURITY_STATIC_WEP;
198 bss->wpa_group = cipher;
199 bss->wpa_pairwise = cipher;
200 bss->rsn_pairwise = cipher;
202 bss->ssid.security_policy = SECURITY_PLAINTEXT;
203 bss->wpa_group = WPA_CIPHER_NONE;
204 bss->wpa_pairwise = WPA_CIPHER_NONE;
205 bss->rsn_pairwise = WPA_CIPHER_NONE;
210 * Enable WPS by default, but require user interaction to actually use
211 * it. Only the internal Registrar is supported.
215 bss->ap_setup_locked = 2;
216 if (wpa_s->conf->config_methods)
217 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
218 os_memcpy(bss->device_type, wpa_s->conf->device_type,
220 if (wpa_s->conf->device_name) {
221 bss->device_name = os_strdup(wpa_s->conf->device_name);
222 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
224 if (wpa_s->conf->manufacturer)
225 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
226 if (wpa_s->conf->model_name)
227 bss->model_name = os_strdup(wpa_s->conf->model_name);
228 if (wpa_s->conf->model_number)
229 bss->model_number = os_strdup(wpa_s->conf->model_number);
230 if (wpa_s->conf->serial_number)
231 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
232 if (is_nil_uuid(wpa_s->conf->uuid))
233 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
235 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
236 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
237 #endif /* CONFIG_WPS */
239 if (wpa_s->max_stations &&
240 wpa_s->max_stations < wpa_s->conf->max_num_sta)
241 bss->max_num_sta = wpa_s->max_stations;
243 bss->max_num_sta = wpa_s->conf->max_num_sta;
245 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
251 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
254 struct wpa_supplicant *wpa_s = ctx;
255 const struct ieee80211_mgmt *mgmt;
258 mgmt = (const struct ieee80211_mgmt *) buf;
259 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
262 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
263 mgmt->u.action.category,
264 &mgmt->u.action.u.vs_public_action.action,
265 len - hdr_len, freq);
266 #endif /* CONFIG_P2P */
270 static void ap_wps_event_cb(void *ctx, enum wps_event event,
271 union wps_event_data *data)
274 struct wpa_supplicant *wpa_s = ctx;
276 if (event == WPS_EV_FAIL) {
277 struct wps_event_fail *fail = &data->fail;
279 if (wpa_s->parent && wpa_s->parent != wpa_s &&
280 wpa_s == wpa_s->global->p2p_group_formation) {
282 * src/ap/wps_hostapd.c has already sent this on the
283 * main interface, so only send on the parent interface
286 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
287 "msg=%d config_error=%d",
288 fail->msg, fail->config_error);
290 wpas_p2p_wps_failed(wpa_s, fail);
292 #endif /* CONFIG_P2P */
296 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
299 wpas_notify_sta_authorized(ctx, mac_addr, authorized);
303 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
306 struct wpa_supplicant *wpa_s = ctx;
307 const struct ieee80211_mgmt *mgmt;
310 mgmt = (const struct ieee80211_mgmt *) buf;
311 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
314 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
315 mgmt->u.action.category,
316 &mgmt->u.action.u.vs_public_action.action,
317 len - hdr_len, freq);
318 #endif /* CONFIG_P2P */
323 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
324 const u8 *bssid, const u8 *ie, size_t ie_len)
327 struct wpa_supplicant *wpa_s = ctx;
328 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len);
329 #else /* CONFIG_P2P */
331 #endif /* CONFIG_P2P */
335 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
339 struct wpa_supplicant *wpa_s = ctx;
340 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
341 #endif /* CONFIG_P2P */
345 static void wpas_ap_configured_cb(void *ctx)
347 struct wpa_supplicant *wpa_s = ctx;
349 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
351 if (wpa_s->ap_configured_cb)
352 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
353 wpa_s->ap_configured_cb_data);
357 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
358 struct wpa_ssid *ssid)
360 struct wpa_driver_associate_params params;
361 struct hostapd_iface *hapd_iface;
362 struct hostapd_config *conf;
365 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
366 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
370 wpa_supplicant_ap_deinit(wpa_s);
372 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
373 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
375 os_memset(¶ms, 0, sizeof(params));
376 params.ssid = ssid->ssid;
377 params.ssid_len = ssid->ssid_len;
378 switch (ssid->mode) {
379 case WPAS_MODE_INFRA:
380 params.mode = IEEE80211_MODE_INFRA;
383 params.mode = IEEE80211_MODE_IBSS;
386 case WPAS_MODE_P2P_GO:
387 case WPAS_MODE_P2P_GROUP_FORMATION:
388 params.mode = IEEE80211_MODE_AP;
391 params.freq = ssid->frequency;
393 params.wpa_proto = ssid->proto;
394 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
395 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
397 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
398 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
400 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
401 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
402 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
403 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
404 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
405 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
407 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
411 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
412 params.group_suite = params.pairwise_suite;
415 if (ssid->mode == WPAS_MODE_P2P_GO ||
416 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
418 wpa_drv_set_intra_bss(wpa_s, wpa_s->conf->p2p_intra_bss);
419 #endif /* CONFIG_P2P */
421 if (wpa_s->parent->set_ap_uapsd)
422 params.uapsd = wpa_s->parent->ap_uapsd;
426 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
427 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
431 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
432 if (hapd_iface == NULL)
434 hapd_iface->owner = wpa_s;
436 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
438 wpa_supplicant_ap_deinit(wpa_s);
442 if (params.uapsd > 0) {
443 conf->bss->wmm_enabled = 1;
444 conf->bss->wmm_uapsd = 1;
447 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
448 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
449 wpa_supplicant_ap_deinit(wpa_s);
454 if (ssid->mode == WPAS_MODE_P2P_GO)
455 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
456 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
457 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
459 #endif /* CONFIG_P2P */
461 hapd_iface->num_bss = conf->num_bss;
462 hapd_iface->bss = os_zalloc(conf->num_bss *
463 sizeof(struct hostapd_data *));
464 if (hapd_iface->bss == NULL) {
465 wpa_supplicant_ap_deinit(wpa_s);
469 for (i = 0; i < conf->num_bss; i++) {
471 hostapd_alloc_bss_data(hapd_iface, conf,
473 if (hapd_iface->bss[i] == NULL) {
474 wpa_supplicant_ap_deinit(wpa_s);
478 hapd_iface->bss[i]->msg_ctx = wpa_s;
479 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
480 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
481 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
482 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
483 hostapd_register_probereq_cb(hapd_iface->bss[i],
484 ap_probe_req_rx, wpa_s);
485 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
486 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
487 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
488 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
489 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
490 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
492 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
493 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(
494 wpa_s, ssid->p2p_persistent_group,
495 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION);
496 #endif /* CONFIG_P2P */
497 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
498 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
501 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
502 hapd_iface->bss[0]->driver = wpa_s->driver;
503 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
505 wpa_s->current_ssid = ssid;
506 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
507 wpa_s->assoc_freq = ssid->frequency;
509 if (hostapd_setup_interface(wpa_s->ap_iface)) {
510 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
511 wpa_supplicant_ap_deinit(wpa_s);
519 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
522 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
523 #endif /* CONFIG_WPS */
525 if (wpa_s->ap_iface == NULL)
528 wpa_s->current_ssid = NULL;
529 wpa_s->assoc_freq = 0;
530 wpa_s->reassociated_connection = 0;
532 if (wpa_s->ap_iface->bss)
533 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
534 wpas_p2p_group_deinit(wpa_s);
535 #endif /* CONFIG_P2P */
536 hostapd_interface_deinit(wpa_s->ap_iface);
537 hostapd_interface_free(wpa_s->ap_iface);
538 wpa_s->ap_iface = NULL;
539 wpa_drv_deinit_ap(wpa_s);
543 void ap_tx_status(void *ctx, const u8 *addr,
544 const u8 *buf, size_t len, int ack)
547 struct wpa_supplicant *wpa_s = ctx;
548 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
549 #endif /* NEED_AP_MLME */
553 void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
556 struct wpa_supplicant *wpa_s = ctx;
557 const struct ieee80211_hdr *hdr =
558 (const struct ieee80211_hdr *) frame;
559 u16 fc = le_to_host16(hdr->frame_control);
560 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
561 (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
562 (WLAN_FC_TODS | WLAN_FC_FROMDS));
563 #endif /* NEED_AP_MLME */
567 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
570 struct wpa_supplicant *wpa_s = ctx;
571 struct hostapd_frame_info fi;
572 os_memset(&fi, 0, sizeof(fi));
573 fi.datarate = rx_mgmt->datarate;
574 fi.ssi_signal = rx_mgmt->ssi_signal;
575 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
576 rx_mgmt->frame_len, &fi);
577 #endif /* NEED_AP_MLME */
581 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
584 struct wpa_supplicant *wpa_s = ctx;
585 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
586 #endif /* NEED_AP_MLME */
590 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
591 const u8 *src_addr, const u8 *buf, size_t len)
593 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
599 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
600 const u8 *p2p_dev_addr)
602 if (!wpa_s->ap_iface)
604 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
609 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data *hapd,
610 struct sta_info *sta, void *ctx)
612 if (sta && (sta->flags & WLAN_STA_WPS)) {
613 ap_sta_deauthenticate(hapd, sta,
614 WLAN_REASON_PREV_AUTH_NOT_VALID);
615 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
616 __func__, MAC2STR(sta->addr));
624 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
626 struct wps_registrar *reg;
627 int reg_sel = 0, wps_sta = 0;
629 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
632 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
633 reg_sel = wps_registrar_wps_cancel(reg);
634 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
635 wpa_supplicant_ap_wps_sta_cancel, NULL);
637 if (!reg_sel && !wps_sta) {
638 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
644 * There are 2 cases to return wps cancel as success:
645 * 1. When wps cancel was initiated but no connection has been
646 * established with client yet.
647 * 2. Client is in the middle of exchanging WPS messages.
654 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
655 const char *pin, char *buf, size_t buflen)
657 int ret, ret_len = 0;
659 if (!wpa_s->ap_iface)
663 unsigned int rpin = wps_generate_pin();
664 ret_len = os_snprintf(buf, buflen, "%d", rpin);
667 ret_len = os_snprintf(buf, buflen, "%s", pin);
669 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
677 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
679 struct wpa_supplicant *wpa_s = eloop_data;
680 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
681 wpas_wps_ap_pin_disable(wpa_s);
685 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
687 struct hostapd_data *hapd;
689 if (wpa_s->ap_iface == NULL)
691 hapd = wpa_s->ap_iface->bss[0];
692 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
693 hapd->ap_pin_failures = 0;
694 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
696 eloop_register_timeout(timeout, 0,
697 wpas_wps_ap_pin_timeout, wpa_s, NULL);
701 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
703 struct hostapd_data *hapd;
705 if (wpa_s->ap_iface == NULL)
707 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
708 hapd = wpa_s->ap_iface->bss[0];
709 os_free(hapd->conf->ap_pin);
710 hapd->conf->ap_pin = NULL;
711 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
715 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
717 struct hostapd_data *hapd;
721 if (wpa_s->ap_iface == NULL)
723 hapd = wpa_s->ap_iface->bss[0];
724 pin = wps_generate_pin();
725 os_snprintf(pin_txt, sizeof(pin_txt), "%u", pin);
726 os_free(hapd->conf->ap_pin);
727 hapd->conf->ap_pin = os_strdup(pin_txt);
728 if (hapd->conf->ap_pin == NULL)
730 wpas_wps_ap_pin_enable(wpa_s, timeout);
732 return hapd->conf->ap_pin;
736 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
738 struct hostapd_data *hapd;
739 if (wpa_s->ap_iface == NULL)
741 hapd = wpa_s->ap_iface->bss[0];
742 return hapd->conf->ap_pin;
746 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
749 struct hostapd_data *hapd;
753 if (wpa_s->ap_iface == NULL)
755 hapd = wpa_s->ap_iface->bss[0];
756 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
757 if (ret < 0 || ret >= (int) sizeof(pin_txt))
759 os_free(hapd->conf->ap_pin);
760 hapd->conf->ap_pin = os_strdup(pin_txt);
761 if (hapd->conf->ap_pin == NULL)
763 wpas_wps_ap_pin_enable(wpa_s, timeout);
769 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
771 struct hostapd_data *hapd;
773 if (wpa_s->ap_iface == NULL)
775 hapd = wpa_s->ap_iface->bss[0];
778 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
779 * PIN if this happens multiple times to slow down brute force attacks.
781 hapd->ap_pin_failures++;
782 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
783 hapd->ap_pin_failures);
784 if (hapd->ap_pin_failures < 3)
787 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
788 hapd->ap_pin_failures = 0;
789 os_free(hapd->conf->ap_pin);
790 hapd->conf->ap_pin = NULL;
793 #endif /* CONFIG_WPS */
796 #ifdef CONFIG_CTRL_IFACE
798 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
799 char *buf, size_t buflen)
801 if (wpa_s->ap_iface == NULL)
803 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
808 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
809 char *buf, size_t buflen)
811 if (wpa_s->ap_iface == NULL)
813 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
818 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
819 char *buf, size_t buflen)
821 if (wpa_s->ap_iface == NULL)
823 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
828 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
829 size_t buflen, int verbose)
831 char *pos = buf, *end = buf + buflen;
833 struct hostapd_bss_config *conf;
835 if (wpa_s->ap_iface == NULL)
838 conf = wpa_s->ap_iface->bss[0]->conf;
842 ret = os_snprintf(pos, end - pos,
843 "pairwise_cipher=%s\n"
846 wpa_cipher_txt(conf->rsn_pairwise),
847 wpa_cipher_txt(conf->wpa_group),
848 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
850 if (ret < 0 || ret >= end - pos)
856 #endif /* CONFIG_CTRL_IFACE */
859 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
861 struct hostapd_iface *iface = wpa_s->ap_iface;
862 struct wpa_ssid *ssid = wpa_s->current_ssid;
863 struct hostapd_data *hapd;
865 if (ssid == NULL || wpa_s->ap_iface == NULL)
869 if (ssid->mode == WPAS_MODE_P2P_GO)
870 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
871 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
872 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
874 #endif /* CONFIG_P2P */
876 ieee802_11_set_beacons(iface);
877 hapd = iface->bss[0];
878 hostapd_set_ap_wps_ie(hapd);
884 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
887 struct hostapd_data *hapd;
888 struct hostapd_bss_config *conf;
890 if (!wpa_s->ap_iface)
894 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
897 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
899 hapd = wpa_s->ap_iface->bss[0];
902 os_free(conf->accept_mac);
903 conf->accept_mac = NULL;
904 conf->num_accept_mac = 0;
905 os_free(conf->deny_mac);
906 conf->deny_mac = NULL;
907 conf->num_deny_mac = 0;
910 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
914 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
915 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
916 if (conf->accept_mac == NULL)
918 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
919 conf->num_accept_mac = 1;