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[ssid->ssid_len] = '\0';
154 bss->ssid.ssid_len = ssid->ssid_len;
155 bss->ssid.ssid_set = 1;
157 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
160 bss->auth_algs = ssid->auth_alg;
162 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
163 bss->wpa = ssid->proto;
164 bss->wpa_key_mgmt = ssid->key_mgmt;
165 bss->wpa_pairwise = ssid->pairwise_cipher;
166 if (ssid->passphrase) {
167 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
168 } else if (ssid->psk_set) {
169 os_free(bss->ssid.wpa_psk);
170 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
171 if (bss->ssid.wpa_psk == NULL)
173 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
174 bss->ssid.wpa_psk->group = 1;
175 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
176 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
177 struct hostapd_wep_keys *wep = &bss->ssid.wep;
179 for (i = 0; i < NUM_WEP_KEYS; i++) {
180 if (ssid->wep_key_len[i] == 0)
182 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
183 if (wep->key[i] == NULL)
185 os_memcpy(wep->key[i], ssid->wep_key[i],
186 ssid->wep_key_len[i]);
187 wep->len[i] = ssid->wep_key_len[i];
189 wep->idx = ssid->wep_tx_keyidx;
193 if (ssid->ap_max_inactivity)
194 bss->ap_max_inactivity = ssid->ap_max_inactivity;
196 if (ssid->dtim_period)
197 bss->dtim_period = ssid->dtim_period;
199 /* Select group cipher based on the enabled pairwise cipher suites */
202 pairwise |= bss->wpa_pairwise;
204 if (bss->rsn_pairwise == 0)
205 bss->rsn_pairwise = bss->wpa_pairwise;
206 pairwise |= bss->rsn_pairwise;
208 if (pairwise & WPA_CIPHER_TKIP)
209 bss->wpa_group = WPA_CIPHER_TKIP;
211 bss->wpa_group = WPA_CIPHER_CCMP;
213 if (bss->wpa && bss->ieee802_1x)
214 bss->ssid.security_policy = SECURITY_WPA;
216 bss->ssid.security_policy = SECURITY_WPA_PSK;
217 else if (bss->ieee802_1x) {
218 int cipher = WPA_CIPHER_NONE;
219 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
220 bss->ssid.wep.default_len = bss->default_wep_key_len;
221 if (bss->default_wep_key_len)
222 cipher = bss->default_wep_key_len >= 13 ?
223 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
224 bss->wpa_group = cipher;
225 bss->wpa_pairwise = cipher;
226 bss->rsn_pairwise = cipher;
227 } else if (bss->ssid.wep.keys_set) {
228 int cipher = WPA_CIPHER_WEP40;
229 if (bss->ssid.wep.len[0] >= 13)
230 cipher = WPA_CIPHER_WEP104;
231 bss->ssid.security_policy = SECURITY_STATIC_WEP;
232 bss->wpa_group = cipher;
233 bss->wpa_pairwise = cipher;
234 bss->rsn_pairwise = cipher;
236 bss->ssid.security_policy = SECURITY_PLAINTEXT;
237 bss->wpa_group = WPA_CIPHER_NONE;
238 bss->wpa_pairwise = WPA_CIPHER_NONE;
239 bss->rsn_pairwise = WPA_CIPHER_NONE;
244 * Enable WPS by default for open and WPA/WPA2-Personal network, but
245 * require user interaction to actually use it. Only the internal
246 * Registrar is supported.
248 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
249 bss->ssid.security_policy != SECURITY_PLAINTEXT)
252 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
253 (!(pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
254 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
256 #endif /* CONFIG_WPS2 */
259 if (!ssid->ignore_broadcast_ssid)
262 bss->ap_setup_locked = 2;
263 if (wpa_s->conf->config_methods)
264 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
265 os_memcpy(bss->device_type, wpa_s->conf->device_type,
267 if (wpa_s->conf->device_name) {
268 bss->device_name = os_strdup(wpa_s->conf->device_name);
269 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
271 if (wpa_s->conf->manufacturer)
272 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
273 if (wpa_s->conf->model_name)
274 bss->model_name = os_strdup(wpa_s->conf->model_name);
275 if (wpa_s->conf->model_number)
276 bss->model_number = os_strdup(wpa_s->conf->model_number);
277 if (wpa_s->conf->serial_number)
278 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
279 if (is_nil_uuid(wpa_s->conf->uuid))
280 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
282 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
283 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
284 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
286 #endif /* CONFIG_WPS */
288 if (wpa_s->max_stations &&
289 wpa_s->max_stations < wpa_s->conf->max_num_sta)
290 bss->max_num_sta = wpa_s->max_stations;
292 bss->max_num_sta = wpa_s->conf->max_num_sta;
294 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
300 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
303 struct wpa_supplicant *wpa_s = ctx;
304 const struct ieee80211_mgmt *mgmt;
307 mgmt = (const struct ieee80211_mgmt *) buf;
308 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
311 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
312 mgmt->u.action.category,
313 &mgmt->u.action.u.vs_public_action.action,
314 len - hdr_len, freq);
315 #endif /* CONFIG_P2P */
319 static void ap_wps_event_cb(void *ctx, enum wps_event event,
320 union wps_event_data *data)
323 struct wpa_supplicant *wpa_s = ctx;
325 if (event == WPS_EV_FAIL) {
326 struct wps_event_fail *fail = &data->fail;
328 if (wpa_s->parent && wpa_s->parent != wpa_s &&
329 wpa_s == wpa_s->global->p2p_group_formation) {
331 * src/ap/wps_hostapd.c has already sent this on the
332 * main interface, so only send on the parent interface
335 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
336 "msg=%d config_error=%d",
337 fail->msg, fail->config_error);
339 wpas_p2p_wps_failed(wpa_s, fail);
341 #endif /* CONFIG_P2P */
345 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
346 int authorized, const u8 *p2p_dev_addr)
348 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
352 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
355 struct wpa_supplicant *wpa_s = ctx;
356 const struct ieee80211_mgmt *mgmt;
359 mgmt = (const struct ieee80211_mgmt *) buf;
360 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
363 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
364 mgmt->u.action.category,
365 &mgmt->u.action.u.vs_public_action.action,
366 len - hdr_len, freq);
367 #endif /* CONFIG_P2P */
372 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
373 const u8 *bssid, const u8 *ie, size_t ie_len,
377 struct wpa_supplicant *wpa_s = ctx;
378 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
380 #else /* CONFIG_P2P */
382 #endif /* CONFIG_P2P */
386 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
390 struct wpa_supplicant *wpa_s = ctx;
391 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
392 #endif /* CONFIG_P2P */
396 static void wpas_ap_configured_cb(void *ctx)
398 struct wpa_supplicant *wpa_s = ctx;
400 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
402 if (wpa_s->ap_configured_cb)
403 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
404 wpa_s->ap_configured_cb_data);
408 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
409 struct wpa_ssid *ssid)
411 struct wpa_driver_associate_params params;
412 struct hostapd_iface *hapd_iface;
413 struct hostapd_config *conf;
416 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
417 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
421 wpa_supplicant_ap_deinit(wpa_s);
423 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
424 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
426 os_memset(¶ms, 0, sizeof(params));
427 params.ssid = ssid->ssid;
428 params.ssid_len = ssid->ssid_len;
429 switch (ssid->mode) {
430 case WPAS_MODE_INFRA:
431 params.mode = IEEE80211_MODE_INFRA;
434 params.mode = IEEE80211_MODE_IBSS;
437 case WPAS_MODE_P2P_GO:
438 case WPAS_MODE_P2P_GROUP_FORMATION:
439 params.mode = IEEE80211_MODE_AP;
442 params.freq = ssid->frequency;
444 params.wpa_proto = ssid->proto;
445 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
446 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
448 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
449 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
451 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
452 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
453 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
454 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
455 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
456 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
458 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
462 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
463 params.group_suite = params.pairwise_suite;
466 if (ssid->mode == WPAS_MODE_P2P_GO ||
467 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
469 #endif /* CONFIG_P2P */
471 if (wpa_s->parent->set_ap_uapsd)
472 params.uapsd = wpa_s->parent->ap_uapsd;
476 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
477 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
481 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
482 if (hapd_iface == NULL)
484 hapd_iface->owner = wpa_s;
485 hapd_iface->drv_flags = wpa_s->drv_flags;
486 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
488 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
490 wpa_supplicant_ap_deinit(wpa_s);
494 if (params.uapsd > 0) {
495 conf->bss->wmm_enabled = 1;
496 conf->bss->wmm_uapsd = 1;
499 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
500 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
501 wpa_supplicant_ap_deinit(wpa_s);
506 if (ssid->mode == WPAS_MODE_P2P_GO)
507 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
508 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
509 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
511 #endif /* CONFIG_P2P */
513 hapd_iface->num_bss = conf->num_bss;
514 hapd_iface->bss = os_zalloc(conf->num_bss *
515 sizeof(struct hostapd_data *));
516 if (hapd_iface->bss == NULL) {
517 wpa_supplicant_ap_deinit(wpa_s);
521 for (i = 0; i < conf->num_bss; i++) {
523 hostapd_alloc_bss_data(hapd_iface, conf,
525 if (hapd_iface->bss[i] == NULL) {
526 wpa_supplicant_ap_deinit(wpa_s);
530 hapd_iface->bss[i]->msg_ctx = wpa_s;
531 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
532 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
533 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
534 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
535 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
536 hostapd_register_probereq_cb(hapd_iface->bss[i],
537 ap_probe_req_rx, wpa_s);
538 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
539 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
540 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
541 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
542 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
543 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
545 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
546 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
548 #endif /* CONFIG_P2P */
549 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
550 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
553 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
554 hapd_iface->bss[0]->driver = wpa_s->driver;
555 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
557 wpa_s->current_ssid = ssid;
558 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
559 wpa_s->assoc_freq = ssid->frequency;
561 if (hostapd_setup_interface(wpa_s->ap_iface)) {
562 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
563 wpa_supplicant_ap_deinit(wpa_s);
571 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
574 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
575 #endif /* CONFIG_WPS */
577 if (wpa_s->ap_iface == NULL)
580 wpa_s->current_ssid = NULL;
581 wpa_s->assoc_freq = 0;
582 wpa_s->reassociated_connection = 0;
584 if (wpa_s->ap_iface->bss)
585 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
586 wpas_p2p_group_deinit(wpa_s);
587 #endif /* CONFIG_P2P */
588 hostapd_interface_deinit(wpa_s->ap_iface);
589 hostapd_interface_free(wpa_s->ap_iface);
590 wpa_s->ap_iface = NULL;
591 wpa_drv_deinit_ap(wpa_s);
595 void ap_tx_status(void *ctx, const u8 *addr,
596 const u8 *buf, size_t len, int ack)
599 struct wpa_supplicant *wpa_s = ctx;
600 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
601 #endif /* NEED_AP_MLME */
605 void ap_eapol_tx_status(void *ctx, const u8 *dst,
606 const u8 *data, size_t len, int ack)
609 struct wpa_supplicant *wpa_s = ctx;
610 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
611 #endif /* NEED_AP_MLME */
615 void ap_client_poll_ok(void *ctx, const u8 *addr)
618 struct wpa_supplicant *wpa_s = ctx;
620 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
621 #endif /* NEED_AP_MLME */
625 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
628 struct wpa_supplicant *wpa_s = ctx;
629 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
630 #endif /* NEED_AP_MLME */
634 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
637 struct wpa_supplicant *wpa_s = ctx;
638 struct hostapd_frame_info fi;
639 os_memset(&fi, 0, sizeof(fi));
640 fi.datarate = rx_mgmt->datarate;
641 fi.ssi_signal = rx_mgmt->ssi_signal;
642 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
643 rx_mgmt->frame_len, &fi);
644 #endif /* NEED_AP_MLME */
648 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
651 struct wpa_supplicant *wpa_s = ctx;
652 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
653 #endif /* NEED_AP_MLME */
657 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
658 const u8 *src_addr, const u8 *buf, size_t len)
660 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
666 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
667 const u8 *p2p_dev_addr)
669 if (!wpa_s->ap_iface)
671 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
676 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
678 struct wps_registrar *reg;
679 int reg_sel = 0, wps_sta = 0;
681 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
684 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
685 reg_sel = wps_registrar_wps_cancel(reg);
686 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
687 ap_sta_wps_cancel, NULL);
689 if (!reg_sel && !wps_sta) {
690 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
696 * There are 2 cases to return wps cancel as success:
697 * 1. When wps cancel was initiated but no connection has been
698 * established with client yet.
699 * 2. Client is in the middle of exchanging WPS messages.
706 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
707 const char *pin, char *buf, size_t buflen)
709 int ret, ret_len = 0;
711 if (!wpa_s->ap_iface)
715 unsigned int rpin = wps_generate_pin();
716 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
719 ret_len = os_snprintf(buf, buflen, "%s", pin);
721 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
729 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
731 struct wpa_supplicant *wpa_s = eloop_data;
732 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
733 wpas_wps_ap_pin_disable(wpa_s);
737 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
739 struct hostapd_data *hapd;
741 if (wpa_s->ap_iface == NULL)
743 hapd = wpa_s->ap_iface->bss[0];
744 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
745 hapd->ap_pin_failures = 0;
746 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
748 eloop_register_timeout(timeout, 0,
749 wpas_wps_ap_pin_timeout, wpa_s, NULL);
753 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
755 struct hostapd_data *hapd;
757 if (wpa_s->ap_iface == NULL)
759 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
760 hapd = wpa_s->ap_iface->bss[0];
761 os_free(hapd->conf->ap_pin);
762 hapd->conf->ap_pin = NULL;
763 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
767 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
769 struct hostapd_data *hapd;
773 if (wpa_s->ap_iface == NULL)
775 hapd = wpa_s->ap_iface->bss[0];
776 pin = wps_generate_pin();
777 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
778 os_free(hapd->conf->ap_pin);
779 hapd->conf->ap_pin = os_strdup(pin_txt);
780 if (hapd->conf->ap_pin == NULL)
782 wpas_wps_ap_pin_enable(wpa_s, timeout);
784 return hapd->conf->ap_pin;
788 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
790 struct hostapd_data *hapd;
791 if (wpa_s->ap_iface == NULL)
793 hapd = wpa_s->ap_iface->bss[0];
794 return hapd->conf->ap_pin;
798 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
801 struct hostapd_data *hapd;
805 if (wpa_s->ap_iface == NULL)
807 hapd = wpa_s->ap_iface->bss[0];
808 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
809 if (ret < 0 || ret >= (int) sizeof(pin_txt))
811 os_free(hapd->conf->ap_pin);
812 hapd->conf->ap_pin = os_strdup(pin_txt);
813 if (hapd->conf->ap_pin == NULL)
815 wpas_wps_ap_pin_enable(wpa_s, timeout);
821 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
823 struct hostapd_data *hapd;
825 if (wpa_s->ap_iface == NULL)
827 hapd = wpa_s->ap_iface->bss[0];
830 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
831 * PIN if this happens multiple times to slow down brute force attacks.
833 hapd->ap_pin_failures++;
834 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
835 hapd->ap_pin_failures);
836 if (hapd->ap_pin_failures < 3)
839 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
840 hapd->ap_pin_failures = 0;
841 os_free(hapd->conf->ap_pin);
842 hapd->conf->ap_pin = NULL;
845 #endif /* CONFIG_WPS */
848 #ifdef CONFIG_CTRL_IFACE
850 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
851 char *buf, size_t buflen)
853 if (wpa_s->ap_iface == NULL)
855 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
860 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
861 char *buf, size_t buflen)
863 if (wpa_s->ap_iface == NULL)
865 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
870 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
871 char *buf, size_t buflen)
873 if (wpa_s->ap_iface == NULL)
875 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
880 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
883 if (wpa_s->ap_iface == NULL)
885 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
890 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
893 if (wpa_s->ap_iface == NULL)
895 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
900 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
901 size_t buflen, int verbose)
903 char *pos = buf, *end = buf + buflen;
905 struct hostapd_bss_config *conf;
907 if (wpa_s->ap_iface == NULL)
910 conf = wpa_s->ap_iface->bss[0]->conf;
914 ret = os_snprintf(pos, end - pos,
915 "pairwise_cipher=%s\n"
918 wpa_cipher_txt(conf->rsn_pairwise),
919 wpa_cipher_txt(conf->wpa_group),
920 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
922 if (ret < 0 || ret >= end - pos)
928 #endif /* CONFIG_CTRL_IFACE */
931 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
933 struct hostapd_iface *iface = wpa_s->ap_iface;
934 struct wpa_ssid *ssid = wpa_s->current_ssid;
935 struct hostapd_data *hapd;
937 if (ssid == NULL || wpa_s->ap_iface == NULL ||
938 ssid->mode == WPAS_MODE_INFRA ||
939 ssid->mode == WPAS_MODE_IBSS)
943 if (ssid->mode == WPAS_MODE_P2P_GO)
944 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
945 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
946 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
948 #endif /* CONFIG_P2P */
950 hapd = iface->bss[0];
951 if (hapd->drv_priv == NULL)
953 ieee802_11_set_beacons(iface);
954 hostapd_set_ap_wps_ie(hapd);
960 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
963 if (!wpa_s->ap_iface)
966 wpa_s->assoc_freq = freq;
967 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset);
971 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
974 struct hostapd_data *hapd;
975 struct hostapd_bss_config *conf;
977 if (!wpa_s->ap_iface)
981 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
984 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
986 hapd = wpa_s->ap_iface->bss[0];
989 os_free(conf->accept_mac);
990 conf->accept_mac = NULL;
991 conf->num_accept_mac = 0;
992 os_free(conf->deny_mac);
993 conf->deny_mac = NULL;
994 conf->num_deny_mac = 0;
997 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1001 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1002 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1003 if (conf->accept_mac == NULL)
1005 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1006 conf->num_accept_mac = 1;