2 * WPA Supplicant - Client mode MLME
3 * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
21 #include "config_ssid.h"
22 #include "wpa_supplicant_i.h"
25 #include "rsn_supp/wpa.h"
26 #include "common/ieee802_11_defs.h"
27 #include "common/ieee802_11_common.h"
31 /* Timeouts and intervals in milliseconds */
32 #define IEEE80211_AUTH_TIMEOUT (200)
33 #define IEEE80211_AUTH_MAX_TRIES 3
34 #define IEEE80211_ASSOC_TIMEOUT (200)
35 #define IEEE80211_ASSOC_MAX_TRIES 3
36 #define IEEE80211_MONITORING_INTERVAL (2000)
37 #define IEEE80211_PROBE_INTERVAL (60000)
38 #define IEEE80211_RETRY_AUTH_INTERVAL (1000)
39 #define IEEE80211_SCAN_INTERVAL (2000)
40 #define IEEE80211_SCAN_INTERVAL_SLOW (15000)
41 #define IEEE80211_IBSS_JOIN_TIMEOUT (20000)
43 #define IEEE80211_PROBE_DELAY (33)
44 #define IEEE80211_CHANNEL_TIME (33)
45 #define IEEE80211_PASSIVE_CHANNEL_TIME (200)
46 #define IEEE80211_SCAN_RESULT_EXPIRE (10000)
47 #define IEEE80211_IBSS_MERGE_INTERVAL (30000)
48 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60000)
50 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
53 #define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))
56 struct ieee80211_sta_bss
{
57 struct ieee80211_sta_bss
*next
;
58 struct ieee80211_sta_bss
*hnext
;
61 u8 ssid
[MAX_SSID_LEN
];
63 u16 capability
; /* host byte order */
78 #define IEEE80211_MAX_SUPP_RATES 32
79 u8 supp_rates
[IEEE80211_MAX_SUPP_RATES
];
80 size_t supp_rates_len
;
85 struct os_time last_update
;
89 static void ieee80211_send_probe_req(struct wpa_supplicant
*wpa_s
,
91 const u8
*ssid
, size_t ssid_len
);
92 static struct ieee80211_sta_bss
*
93 ieee80211_bss_get(struct wpa_supplicant
*wpa_s
, const u8
*bssid
);
94 static int ieee80211_sta_find_ibss(struct wpa_supplicant
*wpa_s
);
95 static int ieee80211_sta_wep_configured(struct wpa_supplicant
*wpa_s
);
96 static void ieee80211_sta_timer(void *eloop_ctx
, void *timeout_ctx
);
97 static void ieee80211_sta_scan_timer(void *eloop_ctx
, void *timeout_ctx
);
98 static void ieee80211_build_tspec(struct wpabuf
*buf
);
99 static int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant
*wpa_s
,
100 const u8
*ies
, size_t ies_len
);
103 static int ieee80211_sta_set_channel(struct wpa_supplicant
*wpa_s
,
104 enum hostapd_hw_mode phymode
, int chan
,
108 struct hostapd_hw_modes
*mode
;
110 for (i
= 0; i
< wpa_s
->mlme
.num_modes
; i
++) {
111 mode
= &wpa_s
->mlme
.modes
[i
];
112 if (mode
->mode
== phymode
) {
113 wpa_s
->mlme
.curr_rates
= mode
->rates
;
114 wpa_s
->mlme
.num_curr_rates
= mode
->num_rates
;
119 return wpa_drv_set_channel(wpa_s
, phymode
, chan
, freq
);
123 static int ecw2cw(int ecw
)
134 static void ieee80211_sta_wmm_params(struct wpa_supplicant
*wpa_s
,
135 const u8
*wmm_param
, size_t wmm_param_len
)
142 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
144 count
= wmm_param
[6] & 0x0f;
145 if (count
== wpa_s
->mlme
.wmm_last_param_set
)
147 wpa_s
->mlme
.wmm_last_param_set
= count
;
150 left
= wmm_param_len
- 8;
153 for (; left
>= 4; left
-= 4, pos
+= 4) {
154 int aci
= (pos
[0] >> 5) & 0x03;
155 int acm
= (pos
[0] >> 4) & 0x01;
156 int aifs
, cw_max
, cw_min
, burst_time
;
161 wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
165 wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
169 wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
174 wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
178 aifs
= pos
[0] & 0x0f;
179 cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
180 cw_min
= ecw2cw(pos
[1] & 0x0f);
181 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
182 burst_time
= (pos
[2] | (pos
[3] << 8)) * 32 / 100;
183 wpa_printf(MSG_DEBUG
, "MLME: WMM aci=%d acm=%d aifs=%d "
184 "cWmin=%d cWmax=%d burst=%d",
185 aci
, acm
, aifs
, cw_min
, cw_max
, burst_time
);
186 /* TODO: driver configuration */
191 static void ieee80211_set_associated(struct wpa_supplicant
*wpa_s
, int assoc
)
193 if (wpa_s
->mlme
.associated
== assoc
&& !assoc
)
196 wpa_s
->mlme
.associated
= assoc
;
199 union wpa_event_data data
;
200 os_memset(&data
, 0, sizeof(data
));
201 wpa_s
->mlme
.prev_bssid_set
= 1;
202 os_memcpy(wpa_s
->mlme
.prev_bssid
, wpa_s
->bssid
, ETH_ALEN
);
203 data
.assoc_info
.req_ies
= wpa_s
->mlme
.assocreq_ies
;
204 data
.assoc_info
.req_ies_len
= wpa_s
->mlme
.assocreq_ies_len
;
205 data
.assoc_info
.resp_ies
= wpa_s
->mlme
.assocresp_ies
;
206 data
.assoc_info
.resp_ies_len
= wpa_s
->mlme
.assocresp_ies_len
;
207 data
.assoc_info
.freq
= wpa_s
->mlme
.freq
;
208 wpa_supplicant_event(wpa_s
, EVENT_ASSOC
, &data
);
210 wpa_supplicant_event(wpa_s
, EVENT_DISASSOC
, NULL
);
212 os_get_time(&wpa_s
->mlme
.last_probe
);
216 static int ieee80211_sta_tx(struct wpa_supplicant
*wpa_s
, const u8
*buf
,
219 return wpa_drv_send_mlme(wpa_s
, buf
, len
);
223 static void ieee80211_send_auth(struct wpa_supplicant
*wpa_s
,
224 int transaction
, const u8
*extra
,
225 size_t extra_len
, int encrypt
)
229 struct ieee80211_mgmt
*mgmt
;
231 buf
= os_malloc(sizeof(*mgmt
) + 6 + extra_len
);
233 wpa_printf(MSG_DEBUG
, "MLME: failed to allocate buffer for "
238 mgmt
= (struct ieee80211_mgmt
*) buf
;
240 os_memset(mgmt
, 0, 24 + 6);
241 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
244 mgmt
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
245 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
246 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
247 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
248 mgmt
->u
.auth
.auth_alg
= host_to_le16(wpa_s
->mlme
.auth_alg
);
249 mgmt
->u
.auth
.auth_transaction
= host_to_le16(transaction
);
250 wpa_s
->mlme
.auth_transaction
= transaction
+ 1;
251 mgmt
->u
.auth
.status_code
= host_to_le16(0);
253 os_memcpy(buf
+ len
, extra
, extra_len
);
257 ieee80211_sta_tx(wpa_s
, buf
, len
);
262 static void ieee80211_reschedule_timer(struct wpa_supplicant
*wpa_s
, int ms
)
264 eloop_cancel_timeout(ieee80211_sta_timer
, wpa_s
, NULL
);
265 eloop_register_timeout(ms
/ 1000, 1000 * (ms
% 1000),
266 ieee80211_sta_timer
, wpa_s
, NULL
);
270 static void ieee80211_authenticate(struct wpa_supplicant
*wpa_s
)
275 wpa_s
->mlme
.auth_tries
++;
276 if (wpa_s
->mlme
.auth_tries
> IEEE80211_AUTH_MAX_TRIES
) {
277 wpa_printf(MSG_DEBUG
, "MLME: authentication with AP " MACSTR
278 " timed out", MAC2STR(wpa_s
->bssid
));
282 wpa_s
->mlme
.state
= IEEE80211_AUTHENTICATE
;
283 wpa_printf(MSG_DEBUG
, "MLME: authenticate with AP " MACSTR
,
284 MAC2STR(wpa_s
->bssid
));
289 #ifdef CONFIG_IEEE80211R
290 if ((wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_802_1X
||
291 wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_PSK
) &&
292 wpa_s
->mlme
.ft_ies
) {
293 struct ieee80211_sta_bss
*bss
;
294 struct rsn_mdie
*mdie
= NULL
;
295 bss
= ieee80211_bss_get(wpa_s
, wpa_s
->bssid
);
296 if (bss
&& bss
->mdie_len
>= 2 + sizeof(*mdie
))
297 mdie
= (struct rsn_mdie
*) (bss
->mdie
+ 2);
299 os_memcmp(mdie
->mobility_domain
, wpa_s
->mlme
.current_md
,
300 MOBILITY_DOMAIN_ID_LEN
) == 0) {
301 wpa_printf(MSG_DEBUG
, "MLME: Trying to use FT "
303 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_FT
;
304 extra
= wpa_s
->mlme
.ft_ies
;
305 extra_len
= wpa_s
->mlme
.ft_ies_len
;
308 #endif /* CONFIG_IEEE80211R */
310 ieee80211_send_auth(wpa_s
, 1, extra
, extra_len
, 0);
312 ieee80211_reschedule_timer(wpa_s
, IEEE80211_AUTH_TIMEOUT
);
316 static void ieee80211_send_assoc(struct wpa_supplicant
*wpa_s
)
318 struct ieee80211_mgmt
*mgmt
;
322 struct ieee80211_sta_bss
*bss
;
326 if (wpa_s
->mlme
.curr_rates
== NULL
) {
327 wpa_printf(MSG_DEBUG
, "MLME: curr_rates not set for assoc");
331 buflen
= sizeof(*mgmt
) + 200 + wpa_s
->mlme
.extra_ie_len
+
332 wpa_s
->mlme
.ssid_len
;
333 #ifdef CONFIG_IEEE80211R
334 if (wpa_s
->mlme
.ft_ies
)
335 buflen
+= wpa_s
->mlme
.ft_ies_len
;
336 #endif /* CONFIG_IEEE80211R */
337 buf
= os_malloc(buflen
);
339 wpa_printf(MSG_DEBUG
, "MLME: failed to allocate buffer for "
345 capab
= wpa_s
->mlme
.capab
;
346 if (wpa_s
->mlme
.phymode
== HOSTAPD_MODE_IEEE80211G
) {
347 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
|
348 WLAN_CAPABILITY_SHORT_PREAMBLE
;
350 bss
= ieee80211_bss_get(wpa_s
, wpa_s
->bssid
);
352 capab
|= WLAN_CAPABILITY_ESS
; /* wrong, but needed by some APs */
353 if (bss
->capability
& WLAN_CAPABILITY_PRIVACY
)
354 capab
|= WLAN_CAPABILITY_PRIVACY
;
362 mgmt
= (struct ieee80211_mgmt
*) buf
;
364 os_memset(mgmt
, 0, 24);
365 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
366 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
367 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
369 if (wpa_s
->mlme
.prev_bssid_set
) {
371 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
372 WLAN_FC_STYPE_REASSOC_REQ
);
373 mgmt
->u
.reassoc_req
.capab_info
= host_to_le16(capab
);
374 mgmt
->u
.reassoc_req
.listen_interval
= host_to_le16(1);
375 os_memcpy(mgmt
->u
.reassoc_req
.current_ap
,
376 wpa_s
->mlme
.prev_bssid
,
380 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
381 WLAN_FC_STYPE_ASSOC_REQ
);
382 mgmt
->u
.assoc_req
.capab_info
= host_to_le16(capab
);
383 mgmt
->u
.assoc_req
.listen_interval
= host_to_le16(1);
387 ies
= pos
= buf
+ blen
;
388 blen
+= 2 + wpa_s
->mlme
.ssid_len
;
389 *pos
++ = WLAN_EID_SSID
;
390 *pos
++ = wpa_s
->mlme
.ssid_len
;
391 os_memcpy(pos
, wpa_s
->mlme
.ssid
, wpa_s
->mlme
.ssid_len
);
393 len
= wpa_s
->mlme
.num_curr_rates
;
398 *pos
++ = WLAN_EID_SUPP_RATES
;
400 for (i
= 0; i
< len
; i
++)
401 *pos
++ = (u8
) (wpa_s
->mlme
.curr_rates
[i
] / 5);
403 if (wpa_s
->mlme
.num_curr_rates
> len
) {
405 blen
+= wpa_s
->mlme
.num_curr_rates
- len
+ 2;
406 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
407 *pos
++ = wpa_s
->mlme
.num_curr_rates
- len
;
408 for (i
= len
; i
< wpa_s
->mlme
.num_curr_rates
; i
++)
409 *pos
++ = (u8
) (wpa_s
->mlme
.curr_rates
[i
] / 5);
412 if (wpa_s
->mlme
.extra_ie
&& wpa_s
->mlme
.auth_alg
!= WLAN_AUTH_FT
) {
414 blen
+= wpa_s
->mlme
.extra_ie_len
;
415 os_memcpy(pos
, wpa_s
->mlme
.extra_ie
, wpa_s
->mlme
.extra_ie_len
);
418 #ifdef CONFIG_IEEE80211R
419 if ((wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_802_1X
||
420 wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_PSK
) &&
421 wpa_s
->mlme
.auth_alg
!= WLAN_AUTH_FT
&&
423 bss
->mdie_len
>= 2 + sizeof(struct rsn_mdie
) &&
424 bss
->mdie
[1] >= sizeof(struct rsn_mdie
)) {
426 blen
+= 2 + sizeof(struct rsn_mdie
);
427 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
428 *pos
++ = sizeof(struct rsn_mdie
);
429 os_memcpy(pos
, bss
->mdie
+ 2, MOBILITY_DOMAIN_ID_LEN
);
430 pos
+= MOBILITY_DOMAIN_ID_LEN
;
431 *pos
++ = 0; /* FIX: copy from the target AP's MDIE */
434 if ((wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_802_1X
||
435 wpa_s
->mlme
.key_mgmt
== KEY_MGMT_FT_PSK
) &&
436 wpa_s
->mlme
.auth_alg
== WLAN_AUTH_FT
&& wpa_s
->mlme
.ft_ies
) {
438 os_memcpy(pos
, wpa_s
->mlme
.ft_ies
, wpa_s
->mlme
.ft_ies_len
);
439 pos
+= wpa_s
->mlme
.ft_ies_len
;
440 blen
+= wpa_s
->mlme
.ft_ies_len
;
442 #endif /* CONFIG_IEEE80211R */
444 if (wmm
&& wpa_s
->mlme
.wmm_enabled
) {
447 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
448 *pos
++ = 7; /* len */
449 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
452 *pos
++ = 2; /* WMM */
453 *pos
++ = 0; /* WMM info */
454 *pos
++ = 1; /* WMM ver */
458 os_free(wpa_s
->mlme
.assocreq_ies
);
459 wpa_s
->mlme
.assocreq_ies_len
= (buf
+ blen
) - ies
;
460 wpa_s
->mlme
.assocreq_ies
= os_malloc(wpa_s
->mlme
.assocreq_ies_len
);
461 if (wpa_s
->mlme
.assocreq_ies
) {
462 os_memcpy(wpa_s
->mlme
.assocreq_ies
, ies
,
463 wpa_s
->mlme
.assocreq_ies_len
);
466 ieee80211_sta_tx(wpa_s
, buf
, blen
);
471 static void ieee80211_send_deauth(struct wpa_supplicant
*wpa_s
, u16 reason
)
475 struct ieee80211_mgmt
*mgmt
;
477 buf
= os_zalloc(sizeof(*mgmt
));
479 wpa_printf(MSG_DEBUG
, "MLME: failed to allocate buffer for "
484 mgmt
= (struct ieee80211_mgmt
*) buf
;
486 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
487 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
488 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
489 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
490 WLAN_FC_STYPE_DEAUTH
);
492 mgmt
->u
.deauth
.reason_code
= host_to_le16(reason
);
494 ieee80211_sta_tx(wpa_s
, buf
, len
);
499 static void ieee80211_send_disassoc(struct wpa_supplicant
*wpa_s
, u16 reason
)
503 struct ieee80211_mgmt
*mgmt
;
505 buf
= os_zalloc(sizeof(*mgmt
));
507 wpa_printf(MSG_DEBUG
, "MLME: failed to allocate buffer for "
512 mgmt
= (struct ieee80211_mgmt
*) buf
;
514 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
515 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
516 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
517 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
518 WLAN_FC_STYPE_DISASSOC
);
520 mgmt
->u
.disassoc
.reason_code
= host_to_le16(reason
);
522 ieee80211_sta_tx(wpa_s
, buf
, len
);
527 static int ieee80211_privacy_mismatch(struct wpa_supplicant
*wpa_s
)
529 struct ieee80211_sta_bss
*bss
;
532 if (wpa_s
->mlme
.mixed_cell
||
533 wpa_s
->mlme
.key_mgmt
!= KEY_MGMT_NONE
)
536 bss
= ieee80211_bss_get(wpa_s
, wpa_s
->bssid
);
540 if (ieee80211_sta_wep_configured(wpa_s
) !=
541 !!(bss
->capability
& WLAN_CAPABILITY_PRIVACY
))
548 static void ieee80211_associate(struct wpa_supplicant
*wpa_s
)
550 wpa_s
->mlme
.assoc_tries
++;
551 if (wpa_s
->mlme
.assoc_tries
> IEEE80211_ASSOC_MAX_TRIES
) {
552 wpa_printf(MSG_DEBUG
, "MLME: association with AP " MACSTR
553 " timed out", MAC2STR(wpa_s
->bssid
));
557 wpa_s
->mlme
.state
= IEEE80211_ASSOCIATE
;
558 wpa_printf(MSG_DEBUG
, "MLME: associate with AP " MACSTR
,
559 MAC2STR(wpa_s
->bssid
));
560 if (ieee80211_privacy_mismatch(wpa_s
)) {
561 wpa_printf(MSG_DEBUG
, "MLME: mismatch in privacy "
562 "configuration and mixed-cell disabled - abort "
567 ieee80211_send_assoc(wpa_s
);
569 ieee80211_reschedule_timer(wpa_s
, IEEE80211_ASSOC_TIMEOUT
);
573 static void ieee80211_associated(struct wpa_supplicant
*wpa_s
)
577 /* TODO: start monitoring current AP signal quality and number of
578 * missed beacons. Scan other channels every now and then and search
580 /* TODO: remove expired BSSes */
582 wpa_s
->mlme
.state
= IEEE80211_ASSOCIATED
;
585 sta
= sta_info_get(local
, wpa_s
->bssid
);
587 wpa_printf(MSG_DEBUG
"MLME: No STA entry for own AP " MACSTR
,
588 MAC2STR(wpa_s
->bssid
));
592 if (time_after(jiffies
,
593 sta
->last_rx
+ IEEE80211_MONITORING_INTERVAL
)) {
594 if (wpa_s
->mlme
.probereq_poll
) {
595 wpa_printf(MSG_DEBUG
"MLME: No ProbeResp from "
596 "current AP " MACSTR
" - assume "
598 MAC2STR(wpa_s
->bssid
));
601 ieee80211_send_probe_req(
603 wpa_s
->mlme
.scan_ssid
,
604 wpa_s
->mlme
.scan_ssid_len
);
605 wpa_s
->mlme
.probereq_poll
= 1;
608 wpa_s
->mlme
.probereq_poll
= 0;
609 if (time_after(jiffies
, wpa_s
->mlme
.last_probe
+
610 IEEE80211_PROBE_INTERVAL
)) {
611 wpa_s
->mlme
.last_probe
= jiffies
;
612 ieee80211_send_probe_req(wpa_s
->bssid
,
614 wpa_s
->mlme
.ssid_len
);
617 sta_info_release(local
, sta
);
623 wpa_supplicant_event(wpa_s
, EVENT_DISASSOC
, NULL
);
624 ieee80211_reschedule_timer(wpa_s
,
625 IEEE80211_MONITORING_INTERVAL
+
628 ieee80211_reschedule_timer(wpa_s
,
629 IEEE80211_MONITORING_INTERVAL
);
634 static void ieee80211_send_probe_req(struct wpa_supplicant
*wpa_s
,
636 const u8
*ssid
, size_t ssid_len
)
640 struct ieee80211_mgmt
*mgmt
;
641 u8
*pos
, *supp_rates
;
642 u8
*esupp_rates
= NULL
;
645 buf
= os_malloc(sizeof(*mgmt
) + 200 + wpa_s
->mlme
.extra_probe_ie_len
);
647 wpa_printf(MSG_DEBUG
, "MLME: failed to allocate buffer for "
652 mgmt
= (struct ieee80211_mgmt
*) buf
;
654 os_memset(mgmt
, 0, 24);
655 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
656 WLAN_FC_STYPE_PROBE_REQ
);
657 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
659 os_memcpy(mgmt
->da
, dst
, ETH_ALEN
);
660 os_memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
662 os_memset(mgmt
->da
, 0xff, ETH_ALEN
);
663 os_memset(mgmt
->bssid
, 0xff, ETH_ALEN
);
667 *pos
++ = WLAN_EID_SSID
;
669 os_memcpy(pos
, ssid
, ssid_len
);
671 supp_rates
= buf
+ len
;
673 supp_rates
[0] = WLAN_EID_SUPP_RATES
;
675 for (i
= 0; i
< wpa_s
->mlme
.num_curr_rates
; i
++) {
680 } else if (supp_rates
[1] == 8) {
682 esupp_rates
[0] = WLAN_EID_EXT_SUPP_RATES
;
684 pos
= &esupp_rates
[2];
691 *pos
++ = wpa_s
->mlme
.curr_rates
[i
] / 5;
694 if (wpa_s
->mlme
.extra_probe_ie
) {
695 os_memcpy(pos
, wpa_s
->mlme
.extra_probe_ie
,
696 wpa_s
->mlme
.extra_probe_ie_len
);
697 len
+= wpa_s
->mlme
.extra_probe_ie_len
;
700 ieee80211_sta_tx(wpa_s
, buf
, len
);
705 extern int using_wep
;
706 static int ieee80211_sta_wep_configured(struct wpa_supplicant
*wpa_s
)
709 if (sdata
== NULL
|| sdata
->default_key
== NULL
||
710 sdata
->default_key
->alg
!= ALG_WEP
)
720 static void ieee80211_auth_completed(struct wpa_supplicant
*wpa_s
)
722 wpa_printf(MSG_DEBUG
, "MLME: authenticated");
723 wpa_s
->mlme
.authenticated
= 1;
724 ieee80211_associate(wpa_s
);
728 static void ieee80211_auth_challenge(struct wpa_supplicant
*wpa_s
,
729 struct ieee80211_mgmt
*mgmt
,
731 struct ieee80211_rx_status
*rx_status
)
734 struct ieee802_11_elems elems
;
736 wpa_printf(MSG_DEBUG
, "MLME: replying to auth challenge");
737 pos
= mgmt
->u
.auth
.variable
;
738 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
, 0)
740 wpa_printf(MSG_DEBUG
, "MLME: failed to parse Auth(challenge)");
743 if (elems
.challenge
== NULL
) {
744 wpa_printf(MSG_DEBUG
, "MLME: no challenge IE in shared key "
748 ieee80211_send_auth(wpa_s
, 3, elems
.challenge
- 2,
749 elems
.challenge_len
+ 2, 1);
753 static void ieee80211_rx_mgmt_auth(struct wpa_supplicant
*wpa_s
,
754 struct ieee80211_mgmt
*mgmt
,
756 struct ieee80211_rx_status
*rx_status
)
758 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
759 u16 auth_alg
, auth_transaction
, status_code
;
762 adhoc
= ssid
&& ssid
->mode
== WPAS_MODE_IBSS
;
764 if (wpa_s
->mlme
.state
!= IEEE80211_AUTHENTICATE
&& !adhoc
) {
765 wpa_printf(MSG_DEBUG
, "MLME: authentication frame received "
766 "from " MACSTR
", but not in authenticate state - "
767 "ignored", MAC2STR(mgmt
->sa
));
772 wpa_printf(MSG_DEBUG
, "MLME: too short (%lu) authentication "
773 "frame received from " MACSTR
" - ignored",
774 (unsigned long) len
, MAC2STR(mgmt
->sa
));
778 if (!adhoc
&& os_memcmp(wpa_s
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
779 wpa_printf(MSG_DEBUG
, "MLME: authentication frame received "
780 "from unknown AP (SA=" MACSTR
" BSSID=" MACSTR
782 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
));
786 if (adhoc
&& os_memcmp(wpa_s
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0) {
787 wpa_printf(MSG_DEBUG
, "MLME: authentication frame received "
788 "from unknown BSSID (SA=" MACSTR
" BSSID=" MACSTR
790 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
));
794 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
795 auth_transaction
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
796 status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
798 wpa_printf(MSG_DEBUG
, "MLME: RX authentication from " MACSTR
799 " (alg=%d transaction=%d status=%d)",
800 MAC2STR(mgmt
->sa
), auth_alg
, auth_transaction
, status_code
);
803 /* IEEE 802.11 standard does not require authentication in IBSS
804 * networks and most implementations do not seem to use it.
805 * However, try to reply to authentication attempts if someone
806 * has actually implemented this.
807 * TODO: Could implement shared key authentication. */
808 if (auth_alg
!= WLAN_AUTH_OPEN
|| auth_transaction
!= 1) {
809 wpa_printf(MSG_DEBUG
, "MLME: unexpected IBSS "
810 "authentication frame (alg=%d "
812 auth_alg
, auth_transaction
);
815 ieee80211_send_auth(wpa_s
, 2, NULL
, 0, 0);
818 if (auth_alg
!= wpa_s
->mlme
.auth_alg
||
819 auth_transaction
!= wpa_s
->mlme
.auth_transaction
) {
820 wpa_printf(MSG_DEBUG
, "MLME: unexpected authentication frame "
821 "(alg=%d transaction=%d)",
822 auth_alg
, auth_transaction
);
826 if (status_code
!= WLAN_STATUS_SUCCESS
) {
827 wpa_printf(MSG_DEBUG
, "MLME: AP denied authentication "
828 "(auth_alg=%d code=%d)", wpa_s
->mlme
.auth_alg
,
830 if (status_code
== WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
) {
831 const int num_algs
= 3;
834 algs
[0] = algs
[1] = algs
[2] = 0xff;
835 if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_OPEN
)
836 algs
[0] = WLAN_AUTH_OPEN
;
837 if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_SHARED
)
838 algs
[1] = WLAN_AUTH_SHARED_KEY
;
839 if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_LEAP
)
840 algs
[2] = WLAN_AUTH_LEAP
;
841 if (wpa_s
->mlme
.auth_alg
== WLAN_AUTH_OPEN
)
843 else if (wpa_s
->mlme
.auth_alg
== WLAN_AUTH_SHARED_KEY
)
847 for (i
= 0; i
< num_algs
; i
++) {
851 if (algs
[pos
] == wpa_s
->mlme
.auth_alg
||
854 if (algs
[pos
] == WLAN_AUTH_SHARED_KEY
&&
855 !ieee80211_sta_wep_configured(wpa_s
))
857 wpa_s
->mlme
.auth_alg
= algs
[pos
];
858 wpa_printf(MSG_DEBUG
, "MLME: set auth_alg=%d "
860 wpa_s
->mlme
.auth_alg
);
867 switch (wpa_s
->mlme
.auth_alg
) {
870 ieee80211_auth_completed(wpa_s
);
872 case WLAN_AUTH_SHARED_KEY
:
873 if (wpa_s
->mlme
.auth_transaction
== 4)
874 ieee80211_auth_completed(wpa_s
);
876 ieee80211_auth_challenge(wpa_s
, mgmt
, len
,
879 #ifdef CONFIG_IEEE80211R
882 union wpa_event_data data
;
883 struct wpabuf
*ric
= NULL
;
884 os_memset(&data
, 0, sizeof(data
));
885 data
.ft_ies
.ies
= mgmt
->u
.auth
.variable
;
886 data
.ft_ies
.ies_len
= len
-
887 (mgmt
->u
.auth
.variable
- (u8
*) mgmt
);
888 os_memcpy(data
.ft_ies
.target_ap
, wpa_s
->bssid
, ETH_ALEN
);
889 if (os_strcmp(wpa_s
->driver
->name
, "test") == 0 &&
890 wpa_s
->mlme
.wmm_enabled
) {
891 ric
= wpabuf_alloc(200);
893 /* Build simple RIC-Request: RDIE | TSPEC */
895 /* RIC Data (RDIE) */
896 wpabuf_put_u8(ric
, WLAN_EID_RIC_DATA
);
897 wpabuf_put_u8(ric
, 4);
898 wpabuf_put_u8(ric
, 0); /* RDIE Identifier */
899 wpabuf_put_u8(ric
, 1); /* Resource Descriptor
901 wpabuf_put_le16(ric
, 0); /* Status Code */
904 ieee80211_build_tspec(ric
);
906 data
.ft_ies
.ric_ies
= wpabuf_head(ric
);
907 data
.ft_ies
.ric_ies_len
= wpabuf_len(ric
);
911 wpa_supplicant_event(wpa_s
, EVENT_FT_RESPONSE
, &data
);
913 ieee80211_auth_completed(wpa_s
);
916 #endif /* CONFIG_IEEE80211R */
921 static void ieee80211_rx_mgmt_deauth(struct wpa_supplicant
*wpa_s
,
922 struct ieee80211_mgmt
*mgmt
,
924 struct ieee80211_rx_status
*rx_status
)
929 wpa_printf(MSG_DEBUG
, "MLME: too short (%lu) deauthentication "
930 "frame received from " MACSTR
" - ignored",
931 (unsigned long) len
, MAC2STR(mgmt
->sa
));
935 if (os_memcmp(wpa_s
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
936 wpa_printf(MSG_DEBUG
, "MLME: deauthentication frame received "
937 "from unknown AP (SA=" MACSTR
" BSSID=" MACSTR
939 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
));
943 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
945 wpa_printf(MSG_DEBUG
, "MLME: RX deauthentication from " MACSTR
946 " (reason=%d)", MAC2STR(mgmt
->sa
), reason_code
);
948 if (wpa_s
->mlme
.authenticated
)
949 wpa_printf(MSG_DEBUG
, "MLME: deauthenticated");
951 if (wpa_s
->mlme
.state
== IEEE80211_AUTHENTICATE
||
952 wpa_s
->mlme
.state
== IEEE80211_ASSOCIATE
||
953 wpa_s
->mlme
.state
== IEEE80211_ASSOCIATED
) {
954 wpa_s
->mlme
.state
= IEEE80211_AUTHENTICATE
;
955 ieee80211_reschedule_timer(wpa_s
,
956 IEEE80211_RETRY_AUTH_INTERVAL
);
959 ieee80211_set_associated(wpa_s
, 0);
960 wpa_s
->mlme
.authenticated
= 0;
964 static void ieee80211_rx_mgmt_disassoc(struct wpa_supplicant
*wpa_s
,
965 struct ieee80211_mgmt
*mgmt
,
967 struct ieee80211_rx_status
*rx_status
)
972 wpa_printf(MSG_DEBUG
, "MLME: too short (%lu) disassociation "
973 "frame received from " MACSTR
" - ignored",
974 (unsigned long) len
, MAC2STR(mgmt
->sa
));
978 if (os_memcmp(wpa_s
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
979 wpa_printf(MSG_DEBUG
, "MLME: disassociation frame received "
980 "from unknown AP (SA=" MACSTR
" BSSID=" MACSTR
982 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
));
986 reason_code
= le_to_host16(mgmt
->u
.disassoc
.reason_code
);
988 wpa_printf(MSG_DEBUG
, "MLME: RX disassociation from " MACSTR
989 " (reason=%d)", MAC2STR(mgmt
->sa
), reason_code
);
991 if (wpa_s
->mlme
.associated
)
992 wpa_printf(MSG_DEBUG
, "MLME: disassociated");
994 if (wpa_s
->mlme
.state
== IEEE80211_ASSOCIATED
) {
995 wpa_s
->mlme
.state
= IEEE80211_ASSOCIATE
;
996 ieee80211_reschedule_timer(wpa_s
,
997 IEEE80211_RETRY_AUTH_INTERVAL
);
1000 ieee80211_set_associated(wpa_s
, 0);
1004 static void ieee80211_build_tspec(struct wpabuf
*buf
)
1006 struct wmm_tspec_element
*tspec
;
1009 tspec
= wpabuf_put(buf
, sizeof(*tspec
));
1010 tspec
->eid
= WLAN_EID_VENDOR_SPECIFIC
;
1011 tspec
->length
= sizeof(*tspec
) - 2;
1012 tspec
->oui
[0] = 0x00;
1013 tspec
->oui
[1] = 0x50;
1014 tspec
->oui
[2] = 0xf2;
1015 tspec
->oui_type
= 2;
1016 tspec
->oui_subtype
= 2;
1021 tspec
->ts_info
[0] = (tid
<< 1) |
1022 (WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
<< 5) |
1024 tspec
->ts_info
[1] = up
<< 3;
1025 tspec
->nominal_msdu_size
= host_to_le16(1530);
1026 tspec
->mean_data_rate
= host_to_le32(128000); /* bits per second */
1027 tspec
->minimum_phy_rate
= host_to_le32(6000000);
1028 tspec
->surplus_bandwidth_allowance
= host_to_le16(0x3000); /* 150% */
1032 static void ieee80211_tx_addts(struct wpa_supplicant
*wpa_s
)
1035 struct ieee80211_mgmt
*mgmt
;
1038 wpa_printf(MSG_DEBUG
, "MLME: Send ADDTS Request for Voice TSPEC");
1040 alen
= mgmt
->u
.action
.u
.wmm_action
.variable
- (u8
*) mgmt
;
1042 buf
= wpabuf_alloc(alen
+ sizeof(struct wmm_tspec_element
));
1046 mgmt
= wpabuf_put(buf
, alen
);
1047 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
1048 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
1049 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
1050 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
1051 WLAN_FC_STYPE_ACTION
);
1052 mgmt
->u
.action
.category
= WLAN_ACTION_WMM
;
1053 mgmt
->u
.action
.u
.wmm_action
.action_code
= WMM_ACTION_CODE_ADDTS_REQ
;
1054 mgmt
->u
.action
.u
.wmm_action
.dialog_token
= 1;
1055 mgmt
->u
.action
.u
.wmm_action
.status_code
= 0;
1057 ieee80211_build_tspec(buf
);
1059 ieee80211_sta_tx(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
));
1064 static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant
*wpa_s
,
1065 struct ieee80211_mgmt
*mgmt
,
1067 struct ieee80211_rx_status
*rx_status
,
1072 u16 capab_info
, status_code
, aid
;
1073 struct ieee802_11_elems elems
;
1076 /* AssocResp and ReassocResp have identical structure, so process both
1077 * of them in this function. */
1079 if (wpa_s
->mlme
.state
!= IEEE80211_ASSOCIATE
) {
1080 wpa_printf(MSG_DEBUG
, "MLME: association frame received from "
1081 MACSTR
", but not in associate state - ignored",
1087 wpa_printf(MSG_DEBUG
, "MLME: too short (%lu) association "
1088 "frame received from " MACSTR
" - ignored",
1089 (unsigned long) len
, MAC2STR(mgmt
->sa
));
1093 if (os_memcmp(wpa_s
->bssid
, mgmt
->sa
, ETH_ALEN
) != 0) {
1094 wpa_printf(MSG_DEBUG
, "MLME: association frame received from "
1095 "unknown AP (SA=" MACSTR
" BSSID=" MACSTR
") - "
1096 "ignored", MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
));
1100 capab_info
= le_to_host16(mgmt
->u
.assoc_resp
.capab_info
);
1101 status_code
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1102 aid
= le_to_host16(mgmt
->u
.assoc_resp
.aid
);
1103 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1104 wpa_printf(MSG_DEBUG
, "MLME: invalid aid value %d; bits 15:14 "
1106 aid
&= ~(BIT(15) | BIT(14));
1108 wpa_printf(MSG_DEBUG
, "MLME: RX %sssocResp from " MACSTR
1109 " (capab=0x%x status=%d aid=%d)",
1110 reassoc
? "Rea" : "A", MAC2STR(mgmt
->sa
),
1111 capab_info
, status_code
, aid
);
1113 pos
= mgmt
->u
.assoc_resp
.variable
;
1114 if (ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
, 0)
1116 wpa_printf(MSG_DEBUG
, "MLME: failed to parse AssocResp");
1120 if (status_code
!= WLAN_STATUS_SUCCESS
) {
1121 wpa_printf(MSG_DEBUG
, "MLME: AP denied association (code=%d)",
1123 #ifdef CONFIG_IEEE80211W
1124 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
1125 elems
.timeout_int
&& elems
.timeout_int_len
== 5 &&
1126 elems
.timeout_int
[0] == WLAN_TIMEOUT_ASSOC_COMEBACK
) {
1128 tu
= WPA_GET_LE32(elems
.timeout_int
+ 1);
1129 ms
= tu
* 1024 / 1000;
1130 wpa_printf(MSG_DEBUG
, "MLME: AP rejected association "
1131 "temporarily; comeback duration %u TU "
1133 if (ms
> IEEE80211_ASSOC_TIMEOUT
) {
1134 wpa_printf(MSG_DEBUG
, "MLME: Update timer "
1135 "based on comeback duration");
1136 ieee80211_reschedule_timer(wpa_s
, ms
);
1139 #endif /* CONFIG_IEEE80211W */
1143 if (elems
.supp_rates
== NULL
) {
1144 wpa_printf(MSG_DEBUG
, "MLME: no SuppRates element in "
1149 if (wpa_s
->mlme
.auth_alg
== WLAN_AUTH_FT
) {
1151 wpa_printf(MSG_DEBUG
, "MLME: AP tried to use "
1152 "association, not reassociation, response "
1156 if (wpa_ft_validate_reassoc_resp(
1157 wpa_s
->wpa
, pos
, len
- (pos
- (u8
*) mgmt
),
1159 wpa_printf(MSG_DEBUG
, "MLME: FT validation of Reassoc"
1163 } else if (wpa_sm_set_ft_params(wpa_s
->wpa
, pos
,
1164 len
- (pos
- (u8
*) mgmt
)) < 0)
1167 wpa_printf(MSG_DEBUG
, "MLME: associated");
1168 wpa_s
->mlme
.aid
= aid
;
1169 wpa_s
->mlme
.ap_capab
= capab_info
;
1171 os_free(wpa_s
->mlme
.assocresp_ies
);
1172 wpa_s
->mlme
.assocresp_ies_len
= len
- (pos
- (u8
*) mgmt
);
1173 wpa_s
->mlme
.assocresp_ies
= os_malloc(wpa_s
->mlme
.assocresp_ies_len
);
1174 if (wpa_s
->mlme
.assocresp_ies
) {
1175 os_memcpy(wpa_s
->mlme
.assocresp_ies
, pos
,
1176 wpa_s
->mlme
.assocresp_ies_len
);
1179 ieee80211_set_associated(wpa_s
, 1);
1181 rates_len
= elems
.supp_rates_len
;
1182 if (rates_len
> sizeof(rates
))
1183 rates_len
= sizeof(rates
);
1184 os_memcpy(rates
, elems
.supp_rates
, rates_len
);
1185 if (elems
.ext_supp_rates
) {
1186 size_t _len
= elems
.ext_supp_rates_len
;
1187 if (_len
> sizeof(rates
) - rates_len
)
1188 _len
= sizeof(rates
) - rates_len
;
1189 os_memcpy(rates
+ rates_len
, elems
.ext_supp_rates
, _len
);
1193 if (wpa_drv_set_bssid(wpa_s
, wpa_s
->bssid
) < 0) {
1194 wpa_printf(MSG_DEBUG
, "MLME: failed to set BSSID for the "
1197 if (wpa_drv_set_ssid(wpa_s
, wpa_s
->mlme
.ssid
, wpa_s
->mlme
.ssid_len
) <
1199 wpa_printf(MSG_DEBUG
, "MLME: failed to set SSID for the "
1202 if (wpa_drv_set_associd(wpa_s
, wpa_s
->mlme
.aid
) < 0) {
1203 wpa_printf(MSG_DEBUG
, "MLME: failed to set AID for the "
1206 if (wpa_drv_set_capabilities(wpa_s
, wpa_s
->mlme
.ap_capab
) < 0) {
1207 wpa_printf(MSG_DEBUG
, "MLME: failed to set negotiated"
1208 "capabilities for the netstack");
1211 /* Remove STA entry before adding a new one just in case to avoid
1212 * problems with existing configuration (e.g., keys). */
1213 wpa_drv_mlme_remove_sta(wpa_s
, wpa_s
->bssid
);
1214 if (wpa_drv_mlme_add_sta(wpa_s
, wpa_s
->bssid
, rates
, rates_len
) < 0) {
1215 wpa_printf(MSG_DEBUG
, "MLME: failed to add STA entry to the "
1219 if (elems
.wmm
&& wpa_s
->mlme
.wmm_enabled
)
1220 ieee80211_sta_wmm_params(wpa_s
, elems
.wmm
, elems
.wmm_len
);
1222 ieee80211_associated(wpa_s
);
1224 if (wpa_s
->mlme
.auth_alg
!= WLAN_AUTH_FT
&&
1225 os_strcmp(wpa_s
->driver
->name
, "test") == 0 &&
1226 elems
.wmm
&& wpa_s
->mlme
.wmm_enabled
) {
1227 /* Test WMM-AC - send ADDTS for WMM TSPEC */
1228 ieee80211_tx_addts(wpa_s
);
1233 /* Caller must hold local->sta_bss_lock */
1234 static void __ieee80211_bss_hash_add(struct wpa_supplicant
*wpa_s
,
1235 struct ieee80211_sta_bss
*bss
)
1237 bss
->hnext
= wpa_s
->mlme
.sta_bss_hash
[STA_HASH(bss
->bssid
)];
1238 wpa_s
->mlme
.sta_bss_hash
[STA_HASH(bss
->bssid
)] = bss
;
1242 /* Caller must hold local->sta_bss_lock */
1243 static void __ieee80211_bss_hash_del(struct wpa_supplicant
*wpa_s
,
1244 struct ieee80211_sta_bss
*bss
)
1246 struct ieee80211_sta_bss
*b
, *prev
= NULL
;
1247 b
= wpa_s
->mlme
.sta_bss_hash
[STA_HASH(bss
->bssid
)];
1251 wpa_s
->mlme
.sta_bss_hash
[STA_HASH(bss
->bssid
)]
1254 prev
->hnext
= bss
->hnext
;
1264 static struct ieee80211_sta_bss
*
1265 ieee80211_bss_add(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
1267 struct ieee80211_sta_bss
*bss
;
1269 bss
= os_zalloc(sizeof(*bss
));
1272 os_memcpy(bss
->bssid
, bssid
, ETH_ALEN
);
1274 /* TODO: order by RSSI? */
1275 bss
->next
= wpa_s
->mlme
.sta_bss_list
;
1276 wpa_s
->mlme
.sta_bss_list
= bss
;
1277 __ieee80211_bss_hash_add(wpa_s
, bss
);
1282 static struct ieee80211_sta_bss
*
1283 ieee80211_bss_get(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
1285 struct ieee80211_sta_bss
*bss
;
1287 bss
= wpa_s
->mlme
.sta_bss_hash
[STA_HASH(bssid
)];
1289 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0)
1297 static void ieee80211_bss_free(struct wpa_supplicant
*wpa_s
,
1298 struct ieee80211_sta_bss
*bss
)
1300 __ieee80211_bss_hash_del(wpa_s
, bss
);
1302 os_free(bss
->wpa_ie
);
1303 os_free(bss
->rsn_ie
);
1304 os_free(bss
->wmm_ie
);
1310 static void ieee80211_bss_list_deinit(struct wpa_supplicant
*wpa_s
)
1312 struct ieee80211_sta_bss
*bss
, *prev
;
1314 bss
= wpa_s
->mlme
.sta_bss_list
;
1315 wpa_s
->mlme
.sta_bss_list
= NULL
;
1319 ieee80211_bss_free(wpa_s
, prev
);
1324 static void ieee80211_bss_info(struct wpa_supplicant
*wpa_s
,
1325 struct ieee80211_mgmt
*mgmt
,
1327 struct ieee80211_rx_status
*rx_status
,
1330 struct ieee802_11_elems elems
;
1332 int channel
, /*invalid = 0,*/ clen
;
1333 struct ieee80211_sta_bss
*bss
;
1338 if (!beacon
&& os_memcmp(mgmt
->da
, wpa_s
->own_addr
, ETH_ALEN
))
1339 return; /* ignore ProbeResp to foreign address */
1342 wpa_printf(MSG_MSGDUMP
, "MLME: RX %s from " MACSTR
" to " MACSTR
,
1343 beacon
? "Beacon" : "Probe Response",
1344 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
));
1347 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1351 pos
= mgmt
->u
.beacon
.timestamp
;
1352 timestamp
= WPA_GET_LE64(pos
);
1355 if (local
->conf
.mode
== IW_MODE_ADHOC
&& beacon
&&
1356 os_memcmp(mgmt
->bssid
, local
->bssid
, ETH_ALEN
) == 0) {
1357 #ifdef IEEE80211_IBSS_DEBUG
1358 static unsigned long last_tsf_debug
= 0;
1360 if (local
->hw
->get_tsf
)
1361 tsf
= local
->hw
->get_tsf(local
->mdev
);
1364 if (time_after(jiffies
, last_tsf_debug
+ 5 * HZ
)) {
1365 wpa_printf(MSG_DEBUG
, "RX beacon SA=" MACSTR
" BSSID="
1366 MACSTR
" TSF=0x%llx BCN=0x%llx diff=%lld "
1368 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->bssid
),
1369 tsf
, timestamp
, tsf
- timestamp
, jiffies
);
1370 last_tsf_debug
= jiffies
;
1372 #endif /* IEEE80211_IBSS_DEBUG */
1376 ie_pos
= mgmt
->u
.beacon
.variable
;
1377 ie_len
= len
- baselen
;
1379 if (ieee802_11_parse_elems(ie_pos
, ie_len
, &elems
, 0) == ParseFailed
)
1382 ieee802_11_parse_elems(ie_pos
, ie_len
, &elems
, 0);
1386 if (local
->conf
.mode
== IW_MODE_ADHOC
&& elems
.supp_rates
&&
1387 os_memcmp(mgmt
->bssid
, local
->bssid
, ETH_ALEN
) == 0 &&
1388 (sta
= sta_info_get(local
, mgmt
->sa
))) {
1389 struct ieee80211_rate
*rates
;
1391 u32 supp_rates
, prev_rates
;
1392 int i
, j
, oper_mode
;
1394 rates
= local
->curr_rates
;
1395 num_rates
= local
->num_curr_rates
;
1396 oper_mode
= wpa_s
->mlme
.sta_scanning
?
1397 local
->scan_oper_phymode
: local
->conf
.phymode
;
1398 for (i
= 0; i
< local
->hw
->num_modes
; i
++) {
1399 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[i
];
1400 if (oper_mode
== mode
->mode
) {
1401 rates
= mode
->rates
;
1402 num_rates
= mode
->num_rates
;
1408 for (i
= 0; i
< elems
.supp_rates_len
+
1409 elems
.ext_supp_rates_len
; i
++) {
1412 if (i
< elems
.supp_rates_len
)
1413 rate
= elems
.supp_rates
[i
];
1414 else if (elems
.ext_supp_rates
)
1415 rate
= elems
.ext_supp_rates
1416 [i
- elems
.supp_rates_len
];
1417 own_rate
= 5 * (rate
& 0x7f);
1418 if (oper_mode
== MODE_ATHEROS_TURBO
)
1420 for (j
= 0; j
< num_rates
; j
++)
1421 if (rates
[j
].rate
== own_rate
)
1422 supp_rates
|= BIT(j
);
1425 prev_rates
= sta
->supp_rates
;
1426 sta
->supp_rates
&= supp_rates
;
1427 if (sta
->supp_rates
== 0) {
1428 /* No matching rates - this should not really happen.
1429 * Make sure that at least one rate is marked
1430 * supported to avoid issues with TX rate ctrl. */
1431 sta
->supp_rates
= wpa_s
->mlme
.supp_rates_bits
;
1433 if (sta
->supp_rates
!= prev_rates
) {
1434 wpa_printf(MSG_DEBUG
, "MLME: updated supp_rates set "
1435 "for " MACSTR
" based on beacon info "
1436 "(0x%x & 0x%x -> 0x%x)",
1437 MAC2STR(sta
->addr
), prev_rates
,
1438 supp_rates
, sta
->supp_rates
);
1440 sta_info_release(local
, sta
);
1444 if (elems
.ssid
== NULL
)
1447 if (elems
.ds_params
&& elems
.ds_params_len
== 1)
1448 channel
= elems
.ds_params
[0];
1450 channel
= rx_status
->channel
;
1452 bss
= ieee80211_bss_get(wpa_s
, mgmt
->bssid
);
1454 bss
= ieee80211_bss_add(wpa_s
, mgmt
->bssid
);
1459 /* TODO: order by RSSI? */
1460 spin_lock_bh(&local
->sta_bss_lock
);
1461 list_move_tail(&bss
->list
, &local
->sta_bss_list
);
1462 spin_unlock_bh(&local
->sta_bss_lock
);
1466 if (bss
->probe_resp
&& beacon
) {
1467 /* Do not allow beacon to override data from Probe Response. */
1471 bss
->beacon_int
= le_to_host16(mgmt
->u
.beacon
.beacon_int
);
1472 bss
->capability
= le_to_host16(mgmt
->u
.beacon
.capab_info
);
1474 if (bss
->ie
== NULL
|| bss
->ie_len
< ie_len
) {
1476 bss
->ie
= os_malloc(ie_len
);
1479 os_memcpy(bss
->ie
, ie_pos
, ie_len
);
1480 bss
->ie_len
= ie_len
;
1483 if (elems
.ssid
&& elems
.ssid_len
<= MAX_SSID_LEN
) {
1484 os_memcpy(bss
->ssid
, elems
.ssid
, elems
.ssid_len
);
1485 bss
->ssid_len
= elems
.ssid_len
;
1488 bss
->supp_rates_len
= 0;
1489 if (elems
.supp_rates
) {
1490 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1491 if (clen
> elems
.supp_rates_len
)
1492 clen
= elems
.supp_rates_len
;
1493 os_memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1494 elems
.supp_rates
, clen
);
1495 bss
->supp_rates_len
+= clen
;
1497 if (elems
.ext_supp_rates
) {
1498 clen
= IEEE80211_MAX_SUPP_RATES
- bss
->supp_rates_len
;
1499 if (clen
> elems
.ext_supp_rates_len
)
1500 clen
= elems
.ext_supp_rates_len
;
1501 os_memcpy(&bss
->supp_rates
[bss
->supp_rates_len
],
1502 elems
.ext_supp_rates
, clen
);
1503 bss
->supp_rates_len
+= clen
;
1507 (bss
->wpa_ie
== NULL
|| bss
->wpa_ie_len
!= elems
.wpa_ie_len
||
1508 os_memcmp(bss
->wpa_ie
, elems
.wpa_ie
, elems
.wpa_ie_len
))) {
1509 os_free(bss
->wpa_ie
);
1510 bss
->wpa_ie
= os_malloc(elems
.wpa_ie_len
+ 2);
1512 os_memcpy(bss
->wpa_ie
, elems
.wpa_ie
- 2,
1513 elems
.wpa_ie_len
+ 2);
1514 bss
->wpa_ie_len
= elems
.wpa_ie_len
+ 2;
1516 bss
->wpa_ie_len
= 0;
1517 } else if (!elems
.wpa_ie
&& bss
->wpa_ie
) {
1518 os_free(bss
->wpa_ie
);
1520 bss
->wpa_ie_len
= 0;
1524 (bss
->rsn_ie
== NULL
|| bss
->rsn_ie_len
!= elems
.rsn_ie_len
||
1525 os_memcmp(bss
->rsn_ie
, elems
.rsn_ie
, elems
.rsn_ie_len
))) {
1526 os_free(bss
->rsn_ie
);
1527 bss
->rsn_ie
= os_malloc(elems
.rsn_ie_len
+ 2);
1529 os_memcpy(bss
->rsn_ie
, elems
.rsn_ie
- 2,
1530 elems
.rsn_ie_len
+ 2);
1531 bss
->rsn_ie_len
= elems
.rsn_ie_len
+ 2;
1533 bss
->rsn_ie_len
= 0;
1534 } else if (!elems
.rsn_ie
&& bss
->rsn_ie
) {
1535 os_free(bss
->rsn_ie
);
1537 bss
->rsn_ie_len
= 0;
1541 (bss
->wmm_ie
== NULL
|| bss
->wmm_ie_len
!= elems
.wmm_len
||
1542 os_memcmp(bss
->wmm_ie
, elems
.wmm
, elems
.wmm_len
))) {
1543 os_free(bss
->wmm_ie
);
1544 bss
->wmm_ie
= os_malloc(elems
.wmm_len
+ 2);
1546 os_memcpy(bss
->wmm_ie
, elems
.wmm
- 2,
1548 bss
->wmm_ie_len
= elems
.wmm_len
+ 2;
1550 bss
->wmm_ie_len
= 0;
1551 } else if (!elems
.wmm
&& bss
->wmm_ie
) {
1552 os_free(bss
->wmm_ie
);
1554 bss
->wmm_ie_len
= 0;
1557 #ifdef CONFIG_IEEE80211R
1559 (bss
->mdie
== NULL
|| bss
->mdie_len
!= elems
.mdie_len
||
1560 os_memcmp(bss
->mdie
, elems
.mdie
, elems
.mdie_len
))) {
1562 bss
->mdie
= os_malloc(elems
.mdie_len
+ 2);
1564 os_memcpy(bss
->mdie
, elems
.mdie
- 2,
1565 elems
.mdie_len
+ 2);
1566 bss
->mdie_len
= elems
.mdie_len
+ 2;
1569 } else if (!elems
.mdie
&& bss
->mdie
) {
1574 #endif /* CONFIG_IEEE80211R */
1576 bss
->hw_mode
= wpa_s
->mlme
.phymode
;
1577 bss
->channel
= channel
;
1578 bss
->freq
= wpa_s
->mlme
.freq
;
1579 if (channel
!= wpa_s
->mlme
.channel
&&
1580 (wpa_s
->mlme
.phymode
== HOSTAPD_MODE_IEEE80211G
||
1581 wpa_s
->mlme
.phymode
== HOSTAPD_MODE_IEEE80211B
) &&
1582 channel
>= 1 && channel
<= 14) {
1583 static const int freq_list
[] = {
1584 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1585 2447, 2452, 2457, 2462, 2467, 2472, 2484
1587 /* IEEE 802.11g/b mode can receive packets from neighboring
1588 * channels, so map the channel into frequency. */
1589 bss
->freq
= freq_list
[channel
- 1];
1591 bss
->timestamp
= timestamp
;
1592 os_get_time(&bss
->last_update
);
1593 bss
->rssi
= rx_status
->ssi
;
1599 static void ieee80211_rx_mgmt_probe_resp(struct wpa_supplicant
*wpa_s
,
1600 struct ieee80211_mgmt
*mgmt
,
1602 struct ieee80211_rx_status
*rx_status
)
1604 ieee80211_bss_info(wpa_s
, mgmt
, len
, rx_status
, 0);
1608 static void ieee80211_rx_mgmt_beacon(struct wpa_supplicant
*wpa_s
,
1609 struct ieee80211_mgmt
*mgmt
,
1611 struct ieee80211_rx_status
*rx_status
)
1615 struct ieee802_11_elems elems
;
1617 ieee80211_bss_info(wpa_s
, mgmt
, len
, rx_status
, 1);
1619 if (!wpa_s
->mlme
.associated
||
1620 os_memcmp(wpa_s
->bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1623 /* Process beacon from the current BSS */
1624 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1628 if (ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
, len
- baselen
,
1629 &elems
, 0) == ParseFailed
)
1633 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1635 (elems
.erp_info
[0] & ERP_INFO_USE_PROTECTION
) != 0;
1638 if (use_protection
!= !!wpa_s
->mlme
.use_protection
) {
1639 wpa_printf(MSG_DEBUG
, "MLME: CTS protection %s (BSSID=" MACSTR
1641 use_protection
? "enabled" : "disabled",
1642 MAC2STR(wpa_s
->bssid
));
1643 wpa_s
->mlme
.use_protection
= use_protection
? 1 : 0;
1644 wpa_s
->mlme
.cts_protect_erp_frames
= use_protection
;
1647 if (elems
.wmm
&& wpa_s
->mlme
.wmm_enabled
) {
1648 ieee80211_sta_wmm_params(wpa_s
, elems
.wmm
,
1654 static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant
*wpa_s
,
1655 struct ieee80211_mgmt
*mgmt
,
1657 struct ieee80211_rx_status
*rx_status
)
1659 int tx_last_beacon
, adhoc
;
1661 struct ieee80211_mgmt
*resp
;
1664 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1666 adhoc
= ssid
&& ssid
->mode
== WPAS_MODE_IBSS
;
1668 if (!adhoc
|| wpa_s
->mlme
.state
!= IEEE80211_IBSS_JOINED
||
1669 len
< 24 + 2 || wpa_s
->mlme
.probe_resp
== NULL
)
1673 if (local
->hw
->tx_last_beacon
)
1674 tx_last_beacon
= local
->hw
->tx_last_beacon(local
->mdev
);
1679 #ifdef IEEE80211_IBSS_DEBUG
1680 wpa_printf(MSG_DEBUG
, "MLME: RX ProbeReq SA=" MACSTR
" DA=" MACSTR
1681 " BSSID=" MACSTR
" (tx_last_beacon=%d)",
1682 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
),
1683 MAC2STR(mgmt
->bssid
), tx_last_beacon
);
1684 #endif /* IEEE80211_IBSS_DEBUG */
1686 if (!tx_last_beacon
)
1689 if (os_memcmp(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0 &&
1690 os_memcmp(mgmt
->bssid
, "\xff\xff\xff\xff\xff\xff", ETH_ALEN
) != 0)
1693 end
= ((u8
*) mgmt
) + len
;
1694 pos
= mgmt
->u
.probe_req
.variable
;
1695 if (pos
[0] != WLAN_EID_SSID
||
1696 pos
+ 2 + pos
[1] > end
) {
1697 wpa_printf(MSG_DEBUG
, "MLME: Invalid SSID IE in ProbeReq from "
1698 MACSTR
, MAC2STR(mgmt
->sa
));
1702 (pos
[1] != wpa_s
->mlme
.ssid_len
||
1703 os_memcmp(pos
+ 2, wpa_s
->mlme
.ssid
, wpa_s
->mlme
.ssid_len
) != 0))
1705 /* Ignore ProbeReq for foreign SSID */
1710 /* Reply with ProbeResp */
1711 skb
= skb_copy(wpa_s
->mlme
.probe_resp
, GFP_ATOMIC
);
1715 resp
= (struct ieee80211_mgmt
*) skb
->data
;
1716 os_memcpy(resp
->da
, mgmt
->sa
, ETH_ALEN
);
1717 #ifdef IEEE80211_IBSS_DEBUG
1718 wpa_printf(MSG_DEBUG
, "MLME: Sending ProbeResp to " MACSTR
,
1720 #endif /* IEEE80211_IBSS_DEBUG */
1721 ieee80211_sta_tx(wpa_s
, skb
, 0, 1);
1726 #ifdef CONFIG_IEEE80211R
1727 static void ieee80211_rx_mgmt_ft_action(struct wpa_supplicant
*wpa_s
,
1728 struct ieee80211_mgmt
*mgmt
,
1730 struct ieee80211_rx_status
*rx_status
)
1732 union wpa_event_data data
;
1734 u8
*sta_addr
, *target_ap_addr
;
1736 if (len
< 24 + 1 + sizeof(mgmt
->u
.action
.u
.ft_action_resp
)) {
1737 wpa_printf(MSG_DEBUG
, "MLME: Too short FT Action frame");
1742 * Only FT Action Response is needed for now since reservation
1743 * protocol is not supported.
1745 if (mgmt
->u
.action
.u
.ft_action_resp
.action
!= 2) {
1746 wpa_printf(MSG_DEBUG
, "MLME: Unexpected FT Action %d",
1747 mgmt
->u
.action
.u
.ft_action_resp
.action
);
1751 status
= le_to_host16(mgmt
->u
.action
.u
.ft_action_resp
.status_code
);
1752 sta_addr
= mgmt
->u
.action
.u
.ft_action_resp
.sta_addr
;
1753 target_ap_addr
= mgmt
->u
.action
.u
.ft_action_resp
.target_ap_addr
;
1754 wpa_printf(MSG_DEBUG
, "MLME: Received FT Action Response: STA " MACSTR
1755 " TargetAP " MACSTR
" Status Code %d",
1756 MAC2STR(sta_addr
), MAC2STR(target_ap_addr
), status
);
1757 if (os_memcmp(sta_addr
, wpa_s
->own_addr
, ETH_ALEN
) != 0) {
1758 wpa_printf(MSG_DEBUG
, "MLME: Foreign STA Address " MACSTR
1759 " in FT Action Response", MAC2STR(sta_addr
));
1764 wpa_printf(MSG_DEBUG
, "MLME: FT Action Response indicates "
1765 "failure (status code %d)", status
);
1766 /* TODO: report error to FT code(?) */
1770 os_memset(&data
, 0, sizeof(data
));
1771 data
.ft_ies
.ies
= mgmt
->u
.action
.u
.ft_action_resp
.variable
;
1772 data
.ft_ies
.ies_len
= len
- (mgmt
->u
.action
.u
.ft_action_resp
.variable
-
1774 data
.ft_ies
.ft_action
= 1;
1775 os_memcpy(data
.ft_ies
.target_ap
, target_ap_addr
, ETH_ALEN
);
1776 wpa_supplicant_event(wpa_s
, EVENT_FT_RESPONSE
, &data
);
1777 /* TODO: should only re-associate, if EVENT_FT_RESPONSE was processed
1779 wpa_s
->mlme
.prev_bssid_set
= 1;
1780 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_FT
;
1781 os_memcpy(wpa_s
->mlme
.prev_bssid
, wpa_s
->bssid
, ETH_ALEN
);
1782 os_memcpy(wpa_s
->bssid
, target_ap_addr
, ETH_ALEN
);
1783 ieee80211_associate(wpa_s
);
1785 #endif /* CONFIG_IEEE80211R */
1788 #ifdef CONFIG_IEEE80211W
1790 /* MLME-SAQuery.response */
1791 static int ieee80211_sta_send_sa_query_resp(struct wpa_supplicant
*wpa_s
,
1792 const u8
*addr
, const u8
*trans_id
)
1794 struct ieee80211_mgmt
*mgmt
;
1798 mgmt
= os_zalloc(sizeof(*mgmt
));
1800 wpa_printf(MSG_DEBUG
, "MLME: Failed to allocate buffer for "
1801 "SA Query action frame");
1806 os_memcpy(mgmt
->da
, addr
, ETH_ALEN
);
1807 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
1808 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
1809 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
1810 WLAN_FC_STYPE_ACTION
);
1811 mgmt
->u
.action
.category
= WLAN_ACTION_SA_QUERY
;
1812 mgmt
->u
.action
.u
.sa_query_resp
.action
= WLAN_SA_QUERY_RESPONSE
;
1813 os_memcpy(mgmt
->u
.action
.u
.sa_query_resp
.trans_id
, trans_id
,
1814 WLAN_SA_QUERY_TR_ID_LEN
);
1815 len
+= 1 + sizeof(mgmt
->u
.action
.u
.sa_query_resp
);
1817 res
= ieee80211_sta_tx(wpa_s
, (u8
*) mgmt
, len
);
1824 static void ieee80211_rx_mgmt_sa_query_action(
1825 struct wpa_supplicant
*wpa_s
, struct ieee80211_mgmt
*mgmt
, size_t len
,
1826 struct ieee80211_rx_status
*rx_status
)
1828 if (len
< 24 + 1 + sizeof(mgmt
->u
.action
.u
.sa_query_req
)) {
1829 wpa_printf(MSG_DEBUG
, "MLME: Too short SA Query Action frame");
1833 if (mgmt
->u
.action
.u
.sa_query_req
.action
!= WLAN_SA_QUERY_REQUEST
) {
1834 wpa_printf(MSG_DEBUG
, "MLME: Unexpected SA Query Action %d",
1835 mgmt
->u
.action
.u
.sa_query_req
.action
);
1839 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) != 0) {
1840 wpa_printf(MSG_DEBUG
, "MLME: Ignore SA Query from unknown "
1841 "source " MACSTR
, MAC2STR(mgmt
->sa
));
1845 if (wpa_s
->mlme
.state
== IEEE80211_ASSOCIATE
) {
1846 wpa_printf(MSG_DEBUG
, "MLME: Ignore SA query request during "
1847 "association process");
1851 wpa_printf(MSG_DEBUG
, "MLME: Replying to SA Query request");
1852 ieee80211_sta_send_sa_query_resp(wpa_s
, mgmt
->sa
, mgmt
->u
.action
.u
.
1853 sa_query_req
.trans_id
);
1856 #endif /* CONFIG_IEEE80211W */
1859 static void dump_tspec(struct wmm_tspec_element
*tspec
)
1861 int up
, psb
, dir
, tid
;
1864 up
= (tspec
->ts_info
[1] >> 3) & 0x07;
1865 psb
= (tspec
->ts_info
[1] >> 2) & 0x01;
1866 dir
= (tspec
->ts_info
[0] >> 5) & 0x03;
1867 tid
= (tspec
->ts_info
[0] >> 1) & 0x0f;
1868 wpa_printf(MSG_DEBUG
, "WMM: TS Info: UP=%d PSB=%d Direction=%d TID=%d",
1870 val
= le_to_host16(tspec
->nominal_msdu_size
);
1871 wpa_printf(MSG_DEBUG
, "WMM: Nominal MSDU Size: %d%s",
1872 val
& 0x7fff, val
& 0x8000 ? " (fixed)" : "");
1873 wpa_printf(MSG_DEBUG
, "WMM: Mean Data Rate: %u bps",
1874 le_to_host32(tspec
->mean_data_rate
));
1875 wpa_printf(MSG_DEBUG
, "WMM: Minimum PHY Rate: %u bps",
1876 le_to_host32(tspec
->minimum_phy_rate
));
1877 val
= le_to_host16(tspec
->surplus_bandwidth_allowance
);
1878 wpa_printf(MSG_DEBUG
, "WMM: Surplus Bandwidth Allowance: %u.%04u",
1879 val
>> 13, 10000 * (val
& 0x1fff) / 0x2000);
1880 val
= le_to_host16(tspec
->medium_time
);
1881 wpa_printf(MSG_DEBUG
, "WMM: Medium Time: %u (= %u usec/sec)",
1886 static int is_wmm_tspec(const u8
*ie
, size_t len
)
1888 const struct wmm_tspec_element
*tspec
;
1890 if (len
< sizeof(*tspec
))
1893 tspec
= (const struct wmm_tspec_element
*) ie
;
1894 if (tspec
->eid
!= WLAN_EID_VENDOR_SPECIFIC
||
1895 tspec
->length
< sizeof(*tspec
) - 2 ||
1896 tspec
->oui
[0] != 0x00 || tspec
->oui
[1] != 0x50 ||
1897 tspec
->oui
[2] != 0xf2 || tspec
->oui_type
!= 2 ||
1898 tspec
->oui_subtype
!= 2 || tspec
->version
!= 1)
1905 static void ieee80211_rx_addts_resp(
1906 struct wpa_supplicant
*wpa_s
, struct ieee80211_mgmt
*mgmt
, size_t len
,
1909 struct wmm_tspec_element
*tspec
;
1911 wpa_printf(MSG_DEBUG
, "WMM: Received ADDTS Response");
1912 wpa_hexdump(MSG_MSGDUMP
, "WMM: ADDTS Response IE(s)",
1913 mgmt
->u
.action
.u
.wmm_action
.variable
, var_len
);
1914 if (!is_wmm_tspec(mgmt
->u
.action
.u
.wmm_action
.variable
, var_len
))
1916 tspec
= (struct wmm_tspec_element
*)
1917 mgmt
->u
.action
.u
.wmm_action
.variable
;
1922 static void ieee80211_rx_delts(
1923 struct wpa_supplicant
*wpa_s
, struct ieee80211_mgmt
*mgmt
, size_t len
,
1926 struct wmm_tspec_element
*tspec
;
1928 wpa_printf(MSG_DEBUG
, "WMM: Received DELTS");
1929 wpa_hexdump(MSG_MSGDUMP
, "WMM: DELTS IE(s)",
1930 mgmt
->u
.action
.u
.wmm_action
.variable
, var_len
);
1931 if (!is_wmm_tspec(mgmt
->u
.action
.u
.wmm_action
.variable
, var_len
))
1933 tspec
= (struct wmm_tspec_element
*)
1934 mgmt
->u
.action
.u
.wmm_action
.variable
;
1939 static void ieee80211_rx_mgmt_wmm_action(
1940 struct wpa_supplicant
*wpa_s
, struct ieee80211_mgmt
*mgmt
, size_t len
,
1941 struct ieee80211_rx_status
*rx_status
)
1945 alen
= mgmt
->u
.action
.u
.wmm_action
.variable
- (u8
*) mgmt
;
1947 wpa_printf(MSG_DEBUG
, "WMM: Received Action frame too short");
1951 wpa_printf(MSG_DEBUG
, "WMM: Received Action frame: Action Code %d, "
1952 "Dialog Token %d, Status Code %d",
1953 mgmt
->u
.action
.u
.wmm_action
.action_code
,
1954 mgmt
->u
.action
.u
.wmm_action
.dialog_token
,
1955 mgmt
->u
.action
.u
.wmm_action
.status_code
);
1957 switch (mgmt
->u
.action
.u
.wmm_action
.action_code
) {
1958 case WMM_ACTION_CODE_ADDTS_RESP
:
1959 ieee80211_rx_addts_resp(wpa_s
, mgmt
, len
, len
- alen
);
1961 case WMM_ACTION_CODE_DELTS
:
1962 ieee80211_rx_delts(wpa_s
, mgmt
, len
, len
- alen
);
1965 wpa_printf(MSG_DEBUG
, "WMM: Unsupported Action Code %d",
1966 mgmt
->u
.action
.u
.wmm_action
.action_code
);
1972 static void ieee80211_rx_mgmt_action(struct wpa_supplicant
*wpa_s
,
1973 struct ieee80211_mgmt
*mgmt
,
1975 struct ieee80211_rx_status
*rx_status
)
1977 wpa_printf(MSG_DEBUG
, "MLME: received Action frame");
1982 switch (mgmt
->u
.action
.category
) {
1983 #ifdef CONFIG_IEEE80211R
1984 case WLAN_ACTION_FT
:
1985 ieee80211_rx_mgmt_ft_action(wpa_s
, mgmt
, len
, rx_status
);
1987 #endif /* CONFIG_IEEE80211R */
1988 #ifdef CONFIG_IEEE80211W
1989 case WLAN_ACTION_SA_QUERY
:
1990 ieee80211_rx_mgmt_sa_query_action(wpa_s
, mgmt
, len
, rx_status
);
1992 #endif /* CONFIG_IEEE80211W */
1993 case WLAN_ACTION_WMM
:
1994 ieee80211_rx_mgmt_wmm_action(wpa_s
, mgmt
, len
, rx_status
);
1996 case WLAN_ACTION_PUBLIC
:
1997 if (wpa_s
->mlme
.public_action_cb
) {
1998 wpa_s
->mlme
.public_action_cb(
1999 wpa_s
->mlme
.public_action_cb_ctx
,
2000 (u8
*) mgmt
, len
, rx_status
->freq
);
2005 wpa_printf(MSG_DEBUG
, "MLME: unknown Action Category %d",
2006 mgmt
->u
.action
.category
);
2012 static void ieee80211_sta_rx_mgmt(struct wpa_supplicant
*wpa_s
,
2013 const u8
*buf
, size_t len
,
2014 struct ieee80211_rx_status
*rx_status
)
2016 struct ieee80211_mgmt
*mgmt
;
2022 mgmt
= (struct ieee80211_mgmt
*) buf
;
2023 fc
= le_to_host16(mgmt
->frame_control
);
2025 switch (WLAN_FC_GET_STYPE(fc
)) {
2026 case WLAN_FC_STYPE_PROBE_REQ
:
2027 ieee80211_rx_mgmt_probe_req(wpa_s
, mgmt
, len
, rx_status
);
2029 case WLAN_FC_STYPE_PROBE_RESP
:
2030 ieee80211_rx_mgmt_probe_resp(wpa_s
, mgmt
, len
, rx_status
);
2032 case WLAN_FC_STYPE_BEACON
:
2033 ieee80211_rx_mgmt_beacon(wpa_s
, mgmt
, len
, rx_status
);
2035 case WLAN_FC_STYPE_AUTH
:
2036 ieee80211_rx_mgmt_auth(wpa_s
, mgmt
, len
, rx_status
);
2038 case WLAN_FC_STYPE_ASSOC_RESP
:
2039 ieee80211_rx_mgmt_assoc_resp(wpa_s
, mgmt
, len
, rx_status
, 0);
2041 case WLAN_FC_STYPE_REASSOC_RESP
:
2042 ieee80211_rx_mgmt_assoc_resp(wpa_s
, mgmt
, len
, rx_status
, 1);
2044 case WLAN_FC_STYPE_DEAUTH
:
2045 ieee80211_rx_mgmt_deauth(wpa_s
, mgmt
, len
, rx_status
);
2047 case WLAN_FC_STYPE_DISASSOC
:
2048 ieee80211_rx_mgmt_disassoc(wpa_s
, mgmt
, len
, rx_status
);
2050 case WLAN_FC_STYPE_ACTION
:
2051 ieee80211_rx_mgmt_action(wpa_s
, mgmt
, len
, rx_status
);
2054 wpa_printf(MSG_DEBUG
, "MLME: received unknown management "
2055 "frame - stype=%d", WLAN_FC_GET_STYPE(fc
));
2061 static void ieee80211_sta_rx_scan(struct wpa_supplicant
*wpa_s
,
2062 const u8
*buf
, size_t len
,
2063 struct ieee80211_rx_status
*rx_status
)
2065 struct ieee80211_mgmt
*mgmt
;
2071 mgmt
= (struct ieee80211_mgmt
*) buf
;
2072 fc
= le_to_host16(mgmt
->frame_control
);
2074 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
) {
2075 if (WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
2076 ieee80211_rx_mgmt_probe_resp(wpa_s
, mgmt
,
2078 } else if (WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
) {
2079 ieee80211_rx_mgmt_beacon(wpa_s
, mgmt
, len
, rx_status
);
2085 static int ieee80211_sta_active_ibss(struct wpa_supplicant
*wpa_s
)
2090 list_for_each(ptr
, &local
->sta_list
) {
2091 sta
= list_entry(ptr
, struct sta_info
, list
);
2092 if (sta
->dev
== dev
&&
2093 time_after(sta
->last_rx
+ IEEE80211_IBSS_MERGE_INTERVAL
,
2105 static void ieee80211_sta_expire(struct wpa_supplicant
*wpa_s
)
2108 list_for_each_safe(ptr
, n
, &local
->sta_list
) {
2109 sta
= list_entry(ptr
, struct sta_info
, list
);
2110 if (time_after(jiffies
, sta
->last_rx
+
2111 IEEE80211_IBSS_INACTIVITY_LIMIT
)) {
2112 wpa_printf(MSG_DEBUG
, "MLME: expiring inactive STA "
2113 MACSTR
, MAC2STR(sta
->addr
));
2114 sta_info_free(local
, sta
, 1);
2121 static void ieee80211_sta_merge_ibss(struct wpa_supplicant
*wpa_s
)
2123 struct wpa_driver_scan_params params
;
2125 ieee80211_reschedule_timer(wpa_s
, IEEE80211_IBSS_MERGE_INTERVAL
);
2127 ieee80211_sta_expire(wpa_s
);
2128 if (ieee80211_sta_active_ibss(wpa_s
))
2131 wpa_printf(MSG_DEBUG
, "MLME: No active IBSS STAs - trying to scan for "
2132 "other IBSS networks with same SSID (merge)");
2133 os_memset(¶ms
, 0, sizeof(params
));
2134 params
.ssids
[0].ssid
= wpa_s
->mlme
.ssid
;
2135 params
.ssids
[0].ssid_len
= wpa_s
->mlme
.ssid_len
;
2136 params
.num_ssids
= wpa_s
->mlme
.ssid_len
? 1 : 0;
2137 ieee80211_sta_req_scan(wpa_s
, ¶ms
);
2141 static void ieee80211_sta_timer(void *eloop_ctx
, void *timeout_ctx
)
2143 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2145 switch (wpa_s
->mlme
.state
) {
2146 case IEEE80211_DISABLED
:
2148 case IEEE80211_AUTHENTICATE
:
2149 ieee80211_authenticate(wpa_s
);
2151 case IEEE80211_ASSOCIATE
:
2152 ieee80211_associate(wpa_s
);
2154 case IEEE80211_ASSOCIATED
:
2155 ieee80211_associated(wpa_s
);
2157 case IEEE80211_IBSS_SEARCH
:
2158 ieee80211_sta_find_ibss(wpa_s
);
2160 case IEEE80211_IBSS_JOINED
:
2161 ieee80211_sta_merge_ibss(wpa_s
);
2164 wpa_printf(MSG_DEBUG
, "ieee80211_sta_timer: Unknown state %d",
2169 if (ieee80211_privacy_mismatch(wpa_s
)) {
2170 wpa_printf(MSG_DEBUG
, "MLME: privacy configuration mismatch "
2171 "and mixed-cell disabled - disassociate");
2173 ieee80211_send_disassoc(wpa_s
, WLAN_REASON_UNSPECIFIED
);
2174 ieee80211_set_associated(wpa_s
, 0);
2179 static void ieee80211_sta_new_auth(struct wpa_supplicant
*wpa_s
)
2181 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2182 if (ssid
&& ssid
->mode
!= WPAS_MODE_INFRA
)
2186 if (local
->hw
->reset_tsf
) {
2187 /* Reset own TSF to allow time synchronization work. */
2188 local
->hw
->reset_tsf(local
->mdev
);
2192 wpa_s
->mlme
.wmm_last_param_set
= -1; /* allow any WMM update */
2195 if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_OPEN
)
2196 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_OPEN
;
2197 else if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_SHARED
)
2198 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_SHARED_KEY
;
2199 else if (wpa_s
->mlme
.auth_algs
& WPA_AUTH_ALG_LEAP
)
2200 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_LEAP
;
2202 wpa_s
->mlme
.auth_alg
= WLAN_AUTH_OPEN
;
2203 wpa_printf(MSG_DEBUG
, "MLME: Initial auth_alg=%d",
2204 wpa_s
->mlme
.auth_alg
);
2205 wpa_s
->mlme
.auth_transaction
= -1;
2206 wpa_s
->mlme
.auth_tries
= wpa_s
->mlme
.assoc_tries
= 0;
2207 ieee80211_authenticate(wpa_s
);
2211 static int ieee80211_ibss_allowed(struct wpa_supplicant
*wpa_s
)
2216 for (m
= 0; m
< local
->hw
->num_modes
; m
++) {
2217 struct ieee80211_hw_modes
*mode
= &local
->hw
->modes
[m
];
2218 if (mode
->mode
!= local
->conf
.phymode
)
2220 for (c
= 0; c
< mode
->num_channels
; c
++) {
2221 struct ieee80211_channel
*chan
= &mode
->channels
[c
];
2222 if (chan
->flag
& IEEE80211_CHAN_W_SCAN
&&
2223 chan
->chan
== local
->conf
.channel
) {
2224 if (chan
->flag
& IEEE80211_CHAN_W_IBSS
)
2236 static int ieee80211_sta_join_ibss(struct wpa_supplicant
*wpa_s
,
2237 struct ieee80211_sta_bss
*bss
)
2239 int res
= 0, rates
, done
= 0, bssid_changed
;
2240 struct ieee80211_mgmt
*mgmt
;
2242 struct ieee80211_tx_control control
;
2243 struct ieee80211_rate
*rate
;
2244 struct rate_control_extra extra
;
2249 /* Remove possible STA entries from other IBSS networks. */
2251 sta_info_flush(local
, NULL
);
2253 if (local
->hw
->reset_tsf
) {
2254 /* Reset own TSF to allow time synchronization work. */
2255 local
->hw
->reset_tsf(local
->mdev
);
2258 bssid_changed
= os_memcmp(wpa_s
->bssid
, bss
->bssid
, ETH_ALEN
);
2259 os_memcpy(wpa_s
->bssid
, bss
->bssid
, ETH_ALEN
);
2261 wpas_notify_bssid_changed(wpa_s
);
2264 local
->conf
.beacon_int
= bss
->beacon_int
>= 10 ? bss
->beacon_int
: 10;
2266 sdata
->drop_unencrypted
= bss
->capability
&
2267 host_to_le16(WLAN_CAPABILITY_PRIVACY
) ? 1 : 0;
2271 os_memset(&rq
, 0, sizeof(rq
));
2272 rq
.m
= bss
->freq
* 100000;
2274 res
= ieee80211_ioctl_siwfreq(wpa_s
, NULL
, &rq
, NULL
);
2277 if (!ieee80211_ibss_allowed(wpa_s
)) {
2279 wpa_printf(MSG_DEBUG
, "MLME: IBSS not allowed on channel %d "
2280 "(%d MHz)", local
->conf
.channel
,
2286 /* Set beacon template based on scan results */
2287 buf
= os_malloc(400);
2293 mgmt
= (struct ieee80211_mgmt
*) buf
;
2294 len
+= 24 + sizeof(mgmt
->u
.beacon
);
2295 os_memset(mgmt
, 0, 24 + sizeof(mgmt
->u
.beacon
));
2296 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2297 WLAN_FC_STYPE_BEACON
);
2298 os_memset(mgmt
->da
, 0xff, ETH_ALEN
);
2299 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
2300 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
2302 mgmt
->u
.beacon
.beacon_int
=
2303 host_to_le16(local
->conf
.beacon_int
);
2305 mgmt
->u
.beacon
.capab_info
= host_to_le16(bss
->capability
);
2308 len
+= 2 + wpa_s
->mlme
.ssid_len
;
2309 *pos
++ = WLAN_EID_SSID
;
2310 *pos
++ = wpa_s
->mlme
.ssid_len
;
2311 os_memcpy(pos
, wpa_s
->mlme
.ssid
, wpa_s
->mlme
.ssid_len
);
2313 rates
= bss
->supp_rates_len
;
2318 *pos
++ = WLAN_EID_SUPP_RATES
;
2320 os_memcpy(pos
, bss
->supp_rates
, rates
);
2324 *pos
++ = WLAN_EID_DS_PARAMS
;
2326 *pos
++ = bss
->channel
;
2330 *pos
++ = WLAN_EID_IBSS_PARAMS
;
2332 /* FIX: set ATIM window based on scan results */
2336 if (bss
->supp_rates_len
> 8) {
2337 rates
= bss
->supp_rates_len
- 8;
2340 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
2342 os_memcpy(pos
, &bss
->supp_rates
[8], rates
);
2346 os_memset(&control
, 0, sizeof(control
));
2347 control
.pkt_type
= PKT_PROBE_RESP
;
2348 os_memset(&extra
, 0, sizeof(extra
));
2349 extra
.endidx
= local
->num_curr_rates
;
2350 rate
= rate_control_get_rate(wpa_s
, skb
, &extra
);
2352 wpa_printf(MSG_DEBUG
, "MLME: Failed to determine TX "
2353 "rate for IBSS beacon");
2356 control
.tx_rate
= (wpa_s
->mlme
.short_preamble
&&
2357 (rate
->flags
& IEEE80211_RATE_PREAMBLE2
)) ?
2358 rate
->val2
: rate
->val
;
2359 control
.antenna_sel
= local
->conf
.antenna_sel
;
2360 control
.power_level
= local
->conf
.power_level
;
2362 control
.retry_limit
= 1;
2363 control
.rts_cts_duration
= 0;
2367 wpa_s
->mlme
.probe_resp
= skb_copy(skb
, GFP_ATOMIC
);
2368 if (wpa_s
->mlme
.probe_resp
) {
2369 mgmt
= (struct ieee80211_mgmt
*)
2370 wpa_s
->mlme
.probe_resp
->data
;
2371 mgmt
->frame_control
=
2372 IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
2373 WLAN_FC_STYPE_PROBE_RESP
);
2375 wpa_printf(MSG_DEBUG
, "MLME: Could not allocate "
2376 "ProbeResp template for IBSS");
2379 if (local
->hw
->beacon_update
&&
2380 local
->hw
->beacon_update(wpa_s
, skb
, &control
) == 0) {
2381 wpa_printf(MSG_DEBUG
, "MLME: Configured IBSS beacon "
2382 "template based on scan results");
2387 for (i
= 0; i
< bss
->supp_rates_len
; i
++) {
2388 int rate
= (bss
->supp_rates
[i
] & 0x7f) * 5;
2389 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
2391 for (j
= 0; j
< local
->num_curr_rates
; j
++)
2392 if (local
->curr_rates
[j
] == rate
)
2395 wpa_s
->mlme
.supp_rates_bits
= rates
;
2402 wpa_printf(MSG_DEBUG
, "MLME: Failed to configure IBSS beacon "
2406 wpa_s
->mlme
.state
= IEEE80211_IBSS_JOINED
;
2407 ieee80211_reschedule_timer(wpa_s
, IEEE80211_IBSS_MERGE_INTERVAL
);
2414 static int ieee80211_sta_create_ibss(struct wpa_supplicant
*wpa_s
)
2416 struct ieee80211_sta_bss
*bss
;
2417 u8 bssid
[ETH_ALEN
], *pos
;
2421 /* Easier testing, use fixed BSSID. */
2422 os_memset(bssid
, 0xfe, ETH_ALEN
);
2424 /* Generate random, not broadcast, locally administered BSSID. Mix in
2425 * own MAC address to make sure that devices that do not have proper
2426 * random number generator get different BSSID. */
2427 os_get_random(bssid
, ETH_ALEN
);
2428 for (i
= 0; i
< ETH_ALEN
; i
++)
2429 bssid
[i
] ^= wpa_s
->own_addr
[i
];
2434 wpa_printf(MSG_DEBUG
, "MLME: Creating new IBSS network, BSSID "
2435 MACSTR
"", MAC2STR(bssid
));
2437 bss
= ieee80211_bss_add(wpa_s
, bssid
);
2442 if (local
->conf
.beacon_int
== 0)
2443 local
->conf
.beacon_int
= 100;
2444 bss
->beacon_int
= local
->conf
.beacon_int
;
2445 bss
->hw_mode
= local
->conf
.phymode
;
2446 bss
->channel
= local
->conf
.channel
;
2447 bss
->freq
= local
->conf
.freq
;
2449 os_get_time(&bss
->last_update
);
2450 bss
->capability
= host_to_le16(WLAN_CAPABILITY_IBSS
);
2452 if (sdata
->default_key
) {
2453 bss
->capability
|= host_to_le16(WLAN_CAPABILITY_PRIVACY
);
2455 sdata
->drop_unencrypted
= 0;
2456 bss
->supp_rates_len
= local
->num_curr_rates
;
2458 pos
= bss
->supp_rates
;
2460 for (i
= 0; i
< local
->num_curr_rates
; i
++) {
2461 int rate
= local
->curr_rates
[i
];
2462 if (local
->conf
.phymode
== MODE_ATHEROS_TURBO
)
2464 *pos
++ = (u8
) (rate
/ 5);
2468 return ieee80211_sta_join_ibss(wpa_s
, bss
);
2473 static int ieee80211_sta_find_ibss(struct wpa_supplicant
*wpa_s
)
2475 struct ieee80211_sta_bss
*bss
;
2481 if (wpa_s
->mlme
.ssid_len
== 0)
2484 active_ibss
= ieee80211_sta_active_ibss(wpa_s
);
2485 #ifdef IEEE80211_IBSS_DEBUG
2486 wpa_printf(MSG_DEBUG
, "MLME: sta_find_ibss (active_ibss=%d)",
2488 #endif /* IEEE80211_IBSS_DEBUG */
2489 for (bss
= wpa_s
->mlme
.sta_bss_list
; bss
; bss
= bss
->next
) {
2490 if (wpa_s
->mlme
.ssid_len
!= bss
->ssid_len
||
2491 os_memcmp(wpa_s
->mlme
.ssid
, bss
->ssid
, bss
->ssid_len
) != 0
2492 || !(bss
->capability
& WLAN_CAPABILITY_IBSS
))
2494 #ifdef IEEE80211_IBSS_DEBUG
2495 wpa_printf(MSG_DEBUG
, " bssid=" MACSTR
" found",
2496 MAC2STR(bss
->bssid
));
2497 #endif /* IEEE80211_IBSS_DEBUG */
2498 os_memcpy(bssid
, bss
->bssid
, ETH_ALEN
);
2501 os_memcmp(bssid
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2505 #ifdef IEEE80211_IBSS_DEBUG
2506 wpa_printf(MSG_DEBUG
, " sta_find_ibss: selected " MACSTR
" current "
2507 MACSTR
, MAC2STR(bssid
), MAC2STR(wpa_s
->bssid
));
2508 #endif /* IEEE80211_IBSS_DEBUG */
2509 if (found
&& os_memcmp(wpa_s
->bssid
, bssid
, ETH_ALEN
) != 0 &&
2510 (bss
= ieee80211_bss_get(wpa_s
, bssid
))) {
2511 wpa_printf(MSG_DEBUG
, "MLME: Selected IBSS BSSID " MACSTR
2512 " based on configured SSID",
2514 return ieee80211_sta_join_ibss(wpa_s
, bss
);
2516 #ifdef IEEE80211_IBSS_DEBUG
2517 wpa_printf(MSG_DEBUG
, " did not try to join ibss");
2518 #endif /* IEEE80211_IBSS_DEBUG */
2520 /* Selected IBSS not found in current scan results - try to scan */
2523 if (wpa_s
->mlme
.state
== IEEE80211_IBSS_JOINED
&&
2524 !ieee80211_sta_active_ibss(wpa_s
)) {
2525 ieee80211_reschedule_timer(wpa_s
,
2526 IEEE80211_IBSS_MERGE_INTERVAL
);
2527 } else if (time_after(jiffies
, wpa_s
->mlme
.last_scan_completed
+
2528 IEEE80211_SCAN_INTERVAL
)) {
2529 wpa_printf(MSG_DEBUG
, "MLME: Trigger new scan to find an IBSS "
2531 return ieee80211_sta_req_scan(wpa_s
->mlme
.ssid
,
2532 wpa_s
->mlme
.ssid_len
);
2533 } else if (wpa_s
->mlme
.state
!= IEEE80211_IBSS_JOINED
) {
2534 int interval
= IEEE80211_SCAN_INTERVAL
;
2536 if (time_after(jiffies
, wpa_s
->mlme
.ibss_join_req
+
2537 IEEE80211_IBSS_JOIN_TIMEOUT
)) {
2538 if (wpa_s
->mlme
.create_ibss
&&
2539 ieee80211_ibss_allowed(wpa_s
))
2540 return ieee80211_sta_create_ibss(wpa_s
);
2541 if (wpa_s
->mlme
.create_ibss
) {
2542 wpa_printf(MSG_DEBUG
, "MLME: IBSS not allowed "
2543 "on the configured channel %d "
2545 local
->conf
.channel
,
2549 /* No IBSS found - decrease scan interval and continue
2551 interval
= IEEE80211_SCAN_INTERVAL_SLOW
;
2554 wpa_s
->mlme
.state
= IEEE80211_IBSS_SEARCH
;
2555 ieee80211_reschedule_timer(wpa_s
, interval
);
2564 int ieee80211_sta_get_ssid(struct wpa_supplicant
*wpa_s
, u8
*ssid
,
2567 os_memcpy(ssid
, wpa_s
->mlme
.ssid
, wpa_s
->mlme
.ssid_len
);
2568 *len
= wpa_s
->mlme
.ssid_len
;
2573 int ieee80211_sta_associate(struct wpa_supplicant
*wpa_s
,
2574 struct wpa_driver_associate_params
*params
)
2576 struct ieee80211_sta_bss
*bss
;
2579 wpa_s
->mlme
.bssid_set
= 0;
2580 wpa_s
->mlme
.freq
= params
->freq
;
2581 if (params
->bssid
) {
2582 bssid_changed
= os_memcmp(wpa_s
->bssid
, params
->bssid
,
2584 os_memcpy(wpa_s
->bssid
, params
->bssid
, ETH_ALEN
);
2586 wpas_notify_bssid_changed(wpa_s
);
2588 if (!is_zero_ether_addr(params
->bssid
))
2589 wpa_s
->mlme
.bssid_set
= 1;
2590 bss
= ieee80211_bss_get(wpa_s
, wpa_s
->bssid
);
2592 wpa_s
->mlme
.phymode
= bss
->hw_mode
;
2593 wpa_s
->mlme
.channel
= bss
->channel
;
2594 wpa_s
->mlme
.freq
= bss
->freq
;
2599 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2601 if (local
->hw
->conf_tx
) {
2602 struct ieee80211_tx_queue_params qparam
;
2605 os_memset(&qparam
, 0, sizeof(qparam
));
2606 /* TODO: are these ok defaults for all hw_modes? */
2609 local
->conf
.phymode
== MODE_IEEE80211B
? 31 : 15;
2610 qparam
.cw_max
= 1023;
2611 qparam
.burst_time
= 0;
2612 for (i
= IEEE80211_TX_QUEUE_DATA0
; i
< NUM_TX_DATA_QUEUES
; i
++)
2614 local
->hw
->conf_tx(wpa_s
, i
+ IEEE80211_TX_QUEUE_DATA0
,
2617 /* IBSS uses different parameters for Beacon sending */
2621 local
->hw
->conf_tx(wpa_s
, IEEE80211_TX_QUEUE_BEACON
, &qparam
);
2625 if (wpa_s
->mlme
.ssid_len
!= params
->ssid_len
||
2626 os_memcmp(wpa_s
->mlme
.ssid
, params
->ssid
, params
->ssid_len
) != 0)
2627 wpa_s
->mlme
.prev_bssid_set
= 0;
2628 os_memcpy(wpa_s
->mlme
.ssid
, params
->ssid
, params
->ssid_len
);
2629 os_memset(wpa_s
->mlme
.ssid
+ params
->ssid_len
, 0,
2630 MAX_SSID_LEN
- params
->ssid_len
);
2631 wpa_s
->mlme
.ssid_len
= params
->ssid_len
;
2632 wpa_s
->mlme
.ssid_set
= 1;
2634 os_free(wpa_s
->mlme
.extra_ie
);
2635 if (params
->wpa_ie
== NULL
|| params
->wpa_ie_len
== 0) {
2636 wpa_s
->mlme
.extra_ie
= NULL
;
2637 wpa_s
->mlme
.extra_ie_len
= 0;
2639 wpa_s
->mlme
.extra_ie
= os_malloc(params
->wpa_ie_len
);
2640 if (wpa_s
->mlme
.extra_ie
== NULL
) {
2641 wpa_s
->mlme
.extra_ie_len
= 0;
2644 os_memcpy(wpa_s
->mlme
.extra_ie
, params
->wpa_ie
,
2645 params
->wpa_ie_len
);
2646 wpa_s
->mlme
.extra_ie_len
= params
->wpa_ie_len
;
2649 wpa_s
->mlme
.key_mgmt
= params
->key_mgmt_suite
;
2651 ieee80211_sta_set_channel(wpa_s
, wpa_s
->mlme
.phymode
,
2652 wpa_s
->mlme
.channel
, wpa_s
->mlme
.freq
);
2654 if (params
->mode
== WPAS_MODE_IBSS
&& !wpa_s
->mlme
.bssid_set
) {
2655 os_get_time(&wpa_s
->mlme
.ibss_join_req
);
2656 wpa_s
->mlme
.state
= IEEE80211_IBSS_SEARCH
;
2657 return ieee80211_sta_find_ibss(wpa_s
);
2660 if (wpa_s
->mlme
.bssid_set
)
2661 ieee80211_sta_new_auth(wpa_s
);
2667 static void ieee80211_sta_save_oper_chan(struct wpa_supplicant
*wpa_s
)
2669 wpa_s
->mlme
.scan_oper_channel
= wpa_s
->mlme
.channel
;
2670 wpa_s
->mlme
.scan_oper_freq
= wpa_s
->mlme
.freq
;
2671 wpa_s
->mlme
.scan_oper_phymode
= wpa_s
->mlme
.phymode
;
2675 static int ieee80211_sta_restore_oper_chan(struct wpa_supplicant
*wpa_s
)
2677 wpa_s
->mlme
.channel
= wpa_s
->mlme
.scan_oper_channel
;
2678 wpa_s
->mlme
.freq
= wpa_s
->mlme
.scan_oper_freq
;
2679 wpa_s
->mlme
.phymode
= wpa_s
->mlme
.scan_oper_phymode
;
2680 if (wpa_s
->mlme
.freq
== 0)
2682 return ieee80211_sta_set_channel(wpa_s
, wpa_s
->mlme
.phymode
,
2683 wpa_s
->mlme
.channel
,
2688 static int ieee80211_active_scan(struct wpa_supplicant
*wpa_s
)
2693 for (m
= 0; m
< wpa_s
->mlme
.num_modes
; m
++) {
2694 struct hostapd_hw_modes
*mode
= &wpa_s
->mlme
.modes
[m
];
2695 if ((int) mode
->mode
!= (int) wpa_s
->mlme
.phymode
)
2697 for (c
= 0; c
< mode
->num_channels
; c
++) {
2698 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
2699 if (!(chan
->flag
& HOSTAPD_CHAN_DISABLED
) &&
2700 chan
->chan
== wpa_s
->mlme
.channel
) {
2701 if (!(chan
->flag
& HOSTAPD_CHAN_PASSIVE_SCAN
))
2712 static void ieee80211_sta_scan_timer(void *eloop_ctx
, void *timeout_ctx
)
2714 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2715 struct hostapd_hw_modes
*mode
;
2716 struct hostapd_channel_data
*chan
;
2719 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2722 if (!wpa_s
->mlme
.sta_scanning
|| wpa_s
->mlme
.modes
== NULL
)
2725 adhoc
= ssid
&& ssid
->mode
== 1;
2727 switch (wpa_s
->mlme
.scan_state
) {
2728 case SCAN_SET_CHANNEL
:
2729 mode
= &wpa_s
->mlme
.modes
[wpa_s
->mlme
.scan_hw_mode_idx
];
2730 if (wpa_s
->mlme
.scan_hw_mode_idx
>=
2731 (int) wpa_s
->mlme
.num_modes
||
2732 (wpa_s
->mlme
.scan_hw_mode_idx
+ 1 ==
2733 (int) wpa_s
->mlme
.num_modes
2734 && wpa_s
->mlme
.scan_channel_idx
>= mode
->num_channels
)) {
2735 if (ieee80211_sta_restore_oper_chan(wpa_s
)) {
2736 wpa_printf(MSG_DEBUG
, "MLME: failed to "
2737 "restore operational channel after "
2740 wpa_printf(MSG_DEBUG
, "MLME: scan completed");
2741 wpa_s
->mlme
.sta_scanning
= 0;
2742 os_get_time(&wpa_s
->mlme
.last_scan_completed
);
2743 wpa_supplicant_event(wpa_s
, EVENT_SCAN_RESULTS
, NULL
);
2745 if (!wpa_s
->mlme
.bssid_set
||
2746 (wpa_s
->mlme
.state
==
2747 IEEE80211_IBSS_JOINED
&&
2748 !ieee80211_sta_active_ibss(wpa_s
)))
2749 ieee80211_sta_find_ibss(wpa_s
);
2753 skip
= !(wpa_s
->mlme
.hw_modes
& (1 << mode
->mode
));
2754 chan
= &mode
->channels
[wpa_s
->mlme
.scan_channel_idx
];
2755 if ((chan
->flag
& HOSTAPD_CHAN_DISABLED
) ||
2756 (adhoc
&& (chan
->flag
& HOSTAPD_CHAN_NO_IBSS
)) ||
2757 (wpa_s
->mlme
.hw_modes
& (1 << HOSTAPD_MODE_IEEE80211G
) &&
2758 mode
->mode
== HOSTAPD_MODE_IEEE80211B
&&
2759 wpa_s
->mlme
.scan_skip_11b
))
2761 if (!skip
&& wpa_s
->mlme
.scan_freqs
) {
2763 for (i
= 0; wpa_s
->mlme
.scan_freqs
[i
]; i
++) {
2764 if (wpa_s
->mlme
.scan_freqs
[i
] == chan
->freq
) {
2774 wpa_printf(MSG_MSGDUMP
,
2775 "MLME: scan channel %d (%d MHz)",
2776 chan
->chan
, chan
->freq
);
2778 wpa_s
->mlme
.channel
= chan
->chan
;
2779 wpa_s
->mlme
.freq
= chan
->freq
;
2780 wpa_s
->mlme
.phymode
= mode
->mode
;
2781 if (ieee80211_sta_set_channel(wpa_s
, mode
->mode
,
2782 chan
->chan
, chan
->freq
))
2784 wpa_printf(MSG_DEBUG
, "MLME: failed to set "
2785 "channel %d (%d MHz) for scan",
2786 chan
->chan
, chan
->freq
);
2791 wpa_s
->mlme
.scan_channel_idx
++;
2792 if (wpa_s
->mlme
.scan_channel_idx
>=
2793 wpa_s
->mlme
.modes
[wpa_s
->mlme
.scan_hw_mode_idx
].
2795 wpa_s
->mlme
.scan_hw_mode_idx
++;
2796 wpa_s
->mlme
.scan_channel_idx
= 0;
2804 timeout
= IEEE80211_PROBE_DELAY
;
2805 wpa_s
->mlme
.scan_state
= SCAN_SEND_PROBE
;
2807 case SCAN_SEND_PROBE
:
2808 if (ieee80211_active_scan(wpa_s
)) {
2809 ieee80211_send_probe_req(wpa_s
, NULL
,
2810 wpa_s
->mlme
.scan_ssid
,
2811 wpa_s
->mlme
.scan_ssid_len
);
2812 timeout
= IEEE80211_CHANNEL_TIME
;
2814 timeout
= IEEE80211_PASSIVE_CHANNEL_TIME
;
2816 wpa_s
->mlme
.scan_state
= SCAN_SET_CHANNEL
;
2820 eloop_register_timeout(timeout
/ 1000, 1000 * (timeout
% 1000),
2821 ieee80211_sta_scan_timer
, wpa_s
, NULL
);
2825 int ieee80211_sta_req_scan(struct wpa_supplicant
*wpa_s
,
2826 struct wpa_driver_scan_params
*params
)
2828 const u8
*ssid
= params
->ssids
[0].ssid
;
2829 size_t ssid_len
= params
->ssids
[0].ssid_len
;
2831 if (ssid_len
> MAX_SSID_LEN
)
2834 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2835 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2838 * ScanType: ACTIVE, PASSIVE
2839 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2840 * a Probe frame during active scanning
2842 * MinChannelTime (>= ProbeDelay), in TU
2843 * MaxChannelTime: (>= MinChannelTime), in TU
2846 /* MLME-SCAN.confirm
2848 * ResultCode: SUCCESS, INVALID_PARAMETERS
2851 /* TODO: if assoc, move to power save mode for the duration of the
2854 if (wpa_s
->mlme
.sta_scanning
)
2857 wpa_printf(MSG_DEBUG
, "MLME: starting scan");
2859 ieee80211_sta_set_probe_req_ie(wpa_s
, params
->extra_ies
,
2860 params
->extra_ies_len
);
2862 os_free(wpa_s
->mlme
.scan_freqs
);
2863 if (params
->freqs
) {
2865 for (i
= 0; params
->freqs
[i
]; i
++)
2867 wpa_s
->mlme
.scan_freqs
= os_malloc((i
+ 1) * sizeof(int));
2868 if (wpa_s
->mlme
.scan_freqs
)
2869 os_memcpy(wpa_s
->mlme
.scan_freqs
, params
->freqs
,
2870 (i
+ 1) * sizeof(int));
2872 wpa_s
->mlme
.scan_freqs
= NULL
;
2874 ieee80211_sta_save_oper_chan(wpa_s
);
2876 wpa_s
->mlme
.sta_scanning
= 1;
2877 /* TODO: stop TX queue? */
2880 wpa_s
->mlme
.scan_ssid_len
= ssid_len
;
2881 os_memcpy(wpa_s
->mlme
.scan_ssid
, ssid
, ssid_len
);
2883 wpa_s
->mlme
.scan_ssid_len
= 0;
2884 wpa_s
->mlme
.scan_skip_11b
= 1; /* FIX: clear this if 11g is not
2886 wpa_s
->mlme
.scan_skip_11b
= 0;
2887 wpa_s
->mlme
.scan_state
= SCAN_SET_CHANNEL
;
2888 wpa_s
->mlme
.scan_hw_mode_idx
= 0;
2889 wpa_s
->mlme
.scan_channel_idx
= 0;
2890 eloop_register_timeout(0, 1, ieee80211_sta_scan_timer
, wpa_s
, NULL
);
2896 struct wpa_scan_results
*
2897 ieee80211_sta_get_scan_results(struct wpa_supplicant
*wpa_s
)
2900 struct wpa_scan_results
*res
;
2901 struct wpa_scan_res
*r
;
2902 struct ieee80211_sta_bss
*bss
;
2904 res
= os_zalloc(sizeof(*res
));
2905 for (bss
= wpa_s
->mlme
.sta_bss_list
; bss
; bss
= bss
->next
)
2907 res
->res
= os_zalloc(ap_num
* sizeof(struct wpa_scan_res
*));
2908 if (res
->res
== NULL
) {
2913 for (bss
= wpa_s
->mlme
.sta_bss_list
; bss
; bss
= bss
->next
) {
2914 r
= os_zalloc(sizeof(*r
) + bss
->ie_len
);
2917 os_memcpy(r
->bssid
, bss
->bssid
, ETH_ALEN
);
2918 r
->freq
= bss
->freq
;
2919 r
->beacon_int
= bss
->beacon_int
;
2920 r
->caps
= bss
->capability
;
2921 r
->level
= bss
->rssi
;
2922 r
->tsf
= bss
->timestamp
;
2924 r
->ie_len
= bss
->ie_len
;
2925 os_memcpy(r
+ 1, bss
->ie
, bss
->ie_len
);
2928 res
->res
[res
->num
++] = r
;
2936 struct sta_info
* ieee80211_ibss_add_sta(struct wpa_supplicant
*wpa_s
,
2937 struct sk_buff
*skb
, u8
*bssid
,
2940 struct ieee80211_local
*local
= dev
->priv
;
2941 struct list_head
*ptr
;
2942 struct sta_info
*sta
;
2943 struct wpa_supplicant
*sta_dev
= NULL
;
2945 /* TODO: Could consider removing the least recently used entry and
2946 * allow new one to be added. */
2947 if (local
->num_sta
>= IEEE80211_IBSS_MAX_STA_ENTRIES
) {
2948 if (net_ratelimit()) {
2949 wpa_printf(MSG_DEBUG
, "MLME: No room for a new IBSS "
2950 "STA entry " MACSTR
, MAC2STR(addr
));
2955 spin_lock_bh(&local
->sub_if_lock
);
2956 list_for_each(ptr
, &local
->sub_if_list
) {
2957 sdata
= list_entry(ptr
, struct ieee80211_sub_if_data
, list
);
2958 if (sdata
->type
== IEEE80211_SUB_IF_TYPE_STA
&&
2959 os_memcmp(bssid
, sdata
->u
.sta
.bssid
, ETH_ALEN
) == 0) {
2960 sta_dev
= sdata
->dev
;
2964 spin_unlock_bh(&local
->sub_if_lock
);
2966 if (sta_dev
== NULL
)
2969 wpa_printf(MSG_DEBUG
, "MLME: Adding new IBSS station " MACSTR
2970 " (dev=%s)", MAC2STR(addr
), sta_dev
->name
);
2972 sta
= sta_info_add(wpa_s
, addr
);
2978 sta
->supp_rates
= wpa_s
->mlme
.supp_rates_bits
;
2980 rate_control_rate_init(local
, sta
);
2982 return sta
; /* caller will call sta_info_release() */
2987 int ieee80211_sta_deauthenticate(struct wpa_supplicant
*wpa_s
, u16 reason
)
2989 wpa_printf(MSG_DEBUG
, "MLME: deauthenticate(reason=%d)", reason
);
2991 ieee80211_send_deauth(wpa_s
, reason
);
2992 ieee80211_set_associated(wpa_s
, 0);
2997 int ieee80211_sta_disassociate(struct wpa_supplicant
*wpa_s
, u16 reason
)
2999 wpa_printf(MSG_DEBUG
, "MLME: disassociate(reason=%d)", reason
);
3001 if (!wpa_s
->mlme
.associated
)
3004 ieee80211_send_disassoc(wpa_s
, reason
);
3005 ieee80211_set_associated(wpa_s
, 0);
3010 void ieee80211_sta_rx(struct wpa_supplicant
*wpa_s
, const u8
*buf
, size_t len
,
3011 struct ieee80211_rx_status
*rx_status
)
3013 struct ieee80211_mgmt
*mgmt
;
3017 /* wpa_hexdump(MSG_MSGDUMP, "MLME: Received frame", buf, len); */
3019 if (wpa_s
->mlme
.sta_scanning
) {
3020 ieee80211_sta_rx_scan(wpa_s
, buf
, len
, rx_status
);
3027 mgmt
= (struct ieee80211_mgmt
*) buf
;
3028 fc
= le_to_host16(mgmt
->frame_control
);
3030 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
)
3031 ieee80211_sta_rx_mgmt(wpa_s
, buf
, len
, rx_status
);
3032 else if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_DATA
) {
3033 if ((fc
& (WLAN_FC_TODS
| WLAN_FC_FROMDS
)) !=
3036 /* mgmt->sa is actually BSSID for FromDS data frames */
3037 if (os_memcmp(mgmt
->sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
3039 /* Skip IEEE 802.11 and LLC headers */
3041 if (WPA_GET_BE16(pos
) != ETH_P_EAPOL
)
3044 /* mgmt->bssid is actually BSSID for SA data frames */
3045 wpa_supplicant_rx_eapol(wpa_s
, mgmt
->bssid
,
3046 pos
, buf
+ len
- pos
);
3051 void ieee80211_sta_free_hw_features(struct hostapd_hw_modes
*hw_features
,
3052 size_t num_hw_features
)
3056 if (hw_features
== NULL
)
3059 for (i
= 0; i
< num_hw_features
; i
++) {
3060 os_free(hw_features
[i
].channels
);
3061 os_free(hw_features
[i
].rates
);
3064 os_free(hw_features
);
3068 int ieee80211_sta_init(struct wpa_supplicant
*wpa_s
)
3070 u16 num_modes
, flags
;
3072 wpa_s
->mlme
.modes
= wpa_drv_get_hw_feature_data(wpa_s
, &num_modes
,
3074 if (wpa_s
->mlme
.modes
== NULL
) {
3075 wpa_printf(MSG_ERROR
, "MLME: Failed to read supported "
3076 "channels and rates from the driver");
3080 wpa_s
->mlme
.num_modes
= num_modes
;
3082 wpa_s
->mlme
.hw_modes
= 1 << HOSTAPD_MODE_IEEE80211A
;
3083 wpa_s
->mlme
.hw_modes
|= 1 << HOSTAPD_MODE_IEEE80211B
;
3084 wpa_s
->mlme
.hw_modes
|= 1 << HOSTAPD_MODE_IEEE80211G
;
3086 wpa_s
->mlme
.wmm_enabled
= 1;
3092 void ieee80211_sta_deinit(struct wpa_supplicant
*wpa_s
)
3094 eloop_cancel_timeout(ieee80211_sta_timer
, wpa_s
, NULL
);
3095 eloop_cancel_timeout(ieee80211_sta_scan_timer
, wpa_s
, NULL
);
3096 os_free(wpa_s
->mlme
.extra_ie
);
3097 wpa_s
->mlme
.extra_ie
= NULL
;
3098 os_free(wpa_s
->mlme
.extra_probe_ie
);
3099 wpa_s
->mlme
.extra_probe_ie
= NULL
;
3100 os_free(wpa_s
->mlme
.assocreq_ies
);
3101 wpa_s
->mlme
.assocreq_ies
= NULL
;
3102 os_free(wpa_s
->mlme
.assocresp_ies
);
3103 wpa_s
->mlme
.assocresp_ies
= NULL
;
3104 ieee80211_bss_list_deinit(wpa_s
);
3105 ieee80211_sta_free_hw_features(wpa_s
->mlme
.modes
,
3106 wpa_s
->mlme
.num_modes
);
3107 #ifdef CONFIG_IEEE80211R
3108 os_free(wpa_s
->mlme
.ft_ies
);
3109 wpa_s
->mlme
.ft_ies
= NULL
;
3110 wpa_s
->mlme
.ft_ies_len
= 0;
3111 #endif /* CONFIG_IEEE80211R */
3113 os_free(wpa_s
->mlme
.scan_freqs
);
3114 wpa_s
->mlme
.scan_freqs
= NULL
;
3118 #ifdef CONFIG_IEEE80211R
3120 int ieee80211_sta_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
3121 const u8
*ies
, size_t ies_len
)
3124 wpa_printf(MSG_DEBUG
, "MLME: Clear FT mobility domain");
3125 os_memset(wpa_s
->mlme
.current_md
, 0, MOBILITY_DOMAIN_ID_LEN
);
3127 wpa_printf(MSG_DEBUG
, "MLME: Update FT IEs for MD " MACSTR
,
3129 os_memcpy(wpa_s
->mlme
.current_md
, md
, MOBILITY_DOMAIN_ID_LEN
);
3132 wpa_hexdump(MSG_DEBUG
, "MLME: FT IEs", ies
, ies_len
);
3133 os_free(wpa_s
->mlme
.ft_ies
);
3134 wpa_s
->mlme
.ft_ies
= os_malloc(ies_len
);
3135 if (wpa_s
->mlme
.ft_ies
== NULL
)
3137 os_memcpy(wpa_s
->mlme
.ft_ies
, ies
, ies_len
);
3138 wpa_s
->mlme
.ft_ies_len
= ies_len
;
3144 int ieee80211_sta_send_ft_action(struct wpa_supplicant
*wpa_s
, u8 action
,
3145 const u8
*target_ap
,
3146 const u8
*ies
, size_t ies_len
)
3150 struct ieee80211_mgmt
*mgmt
;
3154 * Action frame payload:
3155 * Category[1] = 6 (Fast BSS Transition)
3156 * Action[1] = 1 (Fast BSS Transition Request)
3162 buf
= os_zalloc(sizeof(*mgmt
) + ies_len
);
3164 wpa_printf(MSG_DEBUG
, "MLME: Failed to allocate buffer for "
3169 mgmt
= (struct ieee80211_mgmt
*) buf
;
3171 os_memcpy(mgmt
->da
, wpa_s
->bssid
, ETH_ALEN
);
3172 os_memcpy(mgmt
->sa
, wpa_s
->own_addr
, ETH_ALEN
);
3173 os_memcpy(mgmt
->bssid
, wpa_s
->bssid
, ETH_ALEN
);
3174 mgmt
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
3175 WLAN_FC_STYPE_ACTION
);
3176 mgmt
->u
.action
.category
= WLAN_ACTION_FT
;
3177 mgmt
->u
.action
.u
.ft_action_req
.action
= action
;
3178 os_memcpy(mgmt
->u
.action
.u
.ft_action_req
.sta_addr
, wpa_s
->own_addr
,
3180 os_memcpy(mgmt
->u
.action
.u
.ft_action_req
.target_ap_addr
, target_ap
,
3182 os_memcpy(mgmt
->u
.action
.u
.ft_action_req
.variable
, ies
, ies_len
);
3183 len
+= 1 + sizeof(mgmt
->u
.action
.u
.ft_action_req
) + ies_len
;
3185 wpa_printf(MSG_DEBUG
, "MLME: Send FT Action Frame: Action=%d "
3186 "Target AP=" MACSTR
" body_len=%lu",
3187 action
, MAC2STR(target_ap
), (unsigned long) ies_len
);
3189 res
= ieee80211_sta_tx(wpa_s
, buf
, len
);
3195 #endif /* CONFIG_IEEE80211R */
3198 static int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant
*wpa_s
,
3199 const u8
*ies
, size_t ies_len
)
3201 os_free(wpa_s
->mlme
.extra_probe_ie
);
3202 wpa_s
->mlme
.extra_probe_ie
= NULL
;
3203 wpa_s
->mlme
.extra_probe_ie_len
= 0;
3208 wpa_s
->mlme
.extra_probe_ie
= os_malloc(ies_len
);
3209 if (wpa_s
->mlme
.extra_probe_ie
== NULL
)
3212 os_memcpy(wpa_s
->mlme
.extra_probe_ie
, ies
, ies_len
);
3213 wpa_s
->mlme
.extra_probe_ie_len
= ies_len
;