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];
50 conf->driver = wpa_s->driver;
52 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
54 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
56 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
57 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
62 /* TODO: enable HT40 if driver supports it;
63 * drop to 11b if driver does not support 11g */
65 #ifdef CONFIG_IEEE80211N
67 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
68 * and a mask of allowed capabilities within conf->ht_capab.
69 * Using default config settings for: conf->ht_op_mode_fixed,
70 * conf->secondary_channel, conf->require_ht
72 if (wpa_s->hw.modes) {
73 struct hostapd_hw_modes *mode = NULL;
75 for (i = 0; i < wpa_s->hw.num_modes; i++) {
76 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
77 mode = &wpa_s->hw.modes[i];
82 #ifdef CONFIG_HT_OVERRIDES
83 if (ssid->disable_ht) {
88 #endif /* CONFIG_HT_OVERRIDES */
90 if (!no_ht && mode && mode->ht_capab) {
93 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
95 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
97 conf->secondary_channel =
98 wpas_p2p_get_ht40_mode(wpa_s, mode,
100 if (conf->secondary_channel)
102 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
103 #endif /* CONFIG_P2P */
106 * white-list capabilities that won't cause issues
107 * to connecting stations, while leaving the current
108 * capabilities intact (currently disabled SMPS).
110 conf->ht_capab |= mode->ht_capab &
111 (HT_CAP_INFO_GREEN_FIELD |
112 HT_CAP_INFO_SHORT_GI20MHZ |
113 HT_CAP_INFO_SHORT_GI40MHZ |
114 HT_CAP_INFO_RX_STBC_MASK |
115 HT_CAP_INFO_MAX_AMSDU_SIZE);
118 #endif /* CONFIG_IEEE80211N */
121 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
122 (ssid->mode == WPAS_MODE_P2P_GO ||
123 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
124 /* Remove 802.11b rates from supported and basic rate sets */
125 int *list = os_malloc(4 * sizeof(int));
132 conf->basic_rates = list;
134 list = os_malloc(9 * sizeof(int));
146 conf->supported_rates = list;
149 bss->isolate = !wpa_s->conf->p2p_intra_bss;
150 #endif /* CONFIG_P2P */
152 if (ssid->ssid_len == 0) {
153 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
156 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
157 bss->ssid.ssid_len = ssid->ssid_len;
158 bss->ssid.ssid_set = 1;
160 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
163 bss->auth_algs = ssid->auth_alg;
165 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
166 bss->wpa = ssid->proto;
167 bss->wpa_key_mgmt = ssid->key_mgmt;
168 bss->wpa_pairwise = ssid->pairwise_cipher;
170 os_free(bss->ssid.wpa_psk);
171 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
172 if (bss->ssid.wpa_psk == NULL)
174 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
175 bss->ssid.wpa_psk->group = 1;
176 } else if (ssid->passphrase) {
177 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
178 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
179 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
180 struct hostapd_wep_keys *wep = &bss->ssid.wep;
182 for (i = 0; i < NUM_WEP_KEYS; i++) {
183 if (ssid->wep_key_len[i] == 0)
185 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
186 if (wep->key[i] == NULL)
188 os_memcpy(wep->key[i], ssid->wep_key[i],
189 ssid->wep_key_len[i]);
190 wep->len[i] = ssid->wep_key_len[i];
192 wep->idx = ssid->wep_tx_keyidx;
196 if (ssid->ap_max_inactivity)
197 bss->ap_max_inactivity = ssid->ap_max_inactivity;
199 if (ssid->dtim_period)
200 bss->dtim_period = ssid->dtim_period;
201 else if (wpa_s->conf->dtim_period)
202 bss->dtim_period = wpa_s->conf->dtim_period;
204 if (ssid->beacon_int)
205 conf->beacon_int = ssid->beacon_int;
206 else if (wpa_s->conf->beacon_int)
207 conf->beacon_int = wpa_s->conf->beacon_int;
209 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
210 bss->rsn_pairwise = bss->wpa_pairwise;
211 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
214 if (bss->wpa && bss->ieee802_1x)
215 bss->ssid.security_policy = SECURITY_WPA;
217 bss->ssid.security_policy = SECURITY_WPA_PSK;
218 else if (bss->ieee802_1x) {
219 int cipher = WPA_CIPHER_NONE;
220 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
221 bss->ssid.wep.default_len = bss->default_wep_key_len;
222 if (bss->default_wep_key_len)
223 cipher = bss->default_wep_key_len >= 13 ?
224 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
225 bss->wpa_group = cipher;
226 bss->wpa_pairwise = cipher;
227 bss->rsn_pairwise = cipher;
228 } else if (bss->ssid.wep.keys_set) {
229 int cipher = WPA_CIPHER_WEP40;
230 if (bss->ssid.wep.len[0] >= 13)
231 cipher = WPA_CIPHER_WEP104;
232 bss->ssid.security_policy = SECURITY_STATIC_WEP;
233 bss->wpa_group = cipher;
234 bss->wpa_pairwise = cipher;
235 bss->rsn_pairwise = cipher;
237 bss->ssid.security_policy = SECURITY_PLAINTEXT;
238 bss->wpa_group = WPA_CIPHER_NONE;
239 bss->wpa_pairwise = WPA_CIPHER_NONE;
240 bss->rsn_pairwise = WPA_CIPHER_NONE;
243 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
244 (bss->wpa_group == WPA_CIPHER_CCMP ||
245 bss->wpa_group == WPA_CIPHER_GCMP)) {
247 * Strong ciphers do not need frequent rekeying, so increase
248 * the default GTK rekeying period to 24 hours.
250 bss->wpa_group_rekey = 86400;
255 * Enable WPS by default for open and WPA/WPA2-Personal network, but
256 * require user interaction to actually use it. Only the internal
257 * Registrar is supported.
259 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
260 bss->ssid.security_policy != SECURITY_PLAINTEXT)
263 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
264 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
265 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
267 #endif /* CONFIG_WPS2 */
270 if (!ssid->ignore_broadcast_ssid)
273 bss->ap_setup_locked = 2;
274 if (wpa_s->conf->config_methods)
275 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
276 os_memcpy(bss->device_type, wpa_s->conf->device_type,
278 if (wpa_s->conf->device_name) {
279 bss->device_name = os_strdup(wpa_s->conf->device_name);
280 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
282 if (wpa_s->conf->manufacturer)
283 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
284 if (wpa_s->conf->model_name)
285 bss->model_name = os_strdup(wpa_s->conf->model_name);
286 if (wpa_s->conf->model_number)
287 bss->model_number = os_strdup(wpa_s->conf->model_number);
288 if (wpa_s->conf->serial_number)
289 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
290 if (is_nil_uuid(wpa_s->conf->uuid))
291 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
293 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
294 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
295 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
297 #endif /* CONFIG_WPS */
299 if (wpa_s->max_stations &&
300 wpa_s->max_stations < wpa_s->conf->max_num_sta)
301 bss->max_num_sta = wpa_s->max_stations;
303 bss->max_num_sta = wpa_s->conf->max_num_sta;
305 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
307 if (wpa_s->conf->ap_vendor_elements) {
308 bss->vendor_elements =
309 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
316 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
319 struct wpa_supplicant *wpa_s = ctx;
320 const struct ieee80211_mgmt *mgmt;
323 mgmt = (const struct ieee80211_mgmt *) buf;
324 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
327 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
328 mgmt->u.action.category,
329 &mgmt->u.action.u.vs_public_action.action,
330 len - hdr_len, freq);
331 #endif /* CONFIG_P2P */
335 static void ap_wps_event_cb(void *ctx, enum wps_event event,
336 union wps_event_data *data)
339 struct wpa_supplicant *wpa_s = ctx;
341 if (event == WPS_EV_FAIL) {
342 struct wps_event_fail *fail = &data->fail;
344 if (wpa_s->parent && wpa_s->parent != wpa_s &&
345 wpa_s == wpa_s->global->p2p_group_formation) {
347 * src/ap/wps_hostapd.c has already sent this on the
348 * main interface, so only send on the parent interface
351 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
352 "msg=%d config_error=%d",
353 fail->msg, fail->config_error);
355 wpas_p2p_wps_failed(wpa_s, fail);
357 #endif /* CONFIG_P2P */
361 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
362 int authorized, const u8 *p2p_dev_addr)
364 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
368 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
371 struct wpa_supplicant *wpa_s = ctx;
372 const struct ieee80211_mgmt *mgmt;
375 mgmt = (const struct ieee80211_mgmt *) buf;
376 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
379 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
380 mgmt->u.action.category,
381 &mgmt->u.action.u.vs_public_action.action,
382 len - hdr_len, freq);
383 #endif /* CONFIG_P2P */
388 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
389 const u8 *bssid, const u8 *ie, size_t ie_len,
393 struct wpa_supplicant *wpa_s = ctx;
394 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
396 #else /* CONFIG_P2P */
398 #endif /* CONFIG_P2P */
402 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
406 struct wpa_supplicant *wpa_s = ctx;
407 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
408 #endif /* CONFIG_P2P */
412 static void wpas_ap_configured_cb(void *ctx)
414 struct wpa_supplicant *wpa_s = ctx;
416 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
418 if (wpa_s->ap_configured_cb)
419 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
420 wpa_s->ap_configured_cb_data);
424 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
425 struct wpa_ssid *ssid)
427 struct wpa_driver_associate_params params;
428 struct hostapd_iface *hapd_iface;
429 struct hostapd_config *conf;
432 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
433 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
437 wpa_supplicant_ap_deinit(wpa_s);
439 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
440 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
442 os_memset(¶ms, 0, sizeof(params));
443 params.ssid = ssid->ssid;
444 params.ssid_len = ssid->ssid_len;
445 switch (ssid->mode) {
446 case WPAS_MODE_INFRA:
447 params.mode = IEEE80211_MODE_INFRA;
450 params.mode = IEEE80211_MODE_IBSS;
453 case WPAS_MODE_P2P_GO:
454 case WPAS_MODE_P2P_GROUP_FORMATION:
455 params.mode = IEEE80211_MODE_AP;
458 if (ssid->frequency == 0)
459 ssid->frequency = 2462; /* default channel 11 */
460 params.freq = ssid->frequency;
462 params.wpa_proto = ssid->proto;
463 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
464 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
466 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
467 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
469 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
471 if (wpa_s->pairwise_cipher < 0) {
472 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
476 params.pairwise_suite =
477 wpa_cipher_to_suite_driver(wpa_s->pairwise_cipher);
478 params.group_suite = params.pairwise_suite;
481 if (ssid->mode == WPAS_MODE_P2P_GO ||
482 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
484 #endif /* CONFIG_P2P */
486 if (wpa_s->parent->set_ap_uapsd)
487 params.uapsd = wpa_s->parent->ap_uapsd;
491 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
492 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
494 if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION &&
495 wpa_s->global->p2p_group_formation == wpa_s)
496 wpas_p2p_group_formation_failed(wpa_s->parent);
497 #endif /* CONFIG_P2P */
501 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
502 if (hapd_iface == NULL)
504 hapd_iface->owner = wpa_s;
505 hapd_iface->drv_flags = wpa_s->drv_flags;
506 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
507 hapd_iface->extended_capa = wpa_s->extended_capa;
508 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
509 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
511 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
513 wpa_supplicant_ap_deinit(wpa_s);
517 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
518 wpa_s->conf->wmm_ac_params,
519 sizeof(wpa_s->conf->wmm_ac_params));
521 if (params.uapsd > 0) {
522 conf->bss->wmm_enabled = 1;
523 conf->bss->wmm_uapsd = 1;
526 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
527 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
528 wpa_supplicant_ap_deinit(wpa_s);
533 if (ssid->mode == WPAS_MODE_P2P_GO)
534 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
535 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
536 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
538 #endif /* CONFIG_P2P */
540 hapd_iface->num_bss = conf->num_bss;
541 hapd_iface->bss = os_calloc(conf->num_bss,
542 sizeof(struct hostapd_data *));
543 if (hapd_iface->bss == NULL) {
544 wpa_supplicant_ap_deinit(wpa_s);
548 for (i = 0; i < conf->num_bss; i++) {
550 hostapd_alloc_bss_data(hapd_iface, conf,
552 if (hapd_iface->bss[i] == NULL) {
553 wpa_supplicant_ap_deinit(wpa_s);
557 hapd_iface->bss[i]->msg_ctx = wpa_s;
558 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
559 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
560 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
561 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
562 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
563 hostapd_register_probereq_cb(hapd_iface->bss[i],
564 ap_probe_req_rx, wpa_s);
565 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
566 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
567 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
568 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
569 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
570 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
572 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
573 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
575 #endif /* CONFIG_P2P */
576 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
577 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
580 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
581 hapd_iface->bss[0]->driver = wpa_s->driver;
582 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
584 wpa_s->current_ssid = ssid;
585 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
586 wpa_s->assoc_freq = ssid->frequency;
588 if (hostapd_setup_interface(wpa_s->ap_iface)) {
589 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
590 wpa_supplicant_ap_deinit(wpa_s);
598 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
601 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
602 #endif /* CONFIG_WPS */
604 if (wpa_s->ap_iface == NULL)
607 wpa_s->current_ssid = NULL;
608 wpa_s->assoc_freq = 0;
610 if (wpa_s->ap_iface->bss)
611 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
612 wpas_p2p_group_deinit(wpa_s);
613 #endif /* CONFIG_P2P */
614 hostapd_interface_deinit(wpa_s->ap_iface);
615 hostapd_interface_free(wpa_s->ap_iface);
616 wpa_s->ap_iface = NULL;
617 wpa_drv_deinit_ap(wpa_s);
621 void ap_tx_status(void *ctx, const u8 *addr,
622 const u8 *buf, size_t len, int ack)
625 struct wpa_supplicant *wpa_s = ctx;
626 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
627 #endif /* NEED_AP_MLME */
631 void ap_eapol_tx_status(void *ctx, const u8 *dst,
632 const u8 *data, size_t len, int ack)
635 struct wpa_supplicant *wpa_s = ctx;
636 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
637 #endif /* NEED_AP_MLME */
641 void ap_client_poll_ok(void *ctx, const u8 *addr)
644 struct wpa_supplicant *wpa_s = ctx;
646 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
647 #endif /* NEED_AP_MLME */
651 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
654 struct wpa_supplicant *wpa_s = ctx;
655 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
656 #endif /* NEED_AP_MLME */
660 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
663 struct wpa_supplicant *wpa_s = ctx;
664 struct hostapd_frame_info fi;
665 os_memset(&fi, 0, sizeof(fi));
666 fi.datarate = rx_mgmt->datarate;
667 fi.ssi_signal = rx_mgmt->ssi_signal;
668 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
669 rx_mgmt->frame_len, &fi);
670 #endif /* NEED_AP_MLME */
674 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
677 struct wpa_supplicant *wpa_s = ctx;
678 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
679 #endif /* NEED_AP_MLME */
683 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
684 const u8 *src_addr, const u8 *buf, size_t len)
686 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
692 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
693 const u8 *p2p_dev_addr)
695 if (!wpa_s->ap_iface)
697 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
702 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
704 struct wps_registrar *reg;
705 int reg_sel = 0, wps_sta = 0;
707 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
710 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
711 reg_sel = wps_registrar_wps_cancel(reg);
712 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
713 ap_sta_wps_cancel, NULL);
715 if (!reg_sel && !wps_sta) {
716 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
722 * There are 2 cases to return wps cancel as success:
723 * 1. When wps cancel was initiated but no connection has been
724 * established with client yet.
725 * 2. Client is in the middle of exchanging WPS messages.
732 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
733 const char *pin, char *buf, size_t buflen,
736 int ret, ret_len = 0;
738 if (!wpa_s->ap_iface)
742 unsigned int rpin = wps_generate_pin();
743 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
746 ret_len = os_snprintf(buf, buflen, "%s", pin);
748 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
756 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
758 struct wpa_supplicant *wpa_s = eloop_data;
759 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
760 wpas_wps_ap_pin_disable(wpa_s);
764 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
766 struct hostapd_data *hapd;
768 if (wpa_s->ap_iface == NULL)
770 hapd = wpa_s->ap_iface->bss[0];
771 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
772 hapd->ap_pin_failures = 0;
773 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
775 eloop_register_timeout(timeout, 0,
776 wpas_wps_ap_pin_timeout, wpa_s, NULL);
780 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
782 struct hostapd_data *hapd;
784 if (wpa_s->ap_iface == NULL)
786 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
787 hapd = wpa_s->ap_iface->bss[0];
788 os_free(hapd->conf->ap_pin);
789 hapd->conf->ap_pin = NULL;
790 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
794 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
796 struct hostapd_data *hapd;
800 if (wpa_s->ap_iface == NULL)
802 hapd = wpa_s->ap_iface->bss[0];
803 pin = wps_generate_pin();
804 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
805 os_free(hapd->conf->ap_pin);
806 hapd->conf->ap_pin = os_strdup(pin_txt);
807 if (hapd->conf->ap_pin == NULL)
809 wpas_wps_ap_pin_enable(wpa_s, timeout);
811 return hapd->conf->ap_pin;
815 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
817 struct hostapd_data *hapd;
818 if (wpa_s->ap_iface == NULL)
820 hapd = wpa_s->ap_iface->bss[0];
821 return hapd->conf->ap_pin;
825 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
828 struct hostapd_data *hapd;
832 if (wpa_s->ap_iface == NULL)
834 hapd = wpa_s->ap_iface->bss[0];
835 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
836 if (ret < 0 || ret >= (int) sizeof(pin_txt))
838 os_free(hapd->conf->ap_pin);
839 hapd->conf->ap_pin = os_strdup(pin_txt);
840 if (hapd->conf->ap_pin == NULL)
842 wpas_wps_ap_pin_enable(wpa_s, timeout);
848 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
850 struct hostapd_data *hapd;
852 if (wpa_s->ap_iface == NULL)
854 hapd = wpa_s->ap_iface->bss[0];
857 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
858 * PIN if this happens multiple times to slow down brute force attacks.
860 hapd->ap_pin_failures++;
861 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
862 hapd->ap_pin_failures);
863 if (hapd->ap_pin_failures < 3)
866 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
867 hapd->ap_pin_failures = 0;
868 os_free(hapd->conf->ap_pin);
869 hapd->conf->ap_pin = NULL;
873 #ifdef CONFIG_WPS_NFC
875 struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
878 struct hostapd_data *hapd;
880 if (wpa_s->ap_iface == NULL)
882 hapd = wpa_s->ap_iface->bss[0];
883 return hostapd_wps_nfc_config_token(hapd, ndef);
887 struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
890 struct hostapd_data *hapd;
892 if (wpa_s->ap_iface == NULL)
894 hapd = wpa_s->ap_iface->bss[0];
895 return hostapd_wps_nfc_hs_cr(hapd, ndef);
898 #endif /* CONFIG_WPS_NFC */
900 #endif /* CONFIG_WPS */
903 #ifdef CONFIG_CTRL_IFACE
905 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
906 char *buf, size_t buflen)
908 if (wpa_s->ap_iface == NULL)
910 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
915 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
916 char *buf, size_t buflen)
918 if (wpa_s->ap_iface == NULL)
920 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
925 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
926 char *buf, size_t buflen)
928 if (wpa_s->ap_iface == NULL)
930 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
935 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
938 if (wpa_s->ap_iface == NULL)
940 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
945 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
948 if (wpa_s->ap_iface == NULL)
950 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
955 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
956 size_t buflen, int verbose)
958 char *pos = buf, *end = buf + buflen;
960 struct hostapd_bss_config *conf;
962 if (wpa_s->ap_iface == NULL)
965 conf = wpa_s->ap_iface->bss[0]->conf;
969 ret = os_snprintf(pos, end - pos,
970 "pairwise_cipher=%s\n"
973 wpa_cipher_txt(conf->rsn_pairwise),
974 wpa_cipher_txt(conf->wpa_group),
975 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
977 if (ret < 0 || ret >= end - pos)
983 #endif /* CONFIG_CTRL_IFACE */
986 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
988 struct hostapd_iface *iface = wpa_s->ap_iface;
989 struct wpa_ssid *ssid = wpa_s->current_ssid;
990 struct hostapd_data *hapd;
992 if (ssid == NULL || wpa_s->ap_iface == NULL ||
993 ssid->mode == WPAS_MODE_INFRA ||
994 ssid->mode == WPAS_MODE_IBSS)
998 if (ssid->mode == WPAS_MODE_P2P_GO)
999 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1000 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1001 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1002 P2P_GROUP_FORMATION;
1003 #endif /* CONFIG_P2P */
1005 hapd = iface->bss[0];
1006 if (hapd->drv_priv == NULL)
1008 ieee802_11_set_beacons(iface);
1009 hostapd_set_ap_wps_ie(hapd);
1015 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
1018 if (!wpa_s->ap_iface)
1021 wpa_s->assoc_freq = freq;
1022 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset);
1026 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1029 struct hostapd_data *hapd;
1030 struct hostapd_bss_config *conf;
1032 if (!wpa_s->ap_iface)
1036 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1039 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1041 hapd = wpa_s->ap_iface->bss[0];
1044 os_free(conf->accept_mac);
1045 conf->accept_mac = NULL;
1046 conf->num_accept_mac = 0;
1047 os_free(conf->deny_mac);
1048 conf->deny_mac = NULL;
1049 conf->num_deny_mac = 0;
1052 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1056 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1057 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1058 if (conf->accept_mac == NULL)
1060 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1061 conf->num_accept_mac = 1;