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 "eapol_supp/eapol_supp_sm.h"
18 #include "crypto/dh_group5.h"
19 #include "ap/hostapd.h"
20 #include "ap/ap_config.h"
21 #include "ap/ap_drv_ops.h"
23 #include "ap/ieee802_11.h"
24 #endif /* NEED_AP_MLME */
25 #include "ap/beacon.h"
26 #include "ap/ieee802_1x.h"
27 #include "ap/wps_hostapd.h"
28 #include "ap/ctrl_iface_ap.h"
30 #include "common/ieee802_11_defs.h"
31 #include "config_ssid.h"
33 #include "wpa_supplicant_i.h"
35 #include "p2p_supplicant.h"
37 #include "ap/sta_info.h"
42 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
43 #endif /* CONFIG_WPS */
46 #ifdef CONFIG_IEEE80211N
47 static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
48 struct hostapd_config *conf,
49 struct hostapd_hw_modes *mode)
52 u8 channel = conf->channel;
54 if (!conf->secondary_channel)
57 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
61 /* Use 80 MHz channel */
62 conf->vht_oper_chwidth = 1;
63 conf->vht_oper_centr_freq_seg0_idx = center_chan;
67 conf->vht_oper_centr_freq_seg0_idx =
68 channel + conf->secondary_channel * 2;
70 #endif /* CONFIG_IEEE80211N */
73 static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
74 struct wpa_ssid *ssid,
75 struct hostapd_config *conf)
77 struct hostapd_bss_config *bss = conf->bss[0];
79 conf->driver = wpa_s->driver;
81 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
83 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
85 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
86 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
91 /* TODO: enable HT40 if driver supports it;
92 * drop to 11b if driver does not support 11g */
94 #ifdef CONFIG_IEEE80211N
96 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
97 * and a mask of allowed capabilities within conf->ht_capab.
98 * Using default config settings for: conf->ht_op_mode_fixed,
99 * conf->secondary_channel, conf->require_ht
101 if (wpa_s->hw.modes) {
102 struct hostapd_hw_modes *mode = NULL;
104 for (i = 0; i < wpa_s->hw.num_modes; i++) {
105 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
106 mode = &wpa_s->hw.modes[i];
111 #ifdef CONFIG_HT_OVERRIDES
112 if (ssid->disable_ht) {
113 conf->ieee80211n = 0;
117 #endif /* CONFIG_HT_OVERRIDES */
119 if (!no_ht && mode && mode->ht_capab) {
120 conf->ieee80211n = 1;
122 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
124 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
126 conf->secondary_channel =
127 wpas_p2p_get_ht40_mode(wpa_s, mode,
129 if (conf->secondary_channel)
131 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
132 #endif /* CONFIG_P2P */
135 * white-list capabilities that won't cause issues
136 * to connecting stations, while leaving the current
137 * capabilities intact (currently disabled SMPS).
139 conf->ht_capab |= mode->ht_capab &
140 (HT_CAP_INFO_GREEN_FIELD |
141 HT_CAP_INFO_SHORT_GI20MHZ |
142 HT_CAP_INFO_SHORT_GI40MHZ |
143 HT_CAP_INFO_RX_STBC_MASK |
144 HT_CAP_INFO_MAX_AMSDU_SIZE);
146 if (mode->vht_capab && ssid->vht) {
147 conf->ieee80211ac = 1;
148 wpas_conf_ap_vht(wpa_s, conf, mode);
152 #endif /* CONFIG_IEEE80211N */
155 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
156 (ssid->mode == WPAS_MODE_P2P_GO ||
157 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
158 /* Remove 802.11b rates from supported and basic rate sets */
159 int *list = os_malloc(4 * sizeof(int));
166 conf->basic_rates = list;
168 list = os_malloc(9 * sizeof(int));
180 conf->supported_rates = list;
183 bss->isolate = !wpa_s->conf->p2p_intra_bss;
184 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
185 #endif /* CONFIG_P2P */
187 if (ssid->ssid_len == 0) {
188 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
191 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
192 bss->ssid.ssid_len = ssid->ssid_len;
193 bss->ssid.ssid_set = 1;
195 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
198 bss->auth_algs = ssid->auth_alg;
200 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
201 bss->wpa = ssid->proto;
202 bss->wpa_key_mgmt = ssid->key_mgmt;
203 bss->wpa_pairwise = ssid->pairwise_cipher;
205 os_free(bss->ssid.wpa_psk);
206 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
207 if (bss->ssid.wpa_psk == NULL)
209 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
210 bss->ssid.wpa_psk->group = 1;
211 } else if (ssid->passphrase) {
212 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
213 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
214 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
215 struct hostapd_wep_keys *wep = &bss->ssid.wep;
217 for (i = 0; i < NUM_WEP_KEYS; i++) {
218 if (ssid->wep_key_len[i] == 0)
220 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
221 if (wep->key[i] == NULL)
223 os_memcpy(wep->key[i], ssid->wep_key[i],
224 ssid->wep_key_len[i]);
225 wep->len[i] = ssid->wep_key_len[i];
227 wep->idx = ssid->wep_tx_keyidx;
231 if (ssid->ap_max_inactivity)
232 bss->ap_max_inactivity = ssid->ap_max_inactivity;
234 if (ssid->dtim_period)
235 bss->dtim_period = ssid->dtim_period;
236 else if (wpa_s->conf->dtim_period)
237 bss->dtim_period = wpa_s->conf->dtim_period;
239 if (ssid->beacon_int)
240 conf->beacon_int = ssid->beacon_int;
241 else if (wpa_s->conf->beacon_int)
242 conf->beacon_int = wpa_s->conf->beacon_int;
244 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
245 bss->rsn_pairwise = bss->wpa_pairwise;
246 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
249 if (bss->wpa && bss->ieee802_1x)
250 bss->ssid.security_policy = SECURITY_WPA;
252 bss->ssid.security_policy = SECURITY_WPA_PSK;
253 else if (bss->ieee802_1x) {
254 int cipher = WPA_CIPHER_NONE;
255 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
256 bss->ssid.wep.default_len = bss->default_wep_key_len;
257 if (bss->default_wep_key_len)
258 cipher = bss->default_wep_key_len >= 13 ?
259 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
260 bss->wpa_group = cipher;
261 bss->wpa_pairwise = cipher;
262 bss->rsn_pairwise = cipher;
263 } else if (bss->ssid.wep.keys_set) {
264 int cipher = WPA_CIPHER_WEP40;
265 if (bss->ssid.wep.len[0] >= 13)
266 cipher = WPA_CIPHER_WEP104;
267 bss->ssid.security_policy = SECURITY_STATIC_WEP;
268 bss->wpa_group = cipher;
269 bss->wpa_pairwise = cipher;
270 bss->rsn_pairwise = cipher;
272 bss->ssid.security_policy = SECURITY_PLAINTEXT;
273 bss->wpa_group = WPA_CIPHER_NONE;
274 bss->wpa_pairwise = WPA_CIPHER_NONE;
275 bss->rsn_pairwise = WPA_CIPHER_NONE;
278 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
279 (bss->wpa_group == WPA_CIPHER_CCMP ||
280 bss->wpa_group == WPA_CIPHER_GCMP ||
281 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
282 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
284 * Strong ciphers do not need frequent rekeying, so increase
285 * the default GTK rekeying period to 24 hours.
287 bss->wpa_group_rekey = 86400;
292 * Enable WPS by default for open and WPA/WPA2-Personal network, but
293 * require user interaction to actually use it. Only the internal
294 * Registrar is supported.
296 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
297 bss->ssid.security_policy != SECURITY_PLAINTEXT)
300 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
301 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
302 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
304 #endif /* CONFIG_WPS2 */
307 if (!ssid->ignore_broadcast_ssid)
310 bss->ap_setup_locked = 2;
311 if (wpa_s->conf->config_methods)
312 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
313 os_memcpy(bss->device_type, wpa_s->conf->device_type,
315 if (wpa_s->conf->device_name) {
316 bss->device_name = os_strdup(wpa_s->conf->device_name);
317 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
319 if (wpa_s->conf->manufacturer)
320 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
321 if (wpa_s->conf->model_name)
322 bss->model_name = os_strdup(wpa_s->conf->model_name);
323 if (wpa_s->conf->model_number)
324 bss->model_number = os_strdup(wpa_s->conf->model_number);
325 if (wpa_s->conf->serial_number)
326 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
327 if (is_nil_uuid(wpa_s->conf->uuid))
328 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
330 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
331 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
332 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
334 #endif /* CONFIG_WPS */
336 if (wpa_s->max_stations &&
337 wpa_s->max_stations < wpa_s->conf->max_num_sta)
338 bss->max_num_sta = wpa_s->max_stations;
340 bss->max_num_sta = wpa_s->conf->max_num_sta;
342 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
344 if (wpa_s->conf->ap_vendor_elements) {
345 bss->vendor_elements =
346 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
353 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
356 struct wpa_supplicant *wpa_s = ctx;
357 const struct ieee80211_mgmt *mgmt;
360 mgmt = (const struct ieee80211_mgmt *) buf;
361 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
364 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
366 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
367 mgmt->u.action.category,
368 &mgmt->u.action.u.vs_public_action.action,
369 len - hdr_len, freq);
370 #endif /* CONFIG_P2P */
374 static void ap_wps_event_cb(void *ctx, enum wps_event event,
375 union wps_event_data *data)
378 struct wpa_supplicant *wpa_s = ctx;
380 if (event == WPS_EV_FAIL) {
381 struct wps_event_fail *fail = &data->fail;
383 if (wpa_s->parent && wpa_s->parent != wpa_s &&
384 wpa_s == wpa_s->global->p2p_group_formation) {
386 * src/ap/wps_hostapd.c has already sent this on the
387 * main interface, so only send on the parent interface
390 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
391 "msg=%d config_error=%d",
392 fail->msg, fail->config_error);
394 wpas_p2p_wps_failed(wpa_s, fail);
396 #endif /* CONFIG_P2P */
400 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
401 int authorized, const u8 *p2p_dev_addr)
403 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
408 static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
409 const u8 *psk, size_t psk_len)
412 struct wpa_supplicant *wpa_s = ctx;
413 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
415 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
417 #endif /* CONFIG_P2P */
420 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
423 struct wpa_supplicant *wpa_s = ctx;
424 const struct ieee80211_mgmt *mgmt;
427 mgmt = (const struct ieee80211_mgmt *) buf;
428 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
431 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
432 mgmt->u.action.category,
433 &mgmt->u.action.u.vs_public_action.action,
434 len - hdr_len, freq);
435 #endif /* CONFIG_P2P */
440 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
441 const u8 *bssid, const u8 *ie, size_t ie_len,
445 struct wpa_supplicant *wpa_s = ctx;
446 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
448 #else /* CONFIG_P2P */
450 #endif /* CONFIG_P2P */
454 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
458 struct wpa_supplicant *wpa_s = ctx;
459 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
460 #endif /* CONFIG_P2P */
464 static void wpas_ap_configured_cb(void *ctx)
466 struct wpa_supplicant *wpa_s = ctx;
468 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
470 if (wpa_s->ap_configured_cb)
471 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
472 wpa_s->ap_configured_cb_data);
476 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
477 struct wpa_ssid *ssid)
479 struct wpa_driver_associate_params params;
480 struct hostapd_iface *hapd_iface;
481 struct hostapd_config *conf;
484 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
485 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
489 wpa_supplicant_ap_deinit(wpa_s);
491 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
492 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
494 os_memset(¶ms, 0, sizeof(params));
495 params.ssid = ssid->ssid;
496 params.ssid_len = ssid->ssid_len;
497 switch (ssid->mode) {
498 case WPAS_MODE_INFRA:
499 params.mode = IEEE80211_MODE_INFRA;
502 params.mode = IEEE80211_MODE_IBSS;
505 case WPAS_MODE_P2P_GO:
506 case WPAS_MODE_P2P_GROUP_FORMATION:
507 params.mode = IEEE80211_MODE_AP;
510 if (ssid->frequency == 0)
511 ssid->frequency = 2462; /* default channel 11 */
512 params.freq = ssid->frequency;
514 params.wpa_proto = ssid->proto;
515 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
516 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
518 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
519 params.key_mgmt_suite = wpa_s->key_mgmt;
521 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
523 if (wpa_s->pairwise_cipher < 0) {
524 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
528 params.pairwise_suite = wpa_s->pairwise_cipher;
529 params.group_suite = params.pairwise_suite;
532 if (ssid->mode == WPAS_MODE_P2P_GO ||
533 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
535 #endif /* CONFIG_P2P */
537 if (wpa_s->parent->set_ap_uapsd)
538 params.uapsd = wpa_s->parent->ap_uapsd;
542 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
543 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
547 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
548 if (hapd_iface == NULL)
550 hapd_iface->owner = wpa_s;
551 hapd_iface->drv_flags = wpa_s->drv_flags;
552 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
553 hapd_iface->extended_capa = wpa_s->extended_capa;
554 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
555 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
557 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
559 wpa_supplicant_ap_deinit(wpa_s);
563 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
564 wpa_s->conf->wmm_ac_params,
565 sizeof(wpa_s->conf->wmm_ac_params));
567 if (params.uapsd > 0) {
568 conf->bss[0]->wmm_enabled = 1;
569 conf->bss[0]->wmm_uapsd = 1;
572 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
573 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
574 wpa_supplicant_ap_deinit(wpa_s);
579 if (ssid->mode == WPAS_MODE_P2P_GO)
580 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
581 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
582 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
584 #endif /* CONFIG_P2P */
586 hapd_iface->num_bss = conf->num_bss;
587 hapd_iface->bss = os_calloc(conf->num_bss,
588 sizeof(struct hostapd_data *));
589 if (hapd_iface->bss == NULL) {
590 wpa_supplicant_ap_deinit(wpa_s);
594 for (i = 0; i < conf->num_bss; i++) {
596 hostapd_alloc_bss_data(hapd_iface, conf,
598 if (hapd_iface->bss[i] == NULL) {
599 wpa_supplicant_ap_deinit(wpa_s);
603 hapd_iface->bss[i]->msg_ctx = wpa_s;
604 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
605 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
606 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
607 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
608 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
609 hostapd_register_probereq_cb(hapd_iface->bss[i],
610 ap_probe_req_rx, wpa_s);
611 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
612 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
613 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
614 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
615 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
616 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
618 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
619 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
620 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
621 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
623 #endif /* CONFIG_P2P */
624 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
625 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
628 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
629 hapd_iface->bss[0]->driver = wpa_s->driver;
630 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
632 wpa_s->current_ssid = ssid;
633 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
634 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
635 wpa_s->assoc_freq = ssid->frequency;
637 if (hostapd_setup_interface(wpa_s->ap_iface)) {
638 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
639 wpa_supplicant_ap_deinit(wpa_s);
647 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
650 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
651 #endif /* CONFIG_WPS */
653 if (wpa_s->ap_iface == NULL)
656 wpa_s->current_ssid = NULL;
657 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
658 wpa_s->assoc_freq = 0;
660 if (wpa_s->ap_iface->bss)
661 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
662 wpas_p2p_group_deinit(wpa_s);
663 #endif /* CONFIG_P2P */
664 hostapd_interface_deinit(wpa_s->ap_iface);
665 hostapd_interface_free(wpa_s->ap_iface);
666 wpa_s->ap_iface = NULL;
667 wpa_drv_deinit_ap(wpa_s);
671 void ap_tx_status(void *ctx, const u8 *addr,
672 const u8 *buf, size_t len, int ack)
675 struct wpa_supplicant *wpa_s = ctx;
676 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
677 #endif /* NEED_AP_MLME */
681 void ap_eapol_tx_status(void *ctx, const u8 *dst,
682 const u8 *data, size_t len, int ack)
685 struct wpa_supplicant *wpa_s = ctx;
686 if (!wpa_s->ap_iface)
688 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
689 #endif /* NEED_AP_MLME */
693 void ap_client_poll_ok(void *ctx, const u8 *addr)
696 struct wpa_supplicant *wpa_s = ctx;
698 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
699 #endif /* NEED_AP_MLME */
703 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
706 struct wpa_supplicant *wpa_s = ctx;
707 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
708 #endif /* NEED_AP_MLME */
712 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
715 struct wpa_supplicant *wpa_s = ctx;
716 struct hostapd_frame_info fi;
717 os_memset(&fi, 0, sizeof(fi));
718 fi.datarate = rx_mgmt->datarate;
719 fi.ssi_signal = rx_mgmt->ssi_signal;
720 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
721 rx_mgmt->frame_len, &fi);
722 #endif /* NEED_AP_MLME */
726 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
729 struct wpa_supplicant *wpa_s = ctx;
730 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
731 #endif /* NEED_AP_MLME */
735 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
736 const u8 *src_addr, const u8 *buf, size_t len)
738 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
744 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
745 const u8 *p2p_dev_addr)
747 if (!wpa_s->ap_iface)
749 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
754 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
756 struct wps_registrar *reg;
757 int reg_sel = 0, wps_sta = 0;
759 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
762 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
763 reg_sel = wps_registrar_wps_cancel(reg);
764 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
765 ap_sta_wps_cancel, NULL);
767 if (!reg_sel && !wps_sta) {
768 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
774 * There are 2 cases to return wps cancel as success:
775 * 1. When wps cancel was initiated but no connection has been
776 * established with client yet.
777 * 2. Client is in the middle of exchanging WPS messages.
784 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
785 const char *pin, char *buf, size_t buflen,
788 int ret, ret_len = 0;
790 if (!wpa_s->ap_iface)
794 unsigned int rpin = wps_generate_pin();
795 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
798 ret_len = os_snprintf(buf, buflen, "%s", pin);
800 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
808 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
810 struct wpa_supplicant *wpa_s = eloop_data;
811 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
812 wpas_wps_ap_pin_disable(wpa_s);
816 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
818 struct hostapd_data *hapd;
820 if (wpa_s->ap_iface == NULL)
822 hapd = wpa_s->ap_iface->bss[0];
823 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
824 hapd->ap_pin_failures = 0;
825 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
827 eloop_register_timeout(timeout, 0,
828 wpas_wps_ap_pin_timeout, wpa_s, NULL);
832 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
834 struct hostapd_data *hapd;
836 if (wpa_s->ap_iface == NULL)
838 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
839 hapd = wpa_s->ap_iface->bss[0];
840 os_free(hapd->conf->ap_pin);
841 hapd->conf->ap_pin = NULL;
842 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
846 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
848 struct hostapd_data *hapd;
852 if (wpa_s->ap_iface == NULL)
854 hapd = wpa_s->ap_iface->bss[0];
855 pin = wps_generate_pin();
856 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
857 os_free(hapd->conf->ap_pin);
858 hapd->conf->ap_pin = os_strdup(pin_txt);
859 if (hapd->conf->ap_pin == NULL)
861 wpas_wps_ap_pin_enable(wpa_s, timeout);
863 return hapd->conf->ap_pin;
867 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
869 struct hostapd_data *hapd;
870 if (wpa_s->ap_iface == NULL)
872 hapd = wpa_s->ap_iface->bss[0];
873 return hapd->conf->ap_pin;
877 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
880 struct hostapd_data *hapd;
884 if (wpa_s->ap_iface == NULL)
886 hapd = wpa_s->ap_iface->bss[0];
887 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
888 if (ret < 0 || ret >= (int) sizeof(pin_txt))
890 os_free(hapd->conf->ap_pin);
891 hapd->conf->ap_pin = os_strdup(pin_txt);
892 if (hapd->conf->ap_pin == NULL)
894 wpas_wps_ap_pin_enable(wpa_s, timeout);
900 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
902 struct hostapd_data *hapd;
904 if (wpa_s->ap_iface == NULL)
906 hapd = wpa_s->ap_iface->bss[0];
909 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
910 * PIN if this happens multiple times to slow down brute force attacks.
912 hapd->ap_pin_failures++;
913 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
914 hapd->ap_pin_failures);
915 if (hapd->ap_pin_failures < 3)
918 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
919 hapd->ap_pin_failures = 0;
920 os_free(hapd->conf->ap_pin);
921 hapd->conf->ap_pin = NULL;
925 #ifdef CONFIG_WPS_NFC
927 struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
930 struct hostapd_data *hapd;
932 if (wpa_s->ap_iface == NULL)
934 hapd = wpa_s->ap_iface->bss[0];
935 return hostapd_wps_nfc_config_token(hapd, ndef);
939 struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
942 struct hostapd_data *hapd;
944 if (wpa_s->ap_iface == NULL)
946 hapd = wpa_s->ap_iface->bss[0];
947 return hostapd_wps_nfc_hs_cr(hapd, ndef);
951 int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
952 const struct wpabuf *req,
953 const struct wpabuf *sel)
955 struct hostapd_data *hapd;
957 if (wpa_s->ap_iface == NULL)
959 hapd = wpa_s->ap_iface->bss[0];
960 return hostapd_wps_nfc_report_handover(hapd, req, sel);
963 #endif /* CONFIG_WPS_NFC */
965 #endif /* CONFIG_WPS */
968 #ifdef CONFIG_CTRL_IFACE
970 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
971 char *buf, size_t buflen)
973 if (wpa_s->ap_iface == NULL)
975 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
980 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
981 char *buf, size_t buflen)
983 if (wpa_s->ap_iface == NULL)
985 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
990 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
991 char *buf, size_t buflen)
993 if (wpa_s->ap_iface == NULL)
995 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
1000 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1001 const char *txtaddr)
1003 if (wpa_s->ap_iface == NULL)
1005 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1010 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1011 const char *txtaddr)
1013 if (wpa_s->ap_iface == NULL)
1015 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1020 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1021 size_t buflen, int verbose)
1023 char *pos = buf, *end = buf + buflen;
1025 struct hostapd_bss_config *conf;
1027 if (wpa_s->ap_iface == NULL)
1030 conf = wpa_s->ap_iface->bss[0]->conf;
1034 ret = os_snprintf(pos, end - pos,
1035 "pairwise_cipher=%s\n"
1038 wpa_cipher_txt(conf->rsn_pairwise),
1039 wpa_cipher_txt(conf->wpa_group),
1040 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1042 if (ret < 0 || ret >= end - pos)
1048 #endif /* CONFIG_CTRL_IFACE */
1051 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1053 struct hostapd_iface *iface = wpa_s->ap_iface;
1054 struct wpa_ssid *ssid = wpa_s->current_ssid;
1055 struct hostapd_data *hapd;
1057 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1058 ssid->mode == WPAS_MODE_INFRA ||
1059 ssid->mode == WPAS_MODE_IBSS)
1063 if (ssid->mode == WPAS_MODE_P2P_GO)
1064 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1065 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1066 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1067 P2P_GROUP_FORMATION;
1068 #endif /* CONFIG_P2P */
1070 hapd = iface->bss[0];
1071 if (hapd->drv_priv == NULL)
1073 ieee802_11_set_beacons(iface);
1074 hostapd_set_ap_wps_ie(hapd);
1080 int ap_switch_channel(struct wpa_supplicant *wpa_s,
1081 struct csa_settings *settings)
1084 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1087 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1088 #else /* NEED_AP_MLME */
1090 #endif /* NEED_AP_MLME */
1094 int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1096 struct csa_settings settings;
1097 int ret = hostapd_parse_csa_settings(pos, &settings);
1102 return ap_switch_channel(wpa_s, &settings);
1106 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
1107 int offset, int width, int cf1, int cf2)
1109 if (!wpa_s->ap_iface)
1112 wpa_s->assoc_freq = freq;
1113 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
1117 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1120 struct hostapd_data *hapd;
1121 struct hostapd_bss_config *conf;
1123 if (!wpa_s->ap_iface)
1127 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1130 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1132 hapd = wpa_s->ap_iface->bss[0];
1135 os_free(conf->accept_mac);
1136 conf->accept_mac = NULL;
1137 conf->num_accept_mac = 0;
1138 os_free(conf->deny_mac);
1139 conf->deny_mac = NULL;
1140 conf->num_deny_mac = 0;
1143 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1147 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1148 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1149 if (conf->accept_mac == NULL)
1151 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1152 conf->num_accept_mac = 1;
1158 #ifdef CONFIG_WPS_NFC
1159 int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1160 const struct wpabuf *pw, const u8 *pubkey_hash)
1162 struct hostapd_data *hapd;
1163 struct wps_context *wps;
1165 if (!wpa_s->ap_iface)
1167 hapd = wpa_s->ap_iface->bss[0];
1170 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1171 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1172 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1176 dh5_free(wps->dh_ctx);
1177 wpabuf_free(wps->dh_pubkey);
1178 wpabuf_free(wps->dh_privkey);
1179 wps->dh_privkey = wpabuf_dup(
1180 wpa_s->parent->conf->wps_nfc_dh_privkey);
1181 wps->dh_pubkey = wpabuf_dup(
1182 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1183 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1185 wpabuf_free(wps->dh_pubkey);
1186 wps->dh_pubkey = NULL;
1187 wpabuf_free(wps->dh_privkey);
1188 wps->dh_privkey = NULL;
1191 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1192 if (wps->dh_ctx == NULL)
1195 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1197 pw ? wpabuf_head(pw) : NULL,
1198 pw ? wpabuf_len(pw) : 0, 1);
1200 #endif /* CONFIG_WPS_NFC */