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;
103 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
105 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
107 conf->secondary_channel =
108 wpas_p2p_get_ht40_mode(wpa_s, mode,
110 if (conf->secondary_channel)
112 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
113 #endif /* CONFIG_P2P */
116 * white-list capabilities that won't cause issues
117 * to connecting stations, while leaving the current
118 * capabilities intact (currently disabled SMPS).
120 conf->ht_capab |= mode->ht_capab &
121 (HT_CAP_INFO_GREEN_FIELD |
122 HT_CAP_INFO_SHORT_GI20MHZ |
123 HT_CAP_INFO_SHORT_GI40MHZ |
124 HT_CAP_INFO_RX_STBC_MASK |
125 HT_CAP_INFO_MAX_AMSDU_SIZE);
128 #endif /* CONFIG_IEEE80211N */
131 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
132 /* Remove 802.11b rates from supported and basic rate sets */
133 int *list = os_malloc(4 * sizeof(int));
140 conf->basic_rates = list;
142 list = os_malloc(9 * sizeof(int));
154 conf->supported_rates = list;
157 bss->isolate = !wpa_s->conf->p2p_intra_bss;
158 #endif /* CONFIG_P2P */
160 if (ssid->ssid_len == 0) {
161 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
164 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
165 bss->ssid.ssid_len = ssid->ssid_len;
166 bss->ssid.ssid_set = 1;
168 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
171 bss->auth_algs = ssid->auth_alg;
173 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
174 bss->wpa = ssid->proto;
175 bss->wpa_key_mgmt = ssid->key_mgmt;
176 bss->wpa_pairwise = ssid->pairwise_cipher;
177 if (ssid->passphrase) {
178 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
179 } else if (ssid->psk_set) {
180 os_free(bss->ssid.wpa_psk);
181 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
182 if (bss->ssid.wpa_psk == NULL)
184 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
185 bss->ssid.wpa_psk->group = 1;
186 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
187 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
188 struct hostapd_wep_keys *wep = &bss->ssid.wep;
190 for (i = 0; i < NUM_WEP_KEYS; i++) {
191 if (ssid->wep_key_len[i] == 0)
193 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
194 if (wep->key[i] == NULL)
196 os_memcpy(wep->key[i], ssid->wep_key[i],
197 ssid->wep_key_len[i]);
198 wep->len[i] = ssid->wep_key_len[i];
200 wep->idx = ssid->wep_tx_keyidx;
204 if (ssid->ap_max_inactivity)
205 bss->ap_max_inactivity = ssid->ap_max_inactivity;
207 if (ssid->dtim_period)
208 bss->dtim_period = ssid->dtim_period;
210 /* Select group cipher based on the enabled pairwise cipher suites */
213 pairwise |= bss->wpa_pairwise;
215 if (bss->rsn_pairwise == 0)
216 bss->rsn_pairwise = bss->wpa_pairwise;
217 pairwise |= bss->rsn_pairwise;
219 if (pairwise & WPA_CIPHER_TKIP)
220 bss->wpa_group = WPA_CIPHER_TKIP;
221 else if ((pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ==
223 bss->wpa_group = WPA_CIPHER_GCMP;
225 bss->wpa_group = WPA_CIPHER_CCMP;
227 if (bss->wpa && bss->ieee802_1x)
228 bss->ssid.security_policy = SECURITY_WPA;
230 bss->ssid.security_policy = SECURITY_WPA_PSK;
231 else if (bss->ieee802_1x) {
232 int cipher = WPA_CIPHER_NONE;
233 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
234 bss->ssid.wep.default_len = bss->default_wep_key_len;
235 if (bss->default_wep_key_len)
236 cipher = bss->default_wep_key_len >= 13 ?
237 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
238 bss->wpa_group = cipher;
239 bss->wpa_pairwise = cipher;
240 bss->rsn_pairwise = cipher;
241 } else if (bss->ssid.wep.keys_set) {
242 int cipher = WPA_CIPHER_WEP40;
243 if (bss->ssid.wep.len[0] >= 13)
244 cipher = WPA_CIPHER_WEP104;
245 bss->ssid.security_policy = SECURITY_STATIC_WEP;
246 bss->wpa_group = cipher;
247 bss->wpa_pairwise = cipher;
248 bss->rsn_pairwise = cipher;
250 bss->ssid.security_policy = SECURITY_PLAINTEXT;
251 bss->wpa_group = WPA_CIPHER_NONE;
252 bss->wpa_pairwise = WPA_CIPHER_NONE;
253 bss->rsn_pairwise = WPA_CIPHER_NONE;
258 * Enable WPS by default for open and WPA/WPA2-Personal network, but
259 * require user interaction to actually use it. Only the internal
260 * Registrar is supported.
262 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
263 bss->ssid.security_policy != SECURITY_PLAINTEXT)
266 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
267 (!(pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
268 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
270 #endif /* CONFIG_WPS2 */
273 if (!ssid->ignore_broadcast_ssid)
276 bss->ap_setup_locked = 2;
277 if (wpa_s->conf->config_methods)
278 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
279 os_memcpy(bss->device_type, wpa_s->conf->device_type,
281 if (wpa_s->conf->device_name) {
282 bss->device_name = os_strdup(wpa_s->conf->device_name);
283 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
285 if (wpa_s->conf->manufacturer)
286 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
287 if (wpa_s->conf->model_name)
288 bss->model_name = os_strdup(wpa_s->conf->model_name);
289 if (wpa_s->conf->model_number)
290 bss->model_number = os_strdup(wpa_s->conf->model_number);
291 if (wpa_s->conf->serial_number)
292 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
293 if (is_nil_uuid(wpa_s->conf->uuid))
294 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
296 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
297 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
298 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
300 #endif /* CONFIG_WPS */
302 if (wpa_s->max_stations &&
303 wpa_s->max_stations < wpa_s->conf->max_num_sta)
304 bss->max_num_sta = wpa_s->max_stations;
306 bss->max_num_sta = wpa_s->conf->max_num_sta;
308 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
314 static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
317 struct wpa_supplicant *wpa_s = ctx;
318 const struct ieee80211_mgmt *mgmt;
321 mgmt = (const struct ieee80211_mgmt *) buf;
322 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
325 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
326 mgmt->u.action.category,
327 &mgmt->u.action.u.vs_public_action.action,
328 len - hdr_len, freq);
329 #endif /* CONFIG_P2P */
333 static void ap_wps_event_cb(void *ctx, enum wps_event event,
334 union wps_event_data *data)
337 struct wpa_supplicant *wpa_s = ctx;
339 if (event == WPS_EV_FAIL) {
340 struct wps_event_fail *fail = &data->fail;
342 if (wpa_s->parent && wpa_s->parent != wpa_s &&
343 wpa_s == wpa_s->global->p2p_group_formation) {
345 * src/ap/wps_hostapd.c has already sent this on the
346 * main interface, so only send on the parent interface
349 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
350 "msg=%d config_error=%d",
351 fail->msg, fail->config_error);
353 wpas_p2p_wps_failed(wpa_s, fail);
355 #endif /* CONFIG_P2P */
359 static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
360 int authorized, const u8 *p2p_dev_addr)
362 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
366 static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
369 struct wpa_supplicant *wpa_s = ctx;
370 const struct ieee80211_mgmt *mgmt;
373 mgmt = (const struct ieee80211_mgmt *) buf;
374 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
377 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
378 mgmt->u.action.category,
379 &mgmt->u.action.u.vs_public_action.action,
380 len - hdr_len, freq);
381 #endif /* CONFIG_P2P */
386 static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
387 const u8 *bssid, const u8 *ie, size_t ie_len,
391 struct wpa_supplicant *wpa_s = ctx;
392 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
394 #else /* CONFIG_P2P */
396 #endif /* CONFIG_P2P */
400 static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
404 struct wpa_supplicant *wpa_s = ctx;
405 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
406 #endif /* CONFIG_P2P */
410 static void wpas_ap_configured_cb(void *ctx)
412 struct wpa_supplicant *wpa_s = ctx;
414 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
416 if (wpa_s->ap_configured_cb)
417 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
418 wpa_s->ap_configured_cb_data);
422 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
423 struct wpa_ssid *ssid)
425 struct wpa_driver_associate_params params;
426 struct hostapd_iface *hapd_iface;
427 struct hostapd_config *conf;
430 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
431 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
435 wpa_supplicant_ap_deinit(wpa_s);
437 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
438 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
440 os_memset(¶ms, 0, sizeof(params));
441 params.ssid = ssid->ssid;
442 params.ssid_len = ssid->ssid_len;
443 switch (ssid->mode) {
444 case WPAS_MODE_INFRA:
445 params.mode = IEEE80211_MODE_INFRA;
448 params.mode = IEEE80211_MODE_IBSS;
451 case WPAS_MODE_P2P_GO:
452 case WPAS_MODE_P2P_GROUP_FORMATION:
453 params.mode = IEEE80211_MODE_AP;
456 params.freq = ssid->frequency;
458 params.wpa_proto = ssid->proto;
459 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
460 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
462 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
463 params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
465 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
466 wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
467 else if (ssid->pairwise_cipher & WPA_CIPHER_GCMP)
468 wpa_s->pairwise_cipher = WPA_CIPHER_GCMP;
469 else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
470 wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
471 else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
472 wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
474 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
478 params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
479 params.group_suite = params.pairwise_suite;
482 if (ssid->mode == WPAS_MODE_P2P_GO ||
483 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
485 #endif /* CONFIG_P2P */
487 if (wpa_s->parent->set_ap_uapsd)
488 params.uapsd = wpa_s->parent->ap_uapsd;
492 if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
493 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
497 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
498 if (hapd_iface == NULL)
500 hapd_iface->owner = wpa_s;
501 hapd_iface->drv_flags = wpa_s->drv_flags;
502 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
504 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
506 wpa_supplicant_ap_deinit(wpa_s);
510 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
511 wpa_s->conf->wmm_ac_params,
512 sizeof(wpa_s->conf->wmm_ac_params));
514 if (params.uapsd > 0) {
515 conf->bss->wmm_enabled = 1;
516 conf->bss->wmm_uapsd = 1;
519 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
520 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
521 wpa_supplicant_ap_deinit(wpa_s);
526 if (ssid->mode == WPAS_MODE_P2P_GO)
527 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
528 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
529 conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
531 #endif /* CONFIG_P2P */
533 hapd_iface->num_bss = conf->num_bss;
534 hapd_iface->bss = os_calloc(conf->num_bss,
535 sizeof(struct hostapd_data *));
536 if (hapd_iface->bss == NULL) {
537 wpa_supplicant_ap_deinit(wpa_s);
541 for (i = 0; i < conf->num_bss; i++) {
543 hostapd_alloc_bss_data(hapd_iface, conf,
545 if (hapd_iface->bss[i] == NULL) {
546 wpa_supplicant_ap_deinit(wpa_s);
550 hapd_iface->bss[i]->msg_ctx = wpa_s;
551 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
552 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
553 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
554 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
555 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
556 hostapd_register_probereq_cb(hapd_iface->bss[i],
557 ap_probe_req_rx, wpa_s);
558 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
559 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
560 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
561 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
562 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
563 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
565 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
566 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
568 #endif /* CONFIG_P2P */
569 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
570 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
573 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
574 hapd_iface->bss[0]->driver = wpa_s->driver;
575 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
577 wpa_s->current_ssid = ssid;
578 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
579 wpa_s->assoc_freq = ssid->frequency;
581 if (hostapd_setup_interface(wpa_s->ap_iface)) {
582 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
583 wpa_supplicant_ap_deinit(wpa_s);
591 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
594 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
595 #endif /* CONFIG_WPS */
597 if (wpa_s->ap_iface == NULL)
600 wpa_s->current_ssid = NULL;
601 wpa_s->assoc_freq = 0;
602 wpa_s->reassociated_connection = 0;
604 if (wpa_s->ap_iface->bss)
605 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
606 wpas_p2p_group_deinit(wpa_s);
607 #endif /* CONFIG_P2P */
608 hostapd_interface_deinit(wpa_s->ap_iface);
609 hostapd_interface_free(wpa_s->ap_iface);
610 wpa_s->ap_iface = NULL;
611 wpa_drv_deinit_ap(wpa_s);
615 void ap_tx_status(void *ctx, const u8 *addr,
616 const u8 *buf, size_t len, int ack)
619 struct wpa_supplicant *wpa_s = ctx;
620 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
621 #endif /* NEED_AP_MLME */
625 void ap_eapol_tx_status(void *ctx, const u8 *dst,
626 const u8 *data, size_t len, int ack)
629 struct wpa_supplicant *wpa_s = ctx;
630 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
631 #endif /* NEED_AP_MLME */
635 void ap_client_poll_ok(void *ctx, const u8 *addr)
638 struct wpa_supplicant *wpa_s = ctx;
640 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
641 #endif /* NEED_AP_MLME */
645 void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
648 struct wpa_supplicant *wpa_s = ctx;
649 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
650 #endif /* NEED_AP_MLME */
654 void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
657 struct wpa_supplicant *wpa_s = ctx;
658 struct hostapd_frame_info fi;
659 os_memset(&fi, 0, sizeof(fi));
660 fi.datarate = rx_mgmt->datarate;
661 fi.ssi_signal = rx_mgmt->ssi_signal;
662 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
663 rx_mgmt->frame_len, &fi);
664 #endif /* NEED_AP_MLME */
668 void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
671 struct wpa_supplicant *wpa_s = ctx;
672 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
673 #endif /* NEED_AP_MLME */
677 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
678 const u8 *src_addr, const u8 *buf, size_t len)
680 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
686 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
687 const u8 *p2p_dev_addr)
689 if (!wpa_s->ap_iface)
691 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
696 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
698 struct wps_registrar *reg;
699 int reg_sel = 0, wps_sta = 0;
701 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
704 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
705 reg_sel = wps_registrar_wps_cancel(reg);
706 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
707 ap_sta_wps_cancel, NULL);
709 if (!reg_sel && !wps_sta) {
710 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
716 * There are 2 cases to return wps cancel as success:
717 * 1. When wps cancel was initiated but no connection has been
718 * established with client yet.
719 * 2. Client is in the middle of exchanging WPS messages.
726 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
727 const char *pin, char *buf, size_t buflen)
729 int ret, ret_len = 0;
731 if (!wpa_s->ap_iface)
735 unsigned int rpin = wps_generate_pin();
736 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
739 ret_len = os_snprintf(buf, buflen, "%s", pin);
741 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
749 static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
751 struct wpa_supplicant *wpa_s = eloop_data;
752 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
753 wpas_wps_ap_pin_disable(wpa_s);
757 static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
759 struct hostapd_data *hapd;
761 if (wpa_s->ap_iface == NULL)
763 hapd = wpa_s->ap_iface->bss[0];
764 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
765 hapd->ap_pin_failures = 0;
766 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
768 eloop_register_timeout(timeout, 0,
769 wpas_wps_ap_pin_timeout, wpa_s, NULL);
773 void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
775 struct hostapd_data *hapd;
777 if (wpa_s->ap_iface == NULL)
779 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
780 hapd = wpa_s->ap_iface->bss[0];
781 os_free(hapd->conf->ap_pin);
782 hapd->conf->ap_pin = NULL;
783 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
787 const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
789 struct hostapd_data *hapd;
793 if (wpa_s->ap_iface == NULL)
795 hapd = wpa_s->ap_iface->bss[0];
796 pin = wps_generate_pin();
797 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
798 os_free(hapd->conf->ap_pin);
799 hapd->conf->ap_pin = os_strdup(pin_txt);
800 if (hapd->conf->ap_pin == NULL)
802 wpas_wps_ap_pin_enable(wpa_s, timeout);
804 return hapd->conf->ap_pin;
808 const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
810 struct hostapd_data *hapd;
811 if (wpa_s->ap_iface == NULL)
813 hapd = wpa_s->ap_iface->bss[0];
814 return hapd->conf->ap_pin;
818 int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
821 struct hostapd_data *hapd;
825 if (wpa_s->ap_iface == NULL)
827 hapd = wpa_s->ap_iface->bss[0];
828 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
829 if (ret < 0 || ret >= (int) sizeof(pin_txt))
831 os_free(hapd->conf->ap_pin);
832 hapd->conf->ap_pin = os_strdup(pin_txt);
833 if (hapd->conf->ap_pin == NULL)
835 wpas_wps_ap_pin_enable(wpa_s, timeout);
841 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
843 struct hostapd_data *hapd;
845 if (wpa_s->ap_iface == NULL)
847 hapd = wpa_s->ap_iface->bss[0];
850 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
851 * PIN if this happens multiple times to slow down brute force attacks.
853 hapd->ap_pin_failures++;
854 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
855 hapd->ap_pin_failures);
856 if (hapd->ap_pin_failures < 3)
859 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
860 hapd->ap_pin_failures = 0;
861 os_free(hapd->conf->ap_pin);
862 hapd->conf->ap_pin = NULL;
865 #endif /* CONFIG_WPS */
868 #ifdef CONFIG_CTRL_IFACE
870 int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
871 char *buf, size_t buflen)
873 if (wpa_s->ap_iface == NULL)
875 return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
880 int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
881 char *buf, size_t buflen)
883 if (wpa_s->ap_iface == NULL)
885 return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
890 int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
891 char *buf, size_t buflen)
893 if (wpa_s->ap_iface == NULL)
895 return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
900 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
903 if (wpa_s->ap_iface == NULL)
905 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
910 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
913 if (wpa_s->ap_iface == NULL)
915 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
920 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
921 size_t buflen, int verbose)
923 char *pos = buf, *end = buf + buflen;
925 struct hostapd_bss_config *conf;
927 if (wpa_s->ap_iface == NULL)
930 conf = wpa_s->ap_iface->bss[0]->conf;
934 ret = os_snprintf(pos, end - pos,
935 "pairwise_cipher=%s\n"
938 wpa_cipher_txt(conf->rsn_pairwise),
939 wpa_cipher_txt(conf->wpa_group),
940 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
942 if (ret < 0 || ret >= end - pos)
948 #endif /* CONFIG_CTRL_IFACE */
951 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
953 struct hostapd_iface *iface = wpa_s->ap_iface;
954 struct wpa_ssid *ssid = wpa_s->current_ssid;
955 struct hostapd_data *hapd;
957 if (ssid == NULL || wpa_s->ap_iface == NULL ||
958 ssid->mode == WPAS_MODE_INFRA ||
959 ssid->mode == WPAS_MODE_IBSS)
963 if (ssid->mode == WPAS_MODE_P2P_GO)
964 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
965 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
966 iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
968 #endif /* CONFIG_P2P */
970 hapd = iface->bss[0];
971 if (hapd->drv_priv == NULL)
973 ieee802_11_set_beacons(iface);
974 hostapd_set_ap_wps_ie(hapd);
980 void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
983 if (!wpa_s->ap_iface)
986 wpa_s->assoc_freq = freq;
987 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset);
991 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
994 struct hostapd_data *hapd;
995 struct hostapd_bss_config *conf;
997 if (!wpa_s->ap_iface)
1001 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1004 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1006 hapd = wpa_s->ap_iface->bss[0];
1009 os_free(conf->accept_mac);
1010 conf->accept_mac = NULL;
1011 conf->num_accept_mac = 0;
1012 os_free(conf->deny_mac);
1013 conf->deny_mac = NULL;
1014 conf->num_deny_mac = 0;
1017 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1021 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1022 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1023 if (conf->accept_mac == NULL)
1025 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1026 conf->num_accept_mac = 1;