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;
186 if (ssid->p2p_group) {
187 os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
188 os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
190 os_memcpy(bss->ip_addr_start,
191 wpa_s->parent->conf->ip_addr_start, 4);
192 os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
195 #endif /* CONFIG_P2P */
197 if (ssid->ssid_len == 0) {
198 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
201 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
202 bss->ssid.ssid_len = ssid->ssid_len;
203 bss->ssid.ssid_set = 1;
205 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
208 bss->auth_algs = ssid->auth_alg;
210 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
211 bss->wpa = ssid->proto;
212 bss->wpa_key_mgmt = ssid->key_mgmt;
213 bss->wpa_pairwise = ssid->pairwise_cipher;
215 os_free(bss->ssid.wpa_psk);
216 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
217 if (bss->ssid.wpa_psk == NULL)
219 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
220 bss->ssid.wpa_psk->group = 1;
221 } else if (ssid->passphrase) {
222 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
223 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
224 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
225 struct hostapd_wep_keys *wep = &bss->ssid.wep;
227 for (i = 0; i < NUM_WEP_KEYS; i++) {
228 if (ssid->wep_key_len[i] == 0)
230 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
231 if (wep->key[i] == NULL)
233 os_memcpy(wep->key[i], ssid->wep_key[i],
234 ssid->wep_key_len[i]);
235 wep->len[i] = ssid->wep_key_len[i];
237 wep->idx = ssid->wep_tx_keyidx;
241 if (ssid->ap_max_inactivity)
242 bss->ap_max_inactivity = ssid->ap_max_inactivity;
244 if (ssid->dtim_period)
245 bss->dtim_period = ssid->dtim_period;
246 else if (wpa_s->conf->dtim_period)
247 bss->dtim_period = wpa_s->conf->dtim_period;
249 if (ssid->beacon_int)
250 conf->beacon_int = ssid->beacon_int;
251 else if (wpa_s->conf->beacon_int)
252 conf->beacon_int = wpa_s->conf->beacon_int;
254 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
255 bss->rsn_pairwise = bss->wpa_pairwise;
256 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
259 if (bss->wpa && bss->ieee802_1x)
260 bss->ssid.security_policy = SECURITY_WPA;
262 bss->ssid.security_policy = SECURITY_WPA_PSK;
263 else if (bss->ieee802_1x) {
264 int cipher = WPA_CIPHER_NONE;
265 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
266 bss->ssid.wep.default_len = bss->default_wep_key_len;
267 if (bss->default_wep_key_len)
268 cipher = bss->default_wep_key_len >= 13 ?
269 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
270 bss->wpa_group = cipher;
271 bss->wpa_pairwise = cipher;
272 bss->rsn_pairwise = cipher;
273 } else if (bss->ssid.wep.keys_set) {
274 int cipher = WPA_CIPHER_WEP40;
275 if (bss->ssid.wep.len[0] >= 13)
276 cipher = WPA_CIPHER_WEP104;
277 bss->ssid.security_policy = SECURITY_STATIC_WEP;
278 bss->wpa_group = cipher;
279 bss->wpa_pairwise = cipher;
280 bss->rsn_pairwise = cipher;
282 bss->ssid.security_policy = SECURITY_PLAINTEXT;
283 bss->wpa_group = WPA_CIPHER_NONE;
284 bss->wpa_pairwise = WPA_CIPHER_NONE;
285 bss->rsn_pairwise = WPA_CIPHER_NONE;
288 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
289 (bss->wpa_group == WPA_CIPHER_CCMP ||
290 bss->wpa_group == WPA_CIPHER_GCMP ||
291 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
292 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
294 * Strong ciphers do not need frequent rekeying, so increase
295 * the default GTK rekeying period to 24 hours.
297 bss->wpa_group_rekey = 86400;
302 * Enable WPS by default for open and WPA/WPA2-Personal network, but
303 * require user interaction to actually use it. Only the internal
304 * Registrar is supported.
306 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
307 bss->ssid.security_policy != SECURITY_PLAINTEXT)
310 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
311 (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
312 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
314 #endif /* CONFIG_WPS2 */
317 if (!ssid->ignore_broadcast_ssid)
320 bss->ap_setup_locked = 2;
321 if (wpa_s->conf->config_methods)
322 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
323 os_memcpy(bss->device_type, wpa_s->conf->device_type,
325 if (wpa_s->conf->device_name) {
326 bss->device_name = os_strdup(wpa_s->conf->device_name);
327 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
329 if (wpa_s->conf->manufacturer)
330 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
331 if (wpa_s->conf->model_name)
332 bss->model_name = os_strdup(wpa_s->conf->model_name);
333 if (wpa_s->conf->model_number)
334 bss->model_number = os_strdup(wpa_s->conf->model_number);
335 if (wpa_s->conf->serial_number)
336 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
337 if (is_nil_uuid(wpa_s->conf->uuid))
338 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
340 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
341 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
342 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
344 #endif /* CONFIG_WPS */
346 if (wpa_s->max_stations &&
347 wpa_s->max_stations < wpa_s->conf->max_num_sta)
348 bss->max_num_sta = wpa_s->max_stations;
350 bss->max_num_sta = wpa_s->conf->max_num_sta;
352 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
354 if (wpa_s->conf->ap_vendor_elements) {
355 bss->vendor_elements =
356 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
363 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
366 struct wpa_supplicant *wpa_s = ctx;
367 const struct ieee80211_mgmt *mgmt;
370 mgmt = (const struct ieee80211_mgmt *) buf;
371 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
374 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
376 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
377 mgmt->u.action.category,
378 &mgmt->u.action.u.vs_public_action.action,
379 len - hdr_len, freq);
380 #endif /* CONFIG_P2P */
384 static void ap_wps_event_cb(void *ctx, enum wps_event event,
385 union wps_event_data *data)
388 struct wpa_supplicant *wpa_s = ctx;
390 if (event == WPS_EV_FAIL) {
391 struct wps_event_fail *fail = &data->fail;
393 if (wpa_s->parent && wpa_s->parent != wpa_s &&
394 wpa_s == wpa_s->global->p2p_group_formation) {
396 * src/ap/wps_hostapd.c has already sent this on the
397 * main interface, so only send on the parent interface
400 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
401 "msg=%d config_error=%d",
402 fail->msg, fail->config_error);
404 wpas_p2p_wps_failed(wpa_s, fail);
406 #endif /* CONFIG_P2P */
410 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
411 int authorized, const u8 *p2p_dev_addr)
413 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
418 static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
419 const u8 *psk, size_t psk_len)
422 struct wpa_supplicant *wpa_s = ctx;
423 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
425 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
427 #endif /* CONFIG_P2P */
430 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
433 struct wpa_supplicant *wpa_s = ctx;
434 const struct ieee80211_mgmt *mgmt;
437 mgmt = (const struct ieee80211_mgmt *) buf;
438 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
441 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
442 mgmt->u.action.category,
443 &mgmt->u.action.u.vs_public_action.action,
444 len - hdr_len, freq);
445 #endif /* CONFIG_P2P */
450 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
451 const u8 *bssid, const u8 *ie, size_t ie_len,
455 struct wpa_supplicant *wpa_s = ctx;
456 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
458 #else /* CONFIG_P2P */
460 #endif /* CONFIG_P2P */
464 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
468 struct wpa_supplicant *wpa_s = ctx;
469 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
470 #endif /* CONFIG_P2P */
474 static void wpas_ap_configured_cb(void *ctx)
476 struct wpa_supplicant *wpa_s = ctx;
478 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
480 if (wpa_s->ap_configured_cb)
481 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
482 wpa_s->ap_configured_cb_data);
486 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
487 struct wpa_ssid *ssid)
489 struct wpa_driver_associate_params params;
490 struct hostapd_iface *hapd_iface;
491 struct hostapd_config *conf;
494 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
495 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
499 wpa_supplicant_ap_deinit(wpa_s);
501 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
502 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
504 os_memset(¶ms, 0, sizeof(params));
505 params.ssid = ssid->ssid;
506 params.ssid_len = ssid->ssid_len;
507 switch (ssid->mode) {
509 case WPAS_MODE_P2P_GO:
510 case WPAS_MODE_P2P_GROUP_FORMATION:
511 params.mode = IEEE80211_MODE_AP;
516 if (ssid->frequency == 0)
517 ssid->frequency = 2462; /* default channel 11 */
518 params.freq = ssid->frequency;
520 params.wpa_proto = ssid->proto;
521 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
522 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
524 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
525 params.key_mgmt_suite = wpa_s->key_mgmt;
527 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
529 if (wpa_s->pairwise_cipher < 0) {
530 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
534 params.pairwise_suite = wpa_s->pairwise_cipher;
535 params.group_suite = params.pairwise_suite;
538 if (ssid->mode == WPAS_MODE_P2P_GO ||
539 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
541 #endif /* CONFIG_P2P */
543 if (wpa_s->parent->set_ap_uapsd)
544 params.uapsd = wpa_s->parent->ap_uapsd;
545 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
546 params.uapsd = 1; /* mandatory for P2P GO */
550 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
551 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
555 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
556 if (hapd_iface == NULL)
558 hapd_iface->owner = wpa_s;
559 hapd_iface->drv_flags = wpa_s->drv_flags;
560 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
561 hapd_iface->extended_capa = wpa_s->extended_capa;
562 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
563 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
565 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
567 wpa_supplicant_ap_deinit(wpa_s);
571 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
572 wpa_s->conf->wmm_ac_params,
573 sizeof(wpa_s->conf->wmm_ac_params));
575 if (params.uapsd > 0) {
576 conf->bss[0]->wmm_enabled = 1;
577 conf->bss[0]->wmm_uapsd = 1;
580 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
581 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
582 wpa_supplicant_ap_deinit(wpa_s);
587 if (ssid->mode == WPAS_MODE_P2P_GO)
588 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
589 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
590 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
592 #endif /* CONFIG_P2P */
594 hapd_iface->num_bss = conf->num_bss;
595 hapd_iface->bss = os_calloc(conf->num_bss,
596 sizeof(struct hostapd_data *));
597 if (hapd_iface->bss == NULL) {
598 wpa_supplicant_ap_deinit(wpa_s);
602 for (i = 0; i < conf->num_bss; i++) {
604 hostapd_alloc_bss_data(hapd_iface, conf,
606 if (hapd_iface->bss[i] == NULL) {
607 wpa_supplicant_ap_deinit(wpa_s);
611 hapd_iface->bss[i]->msg_ctx = wpa_s;
612 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
613 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
614 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
615 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
616 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
617 hostapd_register_probereq_cb(hapd_iface->bss[i],
618 ap_probe_req_rx, wpa_s);
619 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
620 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
621 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
622 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
623 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
624 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
626 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
627 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
628 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
629 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
631 #endif /* CONFIG_P2P */
632 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
633 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
636 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
637 hapd_iface->bss[0]->driver = wpa_s->driver;
638 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
640 wpa_s->current_ssid = ssid;
641 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
642 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
643 wpa_s->assoc_freq = ssid->frequency;
645 if (hostapd_setup_interface(wpa_s->ap_iface)) {
646 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
647 wpa_supplicant_ap_deinit(wpa_s);
655 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
658 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
659 #endif /* CONFIG_WPS */
661 if (wpa_s->ap_iface == NULL)
664 wpa_s->current_ssid = NULL;
665 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
666 wpa_s->assoc_freq = 0;
668 if (wpa_s->ap_iface->bss)
669 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
670 wpas_p2p_group_deinit(wpa_s);
671 #endif /* CONFIG_P2P */
672 hostapd_interface_deinit(wpa_s->ap_iface);
673 hostapd_interface_free(wpa_s->ap_iface);
674 wpa_s->ap_iface = NULL;
675 wpa_drv_deinit_ap(wpa_s);
679 void ap_tx_status(void *ctx, const u8 *addr,
680 const u8 *buf, size_t len, int ack)
683 struct wpa_supplicant *wpa_s = ctx;
684 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
685 #endif /* NEED_AP_MLME */
689 void ap_eapol_tx_status(void *ctx, const u8 *dst,
690 const u8 *data, size_t len, int ack)
693 struct wpa_supplicant *wpa_s = ctx;
694 if (!wpa_s->ap_iface)
696 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
697 #endif /* NEED_AP_MLME */
701 void ap_client_poll_ok(void *ctx, const u8 *addr)
704 struct wpa_supplicant *wpa_s = ctx;
706 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
707 #endif /* NEED_AP_MLME */
711 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
714 struct wpa_supplicant *wpa_s = ctx;
715 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
716 #endif /* NEED_AP_MLME */
720 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
723 struct wpa_supplicant *wpa_s = ctx;
724 struct hostapd_frame_info fi;
725 os_memset(&fi, 0, sizeof(fi));
726 fi.datarate = rx_mgmt->datarate;
727 fi.ssi_signal = rx_mgmt->ssi_signal;
728 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
729 rx_mgmt->frame_len, &fi);
730 #endif /* NEED_AP_MLME */
734 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
737 struct wpa_supplicant *wpa_s = ctx;
738 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
739 #endif /* NEED_AP_MLME */
743 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
744 const u8 *src_addr, const u8 *buf, size_t len)
746 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
752 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
753 const u8 *p2p_dev_addr)
755 if (!wpa_s->ap_iface)
757 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
762 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
764 struct wps_registrar *reg;
765 int reg_sel = 0, wps_sta = 0;
767 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
770 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
771 reg_sel = wps_registrar_wps_cancel(reg);
772 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
773 ap_sta_wps_cancel, NULL);
775 if (!reg_sel && !wps_sta) {
776 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
782 * There are 2 cases to return wps cancel as success:
783 * 1. When wps cancel was initiated but no connection has been
784 * established with client yet.
785 * 2. Client is in the middle of exchanging WPS messages.
792 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
793 const char *pin, char *buf, size_t buflen,
796 int ret, ret_len = 0;
798 if (!wpa_s->ap_iface)
802 unsigned int rpin = wps_generate_pin();
803 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
806 ret_len = os_snprintf(buf, buflen, "%s", pin);
808 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
816 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
818 struct wpa_supplicant *wpa_s = eloop_data;
819 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
820 wpas_wps_ap_pin_disable(wpa_s);
824 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
826 struct hostapd_data *hapd;
828 if (wpa_s->ap_iface == NULL)
830 hapd = wpa_s->ap_iface->bss[0];
831 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
832 hapd->ap_pin_failures = 0;
833 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
835 eloop_register_timeout(timeout, 0,
836 wpas_wps_ap_pin_timeout, wpa_s, NULL);
840 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
842 struct hostapd_data *hapd;
844 if (wpa_s->ap_iface == NULL)
846 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
847 hapd = wpa_s->ap_iface->bss[0];
848 os_free(hapd->conf->ap_pin);
849 hapd->conf->ap_pin = NULL;
850 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
854 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
856 struct hostapd_data *hapd;
860 if (wpa_s->ap_iface == NULL)
862 hapd = wpa_s->ap_iface->bss[0];
863 pin = wps_generate_pin();
864 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
865 os_free(hapd->conf->ap_pin);
866 hapd->conf->ap_pin = os_strdup(pin_txt);
867 if (hapd->conf->ap_pin == NULL)
869 wpas_wps_ap_pin_enable(wpa_s, timeout);
871 return hapd->conf->ap_pin;
875 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
877 struct hostapd_data *hapd;
878 if (wpa_s->ap_iface == NULL)
880 hapd = wpa_s->ap_iface->bss[0];
881 return hapd->conf->ap_pin;
885 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
888 struct hostapd_data *hapd;
892 if (wpa_s->ap_iface == NULL)
894 hapd = wpa_s->ap_iface->bss[0];
895 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
896 if (ret < 0 || ret >= (int) sizeof(pin_txt))
898 os_free(hapd->conf->ap_pin);
899 hapd->conf->ap_pin = os_strdup(pin_txt);
900 if (hapd->conf->ap_pin == NULL)
902 wpas_wps_ap_pin_enable(wpa_s, timeout);
908 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
910 struct hostapd_data *hapd;
912 if (wpa_s->ap_iface == NULL)
914 hapd = wpa_s->ap_iface->bss[0];
917 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
918 * PIN if this happens multiple times to slow down brute force attacks.
920 hapd->ap_pin_failures++;
921 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
922 hapd->ap_pin_failures);
923 if (hapd->ap_pin_failures < 3)
926 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
927 hapd->ap_pin_failures = 0;
928 os_free(hapd->conf->ap_pin);
929 hapd->conf->ap_pin = NULL;
933 #ifdef CONFIG_WPS_NFC
935 struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
938 struct hostapd_data *hapd;
940 if (wpa_s->ap_iface == NULL)
942 hapd = wpa_s->ap_iface->bss[0];
943 return hostapd_wps_nfc_config_token(hapd, ndef);
947 struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
950 struct hostapd_data *hapd;
952 if (wpa_s->ap_iface == NULL)
954 hapd = wpa_s->ap_iface->bss[0];
955 return hostapd_wps_nfc_hs_cr(hapd, ndef);
959 int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
960 const struct wpabuf *req,
961 const struct wpabuf *sel)
963 struct hostapd_data *hapd;
965 if (wpa_s->ap_iface == NULL)
967 hapd = wpa_s->ap_iface->bss[0];
968 return hostapd_wps_nfc_report_handover(hapd, req, sel);
971 #endif /* CONFIG_WPS_NFC */
973 #endif /* CONFIG_WPS */
976 #ifdef CONFIG_CTRL_IFACE
978 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
979 char *buf, size_t buflen)
981 if (wpa_s->ap_iface == NULL)
983 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
988 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
989 char *buf, size_t buflen)
991 if (wpa_s->ap_iface == NULL)
993 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
998 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
999 char *buf, size_t buflen)
1001 if (wpa_s->ap_iface == NULL)
1003 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
1008 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1009 const char *txtaddr)
1011 if (wpa_s->ap_iface == NULL)
1013 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1018 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1019 const char *txtaddr)
1021 if (wpa_s->ap_iface == NULL)
1023 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1028 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1029 size_t buflen, int verbose)
1031 char *pos = buf, *end = buf + buflen;
1033 struct hostapd_bss_config *conf;
1035 if (wpa_s->ap_iface == NULL)
1038 conf = wpa_s->ap_iface->bss[0]->conf;
1042 ret = os_snprintf(pos, end - pos,
1043 "pairwise_cipher=%s\n"
1046 wpa_cipher_txt(conf->rsn_pairwise),
1047 wpa_cipher_txt(conf->wpa_group),
1048 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1050 if (ret < 0 || ret >= end - pos)
1056 #endif /* CONFIG_CTRL_IFACE */
1059 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1061 struct hostapd_iface *iface = wpa_s->ap_iface;
1062 struct wpa_ssid *ssid = wpa_s->current_ssid;
1063 struct hostapd_data *hapd;
1065 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1066 ssid->mode == WPAS_MODE_INFRA ||
1067 ssid->mode == WPAS_MODE_IBSS)
1071 if (ssid->mode == WPAS_MODE_P2P_GO)
1072 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
1073 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1074 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
1075 P2P_GROUP_FORMATION;
1076 #endif /* CONFIG_P2P */
1078 hapd = iface->bss[0];
1079 if (hapd->drv_priv == NULL)
1081 ieee802_11_set_beacons(iface);
1082 hostapd_set_ap_wps_ie(hapd);
1088 int ap_switch_channel(struct wpa_supplicant *wpa_s,
1089 struct csa_settings *settings)
1092 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1095 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1096 #else /* NEED_AP_MLME */
1098 #endif /* NEED_AP_MLME */
1102 int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1104 struct csa_settings settings;
1105 int ret = hostapd_parse_csa_settings(pos, &settings);
1110 return ap_switch_channel(wpa_s, &settings);
1114 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
1115 int offset, int width, int cf1, int cf2)
1117 if (!wpa_s->ap_iface)
1120 wpa_s->assoc_freq = freq;
1121 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset, width, cf1, cf1);
1125 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1128 struct hostapd_data *hapd;
1129 struct hostapd_bss_config *conf;
1131 if (!wpa_s->ap_iface)
1135 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1138 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1140 hapd = wpa_s->ap_iface->bss[0];
1143 os_free(conf->accept_mac);
1144 conf->accept_mac = NULL;
1145 conf->num_accept_mac = 0;
1146 os_free(conf->deny_mac);
1147 conf->deny_mac = NULL;
1148 conf->num_deny_mac = 0;
1151 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1155 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1156 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1157 if (conf->accept_mac == NULL)
1159 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1160 conf->num_accept_mac = 1;
1166 #ifdef CONFIG_WPS_NFC
1167 int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1168 const struct wpabuf *pw, const u8 *pubkey_hash)
1170 struct hostapd_data *hapd;
1171 struct wps_context *wps;
1173 if (!wpa_s->ap_iface)
1175 hapd = wpa_s->ap_iface->bss[0];
1178 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1179 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1180 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1184 dh5_free(wps->dh_ctx);
1185 wpabuf_free(wps->dh_pubkey);
1186 wpabuf_free(wps->dh_privkey);
1187 wps->dh_privkey = wpabuf_dup(
1188 wpa_s->parent->conf->wps_nfc_dh_privkey);
1189 wps->dh_pubkey = wpabuf_dup(
1190 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1191 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1193 wpabuf_free(wps->dh_pubkey);
1194 wps->dh_pubkey = NULL;
1195 wpabuf_free(wps->dh_privkey);
1196 wps->dh_privkey = NULL;
1199 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1200 if (wps->dh_ctx == NULL)
1203 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1205 pw ? wpabuf_head(pw) : NULL,
1206 pw ? wpabuf_len(pw) : 0, 1);
1208 #endif /* CONFIG_WPS_NFC */