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
];
91 if (mode
&& mode
->ht_capab
) {
95 * white-list capabilities that won't cause issues
96 * to connecting stations, while leaving the current
97 * capabilities intact (currently disabled SMPS).
99 conf
->ht_capab
|= mode
->ht_capab
&
100 (HT_CAP_INFO_GREEN_FIELD
|
101 HT_CAP_INFO_SHORT_GI20MHZ
|
102 HT_CAP_INFO_SHORT_GI40MHZ
|
103 HT_CAP_INFO_RX_STBC_MASK
|
104 HT_CAP_INFO_MAX_AMSDU_SIZE
);
107 #endif /* CONFIG_IEEE80211N */
110 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
) {
111 /* Remove 802.11b rates from supported and basic rate sets */
112 int *list
= os_malloc(4 * sizeof(int));
119 conf
->basic_rates
= list
;
121 list
= os_malloc(9 * sizeof(int));
133 conf
->supported_rates
= list
;
136 bss
->isolate
= !wpa_s
->conf
->p2p_intra_bss
;
137 #endif /* CONFIG_P2P */
139 if (ssid
->ssid_len
== 0) {
140 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
143 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
144 bss
->ssid
.ssid
[ssid
->ssid_len
] = '\0';
145 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
146 bss
->ssid
.ssid_set
= 1;
149 bss
->auth_algs
= ssid
->auth_alg
;
151 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
152 bss
->wpa
= ssid
->proto
;
153 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
154 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
155 if (ssid
->passphrase
) {
156 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
157 } else if (ssid
->psk_set
) {
158 os_free(bss
->ssid
.wpa_psk
);
159 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
160 if (bss
->ssid
.wpa_psk
== NULL
)
162 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
163 bss
->ssid
.wpa_psk
->group
= 1;
164 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
165 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
166 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
168 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
169 if (ssid
->wep_key_len
[i
] == 0)
171 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
172 if (wep
->key
[i
] == NULL
)
174 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
175 ssid
->wep_key_len
[i
]);
176 wep
->len
[i
] = ssid
->wep_key_len
[i
];
178 wep
->idx
= ssid
->wep_tx_keyidx
;
182 /* Select group cipher based on the enabled pairwise cipher suites */
185 pairwise
|= bss
->wpa_pairwise
;
187 if (bss
->rsn_pairwise
== 0)
188 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
189 pairwise
|= bss
->rsn_pairwise
;
191 if (pairwise
& WPA_CIPHER_TKIP
)
192 bss
->wpa_group
= WPA_CIPHER_TKIP
;
194 bss
->wpa_group
= WPA_CIPHER_CCMP
;
196 if (bss
->wpa
&& bss
->ieee802_1x
)
197 bss
->ssid
.security_policy
= SECURITY_WPA
;
199 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
200 else if (bss
->ieee802_1x
) {
201 int cipher
= WPA_CIPHER_NONE
;
202 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
203 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
204 if (bss
->default_wep_key_len
)
205 cipher
= bss
->default_wep_key_len
>= 13 ?
206 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
207 bss
->wpa_group
= cipher
;
208 bss
->wpa_pairwise
= cipher
;
209 bss
->rsn_pairwise
= cipher
;
210 } else if (bss
->ssid
.wep
.keys_set
) {
211 int cipher
= WPA_CIPHER_WEP40
;
212 if (bss
->ssid
.wep
.len
[0] >= 13)
213 cipher
= WPA_CIPHER_WEP104
;
214 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
215 bss
->wpa_group
= cipher
;
216 bss
->wpa_pairwise
= cipher
;
217 bss
->rsn_pairwise
= cipher
;
219 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
220 bss
->wpa_group
= WPA_CIPHER_NONE
;
221 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
222 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
227 * Enable WPS by default for open and WPA/WPA2-Personal network, but
228 * require user interaction to actually use it. Only the internal
229 * Registrar is supported.
231 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
232 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
235 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
236 (!(pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
237 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
239 #endif /* CONFIG_WPS2 */
242 bss
->ap_setup_locked
= 2;
243 if (wpa_s
->conf
->config_methods
)
244 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
245 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
247 if (wpa_s
->conf
->device_name
) {
248 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
249 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
251 if (wpa_s
->conf
->manufacturer
)
252 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
253 if (wpa_s
->conf
->model_name
)
254 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
255 if (wpa_s
->conf
->model_number
)
256 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
257 if (wpa_s
->conf
->serial_number
)
258 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
259 if (is_nil_uuid(wpa_s
->conf
->uuid
))
260 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
262 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
263 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
265 #endif /* CONFIG_WPS */
267 if (wpa_s
->max_stations
&&
268 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
269 bss
->max_num_sta
= wpa_s
->max_stations
;
271 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
273 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
279 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
282 struct wpa_supplicant
*wpa_s
= ctx
;
283 const struct ieee80211_mgmt
*mgmt
;
286 mgmt
= (const struct ieee80211_mgmt
*) buf
;
287 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
290 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
291 mgmt
->u
.action
.category
,
292 &mgmt
->u
.action
.u
.vs_public_action
.action
,
293 len
- hdr_len
, freq
);
294 #endif /* CONFIG_P2P */
298 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
299 union wps_event_data
*data
)
302 struct wpa_supplicant
*wpa_s
= ctx
;
304 if (event
== WPS_EV_FAIL
) {
305 struct wps_event_fail
*fail
= &data
->fail
;
307 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
308 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
310 * src/ap/wps_hostapd.c has already sent this on the
311 * main interface, so only send on the parent interface
314 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
315 "msg=%d config_error=%d",
316 fail
->msg
, fail
->config_error
);
318 wpas_p2p_wps_failed(wpa_s
, fail
);
320 #endif /* CONFIG_P2P */
324 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
325 int authorized
, const u8
*p2p_dev_addr
)
327 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
331 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
334 struct wpa_supplicant
*wpa_s
= ctx
;
335 const struct ieee80211_mgmt
*mgmt
;
338 mgmt
= (const struct ieee80211_mgmt
*) buf
;
339 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
342 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
343 mgmt
->u
.action
.category
,
344 &mgmt
->u
.action
.u
.vs_public_action
.action
,
345 len
- hdr_len
, freq
);
346 #endif /* CONFIG_P2P */
351 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
352 const u8
*bssid
, const u8
*ie
, size_t ie_len
)
355 struct wpa_supplicant
*wpa_s
= ctx
;
356 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
);
357 #else /* CONFIG_P2P */
359 #endif /* CONFIG_P2P */
363 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
367 struct wpa_supplicant
*wpa_s
= ctx
;
368 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
369 #endif /* CONFIG_P2P */
373 static void wpas_ap_configured_cb(void *ctx
)
375 struct wpa_supplicant
*wpa_s
= ctx
;
377 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
379 if (wpa_s
->ap_configured_cb
)
380 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
381 wpa_s
->ap_configured_cb_data
);
385 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
386 struct wpa_ssid
*ssid
)
388 struct wpa_driver_associate_params params
;
389 struct hostapd_iface
*hapd_iface
;
390 struct hostapd_config
*conf
;
393 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
394 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
398 wpa_supplicant_ap_deinit(wpa_s
);
400 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
401 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
403 os_memset(¶ms
, 0, sizeof(params
));
404 params
.ssid
= ssid
->ssid
;
405 params
.ssid_len
= ssid
->ssid_len
;
406 switch (ssid
->mode
) {
407 case WPAS_MODE_INFRA
:
408 params
.mode
= IEEE80211_MODE_INFRA
;
411 params
.mode
= IEEE80211_MODE_IBSS
;
414 case WPAS_MODE_P2P_GO
:
415 case WPAS_MODE_P2P_GROUP_FORMATION
:
416 params
.mode
= IEEE80211_MODE_AP
;
419 params
.freq
= ssid
->frequency
;
421 params
.wpa_proto
= ssid
->proto
;
422 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
423 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
425 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
426 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
428 if (ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
)
429 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
430 else if (ssid
->pairwise_cipher
& WPA_CIPHER_TKIP
)
431 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
432 else if (ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)
433 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
435 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
439 params
.pairwise_suite
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
440 params
.group_suite
= params
.pairwise_suite
;
443 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
444 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
446 #endif /* CONFIG_P2P */
448 if (wpa_s
->parent
->set_ap_uapsd
)
449 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
453 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
454 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
458 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
459 if (hapd_iface
== NULL
)
461 hapd_iface
->owner
= wpa_s
;
462 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
463 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
465 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
467 wpa_supplicant_ap_deinit(wpa_s
);
471 if (params
.uapsd
> 0) {
472 conf
->bss
->wmm_enabled
= 1;
473 conf
->bss
->wmm_uapsd
= 1;
476 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
477 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
478 wpa_supplicant_ap_deinit(wpa_s
);
483 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
484 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
485 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
486 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
488 #endif /* CONFIG_P2P */
490 hapd_iface
->num_bss
= conf
->num_bss
;
491 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
492 sizeof(struct hostapd_data
*));
493 if (hapd_iface
->bss
== NULL
) {
494 wpa_supplicant_ap_deinit(wpa_s
);
498 for (i
= 0; i
< conf
->num_bss
; i
++) {
500 hostapd_alloc_bss_data(hapd_iface
, conf
,
502 if (hapd_iface
->bss
[i
] == NULL
) {
503 wpa_supplicant_ap_deinit(wpa_s
);
507 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
508 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
509 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
510 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
511 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
512 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
513 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
514 ap_probe_req_rx
, wpa_s
);
515 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
516 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
517 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
518 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
519 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
520 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
522 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
523 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(
524 wpa_s
, ssid
->p2p_persistent_group
,
525 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
);
526 #endif /* CONFIG_P2P */
527 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
528 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
531 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
532 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
533 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
535 wpa_s
->current_ssid
= ssid
;
536 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
537 wpa_s
->assoc_freq
= ssid
->frequency
;
539 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
540 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
541 wpa_supplicant_ap_deinit(wpa_s
);
549 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
552 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
553 #endif /* CONFIG_WPS */
555 if (wpa_s
->ap_iface
== NULL
)
558 wpa_s
->current_ssid
= NULL
;
559 wpa_s
->assoc_freq
= 0;
560 wpa_s
->reassociated_connection
= 0;
562 if (wpa_s
->ap_iface
->bss
)
563 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
564 wpas_p2p_group_deinit(wpa_s
);
565 #endif /* CONFIG_P2P */
566 hostapd_interface_deinit(wpa_s
->ap_iface
);
567 hostapd_interface_free(wpa_s
->ap_iface
);
568 wpa_s
->ap_iface
= NULL
;
569 wpa_drv_deinit_ap(wpa_s
);
573 void ap_tx_status(void *ctx
, const u8
*addr
,
574 const u8
*buf
, size_t len
, int ack
)
577 struct wpa_supplicant
*wpa_s
= ctx
;
578 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
579 #endif /* NEED_AP_MLME */
583 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
584 const u8
*data
, size_t len
, int ack
)
587 struct wpa_supplicant
*wpa_s
= ctx
;
588 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
589 #endif /* NEED_AP_MLME */
593 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
596 struct wpa_supplicant
*wpa_s
= ctx
;
598 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
599 #endif /* NEED_AP_MLME */
603 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
606 struct wpa_supplicant
*wpa_s
= ctx
;
607 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
608 #endif /* NEED_AP_MLME */
612 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
615 struct wpa_supplicant
*wpa_s
= ctx
;
616 struct hostapd_frame_info fi
;
617 os_memset(&fi
, 0, sizeof(fi
));
618 fi
.datarate
= rx_mgmt
->datarate
;
619 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
620 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
621 rx_mgmt
->frame_len
, &fi
);
622 #endif /* NEED_AP_MLME */
626 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
629 struct wpa_supplicant
*wpa_s
= ctx
;
630 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
631 #endif /* NEED_AP_MLME */
635 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
636 const u8
*src_addr
, const u8
*buf
, size_t len
)
638 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
644 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
645 const u8
*p2p_dev_addr
)
647 if (!wpa_s
->ap_iface
)
649 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
654 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data
*hapd
,
655 struct sta_info
*sta
, void *ctx
)
657 if (sta
&& (sta
->flags
& WLAN_STA_WPS
)) {
658 ap_sta_deauthenticate(hapd
, sta
,
659 WLAN_REASON_PREV_AUTH_NOT_VALID
);
660 wpa_printf(MSG_DEBUG
, "WPS: %s: Deauth sta=" MACSTR
,
661 __func__
, MAC2STR(sta
->addr
));
669 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
671 struct wps_registrar
*reg
;
672 int reg_sel
= 0, wps_sta
= 0;
674 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
677 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
678 reg_sel
= wps_registrar_wps_cancel(reg
);
679 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
680 wpa_supplicant_ap_wps_sta_cancel
, NULL
);
682 if (!reg_sel
&& !wps_sta
) {
683 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
689 * There are 2 cases to return wps cancel as success:
690 * 1. When wps cancel was initiated but no connection has been
691 * established with client yet.
692 * 2. Client is in the middle of exchanging WPS messages.
699 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
700 const char *pin
, char *buf
, size_t buflen
)
702 int ret
, ret_len
= 0;
704 if (!wpa_s
->ap_iface
)
708 unsigned int rpin
= wps_generate_pin();
709 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
712 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
714 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
722 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
724 struct wpa_supplicant
*wpa_s
= eloop_data
;
725 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
726 wpas_wps_ap_pin_disable(wpa_s
);
730 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
732 struct hostapd_data
*hapd
;
734 if (wpa_s
->ap_iface
== NULL
)
736 hapd
= wpa_s
->ap_iface
->bss
[0];
737 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
738 hapd
->ap_pin_failures
= 0;
739 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
741 eloop_register_timeout(timeout
, 0,
742 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
746 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
748 struct hostapd_data
*hapd
;
750 if (wpa_s
->ap_iface
== NULL
)
752 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
753 hapd
= wpa_s
->ap_iface
->bss
[0];
754 os_free(hapd
->conf
->ap_pin
);
755 hapd
->conf
->ap_pin
= NULL
;
756 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
760 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
762 struct hostapd_data
*hapd
;
766 if (wpa_s
->ap_iface
== NULL
)
768 hapd
= wpa_s
->ap_iface
->bss
[0];
769 pin
= wps_generate_pin();
770 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
771 os_free(hapd
->conf
->ap_pin
);
772 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
773 if (hapd
->conf
->ap_pin
== NULL
)
775 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
777 return hapd
->conf
->ap_pin
;
781 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
783 struct hostapd_data
*hapd
;
784 if (wpa_s
->ap_iface
== NULL
)
786 hapd
= wpa_s
->ap_iface
->bss
[0];
787 return hapd
->conf
->ap_pin
;
791 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
794 struct hostapd_data
*hapd
;
798 if (wpa_s
->ap_iface
== NULL
)
800 hapd
= wpa_s
->ap_iface
->bss
[0];
801 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
802 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
804 os_free(hapd
->conf
->ap_pin
);
805 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
806 if (hapd
->conf
->ap_pin
== NULL
)
808 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
814 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
816 struct hostapd_data
*hapd
;
818 if (wpa_s
->ap_iface
== NULL
)
820 hapd
= wpa_s
->ap_iface
->bss
[0];
823 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
824 * PIN if this happens multiple times to slow down brute force attacks.
826 hapd
->ap_pin_failures
++;
827 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
828 hapd
->ap_pin_failures
);
829 if (hapd
->ap_pin_failures
< 3)
832 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
833 hapd
->ap_pin_failures
= 0;
834 os_free(hapd
->conf
->ap_pin
);
835 hapd
->conf
->ap_pin
= NULL
;
838 #endif /* CONFIG_WPS */
841 #ifdef CONFIG_CTRL_IFACE
843 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
844 char *buf
, size_t buflen
)
846 if (wpa_s
->ap_iface
== NULL
)
848 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
853 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
854 char *buf
, size_t buflen
)
856 if (wpa_s
->ap_iface
== NULL
)
858 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
863 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
864 char *buf
, size_t buflen
)
866 if (wpa_s
->ap_iface
== NULL
)
868 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
873 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant
*wpa_s
,
876 if (wpa_s
->ap_iface
== NULL
)
878 return hostapd_ctrl_iface_disassociate(wpa_s
->ap_iface
->bss
[0],
883 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant
*wpa_s
,
886 if (wpa_s
->ap_iface
== NULL
)
888 return hostapd_ctrl_iface_deauthenticate(wpa_s
->ap_iface
->bss
[0],
893 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
894 size_t buflen
, int verbose
)
896 char *pos
= buf
, *end
= buf
+ buflen
;
898 struct hostapd_bss_config
*conf
;
900 if (wpa_s
->ap_iface
== NULL
)
903 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
907 ret
= os_snprintf(pos
, end
- pos
,
908 "pairwise_cipher=%s\n"
911 wpa_cipher_txt(conf
->rsn_pairwise
),
912 wpa_cipher_txt(conf
->wpa_group
),
913 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
915 if (ret
< 0 || ret
>= end
- pos
)
921 #endif /* CONFIG_CTRL_IFACE */
924 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
926 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
927 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
928 struct hostapd_data
*hapd
;
930 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
931 ssid
->mode
== WPAS_MODE_INFRA
||
932 ssid
->mode
== WPAS_MODE_IBSS
)
936 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
937 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
938 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
939 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
941 #endif /* CONFIG_P2P */
943 hapd
= iface
->bss
[0];
944 if (hapd
->drv_priv
== NULL
)
946 ieee802_11_set_beacons(iface
);
947 hostapd_set_ap_wps_ie(hapd
);
953 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
956 struct hostapd_data
*hapd
;
957 struct hostapd_bss_config
*conf
;
959 if (!wpa_s
->ap_iface
)
963 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
966 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
968 hapd
= wpa_s
->ap_iface
->bss
[0];
971 os_free(conf
->accept_mac
);
972 conf
->accept_mac
= NULL
;
973 conf
->num_accept_mac
= 0;
974 os_free(conf
->deny_mac
);
975 conf
->deny_mac
= NULL
;
976 conf
->num_deny_mac
= 0;
979 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
983 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
984 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
985 if (conf
->accept_mac
== NULL
)
987 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
988 conf
->num_accept_mac
= 1;