2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
16 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "utils/eloop.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/wpa_ctrl.h"
22 #include "ap/hostapd.h"
23 #include "ap/ap_config.h"
25 #include "ap/ieee802_11.h"
26 #endif /* NEED_AP_MLME */
27 #include "ap/beacon.h"
28 #include "ap/ieee802_1x.h"
29 #include "ap/wps_hostapd.h"
30 #include "ap/ctrl_iface_ap.h"
31 #include "eap_common/eap_defs.h"
32 #include "eap_server/eap_methods.h"
33 #include "eap_common/eap_wsc_common.h"
35 #include "common/ieee802_11_defs.h"
36 #include "config_ssid.h"
38 #include "wpa_supplicant_i.h"
40 #include "p2p_supplicant.h"
42 #include "ap/sta_info.h"
45 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
);
48 static int wpa_supplicant_conf_ap(struct wpa_supplicant
*wpa_s
,
49 struct wpa_ssid
*ssid
,
50 struct hostapd_config
*conf
)
52 struct hostapd_bss_config
*bss
= &conf
->bss
[0];
55 conf
->driver
= wpa_s
->driver
;
57 os_strlcpy(bss
->iface
, wpa_s
->ifname
, sizeof(bss
->iface
));
59 if (ssid
->frequency
== 0) {
60 /* default channel 11 */
61 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
63 } else if (ssid
->frequency
>= 2412 && ssid
->frequency
<= 2472) {
64 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211G
;
65 conf
->channel
= (ssid
->frequency
- 2407) / 5;
66 } else if ((ssid
->frequency
>= 5180 && ssid
->frequency
<= 5240) ||
67 (ssid
->frequency
>= 5745 && ssid
->frequency
<= 5825)) {
68 conf
->hw_mode
= HOSTAPD_MODE_IEEE80211A
;
69 conf
->channel
= (ssid
->frequency
- 5000) / 5;
71 wpa_printf(MSG_ERROR
, "Unsupported AP mode frequency: %d MHz",
76 /* TODO: enable HT if driver supports it;
77 * drop to 11b if driver does not support 11g */
80 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
) {
81 /* Remove 802.11b rates from supported and basic rate sets */
82 int *list
= os_malloc(4 * sizeof(int));
89 conf
->basic_rates
= list
;
91 list
= os_malloc(9 * sizeof(int));
103 conf
->supported_rates
= list
;
105 #endif /* CONFIG_P2P */
107 if (ssid
->ssid_len
== 0) {
108 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
111 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
112 bss
->ssid
.ssid
[ssid
->ssid_len
] = '\0';
113 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
114 bss
->ssid
.ssid_set
= 1;
116 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
117 bss
->wpa
= ssid
->proto
;
118 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
119 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
120 if (ssid
->passphrase
) {
121 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
122 } else if (ssid
->psk_set
) {
123 os_free(bss
->ssid
.wpa_psk
);
124 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
125 if (bss
->ssid
.wpa_psk
== NULL
)
127 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
128 bss
->ssid
.wpa_psk
->group
= 1;
131 /* Select group cipher based on the enabled pairwise cipher suites */
134 pairwise
|= bss
->wpa_pairwise
;
136 if (bss
->rsn_pairwise
== 0)
137 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
138 pairwise
|= bss
->rsn_pairwise
;
140 if (pairwise
& WPA_CIPHER_TKIP
)
141 bss
->wpa_group
= WPA_CIPHER_TKIP
;
143 bss
->wpa_group
= WPA_CIPHER_CCMP
;
145 if (bss
->wpa
&& bss
->ieee802_1x
)
146 bss
->ssid
.security_policy
= SECURITY_WPA
;
148 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
149 else if (bss
->ieee802_1x
) {
150 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
151 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
152 } else if (bss
->ssid
.wep
.keys_set
)
153 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
155 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
159 * Enable WPS by default, but require user interaction to actually use
160 * it. Only the internal Registrar is supported.
164 bss
->ap_setup_locked
= 2;
165 if (wpa_s
->conf
->config_methods
)
166 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
167 if (wpa_s
->conf
->device_type
)
168 bss
->device_type
= os_strdup(wpa_s
->conf
->device_type
);
169 if (wpa_s
->conf
->device_name
) {
170 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
171 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
173 if (wpa_s
->conf
->manufacturer
)
174 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
175 if (wpa_s
->conf
->model_name
)
176 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
177 if (wpa_s
->conf
->model_number
)
178 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
179 if (wpa_s
->conf
->serial_number
)
180 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
181 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
182 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
183 #endif /* CONFIG_WPS */
185 if (wpa_s
->max_stations
&&
186 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
187 bss
->max_num_sta
= wpa_s
->max_stations
;
189 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
195 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
198 struct wpa_supplicant
*wpa_s
= ctx
;
199 const struct ieee80211_mgmt
*mgmt
;
202 mgmt
= (const struct ieee80211_mgmt
*) buf
;
203 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
206 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
207 mgmt
->u
.action
.category
,
208 &mgmt
->u
.action
.u
.vs_public_action
.action
,
209 len
- hdr_len
, freq
);
210 #endif /* CONFIG_P2P */
214 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
215 union wps_event_data
*data
)
218 struct wpa_supplicant
*wpa_s
= ctx
;
220 if (event
== WPS_EV_FAIL
&& wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
221 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
222 struct wps_event_fail
*fail
= &data
->fail
;
225 * src/ap/wps_hostapd.c has already sent this on the main
226 * interface, so only send on the parent interface here if
229 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
230 "msg=%d config_error=%d",
231 fail
->msg
, fail
->config_error
);
233 #endif /* CONFIG_P2P */
237 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
240 struct wpa_supplicant
*wpa_s
= ctx
;
241 const struct ieee80211_mgmt
*mgmt
;
244 mgmt
= (const struct ieee80211_mgmt
*) buf
;
245 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
248 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
249 mgmt
->u
.action
.category
,
250 &mgmt
->u
.action
.u
.vs_public_action
.action
,
251 len
- hdr_len
, freq
);
252 #endif /* CONFIG_P2P */
257 static int ap_probe_req_rx(void *ctx
, const u8
*addr
, const u8
*ie
,
261 struct wpa_supplicant
*wpa_s
= ctx
;
262 return wpas_p2p_probe_req_rx(wpa_s
, addr
, ie
, ie_len
);
263 #else /* CONFIG_P2P */
265 #endif /* CONFIG_P2P */
269 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
273 struct wpa_supplicant
*wpa_s
= ctx
;
274 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
275 #endif /* CONFIG_P2P */
279 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
280 struct wpa_ssid
*ssid
)
282 struct wpa_driver_associate_params params
;
283 struct hostapd_iface
*hapd_iface
;
284 struct hostapd_config
*conf
;
287 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
288 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
292 wpa_supplicant_ap_deinit(wpa_s
);
294 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
295 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
297 os_memset(¶ms
, 0, sizeof(params
));
298 params
.ssid
= ssid
->ssid
;
299 params
.ssid_len
= ssid
->ssid_len
;
300 switch (ssid
->mode
) {
301 case WPAS_MODE_INFRA
:
302 params
.mode
= IEEE80211_MODE_INFRA
;
305 params
.mode
= IEEE80211_MODE_IBSS
;
308 case WPAS_MODE_P2P_GO
:
309 case WPAS_MODE_P2P_GROUP_FORMATION
:
310 params
.mode
= IEEE80211_MODE_AP
;
313 params
.freq
= ssid
->frequency
;
315 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
316 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
318 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
319 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
321 if (ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
)
322 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
323 else if (ssid
->pairwise_cipher
& WPA_CIPHER_TKIP
)
324 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
325 else if (ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)
326 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
328 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
332 params
.pairwise_suite
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
333 params
.group_suite
= params
.pairwise_suite
;
336 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
337 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
339 wpa_drv_set_intra_bss(wpa_s
, wpa_s
->conf
->p2p_intra_bss
);
340 #endif /* CONFIG_P2P */
342 if (wpa_s
->parent
->set_ap_uapsd
)
343 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
347 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
348 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
352 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
353 if (hapd_iface
== NULL
)
355 hapd_iface
->owner
= wpa_s
;
357 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
359 wpa_supplicant_ap_deinit(wpa_s
);
363 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
364 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
365 wpa_supplicant_ap_deinit(wpa_s
);
370 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
371 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
372 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
373 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
375 #endif /* CONFIG_P2P */
377 hapd_iface
->num_bss
= conf
->num_bss
;
378 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
379 sizeof(struct hostapd_data
*));
380 if (hapd_iface
->bss
== NULL
) {
381 wpa_supplicant_ap_deinit(wpa_s
);
385 for (i
= 0; i
< conf
->num_bss
; i
++) {
387 hostapd_alloc_bss_data(hapd_iface
, conf
,
389 if (hapd_iface
->bss
[i
] == NULL
) {
390 wpa_supplicant_ap_deinit(wpa_s
);
394 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
395 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
396 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
397 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
398 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
399 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
400 ap_probe_req_rx
, wpa_s
);
401 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
402 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
403 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
404 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
406 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
407 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(
408 wpa_s
, ssid
->p2p_persistent_group
,
409 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
);
410 #endif /* CONFIG_P2P */
413 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
414 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
415 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
417 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
418 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
419 wpa_supplicant_ap_deinit(wpa_s
);
423 wpa_s
->current_ssid
= ssid
;
424 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
425 wpa_s
->assoc_freq
= ssid
->frequency
;
426 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
428 if (wpa_s
->ap_configured_cb
)
429 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
430 wpa_s
->ap_configured_cb_data
);
436 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
438 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
440 if (wpa_s
->ap_iface
== NULL
)
443 wpa_s
->current_ssid
= NULL
;
445 if (wpa_s
->ap_iface
->bss
)
446 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
447 wpas_p2p_group_deinit(wpa_s
);
448 #endif /* CONFIG_P2P */
449 hostapd_interface_deinit(wpa_s
->ap_iface
);
450 hostapd_interface_free(wpa_s
->ap_iface
);
451 wpa_s
->ap_iface
= NULL
;
452 wpa_drv_deinit_ap(wpa_s
);
456 void ap_tx_status(void *ctx
, const u8
*addr
,
457 const u8
*buf
, size_t len
, int ack
)
460 struct wpa_supplicant
*wpa_s
= ctx
;
461 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
462 #endif /* NEED_AP_MLME */
466 void ap_rx_from_unknown_sta(void *ctx
, const u8
*frame
, size_t len
)
469 struct wpa_supplicant
*wpa_s
= ctx
;
470 const struct ieee80211_hdr
*hdr
=
471 (const struct ieee80211_hdr
*) frame
;
472 u16 fc
= le_to_host16(hdr
->frame_control
);
473 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], hdr
->addr2
,
474 (fc
& (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) ==
475 (WLAN_FC_TODS
| WLAN_FC_FROMDS
));
476 #endif /* NEED_AP_MLME */
480 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
483 struct wpa_supplicant
*wpa_s
= ctx
;
484 struct hostapd_frame_info fi
;
485 os_memset(&fi
, 0, sizeof(fi
));
486 fi
.datarate
= rx_mgmt
->datarate
;
487 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
488 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
489 rx_mgmt
->frame_len
, &fi
);
490 #endif /* NEED_AP_MLME */
494 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
497 struct wpa_supplicant
*wpa_s
= ctx
;
498 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
499 #endif /* NEED_AP_MLME */
503 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
504 const u8
*src_addr
, const u8
*buf
, size_t len
)
506 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
512 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
514 if (!wpa_s
->ap_iface
)
516 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0]);
520 static int wpa_supplicant_ap_wps_sta_cancel(struct hostapd_data
*hapd
,
521 struct sta_info
*sta
, void *ctx
)
523 if (sta
&& (sta
->flags
& WLAN_STA_WPS
)) {
524 ap_sta_deauthenticate(hapd
, sta
,
525 WLAN_REASON_PREV_AUTH_NOT_VALID
);
526 wpa_printf(MSG_DEBUG
, "WPS: %s: Deauth sta=" MACSTR
,
527 __func__
, MAC2STR(sta
->addr
));
535 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
537 struct wps_registrar
*reg
;
538 int reg_sel
= 0, wps_sta
= 0;
540 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
543 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
544 reg_sel
= wps_registrar_wps_cancel(reg
);
545 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
546 wpa_supplicant_ap_wps_sta_cancel
, NULL
);
548 if (!reg_sel
&& !wps_sta
) {
549 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
555 * There are 2 cases to return wps cancel as success:
556 * 1. When wps cancel was initiated but no connection has been
557 * established with client yet.
558 * 2. Client is in the middle of exchanging WPS messages.
565 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
566 const char *pin
, char *buf
, size_t buflen
)
568 int ret
, ret_len
= 0;
570 if (!wpa_s
->ap_iface
)
574 unsigned int rpin
= wps_generate_pin();
575 ret_len
= os_snprintf(buf
, buflen
, "%d", rpin
);
578 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
580 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
588 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
590 struct wpa_supplicant
*wpa_s
= eloop_data
;
591 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
592 wpas_wps_ap_pin_disable(wpa_s
);
596 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
598 struct hostapd_data
*hapd
;
600 if (wpa_s
->ap_iface
== NULL
)
602 hapd
= wpa_s
->ap_iface
->bss
[0];
603 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
604 hapd
->ap_pin_failures
= 0;
605 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
607 eloop_register_timeout(timeout
, 0,
608 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
612 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
614 struct hostapd_data
*hapd
;
616 if (wpa_s
->ap_iface
== NULL
)
618 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
619 hapd
= wpa_s
->ap_iface
->bss
[0];
620 os_free(hapd
->conf
->ap_pin
);
621 hapd
->conf
->ap_pin
= NULL
;
622 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
626 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
628 struct hostapd_data
*hapd
;
632 if (wpa_s
->ap_iface
== NULL
)
634 hapd
= wpa_s
->ap_iface
->bss
[0];
635 pin
= wps_generate_pin();
636 os_snprintf(pin_txt
, sizeof(pin_txt
), "%u", pin
);
637 os_free(hapd
->conf
->ap_pin
);
638 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
639 if (hapd
->conf
->ap_pin
== NULL
)
641 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
643 return hapd
->conf
->ap_pin
;
647 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
649 struct hostapd_data
*hapd
;
650 if (wpa_s
->ap_iface
== NULL
)
652 hapd
= wpa_s
->ap_iface
->bss
[0];
653 return hapd
->conf
->ap_pin
;
657 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
660 struct hostapd_data
*hapd
;
664 if (wpa_s
->ap_iface
== NULL
)
666 hapd
= wpa_s
->ap_iface
->bss
[0];
667 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
668 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
670 os_free(hapd
->conf
->ap_pin
);
671 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
672 if (hapd
->conf
->ap_pin
== NULL
)
674 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
680 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
682 struct hostapd_data
*hapd
;
684 if (wpa_s
->ap_iface
== NULL
)
686 hapd
= wpa_s
->ap_iface
->bss
[0];
689 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
690 * PIN if this happens multiple times to slow down brute force attacks.
692 hapd
->ap_pin_failures
++;
693 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
694 hapd
->ap_pin_failures
);
695 if (hapd
->ap_pin_failures
< 3)
698 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
699 hapd
->ap_pin_failures
= 0;
700 os_free(hapd
->conf
->ap_pin
);
701 hapd
->conf
->ap_pin
= NULL
;
704 #endif /* CONFIG_WPS */
707 #ifdef CONFIG_CTRL_IFACE
709 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
710 char *buf
, size_t buflen
)
712 if (wpa_s
->ap_iface
== NULL
)
714 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
719 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
720 char *buf
, size_t buflen
)
722 if (wpa_s
->ap_iface
== NULL
)
724 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
729 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
730 char *buf
, size_t buflen
)
732 if (wpa_s
->ap_iface
== NULL
)
734 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
739 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
740 size_t buflen
, int verbose
)
742 char *pos
= buf
, *end
= buf
+ buflen
;
744 struct hostapd_bss_config
*conf
;
746 if (wpa_s
->ap_iface
== NULL
)
749 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
753 ret
= os_snprintf(pos
, end
- pos
,
754 "pairwise_cipher=%s\n"
757 wpa_cipher_txt(conf
->rsn_pairwise
),
758 wpa_cipher_txt(conf
->wpa_group
),
759 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
761 if (ret
< 0 || ret
>= end
- pos
)
767 #endif /* CONFIG_CTRL_IFACE */
770 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
772 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
773 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
774 struct hostapd_data
*hapd
;
776 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
)
780 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
781 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
782 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
783 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
785 #endif /* CONFIG_P2P */
787 ieee802_11_set_beacons(iface
);
788 hapd
= iface
->bss
[0];
789 hapd
->drv
.set_ap_wps_ie(hapd
);
795 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
798 struct hostapd_data
*hapd
;
799 struct hostapd_bss_config
*conf
;
801 if (!wpa_s
->ap_iface
)
805 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
808 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
810 hapd
= wpa_s
->ap_iface
->bss
[0];
813 os_free(conf
->accept_mac
);
814 conf
->accept_mac
= NULL
;
815 conf
->num_accept_mac
= 0;
816 os_free(conf
->deny_mac
);
817 conf
->deny_mac
= NULL
;
818 conf
->num_deny_mac
= 0;
821 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
825 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
826 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
827 if (conf
->accept_mac
== NULL
)
829 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
830 conf
->num_accept_mac
= 1;