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];
50 conf
->driver
= wpa_s
->driver
;
52 os_strlcpy(bss
->iface
, wpa_s
->ifname
, sizeof(bss
->iface
));
54 if (ssid
->frequency
== 0) {
55 /* default channel 11 */
56 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
59 conf
->hw_mode
= ieee80211_freq_to_chan(ssid
->frequency
,
61 if (conf
->hw_mode
== NUM_HOSTAPD_MODES
) {
62 wpa_printf(MSG_ERROR
, "Unsupported AP mode frequency: "
63 "%d MHz", ssid
->frequency
);
68 /* TODO: enable HT40 if driver supports it;
69 * drop to 11b if driver does not support 11g */
71 #ifdef CONFIG_IEEE80211N
73 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
74 * and a mask of allowed capabilities within conf->ht_capab.
75 * Using default config settings for: conf->ht_op_mode_fixed,
76 * conf->secondary_channel, conf->require_ht
78 if (wpa_s
->hw
.modes
) {
79 struct hostapd_hw_modes
*mode
= NULL
;
81 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
82 if (wpa_s
->hw
.modes
[i
].mode
== conf
->hw_mode
) {
83 mode
= &wpa_s
->hw
.modes
[i
];
88 #ifdef CONFIG_HT_OVERRIDES
89 if (ssid
->disable_ht
) {
94 #endif /* CONFIG_HT_OVERRIDES */
96 if (!no_ht
&& mode
&& mode
->ht_capab
) {
99 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211A
&&
101 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
) &&
103 conf
->secondary_channel
=
104 wpas_p2p_get_ht40_mode(wpa_s
, mode
,
106 if (conf
->secondary_channel
)
108 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
;
109 #endif /* CONFIG_P2P */
112 * white-list capabilities that won't cause issues
113 * to connecting stations, while leaving the current
114 * capabilities intact (currently disabled SMPS).
116 conf
->ht_capab
|= mode
->ht_capab
&
117 (HT_CAP_INFO_GREEN_FIELD
|
118 HT_CAP_INFO_SHORT_GI20MHZ
|
119 HT_CAP_INFO_SHORT_GI40MHZ
|
120 HT_CAP_INFO_RX_STBC_MASK
|
121 HT_CAP_INFO_MAX_AMSDU_SIZE
);
124 #endif /* CONFIG_IEEE80211N */
127 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
) {
128 /* Remove 802.11b rates from supported and basic rate sets */
129 int *list
= os_malloc(4 * sizeof(int));
136 conf
->basic_rates
= list
;
138 list
= os_malloc(9 * sizeof(int));
150 conf
->supported_rates
= list
;
153 bss
->isolate
= !wpa_s
->conf
->p2p_intra_bss
;
154 #endif /* CONFIG_P2P */
156 if (ssid
->ssid_len
== 0) {
157 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
160 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
161 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
162 bss
->ssid
.ssid_set
= 1;
164 bss
->ignore_broadcast_ssid
= ssid
->ignore_broadcast_ssid
;
167 bss
->auth_algs
= ssid
->auth_alg
;
169 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
170 bss
->wpa
= ssid
->proto
;
171 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
172 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
174 os_free(bss
->ssid
.wpa_psk
);
175 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
176 if (bss
->ssid
.wpa_psk
== NULL
)
178 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
179 bss
->ssid
.wpa_psk
->group
= 1;
180 } else if (ssid
->passphrase
) {
181 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
182 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
183 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
184 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
186 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
187 if (ssid
->wep_key_len
[i
] == 0)
189 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
190 if (wep
->key
[i
] == NULL
)
192 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
193 ssid
->wep_key_len
[i
]);
194 wep
->len
[i
] = ssid
->wep_key_len
[i
];
196 wep
->idx
= ssid
->wep_tx_keyidx
;
200 if (ssid
->ap_max_inactivity
)
201 bss
->ap_max_inactivity
= ssid
->ap_max_inactivity
;
203 if (ssid
->dtim_period
)
204 bss
->dtim_period
= ssid
->dtim_period
;
205 else if (wpa_s
->conf
->dtim_period
)
206 bss
->dtim_period
= wpa_s
->conf
->dtim_period
;
208 if (ssid
->beacon_int
)
209 conf
->beacon_int
= ssid
->beacon_int
;
210 else if (wpa_s
->conf
->beacon_int
)
211 conf
->beacon_int
= wpa_s
->conf
->beacon_int
;
213 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
214 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
215 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
, bss
->wpa_pairwise
,
218 if (bss
->wpa
&& bss
->ieee802_1x
)
219 bss
->ssid
.security_policy
= SECURITY_WPA
;
221 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
222 else if (bss
->ieee802_1x
) {
223 int cipher
= WPA_CIPHER_NONE
;
224 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
225 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
226 if (bss
->default_wep_key_len
)
227 cipher
= bss
->default_wep_key_len
>= 13 ?
228 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
229 bss
->wpa_group
= cipher
;
230 bss
->wpa_pairwise
= cipher
;
231 bss
->rsn_pairwise
= cipher
;
232 } else if (bss
->ssid
.wep
.keys_set
) {
233 int cipher
= WPA_CIPHER_WEP40
;
234 if (bss
->ssid
.wep
.len
[0] >= 13)
235 cipher
= WPA_CIPHER_WEP104
;
236 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
237 bss
->wpa_group
= cipher
;
238 bss
->wpa_pairwise
= cipher
;
239 bss
->rsn_pairwise
= cipher
;
241 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
242 bss
->wpa_group
= WPA_CIPHER_NONE
;
243 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
244 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
247 if (bss
->wpa_group_rekey
< 86400 && (bss
->wpa
& 2) &&
248 (bss
->wpa_group
== WPA_CIPHER_CCMP
||
249 bss
->wpa_group
== WPA_CIPHER_GCMP
)) {
251 * Strong ciphers do not need frequent rekeying, so increase
252 * the default GTK rekeying period to 24 hours.
254 bss
->wpa_group_rekey
= 86400;
259 * Enable WPS by default for open and WPA/WPA2-Personal network, but
260 * require user interaction to actually use it. Only the internal
261 * Registrar is supported.
263 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
264 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
267 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
268 (!(bss
->rsn_pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
269 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
271 #endif /* CONFIG_WPS2 */
274 if (!ssid
->ignore_broadcast_ssid
)
277 bss
->ap_setup_locked
= 2;
278 if (wpa_s
->conf
->config_methods
)
279 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
280 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
282 if (wpa_s
->conf
->device_name
) {
283 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
284 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
286 if (wpa_s
->conf
->manufacturer
)
287 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
288 if (wpa_s
->conf
->model_name
)
289 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
290 if (wpa_s
->conf
->model_number
)
291 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
292 if (wpa_s
->conf
->serial_number
)
293 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
294 if (is_nil_uuid(wpa_s
->conf
->uuid
))
295 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
297 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
298 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
299 bss
->pbc_in_m1
= wpa_s
->conf
->pbc_in_m1
;
301 #endif /* CONFIG_WPS */
303 if (wpa_s
->max_stations
&&
304 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
305 bss
->max_num_sta
= wpa_s
->max_stations
;
307 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
309 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
311 if (wpa_s
->conf
->ap_vendor_elements
) {
312 bss
->vendor_elements
=
313 wpabuf_dup(wpa_s
->conf
->ap_vendor_elements
);
320 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
323 struct wpa_supplicant
*wpa_s
= ctx
;
324 const struct ieee80211_mgmt
*mgmt
;
327 mgmt
= (const struct ieee80211_mgmt
*) buf
;
328 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
331 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
332 mgmt
->u
.action
.category
,
333 &mgmt
->u
.action
.u
.vs_public_action
.action
,
334 len
- hdr_len
, freq
);
335 #endif /* CONFIG_P2P */
339 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
340 union wps_event_data
*data
)
343 struct wpa_supplicant
*wpa_s
= ctx
;
345 if (event
== WPS_EV_FAIL
) {
346 struct wps_event_fail
*fail
= &data
->fail
;
348 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
349 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
351 * src/ap/wps_hostapd.c has already sent this on the
352 * main interface, so only send on the parent interface
355 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
356 "msg=%d config_error=%d",
357 fail
->msg
, fail
->config_error
);
359 wpas_p2p_wps_failed(wpa_s
, fail
);
361 #endif /* CONFIG_P2P */
365 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
366 int authorized
, const u8
*p2p_dev_addr
)
368 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
372 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
375 struct wpa_supplicant
*wpa_s
= ctx
;
376 const struct ieee80211_mgmt
*mgmt
;
379 mgmt
= (const struct ieee80211_mgmt
*) buf
;
380 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
383 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
384 mgmt
->u
.action
.category
,
385 &mgmt
->u
.action
.u
.vs_public_action
.action
,
386 len
- hdr_len
, freq
);
387 #endif /* CONFIG_P2P */
392 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
393 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
397 struct wpa_supplicant
*wpa_s
= ctx
;
398 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
,
400 #else /* CONFIG_P2P */
402 #endif /* CONFIG_P2P */
406 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
410 struct wpa_supplicant
*wpa_s
= ctx
;
411 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
412 #endif /* CONFIG_P2P */
416 static void wpas_ap_configured_cb(void *ctx
)
418 struct wpa_supplicant
*wpa_s
= ctx
;
420 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
422 if (wpa_s
->ap_configured_cb
)
423 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
424 wpa_s
->ap_configured_cb_data
);
428 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
429 struct wpa_ssid
*ssid
)
431 struct wpa_driver_associate_params params
;
432 struct hostapd_iface
*hapd_iface
;
433 struct hostapd_config
*conf
;
436 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
437 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
441 wpa_supplicant_ap_deinit(wpa_s
);
443 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
444 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
446 os_memset(¶ms
, 0, sizeof(params
));
447 params
.ssid
= ssid
->ssid
;
448 params
.ssid_len
= ssid
->ssid_len
;
449 switch (ssid
->mode
) {
450 case WPAS_MODE_INFRA
:
451 params
.mode
= IEEE80211_MODE_INFRA
;
454 params
.mode
= IEEE80211_MODE_IBSS
;
457 case WPAS_MODE_P2P_GO
:
458 case WPAS_MODE_P2P_GROUP_FORMATION
:
459 params
.mode
= IEEE80211_MODE_AP
;
462 params
.freq
= ssid
->frequency
;
464 params
.wpa_proto
= ssid
->proto
;
465 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
466 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
468 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
469 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
471 wpa_s
->pairwise_cipher
= wpa_pick_pairwise_cipher(ssid
->pairwise_cipher
,
473 if (wpa_s
->pairwise_cipher
< 0) {
474 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
478 params
.pairwise_suite
=
479 wpa_cipher_to_suite_driver(wpa_s
->pairwise_cipher
);
480 params
.group_suite
= params
.pairwise_suite
;
483 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
484 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
486 #endif /* CONFIG_P2P */
488 if (wpa_s
->parent
->set_ap_uapsd
)
489 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
493 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
494 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
498 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
499 if (hapd_iface
== NULL
)
501 hapd_iface
->owner
= wpa_s
;
502 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
503 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
504 hapd_iface
->extended_capa
= wpa_s
->extended_capa
;
505 hapd_iface
->extended_capa_mask
= wpa_s
->extended_capa_mask
;
506 hapd_iface
->extended_capa_len
= wpa_s
->extended_capa_len
;
508 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
510 wpa_supplicant_ap_deinit(wpa_s
);
514 os_memcpy(wpa_s
->ap_iface
->conf
->wmm_ac_params
,
515 wpa_s
->conf
->wmm_ac_params
,
516 sizeof(wpa_s
->conf
->wmm_ac_params
));
518 if (params
.uapsd
> 0) {
519 conf
->bss
->wmm_enabled
= 1;
520 conf
->bss
->wmm_uapsd
= 1;
523 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
524 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
525 wpa_supplicant_ap_deinit(wpa_s
);
530 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
531 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
532 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
533 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
535 #endif /* CONFIG_P2P */
537 hapd_iface
->num_bss
= conf
->num_bss
;
538 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
539 sizeof(struct hostapd_data
*));
540 if (hapd_iface
->bss
== NULL
) {
541 wpa_supplicant_ap_deinit(wpa_s
);
545 for (i
= 0; i
< conf
->num_bss
; i
++) {
547 hostapd_alloc_bss_data(hapd_iface
, conf
,
549 if (hapd_iface
->bss
[i
] == NULL
) {
550 wpa_supplicant_ap_deinit(wpa_s
);
554 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
555 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
556 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
557 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
558 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
559 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
560 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
561 ap_probe_req_rx
, wpa_s
);
562 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
563 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
564 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
565 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
566 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
567 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
569 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
570 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(wpa_s
,
572 #endif /* CONFIG_P2P */
573 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
574 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
577 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
578 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
579 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
581 wpa_s
->current_ssid
= ssid
;
582 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
583 wpa_s
->assoc_freq
= ssid
->frequency
;
585 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
586 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
587 wpa_supplicant_ap_deinit(wpa_s
);
595 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
598 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
599 #endif /* CONFIG_WPS */
601 if (wpa_s
->ap_iface
== NULL
)
604 wpa_s
->current_ssid
= NULL
;
605 wpa_s
->assoc_freq
= 0;
607 if (wpa_s
->ap_iface
->bss
)
608 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
609 wpas_p2p_group_deinit(wpa_s
);
610 #endif /* CONFIG_P2P */
611 hostapd_interface_deinit(wpa_s
->ap_iface
);
612 hostapd_interface_free(wpa_s
->ap_iface
);
613 wpa_s
->ap_iface
= NULL
;
614 wpa_drv_deinit_ap(wpa_s
);
618 void ap_tx_status(void *ctx
, const u8
*addr
,
619 const u8
*buf
, size_t len
, int ack
)
622 struct wpa_supplicant
*wpa_s
= ctx
;
623 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
624 #endif /* NEED_AP_MLME */
628 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
629 const u8
*data
, size_t len
, int ack
)
632 struct wpa_supplicant
*wpa_s
= ctx
;
633 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
634 #endif /* NEED_AP_MLME */
638 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
641 struct wpa_supplicant
*wpa_s
= ctx
;
643 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
644 #endif /* NEED_AP_MLME */
648 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
651 struct wpa_supplicant
*wpa_s
= ctx
;
652 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
653 #endif /* NEED_AP_MLME */
657 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
660 struct wpa_supplicant
*wpa_s
= ctx
;
661 struct hostapd_frame_info fi
;
662 os_memset(&fi
, 0, sizeof(fi
));
663 fi
.datarate
= rx_mgmt
->datarate
;
664 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
665 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
666 rx_mgmt
->frame_len
, &fi
);
667 #endif /* NEED_AP_MLME */
671 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
674 struct wpa_supplicant
*wpa_s
= ctx
;
675 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
676 #endif /* NEED_AP_MLME */
680 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
681 const u8
*src_addr
, const u8
*buf
, size_t len
)
683 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
689 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
690 const u8
*p2p_dev_addr
)
692 if (!wpa_s
->ap_iface
)
694 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
699 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
701 struct wps_registrar
*reg
;
702 int reg_sel
= 0, wps_sta
= 0;
704 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
707 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
708 reg_sel
= wps_registrar_wps_cancel(reg
);
709 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
710 ap_sta_wps_cancel
, NULL
);
712 if (!reg_sel
&& !wps_sta
) {
713 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
719 * There are 2 cases to return wps cancel as success:
720 * 1. When wps cancel was initiated but no connection has been
721 * established with client yet.
722 * 2. Client is in the middle of exchanging WPS messages.
729 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
730 const char *pin
, char *buf
, size_t buflen
,
733 int ret
, ret_len
= 0;
735 if (!wpa_s
->ap_iface
)
739 unsigned int rpin
= wps_generate_pin();
740 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
743 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
745 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
753 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
755 struct wpa_supplicant
*wpa_s
= eloop_data
;
756 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
757 wpas_wps_ap_pin_disable(wpa_s
);
761 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
763 struct hostapd_data
*hapd
;
765 if (wpa_s
->ap_iface
== NULL
)
767 hapd
= wpa_s
->ap_iface
->bss
[0];
768 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
769 hapd
->ap_pin_failures
= 0;
770 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
772 eloop_register_timeout(timeout
, 0,
773 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
777 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
779 struct hostapd_data
*hapd
;
781 if (wpa_s
->ap_iface
== NULL
)
783 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
784 hapd
= wpa_s
->ap_iface
->bss
[0];
785 os_free(hapd
->conf
->ap_pin
);
786 hapd
->conf
->ap_pin
= NULL
;
787 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
791 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
793 struct hostapd_data
*hapd
;
797 if (wpa_s
->ap_iface
== NULL
)
799 hapd
= wpa_s
->ap_iface
->bss
[0];
800 pin
= wps_generate_pin();
801 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
802 os_free(hapd
->conf
->ap_pin
);
803 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
804 if (hapd
->conf
->ap_pin
== NULL
)
806 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
808 return hapd
->conf
->ap_pin
;
812 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
814 struct hostapd_data
*hapd
;
815 if (wpa_s
->ap_iface
== NULL
)
817 hapd
= wpa_s
->ap_iface
->bss
[0];
818 return hapd
->conf
->ap_pin
;
822 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
825 struct hostapd_data
*hapd
;
829 if (wpa_s
->ap_iface
== NULL
)
831 hapd
= wpa_s
->ap_iface
->bss
[0];
832 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
833 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
835 os_free(hapd
->conf
->ap_pin
);
836 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
837 if (hapd
->conf
->ap_pin
== NULL
)
839 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
845 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
847 struct hostapd_data
*hapd
;
849 if (wpa_s
->ap_iface
== NULL
)
851 hapd
= wpa_s
->ap_iface
->bss
[0];
854 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
855 * PIN if this happens multiple times to slow down brute force attacks.
857 hapd
->ap_pin_failures
++;
858 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
859 hapd
->ap_pin_failures
);
860 if (hapd
->ap_pin_failures
< 3)
863 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
864 hapd
->ap_pin_failures
= 0;
865 os_free(hapd
->conf
->ap_pin
);
866 hapd
->conf
->ap_pin
= NULL
;
870 #ifdef CONFIG_WPS_NFC
872 struct wpabuf
* wpas_ap_wps_nfc_config_token(struct wpa_supplicant
*wpa_s
,
875 struct hostapd_data
*hapd
;
877 if (wpa_s
->ap_iface
== NULL
)
879 hapd
= wpa_s
->ap_iface
->bss
[0];
880 return hostapd_wps_nfc_config_token(hapd
, ndef
);
884 struct wpabuf
* wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant
*wpa_s
,
887 struct hostapd_data
*hapd
;
889 if (wpa_s
->ap_iface
== NULL
)
891 hapd
= wpa_s
->ap_iface
->bss
[0];
892 return hostapd_wps_nfc_hs_cr(hapd
, ndef
);
895 #endif /* CONFIG_WPS_NFC */
897 #endif /* CONFIG_WPS */
900 #ifdef CONFIG_CTRL_IFACE
902 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
903 char *buf
, size_t buflen
)
905 if (wpa_s
->ap_iface
== NULL
)
907 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
912 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
913 char *buf
, size_t buflen
)
915 if (wpa_s
->ap_iface
== NULL
)
917 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
922 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
923 char *buf
, size_t buflen
)
925 if (wpa_s
->ap_iface
== NULL
)
927 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
932 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant
*wpa_s
,
935 if (wpa_s
->ap_iface
== NULL
)
937 return hostapd_ctrl_iface_disassociate(wpa_s
->ap_iface
->bss
[0],
942 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant
*wpa_s
,
945 if (wpa_s
->ap_iface
== NULL
)
947 return hostapd_ctrl_iface_deauthenticate(wpa_s
->ap_iface
->bss
[0],
952 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
953 size_t buflen
, int verbose
)
955 char *pos
= buf
, *end
= buf
+ buflen
;
957 struct hostapd_bss_config
*conf
;
959 if (wpa_s
->ap_iface
== NULL
)
962 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
966 ret
= os_snprintf(pos
, end
- pos
,
967 "pairwise_cipher=%s\n"
970 wpa_cipher_txt(conf
->rsn_pairwise
),
971 wpa_cipher_txt(conf
->wpa_group
),
972 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
974 if (ret
< 0 || ret
>= end
- pos
)
980 #endif /* CONFIG_CTRL_IFACE */
983 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
985 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
986 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
987 struct hostapd_data
*hapd
;
989 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
990 ssid
->mode
== WPAS_MODE_INFRA
||
991 ssid
->mode
== WPAS_MODE_IBSS
)
995 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
996 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
997 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
998 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
1000 #endif /* CONFIG_P2P */
1002 hapd
= iface
->bss
[0];
1003 if (hapd
->drv_priv
== NULL
)
1005 ieee802_11_set_beacons(iface
);
1006 hostapd_set_ap_wps_ie(hapd
);
1012 void wpas_ap_ch_switch(struct wpa_supplicant
*wpa_s
, int freq
, int ht
,
1015 if (!wpa_s
->ap_iface
)
1018 wpa_s
->assoc_freq
= freq
;
1019 hostapd_event_ch_switch(wpa_s
->ap_iface
->bss
[0], freq
, ht
, offset
);
1023 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
1026 struct hostapd_data
*hapd
;
1027 struct hostapd_bss_config
*conf
;
1029 if (!wpa_s
->ap_iface
)
1033 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
1036 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
1038 hapd
= wpa_s
->ap_iface
->bss
[0];
1041 os_free(conf
->accept_mac
);
1042 conf
->accept_mac
= NULL
;
1043 conf
->num_accept_mac
= 0;
1044 os_free(conf
->deny_mac
);
1045 conf
->deny_mac
= NULL
;
1046 conf
->num_deny_mac
= 0;
1049 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
1053 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
1054 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
1055 if (conf
->accept_mac
== NULL
)
1057 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
1058 conf
->num_accept_mac
= 1;