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;
148 bss
->ignore_broadcast_ssid
= ssid
->ignore_broadcast_ssid
;
151 bss
->auth_algs
= ssid
->auth_alg
;
153 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
154 bss
->wpa
= ssid
->proto
;
155 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
156 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
157 if (ssid
->passphrase
) {
158 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
159 } else if (ssid
->psk_set
) {
160 os_free(bss
->ssid
.wpa_psk
);
161 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
162 if (bss
->ssid
.wpa_psk
== NULL
)
164 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
165 bss
->ssid
.wpa_psk
->group
= 1;
166 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
167 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
168 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
170 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
171 if (ssid
->wep_key_len
[i
] == 0)
173 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
174 if (wep
->key
[i
] == NULL
)
176 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
177 ssid
->wep_key_len
[i
]);
178 wep
->len
[i
] = ssid
->wep_key_len
[i
];
180 wep
->idx
= ssid
->wep_tx_keyidx
;
184 if (ssid
->ap_max_inactivity
)
185 bss
->ap_max_inactivity
= ssid
->ap_max_inactivity
;
187 /* Select group cipher based on the enabled pairwise cipher suites */
190 pairwise
|= bss
->wpa_pairwise
;
192 if (bss
->rsn_pairwise
== 0)
193 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
194 pairwise
|= bss
->rsn_pairwise
;
196 if (pairwise
& WPA_CIPHER_TKIP
)
197 bss
->wpa_group
= WPA_CIPHER_TKIP
;
199 bss
->wpa_group
= WPA_CIPHER_CCMP
;
201 if (bss
->wpa
&& bss
->ieee802_1x
)
202 bss
->ssid
.security_policy
= SECURITY_WPA
;
204 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
205 else if (bss
->ieee802_1x
) {
206 int cipher
= WPA_CIPHER_NONE
;
207 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
208 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
209 if (bss
->default_wep_key_len
)
210 cipher
= bss
->default_wep_key_len
>= 13 ?
211 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
212 bss
->wpa_group
= cipher
;
213 bss
->wpa_pairwise
= cipher
;
214 bss
->rsn_pairwise
= cipher
;
215 } else if (bss
->ssid
.wep
.keys_set
) {
216 int cipher
= WPA_CIPHER_WEP40
;
217 if (bss
->ssid
.wep
.len
[0] >= 13)
218 cipher
= WPA_CIPHER_WEP104
;
219 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
220 bss
->wpa_group
= cipher
;
221 bss
->wpa_pairwise
= cipher
;
222 bss
->rsn_pairwise
= cipher
;
224 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
225 bss
->wpa_group
= WPA_CIPHER_NONE
;
226 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
227 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
232 * Enable WPS by default for open and WPA/WPA2-Personal network, but
233 * require user interaction to actually use it. Only the internal
234 * Registrar is supported.
236 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
237 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
240 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
241 (!(pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
242 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
244 #endif /* CONFIG_WPS2 */
247 if (!ssid
->ignore_broadcast_ssid
)
250 bss
->ap_setup_locked
= 2;
251 if (wpa_s
->conf
->config_methods
)
252 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
253 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
255 if (wpa_s
->conf
->device_name
) {
256 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
257 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
259 if (wpa_s
->conf
->manufacturer
)
260 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
261 if (wpa_s
->conf
->model_name
)
262 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
263 if (wpa_s
->conf
->model_number
)
264 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
265 if (wpa_s
->conf
->serial_number
)
266 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
267 if (is_nil_uuid(wpa_s
->conf
->uuid
))
268 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
270 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
271 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
273 #endif /* CONFIG_WPS */
275 if (wpa_s
->max_stations
&&
276 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
277 bss
->max_num_sta
= wpa_s
->max_stations
;
279 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
281 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
287 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
290 struct wpa_supplicant
*wpa_s
= ctx
;
291 const struct ieee80211_mgmt
*mgmt
;
294 mgmt
= (const struct ieee80211_mgmt
*) buf
;
295 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
298 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
299 mgmt
->u
.action
.category
,
300 &mgmt
->u
.action
.u
.vs_public_action
.action
,
301 len
- hdr_len
, freq
);
302 #endif /* CONFIG_P2P */
306 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
307 union wps_event_data
*data
)
310 struct wpa_supplicant
*wpa_s
= ctx
;
312 if (event
== WPS_EV_FAIL
) {
313 struct wps_event_fail
*fail
= &data
->fail
;
315 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
316 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
318 * src/ap/wps_hostapd.c has already sent this on the
319 * main interface, so only send on the parent interface
322 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
323 "msg=%d config_error=%d",
324 fail
->msg
, fail
->config_error
);
326 wpas_p2p_wps_failed(wpa_s
, fail
);
328 #endif /* CONFIG_P2P */
332 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
333 int authorized
, const u8
*p2p_dev_addr
)
335 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
339 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
342 struct wpa_supplicant
*wpa_s
= ctx
;
343 const struct ieee80211_mgmt
*mgmt
;
346 mgmt
= (const struct ieee80211_mgmt
*) buf
;
347 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
350 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
351 mgmt
->u
.action
.category
,
352 &mgmt
->u
.action
.u
.vs_public_action
.action
,
353 len
- hdr_len
, freq
);
354 #endif /* CONFIG_P2P */
359 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
360 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
364 struct wpa_supplicant
*wpa_s
= ctx
;
365 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
,
367 #else /* CONFIG_P2P */
369 #endif /* CONFIG_P2P */
373 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
377 struct wpa_supplicant
*wpa_s
= ctx
;
378 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
379 #endif /* CONFIG_P2P */
383 static void wpas_ap_configured_cb(void *ctx
)
385 struct wpa_supplicant
*wpa_s
= ctx
;
387 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
389 if (wpa_s
->ap_configured_cb
)
390 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
391 wpa_s
->ap_configured_cb_data
);
395 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
396 struct wpa_ssid
*ssid
)
398 struct wpa_driver_associate_params params
;
399 struct hostapd_iface
*hapd_iface
;
400 struct hostapd_config
*conf
;
403 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
404 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
408 wpa_supplicant_ap_deinit(wpa_s
);
410 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
411 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
413 os_memset(¶ms
, 0, sizeof(params
));
414 params
.ssid
= ssid
->ssid
;
415 params
.ssid_len
= ssid
->ssid_len
;
416 switch (ssid
->mode
) {
417 case WPAS_MODE_INFRA
:
418 params
.mode
= IEEE80211_MODE_INFRA
;
421 params
.mode
= IEEE80211_MODE_IBSS
;
424 case WPAS_MODE_P2P_GO
:
425 case WPAS_MODE_P2P_GROUP_FORMATION
:
426 params
.mode
= IEEE80211_MODE_AP
;
429 params
.freq
= ssid
->frequency
;
431 params
.wpa_proto
= ssid
->proto
;
432 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
433 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
435 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
436 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
438 if (ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
)
439 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
440 else if (ssid
->pairwise_cipher
& WPA_CIPHER_TKIP
)
441 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
442 else if (ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)
443 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
445 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
449 params
.pairwise_suite
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
450 params
.group_suite
= params
.pairwise_suite
;
453 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
454 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
456 #endif /* CONFIG_P2P */
458 if (wpa_s
->parent
->set_ap_uapsd
)
459 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
463 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
464 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
468 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
469 if (hapd_iface
== NULL
)
471 hapd_iface
->owner
= wpa_s
;
472 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
473 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
475 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
477 wpa_supplicant_ap_deinit(wpa_s
);
481 if (params
.uapsd
> 0) {
482 conf
->bss
->wmm_enabled
= 1;
483 conf
->bss
->wmm_uapsd
= 1;
486 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
487 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
488 wpa_supplicant_ap_deinit(wpa_s
);
493 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
494 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
495 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
496 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
498 #endif /* CONFIG_P2P */
500 hapd_iface
->num_bss
= conf
->num_bss
;
501 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
502 sizeof(struct hostapd_data
*));
503 if (hapd_iface
->bss
== NULL
) {
504 wpa_supplicant_ap_deinit(wpa_s
);
508 for (i
= 0; i
< conf
->num_bss
; i
++) {
510 hostapd_alloc_bss_data(hapd_iface
, conf
,
512 if (hapd_iface
->bss
[i
] == NULL
) {
513 wpa_supplicant_ap_deinit(wpa_s
);
517 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
518 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
519 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
520 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
521 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
522 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
523 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
524 ap_probe_req_rx
, wpa_s
);
525 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
526 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
527 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
528 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
529 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
530 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
532 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
533 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(
534 wpa_s
, ssid
->p2p_persistent_group
,
535 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
);
536 #endif /* CONFIG_P2P */
537 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
538 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
541 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
542 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
543 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
545 wpa_s
->current_ssid
= ssid
;
546 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
547 wpa_s
->assoc_freq
= ssid
->frequency
;
549 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
550 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
551 wpa_supplicant_ap_deinit(wpa_s
);
559 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
562 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
563 #endif /* CONFIG_WPS */
565 if (wpa_s
->ap_iface
== NULL
)
568 wpa_s
->current_ssid
= NULL
;
569 wpa_s
->assoc_freq
= 0;
570 wpa_s
->reassociated_connection
= 0;
572 if (wpa_s
->ap_iface
->bss
)
573 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
574 wpas_p2p_group_deinit(wpa_s
);
575 #endif /* CONFIG_P2P */
576 hostapd_interface_deinit(wpa_s
->ap_iface
);
577 hostapd_interface_free(wpa_s
->ap_iface
);
578 wpa_s
->ap_iface
= NULL
;
579 wpa_drv_deinit_ap(wpa_s
);
583 void ap_tx_status(void *ctx
, const u8
*addr
,
584 const u8
*buf
, size_t len
, int ack
)
587 struct wpa_supplicant
*wpa_s
= ctx
;
588 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
589 #endif /* NEED_AP_MLME */
593 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
594 const u8
*data
, size_t len
, int ack
)
597 struct wpa_supplicant
*wpa_s
= ctx
;
598 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
599 #endif /* NEED_AP_MLME */
603 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
606 struct wpa_supplicant
*wpa_s
= ctx
;
608 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
609 #endif /* NEED_AP_MLME */
613 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
616 struct wpa_supplicant
*wpa_s
= ctx
;
617 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
618 #endif /* NEED_AP_MLME */
622 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
625 struct wpa_supplicant
*wpa_s
= ctx
;
626 struct hostapd_frame_info fi
;
627 os_memset(&fi
, 0, sizeof(fi
));
628 fi
.datarate
= rx_mgmt
->datarate
;
629 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
630 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
631 rx_mgmt
->frame_len
, &fi
);
632 #endif /* NEED_AP_MLME */
636 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
639 struct wpa_supplicant
*wpa_s
= ctx
;
640 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
641 #endif /* NEED_AP_MLME */
645 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
646 const u8
*src_addr
, const u8
*buf
, size_t len
)
648 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
654 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
655 const u8
*p2p_dev_addr
)
657 if (!wpa_s
->ap_iface
)
659 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
664 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
666 struct wps_registrar
*reg
;
667 int reg_sel
= 0, wps_sta
= 0;
669 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
672 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
673 reg_sel
= wps_registrar_wps_cancel(reg
);
674 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
675 ap_sta_wps_cancel
, NULL
);
677 if (!reg_sel
&& !wps_sta
) {
678 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
684 * There are 2 cases to return wps cancel as success:
685 * 1. When wps cancel was initiated but no connection has been
686 * established with client yet.
687 * 2. Client is in the middle of exchanging WPS messages.
694 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
695 const char *pin
, char *buf
, size_t buflen
)
697 int ret
, ret_len
= 0;
699 if (!wpa_s
->ap_iface
)
703 unsigned int rpin
= wps_generate_pin();
704 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
707 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
709 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
717 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
719 struct wpa_supplicant
*wpa_s
= eloop_data
;
720 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
721 wpas_wps_ap_pin_disable(wpa_s
);
725 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
727 struct hostapd_data
*hapd
;
729 if (wpa_s
->ap_iface
== NULL
)
731 hapd
= wpa_s
->ap_iface
->bss
[0];
732 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
733 hapd
->ap_pin_failures
= 0;
734 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
736 eloop_register_timeout(timeout
, 0,
737 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
741 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
743 struct hostapd_data
*hapd
;
745 if (wpa_s
->ap_iface
== NULL
)
747 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
748 hapd
= wpa_s
->ap_iface
->bss
[0];
749 os_free(hapd
->conf
->ap_pin
);
750 hapd
->conf
->ap_pin
= NULL
;
751 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
755 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
757 struct hostapd_data
*hapd
;
761 if (wpa_s
->ap_iface
== NULL
)
763 hapd
= wpa_s
->ap_iface
->bss
[0];
764 pin
= wps_generate_pin();
765 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
766 os_free(hapd
->conf
->ap_pin
);
767 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
768 if (hapd
->conf
->ap_pin
== NULL
)
770 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
772 return hapd
->conf
->ap_pin
;
776 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
778 struct hostapd_data
*hapd
;
779 if (wpa_s
->ap_iface
== NULL
)
781 hapd
= wpa_s
->ap_iface
->bss
[0];
782 return hapd
->conf
->ap_pin
;
786 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
789 struct hostapd_data
*hapd
;
793 if (wpa_s
->ap_iface
== NULL
)
795 hapd
= wpa_s
->ap_iface
->bss
[0];
796 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
797 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
799 os_free(hapd
->conf
->ap_pin
);
800 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
801 if (hapd
->conf
->ap_pin
== NULL
)
803 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
809 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
811 struct hostapd_data
*hapd
;
813 if (wpa_s
->ap_iface
== NULL
)
815 hapd
= wpa_s
->ap_iface
->bss
[0];
818 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
819 * PIN if this happens multiple times to slow down brute force attacks.
821 hapd
->ap_pin_failures
++;
822 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
823 hapd
->ap_pin_failures
);
824 if (hapd
->ap_pin_failures
< 3)
827 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
828 hapd
->ap_pin_failures
= 0;
829 os_free(hapd
->conf
->ap_pin
);
830 hapd
->conf
->ap_pin
= NULL
;
833 #endif /* CONFIG_WPS */
836 #ifdef CONFIG_CTRL_IFACE
838 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
839 char *buf
, size_t buflen
)
841 if (wpa_s
->ap_iface
== NULL
)
843 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
848 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
849 char *buf
, size_t buflen
)
851 if (wpa_s
->ap_iface
== NULL
)
853 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
858 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
859 char *buf
, size_t buflen
)
861 if (wpa_s
->ap_iface
== NULL
)
863 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
868 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant
*wpa_s
,
871 if (wpa_s
->ap_iface
== NULL
)
873 return hostapd_ctrl_iface_disassociate(wpa_s
->ap_iface
->bss
[0],
878 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant
*wpa_s
,
881 if (wpa_s
->ap_iface
== NULL
)
883 return hostapd_ctrl_iface_deauthenticate(wpa_s
->ap_iface
->bss
[0],
888 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
889 size_t buflen
, int verbose
)
891 char *pos
= buf
, *end
= buf
+ buflen
;
893 struct hostapd_bss_config
*conf
;
895 if (wpa_s
->ap_iface
== NULL
)
898 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
902 ret
= os_snprintf(pos
, end
- pos
,
903 "pairwise_cipher=%s\n"
906 wpa_cipher_txt(conf
->rsn_pairwise
),
907 wpa_cipher_txt(conf
->wpa_group
),
908 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
910 if (ret
< 0 || ret
>= end
- pos
)
916 #endif /* CONFIG_CTRL_IFACE */
919 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
921 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
922 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
923 struct hostapd_data
*hapd
;
925 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
926 ssid
->mode
== WPAS_MODE_INFRA
||
927 ssid
->mode
== WPAS_MODE_IBSS
)
931 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
932 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
933 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
934 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
936 #endif /* CONFIG_P2P */
938 hapd
= iface
->bss
[0];
939 if (hapd
->drv_priv
== NULL
)
941 ieee802_11_set_beacons(iface
);
942 hostapd_set_ap_wps_ie(hapd
);
948 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
951 struct hostapd_data
*hapd
;
952 struct hostapd_bss_config
*conf
;
954 if (!wpa_s
->ap_iface
)
958 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
961 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
963 hapd
= wpa_s
->ap_iface
->bss
[0];
966 os_free(conf
->accept_mac
);
967 conf
->accept_mac
= NULL
;
968 conf
->num_accept_mac
= 0;
969 os_free(conf
->deny_mac
);
970 conf
->deny_mac
= NULL
;
971 conf
->num_deny_mac
= 0;
974 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
978 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
979 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
980 if (conf
->accept_mac
== NULL
)
982 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
983 conf
->num_accept_mac
= 1;