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 software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "utils/uuid.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/wpa_ctrl.h"
17 #include "ap/hostapd.h"
18 #include "ap/ap_config.h"
19 #include "ap/ap_drv_ops.h"
21 #include "ap/ieee802_11.h"
22 #endif /* NEED_AP_MLME */
23 #include "ap/beacon.h"
24 #include "ap/ieee802_1x.h"
25 #include "ap/wps_hostapd.h"
26 #include "ap/ctrl_iface_ap.h"
28 #include "common/ieee802_11_defs.h"
29 #include "config_ssid.h"
31 #include "wpa_supplicant_i.h"
33 #include "p2p_supplicant.h"
35 #include "ap/sta_info.h"
40 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
41 #endif /* CONFIG_WPS */
44 static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
45 struct wpa_ssid *ssid,
46 struct hostapd_config *conf)
48 struct hostapd_bss_config *bss = &conf->bss[0];
51 conf->driver = wpa_s->driver;
53 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
55 if (ssid->frequency == 0) {
56 /* default channel 11 */
57 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
59 } else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
60 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
61 conf->channel = (ssid->frequency - 2407) / 5;
62 } else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
63 (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
64 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
65 conf->channel = (ssid->frequency - 5000) / 5;
67 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
72 /* TODO: enable HT40 if driver supports it;
73 * drop to 11b if driver does not support 11g */
75 #ifdef CONFIG_IEEE80211N
77 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
78 * and a mask of allowed capabilities within conf->ht_capab.
79 * Using default config settings for: conf->ht_op_mode_fixed,
80 * conf->secondary_channel, conf->require_ht
82 if (wpa_s->hw.modes) {
83 struct hostapd_hw_modes *mode = NULL;
85 for (i = 0; i < wpa_s->hw.num_modes; i++) {
86 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
87 mode = &wpa_s->hw.modes[i];
92 #ifdef CONFIG_HT_OVERRIDES
93 if (ssid->disable_ht) {
98 #endif /* CONFIG_HT_OVERRIDES */
100 if (!no_ht && mode && mode->ht_capab) {
101 conf->ieee80211n = 1;
104 * white-list capabilities that won't cause issues
105 * to connecting stations, while leaving the current
106 * capabilities intact (currently disabled SMPS).
108 conf->ht_capab |= mode->ht_capab &
109 (HT_CAP_INFO_GREEN_FIELD |
110 HT_CAP_INFO_SHORT_GI20MHZ |
111 HT_CAP_INFO_SHORT_GI40MHZ |
112 HT_CAP_INFO_RX_STBC_MASK |
113 HT_CAP_INFO_MAX_AMSDU_SIZE);
116 #endif /* CONFIG_IEEE80211N */
119 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
120 /* Remove 802.11b rates from supported and basic rate sets */
121 int *list = os_malloc(4 * sizeof(int));
128 conf->basic_rates = list;
130 list = os_malloc(9 * sizeof(int));
142 conf->supported_rates = list;
145 bss->isolate = !wpa_s->conf->p2p_intra_bss;
146 #endif /* CONFIG_P2P */
148 if (ssid->ssid_len == 0) {
149 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
152 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
153 bss->ssid.ssid_len = ssid->ssid_len;
154 bss->ssid.ssid_set = 1;
156 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
159 bss->auth_algs = ssid->auth_alg;
161 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
162 bss->wpa = ssid->proto;
163 bss->wpa_key_mgmt = ssid->key_mgmt;
164 bss->wpa_pairwise = ssid->pairwise_cipher;
165 if (ssid->passphrase) {
166 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
167 } else if (ssid->psk_set) {
168 os_free(bss->ssid.wpa_psk);
169 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
170 if (bss->ssid.wpa_psk == NULL)
172 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
173 bss->ssid.wpa_psk->group = 1;
174 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
175 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
176 struct hostapd_wep_keys *wep = &bss->ssid.wep;
178 for (i = 0; i < NUM_WEP_KEYS; i++) {
179 if (ssid->wep_key_len[i] == 0)
181 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
182 if (wep->key[i] == NULL)
184 os_memcpy(wep->key[i], ssid->wep_key[i],
185 ssid->wep_key_len[i]);
186 wep->len[i] = ssid->wep_key_len[i];
188 wep->idx = ssid->wep_tx_keyidx;
192 if (ssid->ap_max_inactivity)
193 bss->ap_max_inactivity = ssid->ap_max_inactivity;
195 if (ssid->dtim_period)
196 bss->dtim_period = ssid->dtim_period;
198 /* Select group cipher based on the enabled pairwise cipher suites */
201 pairwise |= bss->wpa_pairwise;
203 if (bss->rsn_pairwise == 0)
204 bss->rsn_pairwise = bss->wpa_pairwise;
205 pairwise |= bss->rsn_pairwise;
207 if (pairwise & WPA_CIPHER_TKIP)
208 bss->wpa_group = WPA_CIPHER_TKIP;
210 bss->wpa_group = WPA_CIPHER_CCMP;
212 if (bss->wpa && bss->ieee802_1x)
213 bss->ssid.security_policy = SECURITY_WPA;
215 bss->ssid.security_policy = SECURITY_WPA_PSK;
216 else if (bss->ieee802_1x) {
217 int cipher = WPA_CIPHER_NONE;
218 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
219 bss->ssid.wep.default_len = bss->default_wep_key_len;
220 if (bss->default_wep_key_len)
221 cipher = bss->default_wep_key_len >= 13 ?
222 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
223 bss->wpa_group = cipher;
224 bss->wpa_pairwise = cipher;
225 bss->rsn_pairwise = cipher;
226 } else if (bss->ssid.wep.keys_set) {
227 int cipher = WPA_CIPHER_WEP40;
228 if (bss->ssid.wep.len[0] >= 13)
229 cipher = WPA_CIPHER_WEP104;
230 bss->ssid.security_policy = SECURITY_STATIC_WEP;
231 bss->wpa_group = cipher;
232 bss->wpa_pairwise = cipher;
233 bss->rsn_pairwise = cipher;
235 bss->ssid.security_policy = SECURITY_PLAINTEXT;
236 bss->wpa_group = WPA_CIPHER_NONE;
237 bss->wpa_pairwise = WPA_CIPHER_NONE;
238 bss->rsn_pairwise = WPA_CIPHER_NONE;
243 * Enable WPS by default for open and WPA/WPA2-Personal network, but
244 * require user interaction to actually use it. Only the internal
245 * Registrar is supported.
247 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
248 bss->ssid.security_policy != SECURITY_PLAINTEXT)
251 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
252 (!(pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
253 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
255 #endif /* CONFIG_WPS2 */
258 if (!ssid->ignore_broadcast_ssid)
261 bss->ap_setup_locked = 2;
262 if (wpa_s->conf->config_methods)
263 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
264 os_memcpy(bss->device_type, wpa_s->conf->device_type,
266 if (wpa_s->conf->device_name) {
267 bss->device_name = os_strdup(wpa_s->conf->device_name);
268 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
270 if (wpa_s->conf->manufacturer)
271 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
272 if (wpa_s->conf->model_name)
273 bss->model_name = os_strdup(wpa_s->conf->model_name);
274 if (wpa_s->conf->model_number)
275 bss->model_number = os_strdup(wpa_s->conf->model_number);
276 if (wpa_s->conf->serial_number)
277 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
278 if (is_nil_uuid(wpa_s->conf->uuid))
279 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
281 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
282 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
283 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
285 #endif /* CONFIG_WPS */
287 if (wpa_s->max_stations &&
288 wpa_s->max_stations < wpa_s->conf->max_num_sta)
289 bss->max_num_sta = wpa_s->max_stations;
291 bss->max_num_sta = wpa_s->conf->max_num_sta;
293 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
299 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
302 struct wpa_supplicant *wpa_s = ctx;
303 const struct ieee80211_mgmt *mgmt;
306 mgmt = (const struct ieee80211_mgmt *) buf;
307 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
310 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
311 mgmt->u.action.category,
312 &mgmt->u.action.u.vs_public_action.action,
313 len - hdr_len, freq);
314 #endif /* CONFIG_P2P */
318 static void ap_wps_event_cb(void *ctx, enum wps_event event,
319 union wps_event_data *data)
322 struct wpa_supplicant *wpa_s = ctx;
324 if (event == WPS_EV_FAIL) {
325 struct wps_event_fail *fail = &data->fail;
327 if (wpa_s->parent && wpa_s->parent != wpa_s &&
328 wpa_s == wpa_s->global->p2p_group_formation) {
330 * src/ap/wps_hostapd.c has already sent this on the
331 * main interface, so only send on the parent interface
334 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
335 "msg=%d config_error=%d",
336 fail->msg, fail->config_error);
338 wpas_p2p_wps_failed(wpa_s, fail);
340 #endif /* CONFIG_P2P */
344 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
345 int authorized, const u8 *p2p_dev_addr)
347 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
351 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
354 struct wpa_supplicant *wpa_s = ctx;
355 const struct ieee80211_mgmt *mgmt;
358 mgmt = (const struct ieee80211_mgmt *) buf;
359 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
362 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
363 mgmt->u.action.category,
364 &mgmt->u.action.u.vs_public_action.action,
365 len - hdr_len, freq);
366 #endif /* CONFIG_P2P */
371 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
372 const u8 *bssid, const u8 *ie, size_t ie_len,
376 struct wpa_supplicant *wpa_s = ctx;
377 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
379 #else /* CONFIG_P2P */
381 #endif /* CONFIG_P2P */
385 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
389 struct wpa_supplicant *wpa_s = ctx;
390 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
391 #endif /* CONFIG_P2P */
395 static void wpas_ap_configured_cb(void *ctx)
397 struct wpa_supplicant *wpa_s = ctx;
399 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
401 if (wpa_s->ap_configured_cb)
402 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
403 wpa_s->ap_configured_cb_data);
407 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
408 struct wpa_ssid *ssid)
410 struct wpa_driver_associate_params params;
411 struct hostapd_iface *hapd_iface;
412 struct hostapd_config *conf;
415 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
416 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
420 wpa_supplicant_ap_deinit(wpa_s);
422 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
423 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
425 os_memset(¶ms, 0, sizeof(params));
426 params.ssid = ssid->ssid;
427 params.ssid_len = ssid->ssid_len;
428 switch (ssid->mode) {
429 case WPAS_MODE_INFRA:
430 params.mode = IEEE80211_MODE_INFRA;
433 params.mode = IEEE80211_MODE_IBSS;
436 case WPAS_MODE_P2P_GO:
437 case WPAS_MODE_P2P_GROUP_FORMATION:
438 params.mode = IEEE80211_MODE_AP;
441 params.freq = ssid->frequency;
443 params.wpa_proto = ssid->proto;
444 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
445 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
447 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
448 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
450 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
451 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
452 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
453 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
454 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
455 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
457 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
461 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
462 params.group_suite = params.pairwise_suite;
465 if (ssid->mode == WPAS_MODE_P2P_GO ||
466 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
468 #endif /* CONFIG_P2P */
470 if (wpa_s->parent->set_ap_uapsd)
471 params.uapsd = wpa_s->parent->ap_uapsd;
475 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
476 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
480 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
481 if (hapd_iface == NULL)
483 hapd_iface->owner = wpa_s;
484 hapd_iface->drv_flags = wpa_s->drv_flags;
485 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
487 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
489 wpa_supplicant_ap_deinit(wpa_s);
493 if (params.uapsd > 0) {
494 conf->bss->wmm_enabled = 1;
495 conf->bss->wmm_uapsd = 1;
498 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
499 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
500 wpa_supplicant_ap_deinit(wpa_s);
505 if (ssid->mode == WPAS_MODE_P2P_GO)
506 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
507 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
508 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
510 #endif /* CONFIG_P2P */
512 hapd_iface->num_bss = conf->num_bss;
513 hapd_iface->bss = os_zalloc(conf->num_bss *
514 sizeof(struct hostapd_data *));
515 if (hapd_iface->bss == NULL) {
516 wpa_supplicant_ap_deinit(wpa_s);
520 for (i = 0; i < conf->num_bss; i++) {
522 hostapd_alloc_bss_data(hapd_iface, conf,
524 if (hapd_iface->bss[i] == NULL) {
525 wpa_supplicant_ap_deinit(wpa_s);
529 hapd_iface->bss[i]->msg_ctx = wpa_s;
530 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
531 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
532 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
533 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
534 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
535 hostapd_register_probereq_cb(hapd_iface->bss[i],
536 ap_probe_req_rx, wpa_s);
537 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
538 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
539 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
540 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
541 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
542 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
544 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
545 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
547 #endif /* CONFIG_P2P */
548 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
549 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
552 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
553 hapd_iface->bss[0]->driver = wpa_s->driver;
554 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
556 wpa_s->current_ssid = ssid;
557 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
558 wpa_s->assoc_freq = ssid->frequency;
560 if (hostapd_setup_interface(wpa_s->ap_iface)) {
561 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
562 wpa_supplicant_ap_deinit(wpa_s);
570 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
573 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
574 #endif /* CONFIG_WPS */
576 if (wpa_s->ap_iface == NULL)
579 wpa_s->current_ssid = NULL;
580 wpa_s->assoc_freq = 0;
581 wpa_s->reassociated_connection = 0;
583 if (wpa_s->ap_iface->bss)
584 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
585 wpas_p2p_group_deinit(wpa_s);
586 #endif /* CONFIG_P2P */
587 hostapd_interface_deinit(wpa_s->ap_iface);
588 hostapd_interface_free(wpa_s->ap_iface);
589 wpa_s->ap_iface = NULL;
590 wpa_drv_deinit_ap(wpa_s);
594 void ap_tx_status(void *ctx, const u8 *addr,
595 const u8 *buf, size_t len, int ack)
598 struct wpa_supplicant *wpa_s = ctx;
599 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
600 #endif /* NEED_AP_MLME */
604 void ap_eapol_tx_status(void *ctx, const u8 *dst,
605 const u8 *data, size_t len, int ack)
608 struct wpa_supplicant *wpa_s = ctx;
609 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
610 #endif /* NEED_AP_MLME */
614 void ap_client_poll_ok(void *ctx, const u8 *addr)
617 struct wpa_supplicant *wpa_s = ctx;
619 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
620 #endif /* NEED_AP_MLME */
624 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
627 struct wpa_supplicant *wpa_s = ctx;
628 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
629 #endif /* NEED_AP_MLME */
633 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
636 struct wpa_supplicant *wpa_s = ctx;
637 struct hostapd_frame_info fi;
638 os_memset(&fi, 0, sizeof(fi));
639 fi.datarate = rx_mgmt->datarate;
640 fi.ssi_signal = rx_mgmt->ssi_signal;
641 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
642 rx_mgmt->frame_len, &fi);
643 #endif /* NEED_AP_MLME */
647 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
650 struct wpa_supplicant *wpa_s = ctx;
651 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
652 #endif /* NEED_AP_MLME */
656 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
657 const u8 *src_addr, const u8 *buf, size_t len)
659 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
665 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
666 const u8 *p2p_dev_addr)
668 if (!wpa_s->ap_iface)
670 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
675 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
677 struct wps_registrar *reg;
678 int reg_sel = 0, wps_sta = 0;
680 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
683 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
684 reg_sel = wps_registrar_wps_cancel(reg);
685 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
686 ap_sta_wps_cancel, NULL);
688 if (!reg_sel && !wps_sta) {
689 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
695 * There are 2 cases to return wps cancel as success:
696 * 1. When wps cancel was initiated but no connection has been
697 * established with client yet.
698 * 2. Client is in the middle of exchanging WPS messages.
705 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
706 const char *pin, char *buf, size_t buflen)
708 int ret, ret_len = 0;
710 if (!wpa_s->ap_iface)
714 unsigned int rpin = wps_generate_pin();
715 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
718 ret_len = os_snprintf(buf, buflen, "%s", pin);
720 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
728 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
730 struct wpa_supplicant *wpa_s = eloop_data;
731 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
732 wpas_wps_ap_pin_disable(wpa_s);
736 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
738 struct hostapd_data *hapd;
740 if (wpa_s->ap_iface == NULL)
742 hapd = wpa_s->ap_iface->bss[0];
743 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
744 hapd->ap_pin_failures = 0;
745 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
747 eloop_register_timeout(timeout, 0,
748 wpas_wps_ap_pin_timeout, wpa_s, NULL);
752 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
754 struct hostapd_data *hapd;
756 if (wpa_s->ap_iface == NULL)
758 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
759 hapd = wpa_s->ap_iface->bss[0];
760 os_free(hapd->conf->ap_pin);
761 hapd->conf->ap_pin = NULL;
762 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
766 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
768 struct hostapd_data *hapd;
772 if (wpa_s->ap_iface == NULL)
774 hapd = wpa_s->ap_iface->bss[0];
775 pin = wps_generate_pin();
776 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
777 os_free(hapd->conf->ap_pin);
778 hapd->conf->ap_pin = os_strdup(pin_txt);
779 if (hapd->conf->ap_pin == NULL)
781 wpas_wps_ap_pin_enable(wpa_s, timeout);
783 return hapd->conf->ap_pin;
787 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
789 struct hostapd_data *hapd;
790 if (wpa_s->ap_iface == NULL)
792 hapd = wpa_s->ap_iface->bss[0];
793 return hapd->conf->ap_pin;
797 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
800 struct hostapd_data *hapd;
804 if (wpa_s->ap_iface == NULL)
806 hapd = wpa_s->ap_iface->bss[0];
807 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
808 if (ret < 0 || ret >= (int) sizeof(pin_txt))
810 os_free(hapd->conf->ap_pin);
811 hapd->conf->ap_pin = os_strdup(pin_txt);
812 if (hapd->conf->ap_pin == NULL)
814 wpas_wps_ap_pin_enable(wpa_s, timeout);
820 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
822 struct hostapd_data *hapd;
824 if (wpa_s->ap_iface == NULL)
826 hapd = wpa_s->ap_iface->bss[0];
829 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
830 * PIN if this happens multiple times to slow down brute force attacks.
832 hapd->ap_pin_failures++;
833 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
834 hapd->ap_pin_failures);
835 if (hapd->ap_pin_failures < 3)
838 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
839 hapd->ap_pin_failures = 0;
840 os_free(hapd->conf->ap_pin);
841 hapd->conf->ap_pin = NULL;
844 #endif /* CONFIG_WPS */
847 #ifdef CONFIG_CTRL_IFACE
849 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
850 char *buf, size_t buflen)
852 if (wpa_s->ap_iface == NULL)
854 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
859 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
860 char *buf, size_t buflen)
862 if (wpa_s->ap_iface == NULL)
864 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
869 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
870 char *buf, size_t buflen)
872 if (wpa_s->ap_iface == NULL)
874 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
879 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
882 if (wpa_s->ap_iface == NULL)
884 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
889 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
892 if (wpa_s->ap_iface == NULL)
894 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
899 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
900 size_t buflen, int verbose)
902 char *pos = buf, *end = buf + buflen;
904 struct hostapd_bss_config *conf;
906 if (wpa_s->ap_iface == NULL)
909 conf = wpa_s->ap_iface->bss[0]->conf;
913 ret = os_snprintf(pos, end - pos,
914 "pairwise_cipher=%s\n"
917 wpa_cipher_txt(conf->rsn_pairwise),
918 wpa_cipher_txt(conf->wpa_group),
919 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
921 if (ret < 0 || ret >= end - pos)
927 #endif /* CONFIG_CTRL_IFACE */
930 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
932 struct hostapd_iface *iface = wpa_s->ap_iface;
933 struct wpa_ssid *ssid = wpa_s->current_ssid;
934 struct hostapd_data *hapd;
936 if (ssid == NULL || wpa_s->ap_iface == NULL ||
937 ssid->mode == WPAS_MODE_INFRA ||
938 ssid->mode == WPAS_MODE_IBSS)
942 if (ssid->mode == WPAS_MODE_P2P_GO)
943 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
944 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
945 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
947 #endif /* CONFIG_P2P */
949 hapd = iface->bss[0];
950 if (hapd->drv_priv == NULL)
952 ieee802_11_set_beacons(iface);
953 hostapd_set_ap_wps_ie(hapd);
959 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
962 if (!wpa_s->ap_iface)
965 wpa_s->assoc_freq = freq;
966 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset);
970 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
973 struct hostapd_data *hapd;
974 struct hostapd_bss_config *conf;
976 if (!wpa_s->ap_iface)
980 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
983 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
985 hapd = wpa_s->ap_iface->bss[0];
988 os_free(conf->accept_mac);
989 conf->accept_mac = NULL;
990 conf->num_accept_mac = 0;
991 os_free(conf->deny_mac);
992 conf->deny_mac = NULL;
993 conf->num_deny_mac = 0;
996 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1000 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1001 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1002 if (conf->accept_mac == NULL)
1004 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1005 conf->num_accept_mac = 1;