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
];
92 #ifdef CONFIG_HT_OVERRIDES
93 if (ssid
->disable_ht
) {
98 #endif /* CONFIG_HT_OVERRIDES */
100 if (!no_ht
&& mode
&& mode
->ht_capab
) {
101 conf
->ieee80211n
= 1;
104 * white-list capabilities that won't cause issues
105 * to connecting stations, while leaving the current
106 * capabilities intact (currently disabled SMPS).
108 conf
->ht_capab
|= mode
->ht_capab
&
109 (HT_CAP_INFO_GREEN_FIELD
|
110 HT_CAP_INFO_SHORT_GI20MHZ
|
111 HT_CAP_INFO_SHORT_GI40MHZ
|
112 HT_CAP_INFO_RX_STBC_MASK
|
113 HT_CAP_INFO_MAX_AMSDU_SIZE
);
116 #endif /* CONFIG_IEEE80211N */
119 if (conf
->hw_mode
== HOSTAPD_MODE_IEEE80211G
) {
120 /* Remove 802.11b rates from supported and basic rate sets */
121 int *list
= os_malloc(4 * sizeof(int));
128 conf
->basic_rates
= list
;
130 list
= os_malloc(9 * sizeof(int));
142 conf
->supported_rates
= list
;
145 bss
->isolate
= !wpa_s
->conf
->p2p_intra_bss
;
146 #endif /* CONFIG_P2P */
148 if (ssid
->ssid_len
== 0) {
149 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
152 os_memcpy(bss
->ssid
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
153 bss
->ssid
.ssid
[ssid
->ssid_len
] = '\0';
154 bss
->ssid
.ssid_len
= ssid
->ssid_len
;
155 bss
->ssid
.ssid_set
= 1;
157 bss
->ignore_broadcast_ssid
= ssid
->ignore_broadcast_ssid
;
160 bss
->auth_algs
= ssid
->auth_alg
;
162 if (wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
))
163 bss
->wpa
= ssid
->proto
;
164 bss
->wpa_key_mgmt
= ssid
->key_mgmt
;
165 bss
->wpa_pairwise
= ssid
->pairwise_cipher
;
166 if (ssid
->passphrase
) {
167 bss
->ssid
.wpa_passphrase
= os_strdup(ssid
->passphrase
);
168 } else if (ssid
->psk_set
) {
169 os_free(bss
->ssid
.wpa_psk
);
170 bss
->ssid
.wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
171 if (bss
->ssid
.wpa_psk
== NULL
)
173 os_memcpy(bss
->ssid
.wpa_psk
->psk
, ssid
->psk
, PMK_LEN
);
174 bss
->ssid
.wpa_psk
->group
= 1;
175 } else if (ssid
->wep_key_len
[0] || ssid
->wep_key_len
[1] ||
176 ssid
->wep_key_len
[2] || ssid
->wep_key_len
[3]) {
177 struct hostapd_wep_keys
*wep
= &bss
->ssid
.wep
;
179 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
180 if (ssid
->wep_key_len
[i
] == 0)
182 wep
->key
[i
] = os_malloc(ssid
->wep_key_len
[i
]);
183 if (wep
->key
[i
] == NULL
)
185 os_memcpy(wep
->key
[i
], ssid
->wep_key
[i
],
186 ssid
->wep_key_len
[i
]);
187 wep
->len
[i
] = ssid
->wep_key_len
[i
];
189 wep
->idx
= ssid
->wep_tx_keyidx
;
193 if (ssid
->ap_max_inactivity
)
194 bss
->ap_max_inactivity
= ssid
->ap_max_inactivity
;
196 /* Select group cipher based on the enabled pairwise cipher suites */
199 pairwise
|= bss
->wpa_pairwise
;
201 if (bss
->rsn_pairwise
== 0)
202 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
203 pairwise
|= bss
->rsn_pairwise
;
205 if (pairwise
& WPA_CIPHER_TKIP
)
206 bss
->wpa_group
= WPA_CIPHER_TKIP
;
208 bss
->wpa_group
= WPA_CIPHER_CCMP
;
210 if (bss
->wpa
&& bss
->ieee802_1x
)
211 bss
->ssid
.security_policy
= SECURITY_WPA
;
213 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
214 else if (bss
->ieee802_1x
) {
215 int cipher
= WPA_CIPHER_NONE
;
216 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
217 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
218 if (bss
->default_wep_key_len
)
219 cipher
= bss
->default_wep_key_len
>= 13 ?
220 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
221 bss
->wpa_group
= cipher
;
222 bss
->wpa_pairwise
= cipher
;
223 bss
->rsn_pairwise
= cipher
;
224 } else if (bss
->ssid
.wep
.keys_set
) {
225 int cipher
= WPA_CIPHER_WEP40
;
226 if (bss
->ssid
.wep
.len
[0] >= 13)
227 cipher
= WPA_CIPHER_WEP104
;
228 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
229 bss
->wpa_group
= cipher
;
230 bss
->wpa_pairwise
= cipher
;
231 bss
->rsn_pairwise
= cipher
;
233 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
234 bss
->wpa_group
= WPA_CIPHER_NONE
;
235 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
236 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
241 * Enable WPS by default for open and WPA/WPA2-Personal network, but
242 * require user interaction to actually use it. Only the internal
243 * Registrar is supported.
245 if (bss
->ssid
.security_policy
!= SECURITY_WPA_PSK
&&
246 bss
->ssid
.security_policy
!= SECURITY_PLAINTEXT
)
249 if (bss
->ssid
.security_policy
== SECURITY_WPA_PSK
&&
250 (!(pairwise
& WPA_CIPHER_CCMP
) || !(bss
->wpa
& 2)))
251 goto no_wps
; /* WPS2 does not allow WPA/TKIP-only
253 #endif /* CONFIG_WPS2 */
256 if (!ssid
->ignore_broadcast_ssid
)
259 bss
->ap_setup_locked
= 2;
260 if (wpa_s
->conf
->config_methods
)
261 bss
->config_methods
= os_strdup(wpa_s
->conf
->config_methods
);
262 os_memcpy(bss
->device_type
, wpa_s
->conf
->device_type
,
264 if (wpa_s
->conf
->device_name
) {
265 bss
->device_name
= os_strdup(wpa_s
->conf
->device_name
);
266 bss
->friendly_name
= os_strdup(wpa_s
->conf
->device_name
);
268 if (wpa_s
->conf
->manufacturer
)
269 bss
->manufacturer
= os_strdup(wpa_s
->conf
->manufacturer
);
270 if (wpa_s
->conf
->model_name
)
271 bss
->model_name
= os_strdup(wpa_s
->conf
->model_name
);
272 if (wpa_s
->conf
->model_number
)
273 bss
->model_number
= os_strdup(wpa_s
->conf
->model_number
);
274 if (wpa_s
->conf
->serial_number
)
275 bss
->serial_number
= os_strdup(wpa_s
->conf
->serial_number
);
276 if (is_nil_uuid(wpa_s
->conf
->uuid
))
277 os_memcpy(bss
->uuid
, wpa_s
->wps
->uuid
, WPS_UUID_LEN
);
279 os_memcpy(bss
->uuid
, wpa_s
->conf
->uuid
, WPS_UUID_LEN
);
280 os_memcpy(bss
->os_version
, wpa_s
->conf
->os_version
, 4);
281 bss
->pbc_in_m1
= wpa_s
->conf
->pbc_in_m1
;
283 #endif /* CONFIG_WPS */
285 if (wpa_s
->max_stations
&&
286 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
287 bss
->max_num_sta
= wpa_s
->max_stations
;
289 bss
->max_num_sta
= wpa_s
->conf
->max_num_sta
;
291 bss
->disassoc_low_ack
= wpa_s
->conf
->disassoc_low_ack
;
297 static void ap_public_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
300 struct wpa_supplicant
*wpa_s
= ctx
;
301 const struct ieee80211_mgmt
*mgmt
;
304 mgmt
= (const struct ieee80211_mgmt
*) buf
;
305 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
308 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
309 mgmt
->u
.action
.category
,
310 &mgmt
->u
.action
.u
.vs_public_action
.action
,
311 len
- hdr_len
, freq
);
312 #endif /* CONFIG_P2P */
316 static void ap_wps_event_cb(void *ctx
, enum wps_event event
,
317 union wps_event_data
*data
)
320 struct wpa_supplicant
*wpa_s
= ctx
;
322 if (event
== WPS_EV_FAIL
) {
323 struct wps_event_fail
*fail
= &data
->fail
;
325 if (wpa_s
->parent
&& wpa_s
->parent
!= wpa_s
&&
326 wpa_s
== wpa_s
->global
->p2p_group_formation
) {
328 * src/ap/wps_hostapd.c has already sent this on the
329 * main interface, so only send on the parent interface
332 wpa_msg(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_FAIL
333 "msg=%d config_error=%d",
334 fail
->msg
, fail
->config_error
);
336 wpas_p2p_wps_failed(wpa_s
, fail
);
338 #endif /* CONFIG_P2P */
342 static void ap_sta_authorized_cb(void *ctx
, const u8
*mac_addr
,
343 int authorized
, const u8
*p2p_dev_addr
)
345 wpas_notify_sta_authorized(ctx
, mac_addr
, authorized
, p2p_dev_addr
);
349 static int ap_vendor_action_rx(void *ctx
, const u8
*buf
, size_t len
, int freq
)
352 struct wpa_supplicant
*wpa_s
= ctx
;
353 const struct ieee80211_mgmt
*mgmt
;
356 mgmt
= (const struct ieee80211_mgmt
*) buf
;
357 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
360 wpas_p2p_rx_action(wpa_s
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
361 mgmt
->u
.action
.category
,
362 &mgmt
->u
.action
.u
.vs_public_action
.action
,
363 len
- hdr_len
, freq
);
364 #endif /* CONFIG_P2P */
369 static int ap_probe_req_rx(void *ctx
, const u8
*sa
, const u8
*da
,
370 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
374 struct wpa_supplicant
*wpa_s
= ctx
;
375 return wpas_p2p_probe_req_rx(wpa_s
, sa
, da
, bssid
, ie
, ie_len
,
377 #else /* CONFIG_P2P */
379 #endif /* CONFIG_P2P */
383 static void ap_wps_reg_success_cb(void *ctx
, const u8
*mac_addr
,
387 struct wpa_supplicant
*wpa_s
= ctx
;
388 wpas_p2p_wps_success(wpa_s
, mac_addr
, 1);
389 #endif /* CONFIG_P2P */
393 static void wpas_ap_configured_cb(void *ctx
)
395 struct wpa_supplicant
*wpa_s
= ctx
;
397 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
399 if (wpa_s
->ap_configured_cb
)
400 wpa_s
->ap_configured_cb(wpa_s
->ap_configured_cb_ctx
,
401 wpa_s
->ap_configured_cb_data
);
405 int wpa_supplicant_create_ap(struct wpa_supplicant
*wpa_s
,
406 struct wpa_ssid
*ssid
)
408 struct wpa_driver_associate_params params
;
409 struct hostapd_iface
*hapd_iface
;
410 struct hostapd_config
*conf
;
413 if (ssid
->ssid
== NULL
|| ssid
->ssid_len
== 0) {
414 wpa_printf(MSG_ERROR
, "No SSID configured for AP mode");
418 wpa_supplicant_ap_deinit(wpa_s
);
420 wpa_printf(MSG_DEBUG
, "Setting up AP (SSID='%s')",
421 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
423 os_memset(¶ms
, 0, sizeof(params
));
424 params
.ssid
= ssid
->ssid
;
425 params
.ssid_len
= ssid
->ssid_len
;
426 switch (ssid
->mode
) {
427 case WPAS_MODE_INFRA
:
428 params
.mode
= IEEE80211_MODE_INFRA
;
431 params
.mode
= IEEE80211_MODE_IBSS
;
434 case WPAS_MODE_P2P_GO
:
435 case WPAS_MODE_P2P_GROUP_FORMATION
:
436 params
.mode
= IEEE80211_MODE_AP
;
439 params
.freq
= ssid
->frequency
;
441 params
.wpa_proto
= ssid
->proto
;
442 if (ssid
->key_mgmt
& WPA_KEY_MGMT_PSK
)
443 wpa_s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
445 wpa_s
->key_mgmt
= WPA_KEY_MGMT_NONE
;
446 params
.key_mgmt_suite
= key_mgmt2driver(wpa_s
->key_mgmt
);
448 if (ssid
->pairwise_cipher
& WPA_CIPHER_CCMP
)
449 wpa_s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
450 else if (ssid
->pairwise_cipher
& WPA_CIPHER_TKIP
)
451 wpa_s
->pairwise_cipher
= WPA_CIPHER_TKIP
;
452 else if (ssid
->pairwise_cipher
& WPA_CIPHER_NONE
)
453 wpa_s
->pairwise_cipher
= WPA_CIPHER_NONE
;
455 wpa_printf(MSG_WARNING
, "WPA: Failed to select pairwise "
459 params
.pairwise_suite
= cipher_suite2driver(wpa_s
->pairwise_cipher
);
460 params
.group_suite
= params
.pairwise_suite
;
463 if (ssid
->mode
== WPAS_MODE_P2P_GO
||
464 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
466 #endif /* CONFIG_P2P */
468 if (wpa_s
->parent
->set_ap_uapsd
)
469 params
.uapsd
= wpa_s
->parent
->ap_uapsd
;
473 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
474 wpa_msg(wpa_s
, MSG_INFO
, "Failed to start AP functionality");
478 wpa_s
->ap_iface
= hapd_iface
= os_zalloc(sizeof(*wpa_s
->ap_iface
));
479 if (hapd_iface
== NULL
)
481 hapd_iface
->owner
= wpa_s
;
482 hapd_iface
->drv_flags
= wpa_s
->drv_flags
;
483 hapd_iface
->probe_resp_offloads
= wpa_s
->probe_resp_offloads
;
485 wpa_s
->ap_iface
->conf
= conf
= hostapd_config_defaults();
487 wpa_supplicant_ap_deinit(wpa_s
);
491 if (params
.uapsd
> 0) {
492 conf
->bss
->wmm_enabled
= 1;
493 conf
->bss
->wmm_uapsd
= 1;
496 if (wpa_supplicant_conf_ap(wpa_s
, ssid
, conf
)) {
497 wpa_printf(MSG_ERROR
, "Failed to create AP configuration");
498 wpa_supplicant_ap_deinit(wpa_s
);
503 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
504 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
505 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
506 conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
508 #endif /* CONFIG_P2P */
510 hapd_iface
->num_bss
= conf
->num_bss
;
511 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
512 sizeof(struct hostapd_data
*));
513 if (hapd_iface
->bss
== NULL
) {
514 wpa_supplicant_ap_deinit(wpa_s
);
518 for (i
= 0; i
< conf
->num_bss
; i
++) {
520 hostapd_alloc_bss_data(hapd_iface
, conf
,
522 if (hapd_iface
->bss
[i
] == NULL
) {
523 wpa_supplicant_ap_deinit(wpa_s
);
527 hapd_iface
->bss
[i
]->msg_ctx
= wpa_s
;
528 hapd_iface
->bss
[i
]->msg_ctx_parent
= wpa_s
->parent
;
529 hapd_iface
->bss
[i
]->public_action_cb
= ap_public_action_rx
;
530 hapd_iface
->bss
[i
]->public_action_cb_ctx
= wpa_s
;
531 hapd_iface
->bss
[i
]->vendor_action_cb
= ap_vendor_action_rx
;
532 hapd_iface
->bss
[i
]->vendor_action_cb_ctx
= wpa_s
;
533 hostapd_register_probereq_cb(hapd_iface
->bss
[i
],
534 ap_probe_req_rx
, wpa_s
);
535 hapd_iface
->bss
[i
]->wps_reg_success_cb
= ap_wps_reg_success_cb
;
536 hapd_iface
->bss
[i
]->wps_reg_success_cb_ctx
= wpa_s
;
537 hapd_iface
->bss
[i
]->wps_event_cb
= ap_wps_event_cb
;
538 hapd_iface
->bss
[i
]->wps_event_cb_ctx
= wpa_s
;
539 hapd_iface
->bss
[i
]->sta_authorized_cb
= ap_sta_authorized_cb
;
540 hapd_iface
->bss
[i
]->sta_authorized_cb_ctx
= wpa_s
;
542 hapd_iface
->bss
[i
]->p2p
= wpa_s
->global
->p2p
;
543 hapd_iface
->bss
[i
]->p2p_group
= wpas_p2p_group_init(wpa_s
,
545 #endif /* CONFIG_P2P */
546 hapd_iface
->bss
[i
]->setup_complete_cb
= wpas_ap_configured_cb
;
547 hapd_iface
->bss
[i
]->setup_complete_cb_ctx
= wpa_s
;
550 os_memcpy(hapd_iface
->bss
[0]->own_addr
, wpa_s
->own_addr
, ETH_ALEN
);
551 hapd_iface
->bss
[0]->driver
= wpa_s
->driver
;
552 hapd_iface
->bss
[0]->drv_priv
= wpa_s
->drv_priv
;
554 wpa_s
->current_ssid
= ssid
;
555 os_memcpy(wpa_s
->bssid
, wpa_s
->own_addr
, ETH_ALEN
);
556 wpa_s
->assoc_freq
= ssid
->frequency
;
558 if (hostapd_setup_interface(wpa_s
->ap_iface
)) {
559 wpa_printf(MSG_ERROR
, "Failed to initialize AP interface");
560 wpa_supplicant_ap_deinit(wpa_s
);
568 void wpa_supplicant_ap_deinit(struct wpa_supplicant
*wpa_s
)
571 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
572 #endif /* CONFIG_WPS */
574 if (wpa_s
->ap_iface
== NULL
)
577 wpa_s
->current_ssid
= NULL
;
578 wpa_s
->assoc_freq
= 0;
579 wpa_s
->reassociated_connection
= 0;
581 if (wpa_s
->ap_iface
->bss
)
582 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
583 wpas_p2p_group_deinit(wpa_s
);
584 #endif /* CONFIG_P2P */
585 hostapd_interface_deinit(wpa_s
->ap_iface
);
586 hostapd_interface_free(wpa_s
->ap_iface
);
587 wpa_s
->ap_iface
= NULL
;
588 wpa_drv_deinit_ap(wpa_s
);
592 void ap_tx_status(void *ctx
, const u8
*addr
,
593 const u8
*buf
, size_t len
, int ack
)
596 struct wpa_supplicant
*wpa_s
= ctx
;
597 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], addr
, buf
, len
, ack
);
598 #endif /* NEED_AP_MLME */
602 void ap_eapol_tx_status(void *ctx
, const u8
*dst
,
603 const u8
*data
, size_t len
, int ack
)
606 struct wpa_supplicant
*wpa_s
= ctx
;
607 hostapd_tx_status(wpa_s
->ap_iface
->bss
[0], dst
, data
, len
, ack
);
608 #endif /* NEED_AP_MLME */
612 void ap_client_poll_ok(void *ctx
, const u8
*addr
)
615 struct wpa_supplicant
*wpa_s
= ctx
;
617 hostapd_client_poll_ok(wpa_s
->ap_iface
->bss
[0], addr
);
618 #endif /* NEED_AP_MLME */
622 void ap_rx_from_unknown_sta(void *ctx
, const u8
*addr
, int wds
)
625 struct wpa_supplicant
*wpa_s
= ctx
;
626 ieee802_11_rx_from_unknown(wpa_s
->ap_iface
->bss
[0], addr
, wds
);
627 #endif /* NEED_AP_MLME */
631 void ap_mgmt_rx(void *ctx
, struct rx_mgmt
*rx_mgmt
)
634 struct wpa_supplicant
*wpa_s
= ctx
;
635 struct hostapd_frame_info fi
;
636 os_memset(&fi
, 0, sizeof(fi
));
637 fi
.datarate
= rx_mgmt
->datarate
;
638 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
639 ieee802_11_mgmt(wpa_s
->ap_iface
->bss
[0], rx_mgmt
->frame
,
640 rx_mgmt
->frame_len
, &fi
);
641 #endif /* NEED_AP_MLME */
645 void ap_mgmt_tx_cb(void *ctx
, const u8
*buf
, size_t len
, u16 stype
, int ok
)
648 struct wpa_supplicant
*wpa_s
= ctx
;
649 ieee802_11_mgmt_cb(wpa_s
->ap_iface
->bss
[0], buf
, len
, stype
, ok
);
650 #endif /* NEED_AP_MLME */
654 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant
*wpa_s
,
655 const u8
*src_addr
, const u8
*buf
, size_t len
)
657 ieee802_1x_receive(wpa_s
->ap_iface
->bss
[0], src_addr
, buf
, len
);
663 int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
664 const u8
*p2p_dev_addr
)
666 if (!wpa_s
->ap_iface
)
668 return hostapd_wps_button_pushed(wpa_s
->ap_iface
->bss
[0],
673 int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant
*wpa_s
)
675 struct wps_registrar
*reg
;
676 int reg_sel
= 0, wps_sta
= 0;
678 if (!wpa_s
->ap_iface
|| !wpa_s
->ap_iface
->bss
[0]->wps
)
681 reg
= wpa_s
->ap_iface
->bss
[0]->wps
->registrar
;
682 reg_sel
= wps_registrar_wps_cancel(reg
);
683 wps_sta
= ap_for_each_sta(wpa_s
->ap_iface
->bss
[0],
684 ap_sta_wps_cancel
, NULL
);
686 if (!reg_sel
&& !wps_sta
) {
687 wpa_printf(MSG_DEBUG
, "No WPS operation in progress at this "
693 * There are 2 cases to return wps cancel as success:
694 * 1. When wps cancel was initiated but no connection has been
695 * established with client yet.
696 * 2. Client is in the middle of exchanging WPS messages.
703 int wpa_supplicant_ap_wps_pin(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
704 const char *pin
, char *buf
, size_t buflen
)
706 int ret
, ret_len
= 0;
708 if (!wpa_s
->ap_iface
)
712 unsigned int rpin
= wps_generate_pin();
713 ret_len
= os_snprintf(buf
, buflen
, "%08d", rpin
);
716 ret_len
= os_snprintf(buf
, buflen
, "%s", pin
);
718 ret
= hostapd_wps_add_pin(wpa_s
->ap_iface
->bss
[0], bssid
, "any", pin
,
726 static void wpas_wps_ap_pin_timeout(void *eloop_data
, void *user_ctx
)
728 struct wpa_supplicant
*wpa_s
= eloop_data
;
729 wpa_printf(MSG_DEBUG
, "WPS: AP PIN timed out");
730 wpas_wps_ap_pin_disable(wpa_s
);
734 static void wpas_wps_ap_pin_enable(struct wpa_supplicant
*wpa_s
, int timeout
)
736 struct hostapd_data
*hapd
;
738 if (wpa_s
->ap_iface
== NULL
)
740 hapd
= wpa_s
->ap_iface
->bss
[0];
741 wpa_printf(MSG_DEBUG
, "WPS: Enabling AP PIN (timeout=%d)", timeout
);
742 hapd
->ap_pin_failures
= 0;
743 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
745 eloop_register_timeout(timeout
, 0,
746 wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
750 void wpas_wps_ap_pin_disable(struct wpa_supplicant
*wpa_s
)
752 struct hostapd_data
*hapd
;
754 if (wpa_s
->ap_iface
== NULL
)
756 wpa_printf(MSG_DEBUG
, "WPS: Disabling AP PIN");
757 hapd
= wpa_s
->ap_iface
->bss
[0];
758 os_free(hapd
->conf
->ap_pin
);
759 hapd
->conf
->ap_pin
= NULL
;
760 eloop_cancel_timeout(wpas_wps_ap_pin_timeout
, wpa_s
, NULL
);
764 const char * wpas_wps_ap_pin_random(struct wpa_supplicant
*wpa_s
, int timeout
)
766 struct hostapd_data
*hapd
;
770 if (wpa_s
->ap_iface
== NULL
)
772 hapd
= wpa_s
->ap_iface
->bss
[0];
773 pin
= wps_generate_pin();
774 os_snprintf(pin_txt
, sizeof(pin_txt
), "%08u", pin
);
775 os_free(hapd
->conf
->ap_pin
);
776 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
777 if (hapd
->conf
->ap_pin
== NULL
)
779 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
781 return hapd
->conf
->ap_pin
;
785 const char * wpas_wps_ap_pin_get(struct wpa_supplicant
*wpa_s
)
787 struct hostapd_data
*hapd
;
788 if (wpa_s
->ap_iface
== NULL
)
790 hapd
= wpa_s
->ap_iface
->bss
[0];
791 return hapd
->conf
->ap_pin
;
795 int wpas_wps_ap_pin_set(struct wpa_supplicant
*wpa_s
, const char *pin
,
798 struct hostapd_data
*hapd
;
802 if (wpa_s
->ap_iface
== NULL
)
804 hapd
= wpa_s
->ap_iface
->bss
[0];
805 ret
= os_snprintf(pin_txt
, sizeof(pin_txt
), "%s", pin
);
806 if (ret
< 0 || ret
>= (int) sizeof(pin_txt
))
808 os_free(hapd
->conf
->ap_pin
);
809 hapd
->conf
->ap_pin
= os_strdup(pin_txt
);
810 if (hapd
->conf
->ap_pin
== NULL
)
812 wpas_wps_ap_pin_enable(wpa_s
, timeout
);
818 void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant
*wpa_s
)
820 struct hostapd_data
*hapd
;
822 if (wpa_s
->ap_iface
== NULL
)
824 hapd
= wpa_s
->ap_iface
->bss
[0];
827 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
828 * PIN if this happens multiple times to slow down brute force attacks.
830 hapd
->ap_pin_failures
++;
831 wpa_printf(MSG_DEBUG
, "WPS: AP PIN authentication failure number %u",
832 hapd
->ap_pin_failures
);
833 if (hapd
->ap_pin_failures
< 3)
836 wpa_printf(MSG_DEBUG
, "WPS: Disable AP PIN");
837 hapd
->ap_pin_failures
= 0;
838 os_free(hapd
->conf
->ap_pin
);
839 hapd
->conf
->ap_pin
= NULL
;
842 #endif /* CONFIG_WPS */
845 #ifdef CONFIG_CTRL_IFACE
847 int ap_ctrl_iface_sta_first(struct wpa_supplicant
*wpa_s
,
848 char *buf
, size_t buflen
)
850 if (wpa_s
->ap_iface
== NULL
)
852 return hostapd_ctrl_iface_sta_first(wpa_s
->ap_iface
->bss
[0],
857 int ap_ctrl_iface_sta(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
858 char *buf
, size_t buflen
)
860 if (wpa_s
->ap_iface
== NULL
)
862 return hostapd_ctrl_iface_sta(wpa_s
->ap_iface
->bss
[0], txtaddr
,
867 int ap_ctrl_iface_sta_next(struct wpa_supplicant
*wpa_s
, const char *txtaddr
,
868 char *buf
, size_t buflen
)
870 if (wpa_s
->ap_iface
== NULL
)
872 return hostapd_ctrl_iface_sta_next(wpa_s
->ap_iface
->bss
[0], txtaddr
,
877 int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant
*wpa_s
,
880 if (wpa_s
->ap_iface
== NULL
)
882 return hostapd_ctrl_iface_disassociate(wpa_s
->ap_iface
->bss
[0],
887 int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant
*wpa_s
,
890 if (wpa_s
->ap_iface
== NULL
)
892 return hostapd_ctrl_iface_deauthenticate(wpa_s
->ap_iface
->bss
[0],
897 int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant
*wpa_s
, char *buf
,
898 size_t buflen
, int verbose
)
900 char *pos
= buf
, *end
= buf
+ buflen
;
902 struct hostapd_bss_config
*conf
;
904 if (wpa_s
->ap_iface
== NULL
)
907 conf
= wpa_s
->ap_iface
->bss
[0]->conf
;
911 ret
= os_snprintf(pos
, end
- pos
,
912 "pairwise_cipher=%s\n"
915 wpa_cipher_txt(conf
->rsn_pairwise
),
916 wpa_cipher_txt(conf
->wpa_group
),
917 wpa_key_mgmt_txt(conf
->wpa_key_mgmt
,
919 if (ret
< 0 || ret
>= end
- pos
)
925 #endif /* CONFIG_CTRL_IFACE */
928 int wpa_supplicant_ap_update_beacon(struct wpa_supplicant
*wpa_s
)
930 struct hostapd_iface
*iface
= wpa_s
->ap_iface
;
931 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
932 struct hostapd_data
*hapd
;
934 if (ssid
== NULL
|| wpa_s
->ap_iface
== NULL
||
935 ssid
->mode
== WPAS_MODE_INFRA
||
936 ssid
->mode
== WPAS_MODE_IBSS
)
940 if (ssid
->mode
== WPAS_MODE_P2P_GO
)
941 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
;
942 else if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
)
943 iface
->conf
->bss
[0].p2p
= P2P_ENABLED
| P2P_GROUP_OWNER
|
945 #endif /* CONFIG_P2P */
947 hapd
= iface
->bss
[0];
948 if (hapd
->drv_priv
== NULL
)
950 ieee802_11_set_beacons(iface
);
951 hostapd_set_ap_wps_ie(hapd
);
957 int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant
*wpa_s
,
960 struct hostapd_data
*hapd
;
961 struct hostapd_bss_config
*conf
;
963 if (!wpa_s
->ap_iface
)
967 wpa_printf(MSG_DEBUG
, "AP: Set MAC address filter: " MACSTR
,
970 wpa_printf(MSG_DEBUG
, "AP: Clear MAC address filter");
972 hapd
= wpa_s
->ap_iface
->bss
[0];
975 os_free(conf
->accept_mac
);
976 conf
->accept_mac
= NULL
;
977 conf
->num_accept_mac
= 0;
978 os_free(conf
->deny_mac
);
979 conf
->deny_mac
= NULL
;
980 conf
->num_deny_mac
= 0;
983 conf
->macaddr_acl
= ACCEPT_UNLESS_DENIED
;
987 conf
->macaddr_acl
= DENY_UNLESS_ACCEPTED
;
988 conf
->accept_mac
= os_zalloc(sizeof(struct mac_acl_entry
));
989 if (conf
->accept_mac
== NULL
)
991 os_memcpy(conf
->accept_mac
[0].addr
, addr
, ETH_ALEN
);
992 conf
->num_accept_mac
= 1;