2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "utils/uuid.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/wpa_ctrl.h"
17 #include "eapol_supp/eapol_supp_sm.h"
18 #include "ap/hostapd.h"
19 #include "ap/ap_config.h"
20 #include "ap/ap_drv_ops.h"
22 #include "ap/ieee802_11.h"
23 #endif /* NEED_AP_MLME */
24 #include "ap/beacon.h"
25 #include "ap/ieee802_1x.h"
26 #include "ap/wps_hostapd.h"
27 #include "ap/ctrl_iface_ap.h"
29 #include "common/ieee802_11_defs.h"
30 #include "config_ssid.h"
32 #include "wpa_supplicant_i.h"
34 #include "p2p_supplicant.h"
36 #include "ap/sta_info.h"
41 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
);
42 #endif /* CONFIG_WPS */
45 #ifdef CONFIG_IEEE80211N
46 static void wpas_conf_ap_vht(struct wpa_supplicant
*wpa_s
,
47 struct hostapd_config
*conf
,
48 struct hostapd_hw_modes
*mode
)
51 u8 channel
= conf
->channel
;
53 if (!conf
->secondary_channel
)
56 center_chan
= wpas_p2p_get_vht80_center(wpa_s
, mode
, channel
);
60 /* Use 80 MHz channel */
61 conf
->vht_oper_chwidth
= 1;
62 conf
->vht_oper_centr_freq_seg0_idx
= center_chan
;
66 conf
->vht_oper_centr_freq_seg0_idx
=
67 channel
+ conf
->secondary_channel
* 2;
69 #endif /* CONFIG_IEEE80211N */
72 static int wpa_supplicant_conf_ap(struct wpa_supplicant
*wpa_s
,
73 struct wpa_ssid
*ssid
,
74 struct hostapd_config
*conf
)
76 struct hostapd_bss_config
*bss
= conf
->bss
[0];
78 conf
->driver
= wpa_s
->driver
;
80 os_strlcpy(bss
->iface
, wpa_s
->ifname
, sizeof(bss
->iface
));
82 conf
->hw_mode
= ieee80211_freq_to_chan(ssid
->frequency
,
84 if (conf
->hw_mode
== NUM_HOSTAPD_MODES
) {
85 wpa_printf(MSG_ERROR
, "Unsupported AP mode frequency: %d MHz",
90 /* TODO: enable HT40 if driver supports it;
91 * drop to 11b if driver does not support 11g */
93 #ifdef CONFIG_IEEE80211N
95 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
96 * and a mask of allowed capabilities within conf->ht_capab.
97 * Using default config settings for: conf->ht_op_mode_fixed,
98 * conf->secondary_channel, conf->require_ht
100 if (wpa_s
->hw
.modes
) {
101 struct hostapd_hw_modes
*mode
= NULL
;
103 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
104 if (wpa_s
->hw
.modes
[i
].mode
== conf
->hw_mode
) {
105 mode
= &wpa_s
->hw
.modes
[i
];
110 #ifdef CONFIG_HT_OVERRIDES
111 if (ssid
->disable_ht
) {
112 conf
->ieee80211n
= 0;
116 #endif /* CONFIG_HT_OVERRIDES */
118 if (!no_ht
&& mode
&& mode
->ht_capab
) {
119 conf
->ieee80211n
= 1;
121 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211A
&&
123 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
) &&
125 conf
->secondary_channel
=
126 wpas_p2p_get_ht40_mode(wpa_s
, mode
,
128 if (conf
->secondary_channel
)
130 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
;
131 #endif /* CONFIG_P2P */
134 * white-list capabilities that won't cause issues
135 * to connecting stations, while leaving the current
136 * capabilities intact (currently disabled SMPS).
138 conf
->ht_capab
|= mode
->ht_capab
&
139 (HT_CAP_INFO_GREEN_FIELD
|
140 HT_CAP_INFO_SHORT_GI20MHZ
|
141 HT_CAP_INFO_SHORT_GI40MHZ
|
142 HT_CAP_INFO_RX_STBC_MASK
|
143 HT_CAP_INFO_MAX_AMSDU_SIZE
);
145 if (mode
->vht_capab
&& ssid
->vht
) {
146 conf
->ieee80211ac
= 1;
147 wpas_conf_ap_vht(wpa_s
, conf
, mode
);
151 #endif /* CONFIG_IEEE80211N */
154 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
&&
155 (ssid
->mode
== WPAS_MODE_P2P_GO
||
156 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)) {
157 /* Remove 802.11b rates from supported and basic rate sets */
158 int *list
= os_malloc(4 * sizeof(int));
165 conf
->basic_rates
= list
;
167 list
= os_malloc(9 * sizeof(int));
179 conf
->supported_rates
= list
;
182 bss
->isolate
= !wpa_s
->conf
->p2p_intra_bss
;
183 bss
->force_per_enrollee_psk
= wpa_s
->global
->p2p_per_sta_psk
;
184 #endif /* CONFIG_P2P */
186 if (ssid
->ssid_len
== 0) {
187 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
190 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
191 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
192 bss
->ssid
.ssid_set
= 1;
194 bss
->ignore_broadcast_ssid
= ssid
->ignore_broadcast_ssid
;
197 bss
->auth_algs
= ssid
->auth_alg
;
199 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
200 bss
->wpa
= ssid
->proto
;
201 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
202 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
204 os_free(bss
->ssid
.wpa_psk
);
205 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
206 if (bss
->ssid
.wpa_psk
== NULL
)
208 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
209 bss
->ssid
.wpa_psk
->group
= 1;
210 } else if (ssid
->passphrase
) {
211 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
212 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
213 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
214 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
216 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
217 if (ssid
->wep_key_len
[i
] == 0)
219 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
220 if (wep
->key
[i
] == NULL
)
222 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
223 ssid
->wep_key_len
[i
]);
224 wep
->len
[i
] = ssid
->wep_key_len
[i
];
226 wep
->idx
= ssid
->wep_tx_keyidx
;
230 if (ssid
->ap_max_inactivity
)
231 bss
->ap_max_inactivity
= ssid
->ap_max_inactivity
;
233 if (ssid
->dtim_period
)
234 bss
->dtim_period
= ssid
->dtim_period
;
235 else if (wpa_s
->conf
->dtim_period
)
236 bss
->dtim_period
= wpa_s
->conf
->dtim_period
;
238 if (ssid
->beacon_int
)
239 conf
->beacon_int
= ssid
->beacon_int
;
240 else if (wpa_s
->conf
->beacon_int
)
241 conf
->beacon_int
= wpa_s
->conf
->beacon_int
;
243 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
244 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
245 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
, bss
->wpa_pairwise
,
248 if (bss
->wpa
&& bss
->ieee802_1x
)
249 bss
->ssid
.security_policy
= SECURITY_WPA
;
251 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
252 else if (bss
->ieee802_1x
) {
253 int cipher
= WPA_CIPHER_NONE
;
254 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
255 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
256 if (bss
->default_wep_key_len
)
257 cipher
= bss
->default_wep_key_len
>= 13 ?
258 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
259 bss
->wpa_group
= cipher
;
260 bss
->wpa_pairwise
= cipher
;
261 bss
->rsn_pairwise
= cipher
;
262 } else if (bss
->ssid
.wep
.keys_set
) {
263 int cipher
= WPA_CIPHER_WEP40
;
264 if (bss
->ssid
.wep
.len
[0] >= 13)
265 cipher
= WPA_CIPHER_WEP104
;
266 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
267 bss
->wpa_group
= cipher
;
268 bss
->wpa_pairwise
= cipher
;
269 bss
->rsn_pairwise
= cipher
;
271 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
272 bss
->wpa_group
= WPA_CIPHER_NONE
;
273 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
274 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
277 if (bss
->wpa_group_rekey
< 86400 && (bss
->wpa
& 2) &&
278 (bss
->wpa_group
== WPA_CIPHER_CCMP
||
279 bss
->wpa_group
== WPA_CIPHER_GCMP
)) {
281 * Strong ciphers do not need frequent rekeying, so increase
282 * the default GTK rekeying period to 24 hours.
284 bss
->wpa_group_rekey
= 86400;
289 * Enable WPS by default for open and WPA/WPA2-Personal network, but
290 * require user interaction to actually use it. Only the internal
291 * Registrar is supported.
293 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
294 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
297 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
298 (!(bss
->rsn_pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
299 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
301 #endif /* CONFIG_WPS2 */
304 if (!ssid
->ignore_broadcast_ssid
)
307 bss
->ap_setup_locked
= 2;
308 if (wpa_s
->conf
->config_methods
)
309 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
310 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
312 if (wpa_s
->conf
->device_name
) {
313 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
314 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
316 if (wpa_s
->conf
->manufacturer
)
317 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
318 if (wpa_s
->conf
->model_name
)
319 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
320 if (wpa_s
->conf
->model_number
)
321 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
322 if (wpa_s
->conf
->serial_number
)
323 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
324 if (is_nil_uuid(wpa_s
->conf
->uuid
))
325 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
327 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
328 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
329 bss
->pbc_in_m1
= wpa_s
->conf
->pbc_in_m1
;
331 #endif /* CONFIG_WPS */
333 if (wpa_s
->max_stations
&&
334 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
335 bss
->max_num_sta
= wpa_s
->max_stations
;
337 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
339 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
341 if (wpa_s
->conf
->ap_vendor_elements
) {
342 bss
->vendor_elements
=
343 wpabuf_dup(wpa_s
->conf
->ap_vendor_elements
);
350 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
353 struct wpa_supplicant
*wpa_s
= ctx
;
354 const struct ieee80211_mgmt
*mgmt
;
357 mgmt
= (const struct ieee80211_mgmt
*) buf
;
358 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
361 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
362 mgmt
->u
.action
.category
,
363 &mgmt
->u
.action
.u
.vs_public_action
.action
,
364 len
- hdr_len
, freq
);
365 #endif /* CONFIG_P2P */
369 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
370 union wps_event_data
*data
)
373 struct wpa_supplicant
*wpa_s
= ctx
;
375 if (event
== WPS_EV_FAIL
) {
376 struct wps_event_fail
*fail
= &data
->fail
;
378 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
379 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
381 * src/ap/wps_hostapd.c has already sent this on the
382 * main interface, so only send on the parent interface
385 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
386 "msg=%d config_error=%d",
387 fail
->msg
, fail
->config_error
);
389 wpas_p2p_wps_failed(wpa_s
, fail
);
391 #endif /* CONFIG_P2P */
395 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
396 int authorized
, const u8
*p2p_dev_addr
)
398 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
403 static void ap_new_psk_cb(void *ctx
, const u8
*mac_addr
, const u8
*p2p_dev_addr
,
404 const u8
*psk
, size_t psk_len
)
407 struct wpa_supplicant
*wpa_s
= ctx
;
408 if (wpa_s
->ap_iface
== NULL
|| wpa_s
->current_ssid
== NULL
)
410 wpas_p2p_new_psk_cb(wpa_s
, mac_addr
, p2p_dev_addr
, psk
, psk_len
);
412 #endif /* CONFIG_P2P */
415 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
418 struct wpa_supplicant
*wpa_s
= ctx
;
419 const struct ieee80211_mgmt
*mgmt
;
422 mgmt
= (const struct ieee80211_mgmt
*) buf
;
423 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
426 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
427 mgmt
->u
.action
.category
,
428 &mgmt
->u
.action
.u
.vs_public_action
.action
,
429 len
- hdr_len
, freq
);
430 #endif /* CONFIG_P2P */
435 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
436 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
440 struct wpa_supplicant
*wpa_s
= ctx
;
441 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
,
443 #else /* CONFIG_P2P */
445 #endif /* CONFIG_P2P */
449 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
453 struct wpa_supplicant
*wpa_s
= ctx
;
454 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
455 #endif /* CONFIG_P2P */
459 static void wpas_ap_configured_cb(void *ctx
)
461 struct wpa_supplicant
*wpa_s
= ctx
;
463 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
465 if (wpa_s
->ap_configured_cb
)
466 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
467 wpa_s
->ap_configured_cb_data
);
471 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
472 struct wpa_ssid
*ssid
)
474 struct wpa_driver_associate_params params
;
475 struct hostapd_iface
*hapd_iface
;
476 struct hostapd_config
*conf
;
479 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
480 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
484 wpa_supplicant_ap_deinit(wpa_s
);
486 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
487 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
489 os_memset(¶ms
, 0, sizeof(params
));
490 params
.ssid
= ssid
->ssid
;
491 params
.ssid_len
= ssid
->ssid_len
;
492 switch (ssid
->mode
) {
493 case WPAS_MODE_INFRA
:
494 params
.mode
= IEEE80211_MODE_INFRA
;
497 params
.mode
= IEEE80211_MODE_IBSS
;
500 case WPAS_MODE_P2P_GO
:
501 case WPAS_MODE_P2P_GROUP_FORMATION
:
502 params
.mode
= IEEE80211_MODE_AP
;
505 if (ssid
->frequency
== 0)
506 ssid
->frequency
= 2462; /* default channel 11 */
507 params
.freq
= ssid
->frequency
;
509 params
.wpa_proto
= ssid
->proto
;
510 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
511 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
513 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
514 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
516 wpa_s
->pairwise_cipher
= wpa_pick_pairwise_cipher(ssid
->pairwise_cipher
,
518 if (wpa_s
->pairwise_cipher
< 0) {
519 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
523 params
.pairwise_suite
=
524 wpa_cipher_to_suite_driver(wpa_s
->pairwise_cipher
);
525 params
.group_suite
= params
.pairwise_suite
;
528 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
529 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
531 #endif /* CONFIG_P2P */
533 if (wpa_s
->parent
->set_ap_uapsd
)
534 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
538 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
539 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
543 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
544 if (hapd_iface
== NULL
)
546 hapd_iface
->owner
= wpa_s
;
547 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
548 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
549 hapd_iface
->extended_capa
= wpa_s
->extended_capa
;
550 hapd_iface
->extended_capa_mask
= wpa_s
->extended_capa_mask
;
551 hapd_iface
->extended_capa_len
= wpa_s
->extended_capa_len
;
553 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
555 wpa_supplicant_ap_deinit(wpa_s
);
559 os_memcpy(wpa_s
->ap_iface
->conf
->wmm_ac_params
,
560 wpa_s
->conf
->wmm_ac_params
,
561 sizeof(wpa_s
->conf
->wmm_ac_params
));
563 if (params
.uapsd
> 0) {
564 conf
->bss
[0]->wmm_enabled
= 1;
565 conf
->bss
[0]->wmm_uapsd
= 1;
568 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
569 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
570 wpa_supplicant_ap_deinit(wpa_s
);
575 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
576 conf
->bss
[0]->p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
577 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
578 conf
->bss
[0]->p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
580 #endif /* CONFIG_P2P */
582 hapd_iface
->num_bss
= conf
->num_bss
;
583 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
584 sizeof(struct hostapd_data
*));
585 if (hapd_iface
->bss
== NULL
) {
586 wpa_supplicant_ap_deinit(wpa_s
);
590 for (i
= 0; i
< conf
->num_bss
; i
++) {
592 hostapd_alloc_bss_data(hapd_iface
, conf
,
594 if (hapd_iface
->bss
[i
] == NULL
) {
595 wpa_supplicant_ap_deinit(wpa_s
);
599 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
600 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
601 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
602 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
603 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
604 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
605 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
606 ap_probe_req_rx
, wpa_s
);
607 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
608 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
609 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
610 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
611 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
612 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
614 hapd_iface
->bss
[i
]->new_psk_cb
= ap_new_psk_cb
;
615 hapd_iface
->bss
[i
]->new_psk_cb_ctx
= wpa_s
;
616 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
617 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(wpa_s
,
619 #endif /* CONFIG_P2P */
620 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
621 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
624 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
625 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
626 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
628 wpa_s
->current_ssid
= ssid
;
629 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
630 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
631 wpa_s
->assoc_freq
= ssid
->frequency
;
633 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
634 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
635 wpa_supplicant_ap_deinit(wpa_s
);
643 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
646 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
647 #endif /* CONFIG_WPS */
649 if (wpa_s
->ap_iface
== NULL
)
652 wpa_s
->current_ssid
= NULL
;
653 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
654 wpa_s
->assoc_freq
= 0;
656 if (wpa_s
->ap_iface
->bss
)
657 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
658 wpas_p2p_group_deinit(wpa_s
);
659 #endif /* CONFIG_P2P */
660 hostapd_interface_deinit(wpa_s
->ap_iface
);
661 hostapd_interface_free(wpa_s
->ap_iface
);
662 wpa_s
->ap_iface
= NULL
;
663 wpa_drv_deinit_ap(wpa_s
);
667 void ap_tx_status(void *ctx
, const u8
*addr
,
668 const u8
*buf
, size_t len
, int ack
)
671 struct wpa_supplicant
*wpa_s
= ctx
;
672 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
673 #endif /* NEED_AP_MLME */
677 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
678 const u8
*data
, size_t len
, int ack
)
681 struct wpa_supplicant
*wpa_s
= ctx
;
682 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
683 #endif /* NEED_AP_MLME */
687 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
690 struct wpa_supplicant
*wpa_s
= ctx
;
692 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
693 #endif /* NEED_AP_MLME */
697 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
700 struct wpa_supplicant
*wpa_s
= ctx
;
701 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
702 #endif /* NEED_AP_MLME */
706 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
709 struct wpa_supplicant
*wpa_s
= ctx
;
710 struct hostapd_frame_info fi
;
711 os_memset(&fi
, 0, sizeof(fi
));
712 fi
.datarate
= rx_mgmt
->datarate
;
713 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
714 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
715 rx_mgmt
->frame_len
, &fi
);
716 #endif /* NEED_AP_MLME */
720 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
723 struct wpa_supplicant
*wpa_s
= ctx
;
724 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
725 #endif /* NEED_AP_MLME */
729 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
730 const u8
*src_addr
, const u8
*buf
, size_t len
)
732 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
738 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
739 const u8
*p2p_dev_addr
)
741 if (!wpa_s
->ap_iface
)
743 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
748 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
750 struct wps_registrar
*reg
;
751 int reg_sel
= 0, wps_sta
= 0;
753 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
756 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
757 reg_sel
= wps_registrar_wps_cancel(reg
);
758 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
759 ap_sta_wps_cancel
, NULL
);
761 if (!reg_sel
&& !wps_sta
) {
762 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
768 * There are 2 cases to return wps cancel as success:
769 * 1. When wps cancel was initiated but no connection has been
770 * established with client yet.
771 * 2. Client is in the middle of exchanging WPS messages.
778 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
779 const char *pin
, char *buf
, size_t buflen
,
782 int ret
, ret_len
= 0;
784 if (!wpa_s
->ap_iface
)
788 unsigned int rpin
= wps_generate_pin();
789 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
792 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
794 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
802 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
804 struct wpa_supplicant
*wpa_s
= eloop_data
;
805 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
806 wpas_wps_ap_pin_disable(wpa_s
);
810 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
812 struct hostapd_data
*hapd
;
814 if (wpa_s
->ap_iface
== NULL
)
816 hapd
= wpa_s
->ap_iface
->bss
[0];
817 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
818 hapd
->ap_pin_failures
= 0;
819 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
821 eloop_register_timeout(timeout
, 0,
822 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
826 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
828 struct hostapd_data
*hapd
;
830 if (wpa_s
->ap_iface
== NULL
)
832 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
833 hapd
= wpa_s
->ap_iface
->bss
[0];
834 os_free(hapd
->conf
->ap_pin
);
835 hapd
->conf
->ap_pin
= NULL
;
836 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
840 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
842 struct hostapd_data
*hapd
;
846 if (wpa_s
->ap_iface
== NULL
)
848 hapd
= wpa_s
->ap_iface
->bss
[0];
849 pin
= wps_generate_pin();
850 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
851 os_free(hapd
->conf
->ap_pin
);
852 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
853 if (hapd
->conf
->ap_pin
== NULL
)
855 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
857 return hapd
->conf
->ap_pin
;
861 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
863 struct hostapd_data
*hapd
;
864 if (wpa_s
->ap_iface
== NULL
)
866 hapd
= wpa_s
->ap_iface
->bss
[0];
867 return hapd
->conf
->ap_pin
;
871 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
874 struct hostapd_data
*hapd
;
878 if (wpa_s
->ap_iface
== NULL
)
880 hapd
= wpa_s
->ap_iface
->bss
[0];
881 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
882 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
884 os_free(hapd
->conf
->ap_pin
);
885 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
886 if (hapd
->conf
->ap_pin
== NULL
)
888 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
894 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
896 struct hostapd_data
*hapd
;
898 if (wpa_s
->ap_iface
== NULL
)
900 hapd
= wpa_s
->ap_iface
->bss
[0];
903 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
904 * PIN if this happens multiple times to slow down brute force attacks.
906 hapd
->ap_pin_failures
++;
907 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
908 hapd
->ap_pin_failures
);
909 if (hapd
->ap_pin_failures
< 3)
912 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
913 hapd
->ap_pin_failures
= 0;
914 os_free(hapd
->conf
->ap_pin
);
915 hapd
->conf
->ap_pin
= NULL
;
919 #ifdef CONFIG_WPS_NFC
921 struct wpabuf
* wpas_ap_wps_nfc_config_token(struct wpa_supplicant
*wpa_s
,
924 struct hostapd_data
*hapd
;
926 if (wpa_s
->ap_iface
== NULL
)
928 hapd
= wpa_s
->ap_iface
->bss
[0];
929 return hostapd_wps_nfc_config_token(hapd
, ndef
);
933 struct wpabuf
* wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant
*wpa_s
,
936 struct hostapd_data
*hapd
;
938 if (wpa_s
->ap_iface
== NULL
)
940 hapd
= wpa_s
->ap_iface
->bss
[0];
941 return hostapd_wps_nfc_hs_cr(hapd
, ndef
);
944 #endif /* CONFIG_WPS_NFC */
946 #endif /* CONFIG_WPS */
949 #ifdef CONFIG_CTRL_IFACE
951 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
952 char *buf
, size_t buflen
)
954 if (wpa_s
->ap_iface
== NULL
)
956 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
961 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
962 char *buf
, size_t buflen
)
964 if (wpa_s
->ap_iface
== NULL
)
966 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
971 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
972 char *buf
, size_t buflen
)
974 if (wpa_s
->ap_iface
== NULL
)
976 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
981 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant
*wpa_s
,
984 if (wpa_s
->ap_iface
== NULL
)
986 return hostapd_ctrl_iface_disassociate(wpa_s
->ap_iface
->bss
[0],
991 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant
*wpa_s
,
994 if (wpa_s
->ap_iface
== NULL
)
996 return hostapd_ctrl_iface_deauthenticate(wpa_s
->ap_iface
->bss
[0],
1001 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
1002 size_t buflen
, int verbose
)
1004 char *pos
= buf
, *end
= buf
+ buflen
;
1006 struct hostapd_bss_config
*conf
;
1008 if (wpa_s
->ap_iface
== NULL
)
1011 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
1015 ret
= os_snprintf(pos
, end
- pos
,
1016 "pairwise_cipher=%s\n"
1019 wpa_cipher_txt(conf
->rsn_pairwise
),
1020 wpa_cipher_txt(conf
->wpa_group
),
1021 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
1023 if (ret
< 0 || ret
>= end
- pos
)
1029 #endif /* CONFIG_CTRL_IFACE */
1032 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
1034 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
1035 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1036 struct hostapd_data
*hapd
;
1038 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
1039 ssid
->mode
== WPAS_MODE_INFRA
||
1040 ssid
->mode
== WPAS_MODE_IBSS
)
1044 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
1045 iface
->conf
->bss
[0]->p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
1046 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
1047 iface
->conf
->bss
[0]->p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
1048 P2P_GROUP_FORMATION
;
1049 #endif /* CONFIG_P2P */
1051 hapd
= iface
->bss
[0];
1052 if (hapd
->drv_priv
== NULL
)
1054 ieee802_11_set_beacons(iface
);
1055 hostapd_set_ap_wps_ie(hapd
);
1061 int ap_switch_channel(struct wpa_supplicant
*wpa_s
,
1062 struct csa_settings
*settings
)
1065 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0])
1068 return hostapd_switch_channel(wpa_s
->ap_iface
->bss
[0], settings
);
1069 #else /* NEED_AP_MLME */
1071 #endif /* NEED_AP_MLME */
1075 int ap_ctrl_iface_chanswitch(struct wpa_supplicant
*wpa_s
, const char *pos
)
1077 struct csa_settings settings
;
1078 int ret
= hostapd_parse_csa_settings(pos
, &settings
);
1083 return ap_switch_channel(wpa_s
, &settings
);
1087 void wpas_ap_ch_switch(struct wpa_supplicant
*wpa_s
, int freq
, int ht
,
1090 if (!wpa_s
->ap_iface
)
1093 wpa_s
->assoc_freq
= freq
;
1094 hostapd_event_ch_switch(wpa_s
->ap_iface
->bss
[0], freq
, ht
, offset
);
1098 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
1101 struct hostapd_data
*hapd
;
1102 struct hostapd_bss_config
*conf
;
1104 if (!wpa_s
->ap_iface
)
1108 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
1111 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
1113 hapd
= wpa_s
->ap_iface
->bss
[0];
1116 os_free(conf
->accept_mac
);
1117 conf
->accept_mac
= NULL
;
1118 conf
->num_accept_mac
= 0;
1119 os_free(conf
->deny_mac
);
1120 conf
->deny_mac
= NULL
;
1121 conf
->num_deny_mac
= 0;
1124 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
1128 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
1129 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
1130 if (conf
->accept_mac
== NULL
)
1132 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
1133 conf
->num_accept_mac
= 1;