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"
24 #include "drivers/driver.h"
25 #include "ieee802_11_defs.h"
26 #include "ieee802_11_common.h"
30 /* Timeouts and intervals in milliseconds */
31 #define IEEE80211_AUTH_TIMEOUT (200)
32 #define IEEE80211_AUTH_MAX_TRIES 3
33 #define IEEE80211_ASSOC_TIMEOUT (200)
34 #define IEEE80211_ASSOC_MAX_TRIES 3
35 #define IEEE80211_MONITORING_INTERVAL (2000)
36 #define IEEE80211_PROBE_INTERVAL (60000)
37 #define IEEE80211_RETRY_AUTH_INTERVAL (1000)
38 #define IEEE80211_SCAN_INTERVAL (2000)
39 #define IEEE80211_SCAN_INTERVAL_SLOW (15000)
40 #define IEEE80211_IBSS_JOIN_TIMEOUT (20000)
42 #define IEEE80211_PROBE_DELAY (33)
43 #define IEEE80211_CHANNEL_TIME (33)
44 #define IEEE80211_PASSIVE_CHANNEL_TIME (200)
45 #define IEEE80211_SCAN_RESULT_EXPIRE (10000)
46 #define IEEE80211_IBSS_MERGE_INTERVAL (30000)
47 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60000)
49 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
52 #define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))
55 struct ieee80211_sta_bss {
56 struct ieee80211_sta_bss *next;
57 struct ieee80211_sta_bss *hnext;
60 u8 ssid[MAX_SSID_LEN];
62 u16 capability; /* host byte order */
77 #define IEEE80211_MAX_SUPP_RATES 32
78 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
79 size_t supp_rates_len;
84 struct os_time last_update;
88 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
90 const u8 *ssid, size_t ssid_len);
91 static struct ieee80211_sta_bss *
92 ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid);
93 static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s);
94 static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s);
95 static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx);
96 static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx);
99 static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
100 wpa_hw_mode phymode, int chan,
104 struct wpa_hw_modes *mode;
106 for (i = 0; i < wpa_s->mlme.num_modes; i++) {
107 mode = &wpa_s->mlme.modes[i];
108 if (mode->mode == phymode) {
109 wpa_s->mlme.curr_rates = mode->rates;
110 wpa_s->mlme.num_curr_rates = mode->num_rates;
115 return wpa_drv_set_channel(wpa_s, phymode, chan, freq);
121 static int ecw2cw(int ecw)
133 static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
134 u8 *wmm_param, size_t wmm_param_len)
140 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
142 count = wmm_param[6] & 0x0f;
143 if (count == wpa_s->mlme.wmm_last_param_set)
145 wpa_s->mlme.wmm_last_param_set = count;
148 left = wmm_param_len - 8;
152 for (; left >= 4; left -= 4, pos += 4) {
153 int aci = (pos[0] >> 5) & 0x03;
154 int acm = (pos[0] >> 4) & 0x01;
159 queue = IEEE80211_TX_QUEUE_DATA3;
161 wmm_acm |= BIT(1) | BIT(2);
164 queue = IEEE80211_TX_QUEUE_DATA1;
166 wmm_acm |= BIT(4) | BIT(5);
169 queue = IEEE80211_TX_QUEUE_DATA0;
171 wmm_acm |= BIT(6) | BIT(7);
175 queue = IEEE80211_TX_QUEUE_DATA2;
177 wpa_s->mlme.wmm_acm |= BIT(0) | BIT(3);
181 params.aifs = pos[0] & 0x0f;
182 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
183 params.cw_min = ecw2cw(pos[1] & 0x0f);
184 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
185 params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
186 wpa_printf(MSG_DEBUG, "MLME: WMM queue=%d aci=%d acm=%d "
187 "aifs=%d cWmin=%d cWmax=%d burst=%d",
188 queue, aci, acm, params.aifs, params.cw_min,
189 params.cw_max, params.burst_time);
190 /* TODO: handle ACM (block TX, fallback to next lowest allowed
192 if (local->hw->conf_tx(local->mdev, queue, ¶ms)) {
193 wpa_printf(MSG_DEBUG, "MLME: failed to set TX queue "
194 "parameters for queue %d", queue);
201 static void ieee80211_set_associated(struct wpa_supplicant *wpa_s, int assoc)
203 if (wpa_s->mlme.associated == assoc && !assoc)
206 wpa_s->mlme.associated = assoc;
209 union wpa_event_data data;
210 os_memset(&data, 0, sizeof(data));
211 wpa_s->mlme.prev_bssid_set = 1;
212 os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
213 data.assoc_info.req_ies = wpa_s->mlme.assocreq_ies;
214 data.assoc_info.req_ies_len = wpa_s->mlme.assocreq_ies_len;
215 data.assoc_info.resp_ies = wpa_s->mlme.assocresp_ies;
216 data.assoc_info.resp_ies_len = wpa_s->mlme.assocresp_ies_len;
217 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
219 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
221 os_get_time(&wpa_s->mlme.last_probe);
225 static int ieee80211_sta_tx(struct wpa_supplicant *wpa_s, const u8 *buf,
228 return wpa_drv_send_mlme(wpa_s, buf, len);
232 static void ieee80211_send_auth(struct wpa_supplicant *wpa_s,
233 int transaction, u8 *extra, size_t extra_len,
238 struct ieee80211_mgmt *mgmt;
240 buf = os_malloc(sizeof(*mgmt) + 6 + extra_len);
242 wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
247 mgmt = (struct ieee80211_mgmt *) buf;
249 os_memset(mgmt, 0, 24 + 6);
250 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
253 mgmt->frame_control |= host_to_le16(WLAN_FC_ISWEP);
254 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
255 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
256 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
257 mgmt->u.auth.auth_alg = host_to_le16(wpa_s->mlme.auth_alg);
258 mgmt->u.auth.auth_transaction = host_to_le16(transaction);
259 wpa_s->mlme.auth_transaction = transaction + 1;
260 mgmt->u.auth.status_code = host_to_le16(0);
262 os_memcpy(buf + len, extra, extra_len);
266 ieee80211_sta_tx(wpa_s, buf, len);
271 static void ieee80211_reschedule_timer(struct wpa_supplicant *wpa_s, int ms)
273 eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
274 eloop_register_timeout(ms / 1000, 1000 * (ms % 1000),
275 ieee80211_sta_timer, wpa_s, NULL);
279 static void ieee80211_authenticate(struct wpa_supplicant *wpa_s)
284 wpa_s->mlme.auth_tries++;
285 if (wpa_s->mlme.auth_tries > IEEE80211_AUTH_MAX_TRIES) {
286 wpa_printf(MSG_DEBUG, "MLME: authentication with AP " MACSTR
287 " timed out", MAC2STR(wpa_s->bssid));
291 wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
292 wpa_printf(MSG_DEBUG, "MLME: authenticate with AP " MACSTR,
293 MAC2STR(wpa_s->bssid));
298 #ifdef CONFIG_IEEE80211R
299 if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
300 wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
301 wpa_s->mlme.ft_ies) {
302 struct ieee80211_sta_bss *bss;
303 struct rsn_mdie *mdie = NULL;
304 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
305 if (bss && bss->mdie_len >= 2 + sizeof(*mdie))
306 mdie = (struct rsn_mdie *) (bss->mdie + 2);
308 os_memcmp(mdie->mobility_domain, wpa_s->mlme.current_md,
309 MOBILITY_DOMAIN_ID_LEN) == 0) {
310 wpa_printf(MSG_DEBUG, "MLME: Trying to use FT "
312 wpa_s->mlme.auth_alg = WLAN_AUTH_FT;
313 extra = wpa_s->mlme.ft_ies;
314 extra_len = wpa_s->mlme.ft_ies_len;
317 #endif /* CONFIG_IEEE80211R */
319 ieee80211_send_auth(wpa_s, 1, extra, extra_len, 0);
321 ieee80211_reschedule_timer(wpa_s, IEEE80211_AUTH_TIMEOUT);
325 static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
327 struct ieee80211_mgmt *mgmt;
331 struct ieee80211_sta_bss *bss;
335 if (wpa_s->mlme.curr_rates == NULL) {
336 wpa_printf(MSG_DEBUG, "MLME: curr_rates not set for assoc");
340 buflen = sizeof(*mgmt) + 200 + wpa_s->mlme.extra_ie_len +
341 wpa_s->mlme.ssid_len;
342 #ifdef CONFIG_IEEE80211R
343 if (wpa_s->mlme.ft_ies)
344 buflen += wpa_s->mlme.ft_ies_len;
345 #endif /* CONFIG_IEEE80211R */
346 buf = os_malloc(buflen);
348 wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
354 capab = wpa_s->mlme.capab;
355 if (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G) {
356 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
357 WLAN_CAPABILITY_SHORT_PREAMBLE;
359 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
361 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
362 capab |= WLAN_CAPABILITY_PRIVACY;
368 mgmt = (struct ieee80211_mgmt *) buf;
370 os_memset(mgmt, 0, 24);
371 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
372 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
373 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
375 if (wpa_s->mlme.prev_bssid_set) {
377 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
378 WLAN_FC_STYPE_REASSOC_REQ);
379 mgmt->u.reassoc_req.capab_info = host_to_le16(capab);
380 mgmt->u.reassoc_req.listen_interval = host_to_le16(1);
381 os_memcpy(mgmt->u.reassoc_req.current_ap,
382 wpa_s->mlme.prev_bssid,
386 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
387 WLAN_FC_STYPE_ASSOC_REQ);
388 mgmt->u.assoc_req.capab_info = host_to_le16(capab);
389 mgmt->u.assoc_req.listen_interval = host_to_le16(1);
393 ies = pos = buf + blen;
394 blen += 2 + wpa_s->mlme.ssid_len;
395 *pos++ = WLAN_EID_SSID;
396 *pos++ = wpa_s->mlme.ssid_len;
397 os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
399 len = wpa_s->mlme.num_curr_rates;
404 *pos++ = WLAN_EID_SUPP_RATES;
406 for (i = 0; i < len; i++) {
407 int rate = wpa_s->mlme.curr_rates[i].rate;
408 *pos++ = (u8) (rate / 5);
411 if (wpa_s->mlme.num_curr_rates > len) {
413 blen += wpa_s->mlme.num_curr_rates - len + 2;
414 *pos++ = WLAN_EID_EXT_SUPP_RATES;
415 *pos++ = wpa_s->mlme.num_curr_rates - len;
416 for (i = len; i < wpa_s->mlme.num_curr_rates; i++) {
417 int rate = wpa_s->mlme.curr_rates[i].rate;
418 *pos++ = (u8) (rate / 5);
422 if (wpa_s->mlme.extra_ie && wpa_s->mlme.auth_alg != WLAN_AUTH_FT) {
424 blen += wpa_s->mlme.extra_ie_len;
425 os_memcpy(pos, wpa_s->mlme.extra_ie, wpa_s->mlme.extra_ie_len);
428 #ifdef CONFIG_IEEE80211R
429 if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
430 wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
431 wpa_s->mlme.auth_alg != WLAN_AUTH_FT &&
433 bss->mdie_len >= 2 + sizeof(struct rsn_mdie) &&
434 bss->mdie[1] >= sizeof(struct rsn_mdie)) {
436 blen += 2 + sizeof(struct rsn_mdie);
437 *pos++ = WLAN_EID_MOBILITY_DOMAIN;
438 *pos++ = sizeof(struct rsn_mdie);
439 os_memcpy(pos, bss->mdie + 2, MOBILITY_DOMAIN_ID_LEN);
440 pos += MOBILITY_DOMAIN_ID_LEN;
441 *pos++ = 0; /* FIX: copy from the target AP's MDIE */
444 if ((wpa_s->mlme.key_mgmt == KEY_MGMT_FT_802_1X ||
445 wpa_s->mlme.key_mgmt == KEY_MGMT_FT_PSK) &&
446 wpa_s->mlme.auth_alg == WLAN_AUTH_FT && wpa_s->mlme.ft_ies) {
448 os_memcpy(pos, wpa_s->mlme.ft_ies, wpa_s->mlme.ft_ies_len);
449 pos += wpa_s->mlme.ft_ies_len;
450 blen += wpa_s->mlme.ft_ies_len;
452 #endif /* CONFIG_IEEE80211R */
454 if (wmm && wpa_s->mlme.wmm_enabled) {
457 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
458 *pos++ = 7; /* len */
459 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
462 *pos++ = 2; /* WME */
463 *pos++ = 0; /* WME info */
464 *pos++ = 1; /* WME ver */
468 os_free(wpa_s->mlme.assocreq_ies);
469 wpa_s->mlme.assocreq_ies_len = (buf + blen) - ies;
470 wpa_s->mlme.assocreq_ies = os_malloc(wpa_s->mlme.assocreq_ies_len);
471 if (wpa_s->mlme.assocreq_ies) {
472 os_memcpy(wpa_s->mlme.assocreq_ies, ies,
473 wpa_s->mlme.assocreq_ies_len);
476 ieee80211_sta_tx(wpa_s, buf, blen);
481 static void ieee80211_send_deauth(struct wpa_supplicant *wpa_s, u16 reason)
485 struct ieee80211_mgmt *mgmt;
487 buf = os_zalloc(sizeof(*mgmt));
489 wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
494 mgmt = (struct ieee80211_mgmt *) buf;
496 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
497 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
498 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
499 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
500 WLAN_FC_STYPE_DEAUTH);
502 mgmt->u.deauth.reason_code = host_to_le16(reason);
504 ieee80211_sta_tx(wpa_s, buf, len);
509 static void ieee80211_send_disassoc(struct wpa_supplicant *wpa_s, u16 reason)
513 struct ieee80211_mgmt *mgmt;
515 buf = os_zalloc(sizeof(*mgmt));
517 wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
522 mgmt = (struct ieee80211_mgmt *) buf;
524 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
525 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
526 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
527 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
528 WLAN_FC_STYPE_DISASSOC);
530 mgmt->u.disassoc.reason_code = host_to_le16(reason);
532 ieee80211_sta_tx(wpa_s, buf, len);
537 static int ieee80211_privacy_mismatch(struct wpa_supplicant *wpa_s)
539 struct ieee80211_sta_bss *bss;
542 if (wpa_s->mlme.mixed_cell ||
543 wpa_s->mlme.key_mgmt != KEY_MGMT_NONE)
546 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
550 if (ieee80211_sta_wep_configured(wpa_s) !=
551 !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
558 static void ieee80211_associate(struct wpa_supplicant *wpa_s)
560 wpa_s->mlme.assoc_tries++;
561 if (wpa_s->mlme.assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
562 wpa_printf(MSG_DEBUG, "MLME: association with AP " MACSTR
563 " timed out", MAC2STR(wpa_s->bssid));
567 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
568 wpa_printf(MSG_DEBUG, "MLME: associate with AP " MACSTR,
569 MAC2STR(wpa_s->bssid));
570 if (ieee80211_privacy_mismatch(wpa_s)) {
571 wpa_printf(MSG_DEBUG, "MLME: mismatch in privacy "
572 "configuration and mixed-cell disabled - abort "
577 ieee80211_send_assoc(wpa_s);
579 ieee80211_reschedule_timer(wpa_s, IEEE80211_ASSOC_TIMEOUT);
583 static void ieee80211_associated(struct wpa_supplicant *wpa_s)
587 /* TODO: start monitoring current AP signal quality and number of
588 * missed beacons. Scan other channels every now and then and search
590 /* TODO: remove expired BSSes */
592 wpa_s->mlme.state = IEEE80211_ASSOCIATED;
595 sta = sta_info_get(local, wpa_s->bssid);
597 wpa_printf(MSG_DEBUG "MLME: No STA entry for own AP " MACSTR,
598 MAC2STR(wpa_s->bssid));
602 if (time_after(jiffies,
603 sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
604 if (wpa_s->mlme.probereq_poll) {
605 wpa_printf(MSG_DEBUG "MLME: No ProbeResp from "
606 "current AP " MACSTR " - assume "
608 MAC2STR(wpa_s->bssid));
611 ieee80211_send_probe_req(
613 wpa_s->mlme.scan_ssid,
614 wpa_s->mlme.scan_ssid_len);
615 wpa_s->mlme.probereq_poll = 1;
618 wpa_s->mlme.probereq_poll = 0;
619 if (time_after(jiffies, wpa_s->mlme.last_probe +
620 IEEE80211_PROBE_INTERVAL)) {
621 wpa_s->mlme.last_probe = jiffies;
622 ieee80211_send_probe_req(wpa_s->bssid,
624 wpa_s->mlme.ssid_len);
627 sta_info_release(local, sta);
633 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
634 ieee80211_reschedule_timer(wpa_s,
635 IEEE80211_MONITORING_INTERVAL +
638 ieee80211_reschedule_timer(wpa_s,
639 IEEE80211_MONITORING_INTERVAL);
644 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
646 const u8 *ssid, size_t ssid_len)
650 struct ieee80211_mgmt *mgmt;
651 u8 *pos, *supp_rates;
652 u8 *esupp_rates = NULL;
655 buf = os_malloc(sizeof(*mgmt) + 200 + wpa_s->mlme.extra_probe_ie_len);
657 wpa_printf(MSG_DEBUG, "MLME: failed to allocate buffer for "
662 mgmt = (struct ieee80211_mgmt *) buf;
664 os_memset(mgmt, 0, 24);
665 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
666 WLAN_FC_STYPE_PROBE_REQ);
667 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
669 os_memcpy(mgmt->da, dst, ETH_ALEN);
670 os_memcpy(mgmt->bssid, dst, ETH_ALEN);
672 os_memset(mgmt->da, 0xff, ETH_ALEN);
673 os_memset(mgmt->bssid, 0xff, ETH_ALEN);
677 *pos++ = WLAN_EID_SSID;
679 os_memcpy(pos, ssid, ssid_len);
681 supp_rates = buf + len;
683 supp_rates[0] = WLAN_EID_SUPP_RATES;
685 for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
686 struct wpa_rate_data *rate = &wpa_s->mlme.curr_rates[i];
691 } else if (supp_rates[1] == 8) {
693 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
695 pos = &esupp_rates[2];
702 *pos++ = rate->rate / 5;
705 if (wpa_s->mlme.extra_probe_ie) {
706 os_memcpy(pos, wpa_s->mlme.extra_probe_ie,
707 wpa_s->mlme.extra_probe_ie_len);
708 len += wpa_s->mlme.extra_probe_ie_len;
711 ieee80211_sta_tx(wpa_s, buf, len);
716 static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s)
719 if (sdata == NULL || sdata->default_key == NULL ||
720 sdata->default_key->alg != ALG_WEP)
729 static void ieee80211_auth_completed(struct wpa_supplicant *wpa_s)
731 wpa_printf(MSG_DEBUG, "MLME: authenticated");
732 wpa_s->mlme.authenticated = 1;
733 ieee80211_associate(wpa_s);
737 static void ieee80211_auth_challenge(struct wpa_supplicant *wpa_s,
738 struct ieee80211_mgmt *mgmt,
740 struct ieee80211_rx_status *rx_status)
743 struct ieee802_11_elems elems;
745 wpa_printf(MSG_DEBUG, "MLME: replying to auth challenge");
746 pos = mgmt->u.auth.variable;
747 if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems, 0)
749 wpa_printf(MSG_DEBUG, "MLME: failed to parse Auth(challenge)");
752 if (elems.challenge == NULL) {
753 wpa_printf(MSG_DEBUG, "MLME: no challenge IE in shared key "
757 ieee80211_send_auth(wpa_s, 3, elems.challenge - 2,
758 elems.challenge_len + 2, 1);
762 static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
763 struct ieee80211_mgmt *mgmt,
765 struct ieee80211_rx_status *rx_status)
767 struct wpa_ssid *ssid = wpa_s->current_ssid;
768 u16 auth_alg, auth_transaction, status_code;
771 adhoc = ssid && ssid->mode == 1;
773 if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
774 wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
775 "from " MACSTR ", but not in authenticate state - "
776 "ignored", MAC2STR(mgmt->sa));
781 wpa_printf(MSG_DEBUG, "MLME: too short (%lu) authentication "
782 "frame received from " MACSTR " - ignored",
783 (unsigned long) len, MAC2STR(mgmt->sa));
787 if (!adhoc && os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
788 wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
789 "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
791 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
795 if (adhoc && os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0) {
796 wpa_printf(MSG_DEBUG, "MLME: authentication frame received "
797 "from unknown BSSID (SA=" MACSTR " BSSID=" MACSTR
799 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
803 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
804 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
805 status_code = le_to_host16(mgmt->u.auth.status_code);
807 wpa_printf(MSG_DEBUG, "MLME: RX authentication from " MACSTR
808 " (alg=%d transaction=%d status=%d)",
809 MAC2STR(mgmt->sa), auth_alg, auth_transaction, status_code);
812 /* IEEE 802.11 standard does not require authentication in IBSS
813 * networks and most implementations do not seem to use it.
814 * However, try to reply to authentication attempts if someone
815 * has actually implemented this.
816 * TODO: Could implement shared key authentication. */
817 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
818 wpa_printf(MSG_DEBUG, "MLME: unexpected IBSS "
819 "authentication frame (alg=%d "
821 auth_alg, auth_transaction);
824 ieee80211_send_auth(wpa_s, 2, NULL, 0, 0);
827 if (auth_alg != wpa_s->mlme.auth_alg ||
828 auth_transaction != wpa_s->mlme.auth_transaction) {
829 wpa_printf(MSG_DEBUG, "MLME: unexpected authentication frame "
830 "(alg=%d transaction=%d)",
831 auth_alg, auth_transaction);
835 if (status_code != WLAN_STATUS_SUCCESS) {
836 wpa_printf(MSG_DEBUG, "MLME: AP denied authentication "
837 "(auth_alg=%d code=%d)", wpa_s->mlme.auth_alg,
839 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
840 const int num_algs = 3;
843 algs[0] = algs[1] = algs[2] = 0xff;
844 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
845 algs[0] = WLAN_AUTH_OPEN;
846 if (wpa_s->mlme.auth_algs &
847 IEEE80211_AUTH_ALG_SHARED_KEY)
848 algs[1] = WLAN_AUTH_SHARED_KEY;
849 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
850 algs[2] = WLAN_AUTH_LEAP;
851 if (wpa_s->mlme.auth_alg == WLAN_AUTH_OPEN)
853 else if (wpa_s->mlme.auth_alg == WLAN_AUTH_SHARED_KEY)
857 for (i = 0; i < num_algs; i++) {
861 if (algs[pos] == wpa_s->mlme.auth_alg ||
864 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
865 !ieee80211_sta_wep_configured(wpa_s))
867 wpa_s->mlme.auth_alg = algs[pos];
868 wpa_printf(MSG_DEBUG, "MLME: set auth_alg=%d "
870 wpa_s->mlme.auth_alg);
877 switch (wpa_s->mlme.auth_alg) {
880 ieee80211_auth_completed(wpa_s);
882 case WLAN_AUTH_SHARED_KEY:
883 if (wpa_s->mlme.auth_transaction == 4)
884 ieee80211_auth_completed(wpa_s);
886 ieee80211_auth_challenge(wpa_s, mgmt, len,
889 #ifdef CONFIG_IEEE80211R
892 union wpa_event_data data;
893 os_memset(&data, 0, sizeof(data));
894 data.ft_ies.ies = mgmt->u.auth.variable;
895 data.ft_ies.ies_len = len -
896 (mgmt->u.auth.variable - (u8 *) mgmt);
897 os_memcpy(data.ft_ies.target_ap, wpa_s->bssid, ETH_ALEN);
898 wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
899 ieee80211_auth_completed(wpa_s);
902 #endif /* CONFIG_IEEE80211R */
907 static void ieee80211_rx_mgmt_deauth(struct wpa_supplicant *wpa_s,
908 struct ieee80211_mgmt *mgmt,
910 struct ieee80211_rx_status *rx_status)
915 wpa_printf(MSG_DEBUG, "MLME: too short (%lu) deauthentication "
916 "frame received from " MACSTR " - ignored",
917 (unsigned long) len, MAC2STR(mgmt->sa));
921 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
922 wpa_printf(MSG_DEBUG, "MLME: deauthentication frame received "
923 "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
925 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
929 reason_code = le_to_host16(mgmt->u.deauth.reason_code);
931 wpa_printf(MSG_DEBUG, "MLME: RX deauthentication from " MACSTR
932 " (reason=%d)", MAC2STR(mgmt->sa), reason_code);
934 if (wpa_s->mlme.authenticated)
935 wpa_printf(MSG_DEBUG, "MLME: deauthenticated");
937 if (wpa_s->mlme.state == IEEE80211_AUTHENTICATE ||
938 wpa_s->mlme.state == IEEE80211_ASSOCIATE ||
939 wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
940 wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
941 ieee80211_reschedule_timer(wpa_s,
942 IEEE80211_RETRY_AUTH_INTERVAL);
945 ieee80211_set_associated(wpa_s, 0);
946 wpa_s->mlme.authenticated = 0;
950 static void ieee80211_rx_mgmt_disassoc(struct wpa_supplicant *wpa_s,
951 struct ieee80211_mgmt *mgmt,
953 struct ieee80211_rx_status *rx_status)
958 wpa_printf(MSG_DEBUG, "MLME: too short (%lu) disassociation "
959 "frame received from " MACSTR " - ignored",
960 (unsigned long) len, MAC2STR(mgmt->sa));
964 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
965 wpa_printf(MSG_DEBUG, "MLME: disassociation frame received "
966 "from unknown AP (SA=" MACSTR " BSSID=" MACSTR
968 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
972 reason_code = le_to_host16(mgmt->u.disassoc.reason_code);
974 wpa_printf(MSG_DEBUG, "MLME: RX disassociation from " MACSTR
975 " (reason=%d)", MAC2STR(mgmt->sa), reason_code);
977 if (wpa_s->mlme.associated)
978 wpa_printf(MSG_DEBUG, "MLME: disassociated");
980 if (wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
981 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
982 ieee80211_reschedule_timer(wpa_s,
983 IEEE80211_RETRY_AUTH_INTERVAL);
986 ieee80211_set_associated(wpa_s, 0);
990 static int ieee80211_ft_assoc_resp(struct wpa_supplicant *wpa_s,
991 struct ieee802_11_elems *elems)
993 #ifdef CONFIG_IEEE80211R
994 const u8 *mobility_domain = NULL;
995 const u8 *r0kh_id = NULL;
996 size_t r0kh_id_len = 0;
997 const u8 *r1kh_id = NULL;
998 struct rsn_ftie *hdr;
1001 if (elems->mdie && elems->mdie_len >= MOBILITY_DOMAIN_ID_LEN)
1002 mobility_domain = elems->mdie;
1003 if (elems->ftie && elems->ftie_len >= sizeof(struct rsn_ftie)) {
1004 end = elems->ftie + elems->ftie_len;
1005 hdr = (struct rsn_ftie *) elems->ftie;
1006 pos = (const u8 *) (hdr + 1);
1007 while (pos + 1 < end) {
1008 if (pos + 2 + pos[1] > end)
1010 if (pos[0] == FTIE_SUBELEM_R1KH_ID &&
1011 pos[1] == FT_R1KH_ID_LEN)
1013 else if (pos[0] == FTIE_SUBELEM_R0KH_ID &&
1014 pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) {
1016 r0kh_id_len = pos[1];
1021 return wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
1022 r0kh_id_len, r1kh_id);
1023 #else /* CONFIG_IEEE80211R */
1025 #endif /* CONFIG_IEEE80211R */
1029 static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
1030 struct ieee80211_mgmt *mgmt,
1032 struct ieee80211_rx_status *rx_status,
1037 u16 capab_info, status_code, aid;
1038 struct ieee802_11_elems elems;
1041 /* AssocResp and ReassocResp have identical structure, so process both
1042 * of them in this function. */
1044 if (wpa_s->mlme.state != IEEE80211_ASSOCIATE) {
1045 wpa_printf(MSG_DEBUG, "MLME: association frame received from "
1046 MACSTR ", but not in associate state - ignored",
1052 wpa_printf(MSG_DEBUG, "MLME: too short (%lu) association "
1053 "frame received from " MACSTR " - ignored",
1054 (unsigned long) len, MAC2STR(mgmt->sa));
1058 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1059 wpa_printf(MSG_DEBUG, "MLME: association frame received from "
1060 "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
1061 "ignored", MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid));
1065 capab_info = le_to_host16(mgmt->u.assoc_resp.capab_info);
1066 status_code = le_to_host16(mgmt->u.assoc_resp.status_code);
1067 aid = le_to_host16(mgmt->u.assoc_resp.aid);
1068 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1069 wpa_printf(MSG_DEBUG, "MLME: invalid aid value %d; bits 15:14 "
1071 aid &= ~(BIT(15) | BIT(14));
1073 wpa_printf(MSG_DEBUG, "MLME: RX %sssocResp from " MACSTR
1074 " (capab=0x%x status=%d aid=%d)",
1075 reassoc ? "Rea" : "A", MAC2STR(mgmt->sa),
1076 capab_info, status_code, aid);
1078 pos = mgmt->u.assoc_resp.variable;
1079 if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems, 0)
1081 wpa_printf(MSG_DEBUG, "MLME: failed to parse AssocResp");
1085 if (status_code != WLAN_STATUS_SUCCESS) {
1086 wpa_printf(MSG_DEBUG, "MLME: AP denied association (code=%d)",
1088 #ifdef CONFIG_IEEE80211W
1089 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1090 elems.timeout_int && elems.timeout_int_len == 5 &&
1091 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
1093 tu = WPA_GET_LE32(elems.timeout_int + 1);
1094 ms = tu * 1024 / 1000;
1095 wpa_printf(MSG_DEBUG, "MLME: AP rejected association "
1096 "temporarily; comeback duration %u TU "
1098 if (ms > IEEE80211_ASSOC_TIMEOUT) {
1099 wpa_printf(MSG_DEBUG, "MLME: Update timer "
1100 "based on comeback duration");
1101 ieee80211_reschedule_timer(wpa_s, ms);
1104 #endif /* CONFIG_IEEE80211W */
1108 if (elems.supp_rates == NULL) {
1109 wpa_printf(MSG_DEBUG, "MLME: no SuppRates element in "
1114 if (wpa_s->mlme.auth_alg == WLAN_AUTH_FT) {
1116 wpa_printf(MSG_DEBUG, "MLME: AP tried to use "
1117 "association, not reassociation, response "
1121 if (wpa_ft_validate_reassoc_resp(
1122 wpa_s->wpa, pos, len - (pos - (u8 *) mgmt),
1124 wpa_printf(MSG_DEBUG, "MLME: FT validation of Reassoc"
1128 } else if (ieee80211_ft_assoc_resp(wpa_s, &elems) < 0)
1131 wpa_printf(MSG_DEBUG, "MLME: associated");
1132 wpa_s->mlme.aid = aid;
1133 wpa_s->mlme.ap_capab = capab_info;
1135 os_free(wpa_s->mlme.assocresp_ies);
1136 wpa_s->mlme.assocresp_ies_len = len - (pos - (u8 *) mgmt);
1137 wpa_s->mlme.assocresp_ies = os_malloc(wpa_s->mlme.assocresp_ies_len);
1138 if (wpa_s->mlme.assocresp_ies) {
1139 os_memcpy(wpa_s->mlme.assocresp_ies, pos,
1140 wpa_s->mlme.assocresp_ies_len);
1143 ieee80211_set_associated(wpa_s, 1);
1145 rates_len = elems.supp_rates_len;
1146 if (rates_len > sizeof(rates))
1147 rates_len = sizeof(rates);
1148 os_memcpy(rates, elems.supp_rates, rates_len);
1149 if (elems.ext_supp_rates) {
1150 size_t _len = elems.ext_supp_rates_len;
1151 if (_len > sizeof(rates) - rates_len)
1152 _len = sizeof(rates) - rates_len;
1153 os_memcpy(rates + rates_len, elems.ext_supp_rates, _len);
1157 if (wpa_drv_set_bssid(wpa_s, wpa_s->bssid) < 0) {
1158 wpa_printf(MSG_DEBUG, "MLME: failed to set BSSID for the "
1161 if (wpa_drv_set_ssid(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) <
1163 wpa_printf(MSG_DEBUG, "MLME: failed to set SSID for the "
1167 /* Remove STA entry before adding a new one just in case to avoid
1168 * problems with existing configuration (e.g., keys). */
1169 wpa_drv_mlme_remove_sta(wpa_s, wpa_s->bssid);
1170 if (wpa_drv_mlme_add_sta(wpa_s, wpa_s->bssid, rates, rates_len) < 0) {
1171 wpa_printf(MSG_DEBUG, "MLME: failed to add STA entry to the "
1178 if (elems.wme && wpa_s->mlme.wmm_enabled) {
1179 sta->flags |= WLAN_STA_WME;
1180 ieee80211_sta_wmm_params(wpa_s, elems.wme, elems.wme_len);
1184 ieee80211_associated(wpa_s);
1188 /* Caller must hold local->sta_bss_lock */
1189 static void __ieee80211_bss_hash_add(struct wpa_supplicant *wpa_s,
1190 struct ieee80211_sta_bss *bss)
1192 bss->hnext = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
1193 wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)] = bss;
1197 /* Caller must hold local->sta_bss_lock */
1198 static void __ieee80211_bss_hash_del(struct wpa_supplicant *wpa_s,
1199 struct ieee80211_sta_bss *bss)
1201 struct ieee80211_sta_bss *b, *prev = NULL;
1202 b = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
1206 wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)]
1209 prev->hnext = bss->hnext;
1219 static struct ieee80211_sta_bss *
1220 ieee80211_bss_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
1222 struct ieee80211_sta_bss *bss;
1224 bss = os_zalloc(sizeof(*bss));
1227 os_memcpy(bss->bssid, bssid, ETH_ALEN);
1229 /* TODO: order by RSSI? */
1230 bss->next = wpa_s->mlme.sta_bss_list;
1231 wpa_s->mlme.sta_bss_list = bss;
1232 __ieee80211_bss_hash_add(wpa_s, bss);
1237 static struct ieee80211_sta_bss *
1238 ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid)
1240 struct ieee80211_sta_bss *bss;
1242 bss = wpa_s->mlme.sta_bss_hash[STA_HASH(bssid)];
1244 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
1252 static void ieee80211_bss_free(struct wpa_supplicant *wpa_s,
1253 struct ieee80211_sta_bss *bss)
1255 __ieee80211_bss_hash_del(wpa_s, bss);
1257 os_free(bss->wpa_ie);
1258 os_free(bss->rsn_ie);
1259 os_free(bss->wmm_ie);
1265 static void ieee80211_bss_list_deinit(struct wpa_supplicant *wpa_s)
1267 struct ieee80211_sta_bss *bss, *prev;
1269 bss = wpa_s->mlme.sta_bss_list;
1270 wpa_s->mlme.sta_bss_list = NULL;
1274 ieee80211_bss_free(wpa_s, prev);
1279 static void ieee80211_bss_info(struct wpa_supplicant *wpa_s,
1280 struct ieee80211_mgmt *mgmt,
1282 struct ieee80211_rx_status *rx_status,
1285 struct ieee802_11_elems elems;
1287 int channel, invalid = 0, clen;
1288 struct ieee80211_sta_bss *bss;
1293 if (!beacon && os_memcmp(mgmt->da, wpa_s->own_addr, ETH_ALEN))
1294 return; /* ignore ProbeResp to foreign address */
1297 wpa_printf(MSG_MSGDUMP, "MLME: RX %s from " MACSTR " to " MACSTR,
1298 beacon ? "Beacon" : "Probe Response",
1299 MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
1302 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1306 pos = mgmt->u.beacon.timestamp;
1307 timestamp = WPA_GET_LE64(pos);
1310 if (local->conf.mode == IW_MODE_ADHOC && beacon &&
1311 os_memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0) {
1312 #ifdef IEEE80211_IBSS_DEBUG
1313 static unsigned long last_tsf_debug = 0;
1315 if (local->hw->get_tsf)
1316 tsf = local->hw->get_tsf(local->mdev);
1319 if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
1320 wpa_printf(MSG_DEBUG, "RX beacon SA=" MACSTR " BSSID="
1321 MACSTR " TSF=0x%llx BCN=0x%llx diff=%lld "
1323 MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
1324 tsf, timestamp, tsf - timestamp, jiffies);
1325 last_tsf_debug = jiffies;
1327 #endif /* IEEE80211_IBSS_DEBUG */
1331 ie_pos = mgmt->u.beacon.variable;
1332 ie_len = len - baselen;
1333 if (ieee802_11_parse_elems(ie_pos, ie_len, &elems, 0) == ParseFailed)
1337 if (local->conf.mode == IW_MODE_ADHOC && elems.supp_rates &&
1338 os_memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0 &&
1339 (sta = sta_info_get(local, mgmt->sa))) {
1340 struct ieee80211_rate *rates;
1342 u32 supp_rates, prev_rates;
1343 int i, j, oper_mode;
1345 rates = local->curr_rates;
1346 num_rates = local->num_curr_rates;
1347 oper_mode = wpa_s->mlme.sta_scanning ?
1348 local->scan_oper_phymode : local->conf.phymode;
1349 for (i = 0; i < local->hw->num_modes; i++) {
1350 struct ieee80211_hw_modes *mode = &local->hw->modes[i];
1351 if (oper_mode == mode->mode) {
1352 rates = mode->rates;
1353 num_rates = mode->num_rates;
1359 for (i = 0; i < elems.supp_rates_len +
1360 elems.ext_supp_rates_len; i++) {
1363 if (i < elems.supp_rates_len)
1364 rate = elems.supp_rates[i];
1365 else if (elems.ext_supp_rates)
1366 rate = elems.ext_supp_rates
1367 [i - elems.supp_rates_len];
1368 own_rate = 5 * (rate & 0x7f);
1369 if (oper_mode == MODE_ATHEROS_TURBO)
1371 for (j = 0; j < num_rates; j++)
1372 if (rates[j].rate == own_rate)
1373 supp_rates |= BIT(j);
1376 prev_rates = sta->supp_rates;
1377 sta->supp_rates &= supp_rates;
1378 if (sta->supp_rates == 0) {
1379 /* No matching rates - this should not really happen.
1380 * Make sure that at least one rate is marked
1381 * supported to avoid issues with TX rate ctrl. */
1382 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
1384 if (sta->supp_rates != prev_rates) {
1385 wpa_printf(MSG_DEBUG, "MLME: updated supp_rates set "
1386 "for " MACSTR " based on beacon info "
1387 "(0x%x & 0x%x -> 0x%x)",
1388 MAC2STR(sta->addr), prev_rates,
1389 supp_rates, sta->supp_rates);
1391 sta_info_release(local, sta);
1395 if (elems.ssid == NULL)
1398 if (elems.ds_params && elems.ds_params_len == 1)
1399 channel = elems.ds_params[0];
1401 channel = rx_status->channel;
1403 bss = ieee80211_bss_get(wpa_s, mgmt->bssid);
1405 bss = ieee80211_bss_add(wpa_s, mgmt->bssid);
1410 /* TODO: order by RSSI? */
1411 spin_lock_bh(&local->sta_bss_lock);
1412 list_move_tail(&bss->list, &local->sta_bss_list);
1413 spin_unlock_bh(&local->sta_bss_lock);
1417 if (bss->probe_resp && beacon) {
1418 /* Do not allow beacon to override data from Probe Response. */
1422 bss->beacon_int = le_to_host16(mgmt->u.beacon.beacon_int);
1423 bss->capability = le_to_host16(mgmt->u.beacon.capab_info);
1425 if (bss->ie == NULL || bss->ie_len < ie_len) {
1427 bss->ie = os_malloc(ie_len);
1430 os_memcpy(bss->ie, ie_pos, ie_len);
1431 bss->ie_len = ie_len;
1434 if (elems.ssid && elems.ssid_len <= MAX_SSID_LEN) {
1435 os_memcpy(bss->ssid, elems.ssid, elems.ssid_len);
1436 bss->ssid_len = elems.ssid_len;
1439 bss->supp_rates_len = 0;
1440 if (elems.supp_rates) {
1441 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1442 if (clen > elems.supp_rates_len)
1443 clen = elems.supp_rates_len;
1444 os_memcpy(&bss->supp_rates[bss->supp_rates_len],
1445 elems.supp_rates, clen);
1446 bss->supp_rates_len += clen;
1448 if (elems.ext_supp_rates) {
1449 clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
1450 if (clen > elems.ext_supp_rates_len)
1451 clen = elems.ext_supp_rates_len;
1452 os_memcpy(&bss->supp_rates[bss->supp_rates_len],
1453 elems.ext_supp_rates, clen);
1454 bss->supp_rates_len += clen;
1458 (bss->wpa_ie == NULL || bss->wpa_ie_len != elems.wpa_ie_len ||
1459 os_memcmp(bss->wpa_ie, elems.wpa_ie, elems.wpa_ie_len))) {
1460 os_free(bss->wpa_ie);
1461 bss->wpa_ie = os_malloc(elems.wpa_ie_len + 2);
1463 os_memcpy(bss->wpa_ie, elems.wpa_ie - 2,
1464 elems.wpa_ie_len + 2);
1465 bss->wpa_ie_len = elems.wpa_ie_len + 2;
1467 bss->wpa_ie_len = 0;
1468 } else if (!elems.wpa_ie && bss->wpa_ie) {
1469 os_free(bss->wpa_ie);
1471 bss->wpa_ie_len = 0;
1475 (bss->rsn_ie == NULL || bss->rsn_ie_len != elems.rsn_ie_len ||
1476 os_memcmp(bss->rsn_ie, elems.rsn_ie, elems.rsn_ie_len))) {
1477 os_free(bss->rsn_ie);
1478 bss->rsn_ie = os_malloc(elems.rsn_ie_len + 2);
1480 os_memcpy(bss->rsn_ie, elems.rsn_ie - 2,
1481 elems.rsn_ie_len + 2);
1482 bss->rsn_ie_len = elems.rsn_ie_len + 2;
1484 bss->rsn_ie_len = 0;
1485 } else if (!elems.rsn_ie && bss->rsn_ie) {
1486 os_free(bss->rsn_ie);
1488 bss->rsn_ie_len = 0;
1492 (bss->wmm_ie == NULL || bss->wmm_ie_len != elems.wme_len ||
1493 os_memcmp(bss->wmm_ie, elems.wme, elems.wme_len))) {
1494 os_free(bss->wmm_ie);
1495 bss->wmm_ie = os_malloc(elems.wme_len + 2);
1497 os_memcpy(bss->wmm_ie, elems.wme - 2,
1499 bss->wmm_ie_len = elems.wme_len + 2;
1501 bss->wmm_ie_len = 0;
1502 } else if (!elems.wme && bss->wmm_ie) {
1503 os_free(bss->wmm_ie);
1505 bss->wmm_ie_len = 0;
1508 #ifdef CONFIG_IEEE80211R
1510 (bss->mdie == NULL || bss->mdie_len != elems.mdie_len ||
1511 os_memcmp(bss->mdie, elems.mdie, elems.mdie_len))) {
1513 bss->mdie = os_malloc(elems.mdie_len + 2);
1515 os_memcpy(bss->mdie, elems.mdie - 2,
1516 elems.mdie_len + 2);
1517 bss->mdie_len = elems.mdie_len + 2;
1520 } else if (!elems.mdie && bss->mdie) {
1525 #endif /* CONFIG_IEEE80211R */
1527 bss->hw_mode = wpa_s->mlme.phymode;
1528 bss->channel = channel;
1529 bss->freq = wpa_s->mlme.freq;
1530 if (channel != wpa_s->mlme.channel &&
1531 (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G ||
1532 wpa_s->mlme.phymode == WPA_MODE_IEEE80211B) &&
1533 channel >= 1 && channel <= 14) {
1534 static const int freq_list[] = {
1535 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1536 2447, 2452, 2457, 2462, 2467, 2472, 2484
1538 /* IEEE 802.11g/b mode can receive packets from neighboring
1539 * channels, so map the channel into frequency. */
1540 bss->freq = freq_list[channel - 1];
1542 bss->timestamp = timestamp;
1543 os_get_time(&bss->last_update);
1544 bss->rssi = rx_status->ssi;
1550 static void ieee80211_rx_mgmt_probe_resp(struct wpa_supplicant *wpa_s,
1551 struct ieee80211_mgmt *mgmt,
1553 struct ieee80211_rx_status *rx_status)
1555 ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 0);
1559 static void ieee80211_rx_mgmt_beacon(struct wpa_supplicant *wpa_s,
1560 struct ieee80211_mgmt *mgmt,
1562 struct ieee80211_rx_status *rx_status)
1566 struct ieee802_11_elems elems;
1568 ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 1);
1570 if (!wpa_s->mlme.associated ||
1571 os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0)
1574 /* Process beacon from the current BSS */
1575 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1579 if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
1580 &elems, 0) == ParseFailed)
1584 if (elems.erp_info && elems.erp_info_len >= 1) {
1586 (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
1589 if (use_protection != !!wpa_s->mlme.use_protection) {
1590 wpa_printf(MSG_DEBUG, "MLME: CTS protection %s (BSSID=" MACSTR
1592 use_protection ? "enabled" : "disabled",
1593 MAC2STR(wpa_s->bssid));
1594 wpa_s->mlme.use_protection = use_protection ? 1 : 0;
1595 wpa_s->mlme.cts_protect_erp_frames = use_protection;
1598 if (elems.wme && wpa_s->mlme.wmm_enabled) {
1599 ieee80211_sta_wmm_params(wpa_s, elems.wme,
1605 static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
1606 struct ieee80211_mgmt *mgmt,
1608 struct ieee80211_rx_status *rx_status)
1610 int tx_last_beacon, adhoc;
1612 struct ieee80211_mgmt *resp;
1615 struct wpa_ssid *ssid = wpa_s->current_ssid;
1617 adhoc = ssid && ssid->mode == 1;
1619 if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
1620 len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
1624 if (local->hw->tx_last_beacon)
1625 tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
1630 #ifdef IEEE80211_IBSS_DEBUG
1631 wpa_printf(MSG_DEBUG, "MLME: RX ProbeReq SA=" MACSTR " DA=" MACSTR
1632 " BSSID=" MACSTR " (tx_last_beacon=%d)",
1633 MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
1634 MAC2STR(mgmt->bssid), tx_last_beacon);
1635 #endif /* IEEE80211_IBSS_DEBUG */
1637 if (!tx_last_beacon)
1640 if (os_memcmp(mgmt->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1641 os_memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
1644 end = ((u8 *) mgmt) + len;
1645 pos = mgmt->u.probe_req.variable;
1646 if (pos[0] != WLAN_EID_SSID ||
1647 pos + 2 + pos[1] > end) {
1648 wpa_printf(MSG_DEBUG, "MLME: Invalid SSID IE in ProbeReq from "
1649 MACSTR, MAC2STR(mgmt->sa));
1653 (pos[1] != wpa_s->mlme.ssid_len ||
1654 os_memcmp(pos + 2, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) != 0))
1656 /* Ignore ProbeReq for foreign SSID */
1661 /* Reply with ProbeResp */
1662 skb = skb_copy(wpa_s->mlme.probe_resp, GFP_ATOMIC);
1666 resp = (struct ieee80211_mgmt *) skb->data;
1667 os_memcpy(resp->da, mgmt->sa, ETH_ALEN);
1668 #ifdef IEEE80211_IBSS_DEBUG
1669 wpa_printf(MSG_DEBUG, "MLME: Sending ProbeResp to " MACSTR,
1671 #endif /* IEEE80211_IBSS_DEBUG */
1672 ieee80211_sta_tx(wpa_s, skb, 0, 1);
1677 #ifdef CONFIG_IEEE80211R
1678 static void ieee80211_rx_mgmt_ft_action(struct wpa_supplicant *wpa_s,
1679 struct ieee80211_mgmt *mgmt,
1681 struct ieee80211_rx_status *rx_status)
1683 union wpa_event_data data;
1685 u8 *sta_addr, *target_ap_addr;
1687 if (len < 24 + 1 + sizeof(mgmt->u.action.u.ft_action_resp)) {
1688 wpa_printf(MSG_DEBUG, "MLME: Too short FT Action frame");
1693 * Only FT Action Response is needed for now since reservation
1694 * protocol is not supported.
1696 if (mgmt->u.action.u.ft_action_resp.action != 2) {
1697 wpa_printf(MSG_DEBUG, "MLME: Unexpected FT Action %d",
1698 mgmt->u.action.u.ft_action_resp.action);
1702 status = le_to_host16(mgmt->u.action.u.ft_action_resp.status_code);
1703 sta_addr = mgmt->u.action.u.ft_action_resp.sta_addr;
1704 target_ap_addr = mgmt->u.action.u.ft_action_resp.target_ap_addr;
1705 wpa_printf(MSG_DEBUG, "MLME: Received FT Action Response: STA " MACSTR
1706 " TargetAP " MACSTR " Status Code %d",
1707 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1708 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1709 wpa_printf(MSG_DEBUG, "MLME: Foreign STA Address " MACSTR
1710 " in FT Action Response", MAC2STR(sta_addr));
1716 wpa_printf(MSG_DEBUG, "MLME: FT Action Response indicates "
1717 "failure (status code %d)", status);
1718 /* TODO: report error to FT code(?) */
1722 os_memset(&data, 0, sizeof(data));
1723 data.ft_ies.ies = mgmt->u.action.u.ft_action_resp.variable;
1724 data.ft_ies.ies_len = len - (mgmt->u.action.u.ft_action_resp.variable -
1726 data.ft_ies.ft_action = 1;
1727 os_memcpy(data.ft_ies.target_ap, target_ap_addr, ETH_ALEN);
1728 wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
1729 /* TODO: should only re-associate, if EVENT_FT_RESPONSE was processed
1731 wpa_s->mlme.prev_bssid_set = 1;
1732 wpa_s->mlme.auth_alg = WLAN_AUTH_FT;
1733 os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
1734 os_memcpy(wpa_s->bssid, target_ap_addr, ETH_ALEN);
1735 ieee80211_associate(wpa_s);
1737 #endif /* CONFIG_IEEE80211R */
1740 #ifdef CONFIG_IEEE80211W
1742 /* MLME-SAQuery.response */
1743 static int ieee80211_sta_send_sa_query_resp(struct wpa_supplicant *wpa_s,
1744 const u8 *addr, const u8 *trans_id)
1746 struct ieee80211_mgmt *mgmt;
1750 mgmt = os_zalloc(sizeof(*mgmt));
1752 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
1753 "SA Query action frame");
1758 os_memcpy(mgmt->da, addr, ETH_ALEN);
1759 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
1760 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
1761 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1762 WLAN_FC_STYPE_ACTION);
1763 mgmt->u.action.category = WLAN_ACTION_SA_QUERY;
1764 mgmt->u.action.u.sa_query_resp.action = WLAN_SA_QUERY_RESPONSE;
1765 os_memcpy(mgmt->u.action.u.sa_query_resp.trans_id, trans_id,
1766 WLAN_SA_QUERY_TR_ID_LEN);
1767 len += 1 + sizeof(mgmt->u.action.u.sa_query_resp);
1769 res = ieee80211_sta_tx(wpa_s, (u8 *) mgmt, len);
1776 static void ieee80211_rx_mgmt_sa_query_action(
1777 struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
1778 struct ieee80211_rx_status *rx_status)
1780 if (len < 24 + 1 + sizeof(mgmt->u.action.u.sa_query_req)) {
1781 wpa_printf(MSG_DEBUG, "MLME: Too short SA Query Action frame");
1785 if (mgmt->u.action.u.sa_query_req.action != WLAN_SA_QUERY_REQUEST) {
1786 wpa_printf(MSG_DEBUG, "MLME: Unexpected SA Query Action %d",
1787 mgmt->u.action.u.sa_query_req.action);
1791 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
1792 wpa_printf(MSG_DEBUG, "MLME: Ignore SA Query from unknown "
1793 "source " MACSTR, MAC2STR(mgmt->sa));
1797 if (wpa_s->mlme.state == IEEE80211_ASSOCIATE) {
1798 wpa_printf(MSG_DEBUG, "MLME: Ignore SA query request during "
1799 "association process");
1803 wpa_printf(MSG_DEBUG, "MLME: Replying to SA Query request");
1804 ieee80211_sta_send_sa_query_resp(wpa_s, mgmt->sa, mgmt->u.action.u.
1805 sa_query_req.trans_id);
1808 #endif /* CONFIG_IEEE80211W */
1811 static void ieee80211_rx_mgmt_action(struct wpa_supplicant *wpa_s,
1812 struct ieee80211_mgmt *mgmt,
1814 struct ieee80211_rx_status *rx_status)
1816 wpa_printf(MSG_DEBUG, "MLME: received Action frame");
1821 switch (mgmt->u.action.category) {
1822 #ifdef CONFIG_IEEE80211R
1823 case WLAN_ACTION_FT:
1824 ieee80211_rx_mgmt_ft_action(wpa_s, mgmt, len, rx_status);
1826 #endif /* CONFIG_IEEE80211R */
1827 #ifdef CONFIG_IEEE80211W
1828 case WLAN_ACTION_SA_QUERY:
1829 ieee80211_rx_mgmt_sa_query_action(wpa_s, mgmt, len, rx_status);
1831 #endif /* CONFIG_IEEE80211W */
1833 wpa_printf(MSG_DEBUG, "MLME: unknown Action Category %d",
1834 mgmt->u.action.category);
1840 static void ieee80211_sta_rx_mgmt(struct wpa_supplicant *wpa_s,
1841 const u8 *buf, size_t len,
1842 struct ieee80211_rx_status *rx_status)
1844 struct ieee80211_mgmt *mgmt;
1850 mgmt = (struct ieee80211_mgmt *) buf;
1851 fc = le_to_host16(mgmt->frame_control);
1853 switch (WLAN_FC_GET_STYPE(fc)) {
1854 case WLAN_FC_STYPE_PROBE_REQ:
1855 ieee80211_rx_mgmt_probe_req(wpa_s, mgmt, len, rx_status);
1857 case WLAN_FC_STYPE_PROBE_RESP:
1858 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt, len, rx_status);
1860 case WLAN_FC_STYPE_BEACON:
1861 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1863 case WLAN_FC_STYPE_AUTH:
1864 ieee80211_rx_mgmt_auth(wpa_s, mgmt, len, rx_status);
1866 case WLAN_FC_STYPE_ASSOC_RESP:
1867 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 0);
1869 case WLAN_FC_STYPE_REASSOC_RESP:
1870 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 1);
1872 case WLAN_FC_STYPE_DEAUTH:
1873 ieee80211_rx_mgmt_deauth(wpa_s, mgmt, len, rx_status);
1875 case WLAN_FC_STYPE_DISASSOC:
1876 ieee80211_rx_mgmt_disassoc(wpa_s, mgmt, len, rx_status);
1878 case WLAN_FC_STYPE_ACTION:
1879 ieee80211_rx_mgmt_action(wpa_s, mgmt, len, rx_status);
1882 wpa_printf(MSG_DEBUG, "MLME: received unknown management "
1883 "frame - stype=%d", WLAN_FC_GET_STYPE(fc));
1889 static void ieee80211_sta_rx_scan(struct wpa_supplicant *wpa_s,
1890 const u8 *buf, size_t len,
1891 struct ieee80211_rx_status *rx_status)
1893 struct ieee80211_mgmt *mgmt;
1899 mgmt = (struct ieee80211_mgmt *) buf;
1900 fc = le_to_host16(mgmt->frame_control);
1902 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT) {
1903 if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
1904 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt,
1906 } else if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
1907 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1913 static int ieee80211_sta_active_ibss(struct wpa_supplicant *wpa_s)
1918 list_for_each(ptr, &local->sta_list) {
1919 sta = list_entry(ptr, struct sta_info, list);
1920 if (sta->dev == dev &&
1921 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
1933 static void ieee80211_sta_expire(struct wpa_supplicant *wpa_s)
1936 list_for_each_safe(ptr, n, &local->sta_list) {
1937 sta = list_entry(ptr, struct sta_info, list);
1938 if (time_after(jiffies, sta->last_rx +
1939 IEEE80211_IBSS_INACTIVITY_LIMIT)) {
1940 wpa_printf(MSG_DEBUG, "MLME: expiring inactive STA "
1941 MACSTR, MAC2STR(sta->addr));
1942 sta_info_free(local, sta, 1);
1949 static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
1951 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
1953 ieee80211_sta_expire(wpa_s);
1954 if (ieee80211_sta_active_ibss(wpa_s))
1957 wpa_printf(MSG_DEBUG, "MLME: No active IBSS STAs - trying to scan for "
1958 "other IBSS networks with same SSID (merge)");
1959 ieee80211_sta_req_scan(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
1963 static void ieee80211_sta_timer(void *eloop_ctx, void *timeout_ctx)
1965 struct wpa_supplicant *wpa_s = eloop_ctx;
1967 switch (wpa_s->mlme.state) {
1968 case IEEE80211_DISABLED:
1970 case IEEE80211_AUTHENTICATE:
1971 ieee80211_authenticate(wpa_s);
1973 case IEEE80211_ASSOCIATE:
1974 ieee80211_associate(wpa_s);
1976 case IEEE80211_ASSOCIATED:
1977 ieee80211_associated(wpa_s);
1979 case IEEE80211_IBSS_SEARCH:
1980 ieee80211_sta_find_ibss(wpa_s);
1982 case IEEE80211_IBSS_JOINED:
1983 ieee80211_sta_merge_ibss(wpa_s);
1986 wpa_printf(MSG_DEBUG, "ieee80211_sta_timer: Unknown state %d",
1991 if (ieee80211_privacy_mismatch(wpa_s)) {
1992 wpa_printf(MSG_DEBUG, "MLME: privacy configuration mismatch "
1993 "and mixed-cell disabled - disassociate");
1995 ieee80211_send_disassoc(wpa_s, WLAN_REASON_UNSPECIFIED);
1996 ieee80211_set_associated(wpa_s, 0);
2001 static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
2003 struct wpa_ssid *ssid = wpa_s->current_ssid;
2004 if (ssid && ssid->mode != 0)
2008 if (local->hw->reset_tsf) {
2009 /* Reset own TSF to allow time synchronization work. */
2010 local->hw->reset_tsf(local->mdev);
2014 wpa_s->mlme.wmm_last_param_set = -1; /* allow any WMM update */
2017 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
2018 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2019 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2020 wpa_s->mlme.auth_alg = WLAN_AUTH_SHARED_KEY;
2021 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
2022 wpa_s->mlme.auth_alg = WLAN_AUTH_LEAP;
2024 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2025 wpa_printf(MSG_DEBUG, "MLME: Initial auth_alg=%d",
2026 wpa_s->mlme.auth_alg);
2027 wpa_s->mlme.auth_transaction = -1;
2028 wpa_s->mlme.auth_tries = wpa_s->mlme.assoc_tries = 0;
2029 ieee80211_authenticate(wpa_s);
2033 static int ieee80211_ibss_allowed(struct wpa_supplicant *wpa_s)
2038 for (m = 0; m < local->hw->num_modes; m++) {
2039 struct ieee80211_hw_modes *mode = &local->hw->modes[m];
2040 if (mode->mode != local->conf.phymode)
2042 for (c = 0; c < mode->num_channels; c++) {
2043 struct ieee80211_channel *chan = &mode->channels[c];
2044 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
2045 chan->chan == local->conf.channel) {
2046 if (chan->flag & IEEE80211_CHAN_W_IBSS)
2058 static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
2059 struct ieee80211_sta_bss *bss)
2061 int res = 0, rates, done = 0;
2062 struct ieee80211_mgmt *mgmt;
2064 struct ieee80211_tx_control control;
2065 struct ieee80211_rate *rate;
2066 struct rate_control_extra extra;
2071 /* Remove possible STA entries from other IBSS networks. */
2073 sta_info_flush(local, NULL);
2075 if (local->hw->reset_tsf) {
2076 /* Reset own TSF to allow time synchronization work. */
2077 local->hw->reset_tsf(local->mdev);
2080 os_memcpy(wpa_s->bssid, bss->bssid, ETH_ALEN);
2083 local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2085 sdata->drop_unencrypted = bss->capability &
2086 host_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
2090 os_memset(&rq, 0, sizeof(rq));
2091 rq.m = bss->freq * 100000;
2093 res = ieee80211_ioctl_siwfreq(wpa_s, NULL, &rq, NULL);
2096 if (!ieee80211_ibss_allowed(wpa_s)) {
2098 wpa_printf(MSG_DEBUG, "MLME: IBSS not allowed on channel %d "
2099 "(%d MHz)", local->conf.channel,
2105 /* Set beacon template based on scan results */
2106 buf = os_malloc(400);
2112 mgmt = (struct ieee80211_mgmt *) buf;
2113 len += 24 + sizeof(mgmt->u.beacon);
2114 os_memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2115 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2116 WLAN_FC_STYPE_BEACON);
2117 os_memset(mgmt->da, 0xff, ETH_ALEN);
2118 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
2119 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
2121 mgmt->u.beacon.beacon_int =
2122 host_to_le16(local->conf.beacon_int);
2124 mgmt->u.beacon.capab_info = host_to_le16(bss->capability);
2127 len += 2 + wpa_s->mlme.ssid_len;
2128 *pos++ = WLAN_EID_SSID;
2129 *pos++ = wpa_s->mlme.ssid_len;
2130 os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2132 rates = bss->supp_rates_len;
2137 *pos++ = WLAN_EID_SUPP_RATES;
2139 os_memcpy(pos, bss->supp_rates, rates);
2143 *pos++ = WLAN_EID_DS_PARAMS;
2145 *pos++ = bss->channel;
2149 *pos++ = WLAN_EID_IBSS_PARAMS;
2151 /* FIX: set ATIM window based on scan results */
2155 if (bss->supp_rates_len > 8) {
2156 rates = bss->supp_rates_len - 8;
2159 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2161 os_memcpy(pos, &bss->supp_rates[8], rates);
2165 os_memset(&control, 0, sizeof(control));
2166 control.pkt_type = PKT_PROBE_RESP;
2167 os_memset(&extra, 0, sizeof(extra));
2168 extra.endidx = local->num_curr_rates;
2169 rate = rate_control_get_rate(wpa_s, skb, &extra);
2171 wpa_printf(MSG_DEBUG, "MLME: Failed to determine TX "
2172 "rate for IBSS beacon");
2175 control.tx_rate = (wpa_s->mlme.short_preamble &&
2176 (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
2177 rate->val2 : rate->val;
2178 control.antenna_sel = local->conf.antenna_sel;
2179 control.power_level = local->conf.power_level;
2181 control.retry_limit = 1;
2182 control.rts_cts_duration = 0;
2186 wpa_s->mlme.probe_resp = skb_copy(skb, GFP_ATOMIC);
2187 if (wpa_s->mlme.probe_resp) {
2188 mgmt = (struct ieee80211_mgmt *)
2189 wpa_s->mlme.probe_resp->data;
2190 mgmt->frame_control =
2191 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2192 WLAN_FC_STYPE_PROBE_RESP);
2194 wpa_printf(MSG_DEBUG, "MLME: Could not allocate "
2195 "ProbeResp template for IBSS");
2198 if (local->hw->beacon_update &&
2199 local->hw->beacon_update(wpa_s, skb, &control) == 0) {
2200 wpa_printf(MSG_DEBUG, "MLME: Configured IBSS beacon "
2201 "template based on scan results");
2206 for (i = 0; i < bss->supp_rates_len; i++) {
2207 int rate = (bss->supp_rates[i] & 0x7f) * 5;
2208 if (local->conf.phymode == MODE_ATHEROS_TURBO)
2210 for (j = 0; j < local->num_curr_rates; j++)
2211 if (local->curr_rates[j].rate == rate)
2214 wpa_s->mlme.supp_rates_bits = rates;
2221 wpa_printf(MSG_DEBUG, "MLME: Failed to configure IBSS beacon "
2225 wpa_s->mlme.state = IEEE80211_IBSS_JOINED;
2226 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
2233 static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
2235 struct ieee80211_sta_bss *bss;
2236 u8 bssid[ETH_ALEN], *pos;
2240 /* Easier testing, use fixed BSSID. */
2241 os_memset(bssid, 0xfe, ETH_ALEN);
2243 /* Generate random, not broadcast, locally administered BSSID. Mix in
2244 * own MAC address to make sure that devices that do not have proper
2245 * random number generator get different BSSID. */
2246 os_get_random(bssid, ETH_ALEN);
2247 for (i = 0; i < ETH_ALEN; i++)
2248 bssid[i] ^= wpa_s->own_addr[i];
2253 wpa_printf(MSG_DEBUG, "MLME: Creating new IBSS network, BSSID "
2254 MACSTR "", MAC2STR(bssid));
2256 bss = ieee80211_bss_add(wpa_s, bssid);
2261 if (local->conf.beacon_int == 0)
2262 local->conf.beacon_int = 100;
2263 bss->beacon_int = local->conf.beacon_int;
2264 bss->hw_mode = local->conf.phymode;
2265 bss->channel = local->conf.channel;
2266 bss->freq = local->conf.freq;
2268 os_get_time(&bss->last_update);
2269 bss->capability = host_to_le16(WLAN_CAPABILITY_IBSS);
2271 if (sdata->default_key) {
2272 bss->capability |= host_to_le16(WLAN_CAPABILITY_PRIVACY);
2274 sdata->drop_unencrypted = 0;
2275 bss->supp_rates_len = local->num_curr_rates;
2277 pos = bss->supp_rates;
2279 for (i = 0; i < local->num_curr_rates; i++) {
2280 int rate = local->curr_rates[i].rate;
2281 if (local->conf.phymode == MODE_ATHEROS_TURBO)
2283 *pos++ = (u8) (rate / 5);
2287 return ieee80211_sta_join_ibss(wpa_s, bss);
2292 static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s)
2294 struct ieee80211_sta_bss *bss;
2300 if (wpa_s->mlme.ssid_len == 0)
2303 active_ibss = ieee80211_sta_active_ibss(wpa_s);
2304 #ifdef IEEE80211_IBSS_DEBUG
2305 wpa_printf(MSG_DEBUG, "MLME: sta_find_ibss (active_ibss=%d)",
2307 #endif /* IEEE80211_IBSS_DEBUG */
2308 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2309 if (wpa_s->mlme.ssid_len != bss->ssid_len ||
2310 os_memcmp(wpa_s->mlme.ssid, bss->ssid, bss->ssid_len) != 0
2311 || !(bss->capability & WLAN_CAPABILITY_IBSS))
2313 #ifdef IEEE80211_IBSS_DEBUG
2314 wpa_printf(MSG_DEBUG, " bssid=" MACSTR " found",
2315 MAC2STR(bss->bssid));
2316 #endif /* IEEE80211_IBSS_DEBUG */
2317 os_memcpy(bssid, bss->bssid, ETH_ALEN);
2320 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)
2324 #ifdef IEEE80211_IBSS_DEBUG
2325 wpa_printf(MSG_DEBUG, " sta_find_ibss: selected " MACSTR " current "
2326 MACSTR, MAC2STR(bssid), MAC2STR(wpa_s->bssid));
2327 #endif /* IEEE80211_IBSS_DEBUG */
2328 if (found && os_memcmp(wpa_s->bssid, bssid, ETH_ALEN) != 0 &&
2329 (bss = ieee80211_bss_get(wpa_s, bssid))) {
2330 wpa_printf(MSG_DEBUG, "MLME: Selected IBSS BSSID " MACSTR
2331 " based on configured SSID",
2333 return ieee80211_sta_join_ibss(wpa_s, bss);
2335 #ifdef IEEE80211_IBSS_DEBUG
2336 wpa_printf(MSG_DEBUG, " did not try to join ibss");
2337 #endif /* IEEE80211_IBSS_DEBUG */
2339 /* Selected IBSS not found in current scan results - try to scan */
2342 if (wpa_s->mlme.state == IEEE80211_IBSS_JOINED &&
2343 !ieee80211_sta_active_ibss(wpa_s)) {
2344 ieee80211_reschedule_timer(wpa_s,
2345 IEEE80211_IBSS_MERGE_INTERVAL);
2346 } else if (time_after(jiffies, wpa_s->mlme.last_scan_completed +
2347 IEEE80211_SCAN_INTERVAL)) {
2348 wpa_printf(MSG_DEBUG, "MLME: Trigger new scan to find an IBSS "
2350 return ieee80211_sta_req_scan(wpa_s->mlme.ssid,
2351 wpa_s->mlme.ssid_len);
2352 } else if (wpa_s->mlme.state != IEEE80211_IBSS_JOINED) {
2353 int interval = IEEE80211_SCAN_INTERVAL;
2355 if (time_after(jiffies, wpa_s->mlme.ibss_join_req +
2356 IEEE80211_IBSS_JOIN_TIMEOUT)) {
2357 if (wpa_s->mlme.create_ibss &&
2358 ieee80211_ibss_allowed(wpa_s))
2359 return ieee80211_sta_create_ibss(wpa_s);
2360 if (wpa_s->mlme.create_ibss) {
2361 wpa_printf(MSG_DEBUG, "MLME: IBSS not allowed "
2362 "on the configured channel %d "
2364 local->conf.channel,
2368 /* No IBSS found - decrease scan interval and continue
2370 interval = IEEE80211_SCAN_INTERVAL_SLOW;
2373 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2374 ieee80211_reschedule_timer(wpa_s, interval);
2383 int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid,
2386 os_memcpy(ssid, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2387 *len = wpa_s->mlme.ssid_len;
2392 int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
2393 struct wpa_driver_associate_params *params)
2395 struct ieee80211_sta_bss *bss;
2397 wpa_s->mlme.bssid_set = 0;
2398 wpa_s->mlme.freq = params->freq;
2399 if (params->bssid) {
2400 os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
2401 if (!is_zero_ether_addr(params->bssid))
2402 wpa_s->mlme.bssid_set = 1;
2403 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
2405 wpa_s->mlme.phymode = bss->hw_mode;
2406 wpa_s->mlme.channel = bss->channel;
2407 wpa_s->mlme.freq = bss->freq;
2412 /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
2414 if (local->hw->conf_tx) {
2415 struct ieee80211_tx_queue_params qparam;
2418 os_memset(&qparam, 0, sizeof(qparam));
2419 /* TODO: are these ok defaults for all hw_modes? */
2422 local->conf.phymode == MODE_IEEE80211B ? 31 : 15;
2423 qparam.cw_max = 1023;
2424 qparam.burst_time = 0;
2425 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
2427 local->hw->conf_tx(wpa_s, i + IEEE80211_TX_QUEUE_DATA0,
2430 /* IBSS uses different parameters for Beacon sending */
2434 local->hw->conf_tx(wpa_s, IEEE80211_TX_QUEUE_BEACON, &qparam);
2438 if (wpa_s->mlme.ssid_len != params->ssid_len ||
2439 os_memcmp(wpa_s->mlme.ssid, params->ssid, params->ssid_len) != 0)
2440 wpa_s->mlme.prev_bssid_set = 0;
2441 os_memcpy(wpa_s->mlme.ssid, params->ssid, params->ssid_len);
2442 os_memset(wpa_s->mlme.ssid + params->ssid_len, 0,
2443 MAX_SSID_LEN - params->ssid_len);
2444 wpa_s->mlme.ssid_len = params->ssid_len;
2445 wpa_s->mlme.ssid_set = 1;
2447 os_free(wpa_s->mlme.extra_ie);
2448 if (params->wpa_ie == NULL || params->wpa_ie_len == 0) {
2449 wpa_s->mlme.extra_ie = NULL;
2450 wpa_s->mlme.extra_ie_len = 0;
2452 wpa_s->mlme.extra_ie = os_malloc(params->wpa_ie_len);
2453 if (wpa_s->mlme.extra_ie == NULL) {
2454 wpa_s->mlme.extra_ie_len = 0;
2457 os_memcpy(wpa_s->mlme.extra_ie, params->wpa_ie,
2458 params->wpa_ie_len);
2459 wpa_s->mlme.extra_ie_len = params->wpa_ie_len;
2462 wpa_s->mlme.key_mgmt = params->key_mgmt_suite;
2464 ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2465 wpa_s->mlme.channel, wpa_s->mlme.freq);
2467 if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
2468 os_get_time(&wpa_s->mlme.ibss_join_req);
2469 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2470 return ieee80211_sta_find_ibss(wpa_s);
2473 if (wpa_s->mlme.bssid_set)
2474 ieee80211_sta_new_auth(wpa_s);
2480 static void ieee80211_sta_save_oper_chan(struct wpa_supplicant *wpa_s)
2482 wpa_s->mlme.scan_oper_channel = wpa_s->mlme.channel;
2483 wpa_s->mlme.scan_oper_freq = wpa_s->mlme.freq;
2484 wpa_s->mlme.scan_oper_phymode = wpa_s->mlme.phymode;
2488 static int ieee80211_sta_restore_oper_chan(struct wpa_supplicant *wpa_s)
2490 wpa_s->mlme.channel = wpa_s->mlme.scan_oper_channel;
2491 wpa_s->mlme.freq = wpa_s->mlme.scan_oper_freq;
2492 wpa_s->mlme.phymode = wpa_s->mlme.scan_oper_phymode;
2493 if (wpa_s->mlme.freq == 0)
2495 return ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2496 wpa_s->mlme.channel,
2501 static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
2506 for (m = 0; m < wpa_s->mlme.num_modes; m++) {
2507 struct wpa_hw_modes *mode = &wpa_s->mlme.modes[m];
2508 if ((int) mode->mode != (int) wpa_s->mlme.phymode)
2510 for (c = 0; c < mode->num_channels; c++) {
2511 struct wpa_channel_data *chan = &mode->channels[c];
2512 if (chan->flag & WPA_CHAN_W_SCAN &&
2513 chan->chan == wpa_s->mlme.channel) {
2514 if (chan->flag & WPA_CHAN_W_ACTIVE_SCAN)
2525 static void ieee80211_sta_scan_timer(void *eloop_ctx, void *timeout_ctx)
2527 struct wpa_supplicant *wpa_s = eloop_ctx;
2528 struct wpa_hw_modes *mode;
2529 struct wpa_channel_data *chan;
2532 struct wpa_ssid *ssid = wpa_s->current_ssid;
2535 if (!wpa_s->mlme.sta_scanning || wpa_s->mlme.modes == NULL)
2538 adhoc = ssid && ssid->mode == 1;
2540 switch (wpa_s->mlme.scan_state) {
2541 case SCAN_SET_CHANNEL:
2542 mode = &wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx];
2543 if (wpa_s->mlme.scan_hw_mode_idx >=
2544 (int) wpa_s->mlme.num_modes ||
2545 (wpa_s->mlme.scan_hw_mode_idx + 1 ==
2546 (int) wpa_s->mlme.num_modes
2547 && wpa_s->mlme.scan_channel_idx >= mode->num_channels)) {
2548 if (ieee80211_sta_restore_oper_chan(wpa_s)) {
2549 wpa_printf(MSG_DEBUG, "MLME: failed to "
2550 "restore operational channel after "
2553 wpa_printf(MSG_DEBUG, "MLME: scan completed");
2554 wpa_s->mlme.sta_scanning = 0;
2555 os_get_time(&wpa_s->mlme.last_scan_completed);
2556 wpa_supplicant_event(wpa_s, EVENT_SCAN_RESULTS, NULL);
2558 if (!wpa_s->mlme.bssid_set ||
2559 (wpa_s->mlme.state ==
2560 IEEE80211_IBSS_JOINED &&
2561 !ieee80211_sta_active_ibss(wpa_s)))
2562 ieee80211_sta_find_ibss(wpa_s);
2566 skip = !(wpa_s->mlme.hw_modes & (1 << mode->mode));
2567 chan = &mode->channels[wpa_s->mlme.scan_channel_idx];
2568 if (!(chan->flag & WPA_CHAN_W_SCAN) ||
2569 (adhoc && !(chan->flag & WPA_CHAN_W_IBSS)) ||
2570 (wpa_s->mlme.hw_modes & (1 << WPA_MODE_IEEE80211G) &&
2571 mode->mode == WPA_MODE_IEEE80211B &&
2572 wpa_s->mlme.scan_skip_11b))
2576 wpa_printf(MSG_MSGDUMP,
2577 "MLME: scan channel %d (%d MHz)",
2578 chan->chan, chan->freq);
2580 wpa_s->mlme.channel = chan->chan;
2581 wpa_s->mlme.freq = chan->freq;
2582 wpa_s->mlme.phymode = mode->mode;
2583 if (ieee80211_sta_set_channel(wpa_s, mode->mode,
2584 chan->chan, chan->freq))
2586 wpa_printf(MSG_DEBUG, "MLME: failed to set "
2587 "channel %d (%d MHz) for scan",
2588 chan->chan, chan->freq);
2593 wpa_s->mlme.scan_channel_idx++;
2594 if (wpa_s->mlme.scan_channel_idx >=
2595 wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx].
2597 wpa_s->mlme.scan_hw_mode_idx++;
2598 wpa_s->mlme.scan_channel_idx = 0;
2606 timeout = IEEE80211_PROBE_DELAY;
2607 wpa_s->mlme.scan_state = SCAN_SEND_PROBE;
2609 case SCAN_SEND_PROBE:
2610 if (ieee80211_active_scan(wpa_s)) {
2611 ieee80211_send_probe_req(wpa_s, NULL,
2612 wpa_s->mlme.scan_ssid,
2613 wpa_s->mlme.scan_ssid_len);
2614 timeout = IEEE80211_CHANNEL_TIME;
2616 timeout = IEEE80211_PASSIVE_CHANNEL_TIME;
2618 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2622 eloop_register_timeout(timeout / 1000, 1000 * (timeout % 1000),
2623 ieee80211_sta_scan_timer, wpa_s, NULL);
2627 int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
2630 if (ssid_len > MAX_SSID_LEN)
2633 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
2634 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
2637 * ScanType: ACTIVE, PASSIVE
2638 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
2639 * a Probe frame during active scanning
2641 * MinChannelTime (>= ProbeDelay), in TU
2642 * MaxChannelTime: (>= MinChannelTime), in TU
2645 /* MLME-SCAN.confirm
2647 * ResultCode: SUCCESS, INVALID_PARAMETERS
2650 /* TODO: if assoc, move to power save mode for the duration of the
2653 if (wpa_s->mlme.sta_scanning)
2656 wpa_printf(MSG_DEBUG, "MLME: starting scan");
2658 ieee80211_sta_save_oper_chan(wpa_s);
2660 wpa_s->mlme.sta_scanning = 1;
2661 /* TODO: stop TX queue? */
2664 wpa_s->mlme.scan_ssid_len = ssid_len;
2665 os_memcpy(wpa_s->mlme.scan_ssid, ssid, ssid_len);
2667 wpa_s->mlme.scan_ssid_len = 0;
2668 wpa_s->mlme.scan_skip_11b = 1; /* FIX: clear this is 11g is not
2670 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2671 wpa_s->mlme.scan_hw_mode_idx = 0;
2672 wpa_s->mlme.scan_channel_idx = 0;
2673 eloop_register_timeout(0, 1, ieee80211_sta_scan_timer, wpa_s, NULL);
2679 struct wpa_scan_results *
2680 ieee80211_sta_get_scan_results(struct wpa_supplicant *wpa_s)
2683 struct wpa_scan_results *res;
2684 struct wpa_scan_res *r;
2685 struct ieee80211_sta_bss *bss;
2687 res = os_zalloc(sizeof(*res));
2688 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next)
2690 res->res = os_zalloc(ap_num * sizeof(struct wpa_scan_res *));
2691 if (res->res == NULL) {
2696 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2697 r = os_zalloc(sizeof(*r) + bss->ie_len);
2700 os_memcpy(r->bssid, bss->bssid, ETH_ALEN);
2701 r->freq = bss->freq;
2702 r->beacon_int = bss->beacon_int;
2703 r->caps = bss->capability;
2704 r->level = bss->rssi;
2705 r->tsf = bss->timestamp;
2707 r->ie_len = bss->ie_len;
2708 os_memcpy(r + 1, bss->ie, bss->ie_len);
2711 res->res[res->num++] = r;
2719 struct sta_info * ieee80211_ibss_add_sta(struct wpa_supplicant *wpa_s,
2720 struct sk_buff *skb, u8 *bssid,
2723 struct ieee80211_local *local = dev->priv;
2724 struct list_head *ptr;
2725 struct sta_info *sta;
2726 struct wpa_supplicant *sta_dev = NULL;
2728 /* TODO: Could consider removing the least recently used entry and
2729 * allow new one to be added. */
2730 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
2731 if (net_ratelimit()) {
2732 wpa_printf(MSG_DEBUG, "MLME: No room for a new IBSS "
2733 "STA entry " MACSTR, MAC2STR(addr));
2738 spin_lock_bh(&local->sub_if_lock);
2739 list_for_each(ptr, &local->sub_if_list) {
2740 sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
2741 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA &&
2742 os_memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
2743 sta_dev = sdata->dev;
2747 spin_unlock_bh(&local->sub_if_lock);
2749 if (sta_dev == NULL)
2752 wpa_printf(MSG_DEBUG, "MLME: Adding new IBSS station " MACSTR
2753 " (dev=%s)", MAC2STR(addr), sta_dev->name);
2755 sta = sta_info_add(wpa_s, addr);
2761 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
2763 rate_control_rate_init(local, sta);
2765 return sta; /* caller will call sta_info_release() */
2770 int ieee80211_sta_deauthenticate(struct wpa_supplicant *wpa_s, u16 reason)
2772 wpa_printf(MSG_DEBUG, "MLME: deauthenticate(reason=%d)", reason);
2774 ieee80211_send_deauth(wpa_s, reason);
2775 ieee80211_set_associated(wpa_s, 0);
2780 int ieee80211_sta_disassociate(struct wpa_supplicant *wpa_s, u16 reason)
2782 wpa_printf(MSG_DEBUG, "MLME: disassociate(reason=%d)", reason);
2784 if (!wpa_s->mlme.associated)
2787 ieee80211_send_disassoc(wpa_s, reason);
2788 ieee80211_set_associated(wpa_s, 0);
2793 void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
2794 struct ieee80211_rx_status *rx_status)
2796 struct ieee80211_mgmt *mgmt;
2800 /* wpa_hexdump(MSG_MSGDUMP, "MLME: Received frame", buf, len); */
2802 if (wpa_s->mlme.sta_scanning) {
2803 ieee80211_sta_rx_scan(wpa_s, buf, len, rx_status);
2810 mgmt = (struct ieee80211_mgmt *) buf;
2811 fc = le_to_host16(mgmt->frame_control);
2813 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT)
2814 ieee80211_sta_rx_mgmt(wpa_s, buf, len, rx_status);
2815 else if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA) {
2816 if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) !=
2819 /* mgmt->sa is actually BSSID for FromDS data frames */
2820 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0)
2822 /* Skip IEEE 802.11 and LLC headers */
2824 if (WPA_GET_BE16(pos) != ETH_P_EAPOL)
2827 /* mgmt->bssid is actually BSSID for SA data frames */
2828 wpa_supplicant_rx_eapol(wpa_s, mgmt->bssid,
2829 pos, buf + len - pos);
2834 void ieee80211_sta_free_hw_features(struct wpa_hw_modes *hw_features,
2835 size_t num_hw_features)
2839 if (hw_features == NULL)
2842 for (i = 0; i < num_hw_features; i++) {
2843 os_free(hw_features[i].channels);
2844 os_free(hw_features[i].rates);
2847 os_free(hw_features);
2851 int ieee80211_sta_init(struct wpa_supplicant *wpa_s)
2853 u16 num_modes, flags;
2855 wpa_s->mlme.modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes,
2857 if (wpa_s->mlme.modes == NULL) {
2858 wpa_printf(MSG_ERROR, "MLME: Failed to read supported "
2859 "channels and rates from the driver");
2863 wpa_s->mlme.num_modes = num_modes;
2865 wpa_s->mlme.hw_modes = 1 << WPA_MODE_IEEE80211A;
2866 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211B;
2867 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211G;
2873 void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
2875 eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
2876 eloop_cancel_timeout(ieee80211_sta_scan_timer, wpa_s, NULL);
2877 os_free(wpa_s->mlme.extra_ie);
2878 wpa_s->mlme.extra_ie = NULL;
2879 os_free(wpa_s->mlme.extra_probe_ie);
2880 wpa_s->mlme.extra_probe_ie = NULL;
2881 os_free(wpa_s->mlme.assocreq_ies);
2882 wpa_s->mlme.assocreq_ies = NULL;
2883 os_free(wpa_s->mlme.assocresp_ies);
2884 wpa_s->mlme.assocresp_ies = NULL;
2885 ieee80211_bss_list_deinit(wpa_s);
2886 ieee80211_sta_free_hw_features(wpa_s->mlme.modes,
2887 wpa_s->mlme.num_modes);
2888 #ifdef CONFIG_IEEE80211R
2889 os_free(wpa_s->mlme.ft_ies);
2890 wpa_s->mlme.ft_ies = NULL;
2891 wpa_s->mlme.ft_ies_len = 0;
2892 #endif /* CONFIG_IEEE80211R */
2896 #ifdef CONFIG_IEEE80211R
2898 int ieee80211_sta_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
2899 const u8 *ies, size_t ies_len)
2902 wpa_printf(MSG_DEBUG, "MLME: Clear FT mobility domain");
2903 os_memset(wpa_s->mlme.current_md, 0, MOBILITY_DOMAIN_ID_LEN);
2905 wpa_printf(MSG_DEBUG, "MLME: Update FT IEs for MD " MACSTR,
2907 os_memcpy(wpa_s->mlme.current_md, md, MOBILITY_DOMAIN_ID_LEN);
2910 wpa_hexdump(MSG_DEBUG, "MLME: FT IEs", ies, ies_len);
2911 os_free(wpa_s->mlme.ft_ies);
2912 wpa_s->mlme.ft_ies = os_malloc(ies_len);
2913 if (wpa_s->mlme.ft_ies == NULL)
2915 os_memcpy(wpa_s->mlme.ft_ies, ies, ies_len);
2916 wpa_s->mlme.ft_ies_len = ies_len;
2922 int ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
2923 const u8 *target_ap,
2924 const u8 *ies, size_t ies_len)
2928 struct ieee80211_mgmt *mgmt;
2932 * Action frame payload:
2933 * Category[1] = 6 (Fast BSS Transition)
2934 * Action[1] = 1 (Fast BSS Transition Request)
2940 buf = os_zalloc(sizeof(*mgmt) + ies_len);
2942 wpa_printf(MSG_DEBUG, "MLME: Failed to allocate buffer for "
2947 mgmt = (struct ieee80211_mgmt *) buf;
2949 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
2950 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
2951 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
2952 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
2953 WLAN_FC_STYPE_ACTION);
2954 mgmt->u.action.category = WLAN_ACTION_FT;
2955 mgmt->u.action.u.ft_action_req.action = action;
2956 os_memcpy(mgmt->u.action.u.ft_action_req.sta_addr, wpa_s->own_addr,
2958 os_memcpy(mgmt->u.action.u.ft_action_req.target_ap_addr, target_ap,
2960 os_memcpy(mgmt->u.action.u.ft_action_req.variable, ies, ies_len);
2961 len += 1 + sizeof(mgmt->u.action.u.ft_action_req) + ies_len;
2963 wpa_printf(MSG_DEBUG, "MLME: Send FT Action Frame: Action=%d "
2964 "Target AP=" MACSTR " body_len=%lu",
2965 action, MAC2STR(target_ap), (unsigned long) ies_len);
2967 res = ieee80211_sta_tx(wpa_s, buf, len);
2973 #endif /* CONFIG_IEEE80211R */
2976 int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
2979 os_free(wpa_s->mlme.extra_probe_ie);
2980 wpa_s->mlme.extra_probe_ie = NULL;
2981 wpa_s->mlme.extra_probe_ie_len = 0;
2986 wpa_s->mlme.extra_probe_ie = os_malloc(ies_len);
2987 if (wpa_s->mlme.extra_probe_ie == NULL)
2990 os_memcpy(wpa_s->mlme.extra_probe_ie, ies, ies_len);
2991 wpa_s->mlme.extra_probe_ie_len = ies_len;