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 program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
16 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "utils/eloop.h"
20 #include "utils/uuid.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/wpa_ctrl.h"
23 #include "ap/hostapd.h"
24 #include "ap/ap_config.h"
25 #include "ap/ap_drv_ops.h"
27 #include "ap/ieee802_11.h"
28 #endif /* NEED_AP_MLME */
29 #include "ap/beacon.h"
30 #include "ap/ieee802_1x.h"
31 #include "ap/wps_hostapd.h"
32 #include "ap/ctrl_iface_ap.h"
34 #include "common/ieee802_11_defs.h"
35 #include "config_ssid.h"
37 #include "wpa_supplicant_i.h"
39 #include "p2p_supplicant.h"
41 #include "ap/sta_info.h"
46 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
);
47 #endif /* CONFIG_WPS */
50 static int wpa_supplicant_conf_ap(struct wpa_supplicant
*wpa_s
,
51 struct wpa_ssid
*ssid
,
52 struct hostapd_config
*conf
)
54 struct hostapd_bss_config
*bss
= &conf
->bss
[0];
57 conf
->driver
= wpa_s
->driver
;
59 os_strlcpy(bss
->iface
, wpa_s
->ifname
, sizeof(bss
->iface
));
61 if (ssid
->frequency
== 0) {
62 /* default channel 11 */
63 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
65 } else if (ssid
->frequency
>= 2412 && ssid
->frequency
<= 2472) {
66 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
67 conf
->channel
= (ssid
->frequency
- 2407) / 5;
68 } else if ((ssid
->frequency
>= 5180 && ssid
->frequency
<= 5240) ||
69 (ssid
->frequency
>= 5745 && ssid
->frequency
<= 5825)) {
70 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211A
;
71 conf
->channel
= (ssid
->frequency
- 5000) / 5;
73 wpa_printf(MSG_ERROR
, "Unsupported AP mode frequency: %d MHz",
78 /* TODO: enable HT40 if driver supports it;
79 * drop to 11b if driver does not support 11g */
81 #ifdef CONFIG_IEEE80211N
83 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
84 * and a mask of allowed capabilities within conf->ht_capab.
85 * Using default config settings for: conf->ht_op_mode_fixed,
86 * conf->secondary_channel, conf->require_ht
88 if (wpa_s
->hw
.modes
) {
89 struct hostapd_hw_modes
*mode
= NULL
;
91 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
92 if (wpa_s
->hw
.modes
[i
].mode
== conf
->hw_mode
) {
93 mode
= &wpa_s
->hw
.modes
[i
];
97 if (mode
&& mode
->ht_capab
) {
101 * white-list capabilities that won't cause issues
102 * to connecting stations, while leaving the current
103 * capabilities intact (currently disabled SMPS).
105 conf
->ht_capab
|= mode
->ht_capab
&
106 (HT_CAP_INFO_GREEN_FIELD
|
107 HT_CAP_INFO_SHORT_GI20MHZ
|
108 HT_CAP_INFO_SHORT_GI40MHZ
|
109 HT_CAP_INFO_RX_STBC_MASK
|
110 HT_CAP_INFO_MAX_AMSDU_SIZE
);
113 #endif /* CONFIG_IEEE80211N */
116 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
) {
117 /* Remove 802.11b rates from supported and basic rate sets */
118 int *list
= os_malloc(4 * sizeof(int));
125 conf
->basic_rates
= list
;
127 list
= os_malloc(9 * sizeof(int));
139 conf
->supported_rates
= list
;
142 bss
->isolate
= !wpa_s
->conf
->p2p_intra_bss
;
143 #endif /* CONFIG_P2P */
145 if (ssid
->ssid_len
== 0) {
146 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
149 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
150 bss
->ssid
.ssid
[ssid
->ssid_len
] = '\0';
151 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
152 bss
->ssid
.ssid_set
= 1;
155 bss
->auth_algs
= ssid
->auth_alg
;
157 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
158 bss
->wpa
= ssid
->proto
;
159 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
160 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
161 if (ssid
->passphrase
) {
162 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
163 } else if (ssid
->psk_set
) {
164 os_free(bss
->ssid
.wpa_psk
);
165 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
166 if (bss
->ssid
.wpa_psk
== NULL
)
168 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
169 bss
->ssid
.wpa_psk
->group
= 1;
170 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
171 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
172 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
174 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
175 if (ssid
->wep_key_len
[i
] == 0)
177 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
178 if (wep
->key
[i
] == NULL
)
180 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
181 ssid
->wep_key_len
[i
]);
182 wep
->len
[i
] = ssid
->wep_key_len
[i
];
184 wep
->idx
= ssid
->wep_tx_keyidx
;
188 /* Select group cipher based on the enabled pairwise cipher suites */
191 pairwise
|= bss
->wpa_pairwise
;
193 if (bss
->rsn_pairwise
== 0)
194 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
195 pairwise
|= bss
->rsn_pairwise
;
197 if (pairwise
& WPA_CIPHER_TKIP
)
198 bss
->wpa_group
= WPA_CIPHER_TKIP
;
200 bss
->wpa_group
= WPA_CIPHER_CCMP
;
202 if (bss
->wpa
&& bss
->ieee802_1x
)
203 bss
->ssid
.security_policy
= SECURITY_WPA
;
205 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
206 else if (bss
->ieee802_1x
) {
207 int cipher
= WPA_CIPHER_NONE
;
208 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
209 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
210 if (bss
->default_wep_key_len
)
211 cipher
= bss
->default_wep_key_len
>= 13 ?
212 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
213 bss
->wpa_group
= cipher
;
214 bss
->wpa_pairwise
= cipher
;
215 bss
->rsn_pairwise
= cipher
;
216 } else if (bss
->ssid
.wep
.keys_set
) {
217 int cipher
= WPA_CIPHER_WEP40
;
218 if (bss
->ssid
.wep
.len
[0] >= 13)
219 cipher
= WPA_CIPHER_WEP104
;
220 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
221 bss
->wpa_group
= cipher
;
222 bss
->wpa_pairwise
= cipher
;
223 bss
->rsn_pairwise
= cipher
;
225 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
226 bss
->wpa_group
= WPA_CIPHER_NONE
;
227 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
228 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
233 * Enable WPS by default for open and WPA/WPA2-Personal network, but
234 * require user interaction to actually use it. Only the internal
235 * Registrar is supported.
237 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
238 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
241 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
242 (!(pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
243 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
245 #endif /* CONFIG_WPS2 */
248 bss
->ap_setup_locked
= 2;
249 if (wpa_s
->conf
->config_methods
)
250 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
251 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
253 if (wpa_s
->conf
->device_name
) {
254 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
255 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
257 if (wpa_s
->conf
->manufacturer
)
258 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
259 if (wpa_s
->conf
->model_name
)
260 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
261 if (wpa_s
->conf
->model_number
)
262 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
263 if (wpa_s
->conf
->serial_number
)
264 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
265 if (is_nil_uuid(wpa_s
->conf
->uuid
))
266 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
268 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
269 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
271 #endif /* CONFIG_WPS */
273 if (wpa_s
->max_stations
&&
274 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
275 bss
->max_num_sta
= wpa_s
->max_stations
;
277 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
279 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
285 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
288 struct wpa_supplicant
*wpa_s
= ctx
;
289 const struct ieee80211_mgmt
*mgmt
;
292 mgmt
= (const struct ieee80211_mgmt
*) buf
;
293 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
296 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
297 mgmt
->u
.action
.category
,
298 &mgmt
->u
.action
.u
.vs_public_action
.action
,
299 len
- hdr_len
, freq
);
300 #endif /* CONFIG_P2P */
304 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
305 union wps_event_data
*data
)
308 struct wpa_supplicant
*wpa_s
= ctx
;
310 if (event
== WPS_EV_FAIL
) {
311 struct wps_event_fail
*fail
= &data
->fail
;
313 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
314 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
316 * src/ap/wps_hostapd.c has already sent this on the
317 * main interface, so only send on the parent interface
320 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
321 "msg=%d config_error=%d",
322 fail
->msg
, fail
->config_error
);
324 wpas_p2p_wps_failed(wpa_s
, fail
);
326 #endif /* CONFIG_P2P */
330 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
331 int authorized
, const u8
*p2p_dev_addr
)
333 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
337 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
340 struct wpa_supplicant
*wpa_s
= ctx
;
341 const struct ieee80211_mgmt
*mgmt
;
344 mgmt
= (const struct ieee80211_mgmt
*) buf
;
345 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
348 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
349 mgmt
->u
.action
.category
,
350 &mgmt
->u
.action
.u
.vs_public_action
.action
,
351 len
- hdr_len
, freq
);
352 #endif /* CONFIG_P2P */
357 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
358 const u8
*bssid
, const u8
*ie
, size_t ie_len
)
361 struct wpa_supplicant
*wpa_s
= ctx
;
362 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
);
363 #else /* CONFIG_P2P */
365 #endif /* CONFIG_P2P */
369 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
373 struct wpa_supplicant
*wpa_s
= ctx
;
374 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
375 #endif /* CONFIG_P2P */
379 static void wpas_ap_configured_cb(void *ctx
)
381 struct wpa_supplicant
*wpa_s
= ctx
;
383 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
385 if (wpa_s
->ap_configured_cb
)
386 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
387 wpa_s
->ap_configured_cb_data
);
391 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
392 struct wpa_ssid
*ssid
)
394 struct wpa_driver_associate_params params
;
395 struct hostapd_iface
*hapd_iface
;
396 struct hostapd_config
*conf
;
399 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
400 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
404 wpa_supplicant_ap_deinit(wpa_s
);
406 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
407 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
409 os_memset(¶ms
, 0, sizeof(params
));
410 params
.ssid
= ssid
->ssid
;
411 params
.ssid_len
= ssid
->ssid_len
;
412 switch (ssid
->mode
) {
413 case WPAS_MODE_INFRA
:
414 params
.mode
= IEEE80211_MODE_INFRA
;
417 params
.mode
= IEEE80211_MODE_IBSS
;
420 case WPAS_MODE_P2P_GO
:
421 case WPAS_MODE_P2P_GROUP_FORMATION
:
422 params
.mode
= IEEE80211_MODE_AP
;
425 params
.freq
= ssid
->frequency
;
427 params
.wpa_proto
= ssid
->proto
;
428 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
429 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
431 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
432 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
434 if (ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
)
435 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
436 else if (ssid
->pairwise_cipher
& WPA_CIPHER_TKIP
)
437 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
438 else if (ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)
439 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
441 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
445 params
.pairwise_suite
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
446 params
.group_suite
= params
.pairwise_suite
;
449 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
450 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
452 #endif /* CONFIG_P2P */
454 if (wpa_s
->parent
->set_ap_uapsd
)
455 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
459 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
460 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
464 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
465 if (hapd_iface
== NULL
)
467 hapd_iface
->owner
= wpa_s
;
468 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
469 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
471 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
473 wpa_supplicant_ap_deinit(wpa_s
);
477 if (params
.uapsd
> 0) {
478 conf
->bss
->wmm_enabled
= 1;
479 conf
->bss
->wmm_uapsd
= 1;
482 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
483 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
484 wpa_supplicant_ap_deinit(wpa_s
);
489 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
490 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
491 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
492 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
494 #endif /* CONFIG_P2P */
496 hapd_iface
->num_bss
= conf
->num_bss
;
497 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
498 sizeof(struct hostapd_data
*));
499 if (hapd_iface
->bss
== NULL
) {
500 wpa_supplicant_ap_deinit(wpa_s
);
504 for (i
= 0; i
< conf
->num_bss
; i
++) {
506 hostapd_alloc_bss_data(hapd_iface
, conf
,
508 if (hapd_iface
->bss
[i
] == NULL
) {
509 wpa_supplicant_ap_deinit(wpa_s
);
513 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
514 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
515 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
516 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
517 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
518 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
519 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
520 ap_probe_req_rx
, wpa_s
);
521 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
522 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
523 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
524 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
525 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
526 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
528 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
529 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(
530 wpa_s
, ssid
->p2p_persistent_group
,
531 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
);
532 #endif /* CONFIG_P2P */
533 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
534 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
537 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
538 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
539 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
541 wpa_s
->current_ssid
= ssid
;
542 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
543 wpa_s
->assoc_freq
= ssid
->frequency
;
545 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
546 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
547 wpa_supplicant_ap_deinit(wpa_s
);
555 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
558 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
559 #endif /* CONFIG_WPS */
561 if (wpa_s
->ap_iface
== NULL
)
564 wpa_s
->current_ssid
= NULL
;
565 wpa_s
->assoc_freq
= 0;
566 wpa_s
->reassociated_connection
= 0;
568 if (wpa_s
->ap_iface
->bss
)
569 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
570 wpas_p2p_group_deinit(wpa_s
);
571 #endif /* CONFIG_P2P */
572 hostapd_interface_deinit(wpa_s
->ap_iface
);
573 hostapd_interface_free(wpa_s
->ap_iface
);
574 wpa_s
->ap_iface
= NULL
;
575 wpa_drv_deinit_ap(wpa_s
);
579 void ap_tx_status(void *ctx
, const u8
*addr
,
580 const u8
*buf
, size_t len
, int ack
)
583 struct wpa_supplicant
*wpa_s
= ctx
;
584 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
585 #endif /* NEED_AP_MLME */
589 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
590 const u8
*data
, size_t len
, int ack
)
593 struct wpa_supplicant
*wpa_s
= ctx
;
594 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
595 #endif /* NEED_AP_MLME */
599 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
602 struct wpa_supplicant
*wpa_s
= ctx
;
604 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
605 #endif /* NEED_AP_MLME */
609 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
612 struct wpa_supplicant
*wpa_s
= ctx
;
613 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
614 #endif /* NEED_AP_MLME */
618 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
621 struct wpa_supplicant
*wpa_s
= ctx
;
622 struct hostapd_frame_info fi
;
623 os_memset(&fi
, 0, sizeof(fi
));
624 fi
.datarate
= rx_mgmt
->datarate
;
625 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
626 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
627 rx_mgmt
->frame_len
, &fi
);
628 #endif /* NEED_AP_MLME */
632 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
635 struct wpa_supplicant
*wpa_s
= ctx
;
636 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
637 #endif /* NEED_AP_MLME */
641 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
642 const u8
*src_addr
, const u8
*buf
, size_t len
)
644 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
650 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
651 const u8
*p2p_dev_addr
)
653 if (!wpa_s
->ap_iface
)
655 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
660 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data
*hapd
,
661 struct sta_info
*sta
, void *ctx
)
663 if (sta
&& (sta
->flags
& WLAN_STA_WPS
)) {
664 ap_sta_deauthenticate(hapd
, sta
,
665 WLAN_REASON_PREV_AUTH_NOT_VALID
);
666 wpa_printf(MSG_DEBUG
, "WPS: %s: Deauth sta=" MACSTR
,
667 __func__
, MAC2STR(sta
->addr
));
675 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
677 struct wps_registrar
*reg
;
678 int reg_sel
= 0, wps_sta
= 0;
680 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
683 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
684 reg_sel
= wps_registrar_wps_cancel(reg
);
685 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
686 wpa_supplicant_ap_wps_sta_cancel
, NULL
);
688 if (!reg_sel
&& !wps_sta
) {
689 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
695 * There are 2 cases to return wps cancel as success:
696 * 1. When wps cancel was initiated but no connection has been
697 * established with client yet.
698 * 2. Client is in the middle of exchanging WPS messages.
705 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
706 const char *pin
, char *buf
, size_t buflen
)
708 int ret
, ret_len
= 0;
710 if (!wpa_s
->ap_iface
)
714 unsigned int rpin
= wps_generate_pin();
715 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
718 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
720 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
728 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
730 struct wpa_supplicant
*wpa_s
= eloop_data
;
731 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
732 wpas_wps_ap_pin_disable(wpa_s
);
736 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
738 struct hostapd_data
*hapd
;
740 if (wpa_s
->ap_iface
== NULL
)
742 hapd
= wpa_s
->ap_iface
->bss
[0];
743 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
744 hapd
->ap_pin_failures
= 0;
745 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
747 eloop_register_timeout(timeout
, 0,
748 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
752 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
754 struct hostapd_data
*hapd
;
756 if (wpa_s
->ap_iface
== NULL
)
758 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
759 hapd
= wpa_s
->ap_iface
->bss
[0];
760 os_free(hapd
->conf
->ap_pin
);
761 hapd
->conf
->ap_pin
= NULL
;
762 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
766 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
768 struct hostapd_data
*hapd
;
772 if (wpa_s
->ap_iface
== NULL
)
774 hapd
= wpa_s
->ap_iface
->bss
[0];
775 pin
= wps_generate_pin();
776 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
777 os_free(hapd
->conf
->ap_pin
);
778 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
779 if (hapd
->conf
->ap_pin
== NULL
)
781 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
783 return hapd
->conf
->ap_pin
;
787 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
789 struct hostapd_data
*hapd
;
790 if (wpa_s
->ap_iface
== NULL
)
792 hapd
= wpa_s
->ap_iface
->bss
[0];
793 return hapd
->conf
->ap_pin
;
797 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
800 struct hostapd_data
*hapd
;
804 if (wpa_s
->ap_iface
== NULL
)
806 hapd
= wpa_s
->ap_iface
->bss
[0];
807 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
808 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
810 os_free(hapd
->conf
->ap_pin
);
811 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
812 if (hapd
->conf
->ap_pin
== NULL
)
814 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
820 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
822 struct hostapd_data
*hapd
;
824 if (wpa_s
->ap_iface
== NULL
)
826 hapd
= wpa_s
->ap_iface
->bss
[0];
829 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
830 * PIN if this happens multiple times to slow down brute force attacks.
832 hapd
->ap_pin_failures
++;
833 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
834 hapd
->ap_pin_failures
);
835 if (hapd
->ap_pin_failures
< 3)
838 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
839 hapd
->ap_pin_failures
= 0;
840 os_free(hapd
->conf
->ap_pin
);
841 hapd
->conf
->ap_pin
= NULL
;
844 #endif /* CONFIG_WPS */
847 #ifdef CONFIG_CTRL_IFACE
849 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
850 char *buf
, size_t buflen
)
852 if (wpa_s
->ap_iface
== NULL
)
854 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
859 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
860 char *buf
, size_t buflen
)
862 if (wpa_s
->ap_iface
== NULL
)
864 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
869 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
870 char *buf
, size_t buflen
)
872 if (wpa_s
->ap_iface
== NULL
)
874 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
879 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
880 size_t buflen
, int verbose
)
882 char *pos
= buf
, *end
= buf
+ buflen
;
884 struct hostapd_bss_config
*conf
;
886 if (wpa_s
->ap_iface
== NULL
)
889 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
893 ret
= os_snprintf(pos
, end
- pos
,
894 "pairwise_cipher=%s\n"
897 wpa_cipher_txt(conf
->rsn_pairwise
),
898 wpa_cipher_txt(conf
->wpa_group
),
899 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
901 if (ret
< 0 || ret
>= end
- pos
)
907 #endif /* CONFIG_CTRL_IFACE */
910 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
912 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
913 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
914 struct hostapd_data
*hapd
;
916 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
917 ssid
->mode
== WPAS_MODE_INFRA
||
918 ssid
->mode
== WPAS_MODE_IBSS
)
922 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
923 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
924 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
925 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
927 #endif /* CONFIG_P2P */
929 hapd
= iface
->bss
[0];
930 if (hapd
->drv_priv
== NULL
)
932 ieee802_11_set_beacons(iface
);
933 hostapd_set_ap_wps_ie(hapd
);
939 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
942 struct hostapd_data
*hapd
;
943 struct hostapd_bss_config
*conf
;
945 if (!wpa_s
->ap_iface
)
949 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
952 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
954 hapd
= wpa_s
->ap_iface
->bss
[0];
957 os_free(conf
->accept_mac
);
958 conf
->accept_mac
= NULL
;
959 conf
->num_accept_mac
= 0;
960 os_free(conf
->deny_mac
);
961 conf
->deny_mac
= NULL
;
962 conf
->num_deny_mac
= 0;
965 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
969 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
970 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
971 if (conf
->accept_mac
== NULL
)
973 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
974 conf
->num_accept_mac
= 1;