Home | History | Annotate | Download | only in wpa_supplicant

Lines Matching refs:wpa_s

88 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
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);
99 static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
106 for (i = 0; i < wpa_s->mlme.num_modes; i++) {
107 mode = &wpa_s->mlme.modes[i];
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);
133 static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
143 if (count == wpa_s->mlme.wmm_last_param_set)
145 wpa_s->mlme.wmm_last_param_set = count;
177 wpa_s->mlme.wmm_acm |= BIT(0) | BIT(3);
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;
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,
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);
259 wpa_s->mlme.auth_transaction = transaction + 1;
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);
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) {
287 " timed out", MAC2STR(wpa_s->bssid));
291 wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
293 MAC2STR(wpa_s->bssid));
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) {
304 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
308 os_memcmp(mdie->mobility_domain, wpa_s->mlme.current_md,
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;
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)
335 if (wpa_s->mlme.curr_rates == NULL) {
340 buflen = sizeof(*mgmt) + 200 + wpa_s->mlme.extra_ie_len +
341 wpa_s->mlme.ssid_len;
343 if (wpa_s->mlme.ft_ies)
344 buflen += wpa_s->mlme.ft_ies_len;
354 capab = wpa_s->mlme.capab;
355 if (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G) {
359 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
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) {
382 wpa_s->mlme.prev_bssid,
394 blen += 2 + wpa_s->mlme.ssid_len;
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;
407 int rate = wpa_s->mlme.curr_rates[i].rate;
411 if (wpa_s->mlme.num_curr_rates > len) {
413 blen += wpa_s->mlme.num_curr_rates - len + 2;
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;
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);
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 &&
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;
454 if (wmm && wpa_s->mlme.wmm_enabled) {
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)
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);
504 ieee80211_sta_tx(wpa_s, buf, len);
509 static void ieee80211_send_disassoc(struct wpa_supplicant *wpa_s, u16 reason)
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);
532 ieee80211_sta_tx(wpa_s, buf, len);
537 static int ieee80211_privacy_mismatch(struct wpa_supplicant *wpa_s)
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) !=
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) {
563 " timed out", MAC2STR(wpa_s->bssid));
567 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
569 MAC2STR(wpa_s->bssid));
570 if (ieee80211_privacy_mismatch(wpa_s)) {
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)
592 wpa_s->mlme.state = IEEE80211_ASSOCIATED;
595 sta = sta_info_get(local, wpa_s->bssid);
598 MAC2STR(wpa_s->bssid));
604 if (wpa_s->mlme.probereq_poll) {
608 MAC2STR(wpa_s->bssid));
612 wpa_s->bssid,
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 +
621 wpa_s->mlme.last_probe = jiffies;
622 ieee80211_send_probe_req(wpa_s->bssid,
623 wpa_s->mlme.ssid,
624 wpa_s->mlme.ssid_len);
633 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
634 ieee80211_reschedule_timer(wpa_s,
638 ieee80211_reschedule_timer(wpa_s,
644 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
655 buf = os_malloc(sizeof(*mgmt) + 200 + wpa_s->mlme.extra_probe_ie_len);
667 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
685 for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
686 struct wpa_rate_data *rate = &wpa_s->mlme.curr_rates[i];
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)
729 static void ieee80211_auth_completed(struct wpa_supplicant *wpa_s)
732 wpa_s->mlme.authenticated = 1;
733 ieee80211_associate(wpa_s);
737 static void ieee80211_auth_challenge(struct wpa_supplicant *wpa_s,
757 ieee80211_send_auth(wpa_s, 3, elems.challenge - 2,
762 static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
767 struct wpa_ssid *ssid = wpa_s->current_ssid;
773 if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
787 if (!adhoc && os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
795 if (adhoc && os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0) {
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) {
837 "(auth_alg=%d code=%d)", wpa_s->mlme.auth_alg,
844 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
846 if (wpa_s->mlme.auth_algs &
849 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
851 if (wpa_s->mlme.auth_alg == WLAN_AUTH_OPEN)
853 else if (wpa_s->mlme.auth_alg == WLAN_AUTH_SHARED_KEY)
861 if (algs[pos] == wpa_s->mlme.auth_alg ||
865 !ieee80211_sta_wep_configured(wpa_s))
867 wpa_s->mlme.auth_alg = algs[pos];
870 wpa_s->mlme.auth_alg);
877 switch (wpa_s->mlme.auth_alg) {
880 ieee80211_auth_completed(wpa_s);
883 if (wpa_s->mlme.auth_transaction == 4)
884 ieee80211_auth_completed(wpa_s);
886 ieee80211_auth_challenge(wpa_s, mgmt, len,
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);
907 static void ieee80211_rx_mgmt_deauth(struct wpa_supplicant *wpa_s,
921 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
934 if (wpa_s->mlme.authenticated)
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,
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,
964 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
977 if (wpa_s->mlme.associated)
980 if (wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
981 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
982 ieee80211_reschedule_timer(wpa_s,
986 ieee80211_set_associated(wpa_s, 0);
990 static int ieee80211_ft_assoc_resp(struct wpa_supplicant *wpa_s,
1021 return wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
1029 static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
1044 if (wpa_s->mlme.state != IEEE80211_ASSOCIATE) {
1058 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1101 ieee80211_reschedule_timer(wpa_s, ms);
1114 if (wpa_s->mlme.auth_alg == WLAN_AUTH_FT) {
1122 wpa_s->wpa, pos, len - (pos - (u8 *) mgmt),
1128 } else if (ieee80211_ft_assoc_resp(wpa_s, &elems) < 0)
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);
1157 if (wpa_drv_set_bssid(wpa_s, wpa_s->bssid) < 0) {
1161 if (wpa_drv_set_ssid(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) <
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) {
1178 if (elems.wmm && wpa_s->mlme.wmm_enabled) {
1180 ieee80211_sta_wmm_params(wpa_s, elems.wmm, elems.wmm_len);
1184 ieee80211_associated(wpa_s);
1189 static void __ieee80211_bss_hash_add(struct wpa_supplicant *wpa_s,
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;
1198 wpa_s,
1202 b = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
1206 wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)]
1220 ieee80211_bss_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
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);
1238 ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid)
1242 bss = wpa_s->mlme.sta_bss_hash[STA_HASH(bssid)];
1252 static void ieee80211_bss_free(struct wpa_supplicant *wpa_s,
1255 __ieee80211_bss_hash_del(wpa_s, bss);
1265 static void ieee80211_bss_list_deinit(struct wpa_supplicant *wpa_s)
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,
1293 if (!beacon && os_memcmp(mgmt->da, wpa_s->own_addr, ETH_ALEN))
1347 oper_mode = wpa_s->mlme.sta_scanning ?
1382 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
1403 bss = ieee80211_bss_get(wpa_s, mgmt->bssid);
1405 bss = ieee80211_bss_add(wpa_s, mgmt->bssid);
1527 bss->hw_mode = wpa_s->mlme.phymode;
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) &&
1550 static void ieee80211_rx_mgmt_probe_resp(struct wpa_supplicant *wpa_s,
1555 ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 0);
1559 static void ieee80211_rx_mgmt_beacon(struct wpa_supplicant *wpa_s,
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)
1589 if (use_protection != !!wpa_s->mlme.use_protection) {
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.wmm && wpa_s->mlme.wmm_enabled) {
1599 ieee80211_sta_wmm_params(wpa_s, elems.wmm,
1605 static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
1615 struct wpa_ssid *ssid = wpa_s->current_ssid;
1619 if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
1620 len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
1640 if (os_memcmp(mgmt->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1653 (pos[1] != wpa_s->mlme.ssid_len ||
1654 os_memcmp(pos + 2, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) != 0))
1662 skb = skb_copy(wpa_s->mlme.probe_resp, GFP_ATOMIC);
1672 ieee80211_sta_tx(wpa_s, skb, 0, 1);
1678 static void ieee80211_rx_mgmt_ft_action(struct wpa_supplicant *wpa_s,
1708 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1727 wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &data);
1730 wpa_s->mlme.prev_bssid_set = 1;
1731 wpa_s->mlme.auth_alg = WLAN_AUTH_FT;
1732 os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
1733 os_memcpy(wpa_s->bssid, target_ap_addr, ETH_ALEN);
1734 ieee80211_associate(wpa_s);
1742 static int ieee80211_sta_send_sa_query_resp(struct wpa_supplicant *wpa_s,
1758 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
1759 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
1768 res = ieee80211_sta_tx(wpa_s, (u8 *) mgmt, len);
1776 struct wpa_supplicant *wpa_s, struct ieee80211_mgmt *mgmt, size_t len,
1790 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0) {
1796 if (wpa_s->mlme.state == IEEE80211_ASSOCIATE) {
1803 ieee80211_sta_send_sa_query_resp(wpa_s, mgmt->sa, mgmt->u.action.u.
1810 static void ieee80211_rx_mgmt_action(struct wpa_supplicant *wpa_s,
1823 ieee80211_rx_mgmt_ft_action(wpa_s, mgmt, len, rx_status);
1828 ieee80211_rx_mgmt_sa_query_action(wpa_s, mgmt, len, rx_status);
1839 static void ieee80211_sta_rx_mgmt(struct wpa_supplicant *wpa_s,
1854 ieee80211_rx_mgmt_probe_req(wpa_s, mgmt, len, rx_status);
1857 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt, len, rx_status);
1860 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1863 ieee80211_rx_mgmt_auth(wpa_s, mgmt, len, rx_status);
1866 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 0);
1869 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 1);
1872 ieee80211_rx_mgmt_deauth(wpa_s, mgmt, len, rx_status);
1875 ieee80211_rx_mgmt_disassoc(wpa_s, mgmt, len, rx_status);
1878 ieee80211_rx_mgmt_action(wpa_s, mgmt, len, rx_status);
1888 static void ieee80211_sta_rx_scan(struct wpa_supplicant *wpa_s,
1903 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt,
1906 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1912 static int ieee80211_sta_active_ibss(struct wpa_supplicant *wpa_s)
1932 static void ieee80211_sta_expire(struct wpa_supplicant *wpa_s)
1948 static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
1950 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
1952 ieee80211_sta_expire(wpa_s);
1953 if (ieee80211_sta_active_ibss(wpa_s))
1958 ieee80211_sta_req_scan(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
1964 struct wpa_supplicant *wpa_s = eloop_ctx;
1966 switch (wpa_s->mlme.state) {
1970 ieee80211_authenticate(wpa_s);
1973 ieee80211_associate(wpa_s);
1976 ieee80211_associated(wpa_s);
1979 ieee80211_sta_find_ibss(wpa_s);
1982 ieee80211_sta_merge_ibss(wpa_s);
1986 wpa_s->mlme.state);
1990 if (ieee80211_privacy_mismatch(wpa_s)) {
1994 ieee80211_send_disassoc(wpa_s, WLAN_REASON_UNSPECIFIED);
1995 ieee80211_set_associated(wpa_s, 0);
2000 static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
2002 struct wpa_ssid *ssid = wpa_s->current_ssid;
2013 wpa_s->mlme.wmm_last_param_set = -1; /* allow any WMM update */
2016 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
2017 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2018 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2019 wpa_s->mlme.auth_alg = WLAN_AUTH_SHARED_KEY;
2020 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
2021 wpa_s->mlme.auth_alg = WLAN_AUTH_LEAP;
2023 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2025 wpa_s->mlme.auth_alg);
2026 wpa_s->mlme.auth_transaction = -1;
2027 wpa_s->mlme.auth_tries = wpa_s->mlme.assoc_tries = 0;
2028 ieee80211_authenticate(wpa_s);
2032 static int ieee80211_ibss_allowed(struct wpa_supplicant *wpa_s)
2057 static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
2079 os_memcpy(wpa_s->bssid, bss->bssid, ETH_ALEN);
2092 res = ieee80211_ioctl_siwfreq(wpa_s, NULL, &rq, NULL);
2095 if (!ieee80211_ibss_allowed(wpa_s)) {
2117 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
2118 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
2126 len += 2 + wpa_s->mlme.ssid_len;
2128 *pos++ = wpa_s->mlme.ssid_len;
2129 os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2168 rate = rate_control_get_rate(wpa_s, skb, &extra);
2174 control.tx_rate = (wpa_s->mlme.short_preamble &&
2185 wpa_s->mlme.probe_resp = skb_copy(skb, GFP_ATOMIC);
2186 if (wpa_s->mlme.probe_resp) {
2188 wpa_s->mlme.probe_resp->data;
2198 local->hw->beacon_update(wpa_s, skb, &control) == 0) {
2213 wpa_s->mlme.supp_rates_bits = rates;
2224 wpa_s->mlme.state = IEEE80211_IBSS_JOINED;
2225 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
2232 static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
2247 bssid[i] ^= wpa_s->own_addr[i];
2255 bss = ieee80211_bss_add(wpa_s, bssid);
2286 return ieee80211_sta_join_ibss(wpa_s, bss);
2291 static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s)
2299 if (wpa_s->mlme.ssid_len == 0)
2302 active_ibss = ieee80211_sta_active_ibss(wpa_s);
2307 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2308 if (wpa_s->mlme.ssid_len != bss->ssid_len ||
2309 os_memcmp(wpa_s->mlme.ssid, bss->ssid, bss->ssid_len) != 0
2319 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)
2325 MACSTR, MAC2STR(bssid), MAC2STR(wpa_s->bssid));
2327 if (found && os_memcmp(wpa_s->bssid, bssid, ETH_ALEN) != 0 &&
2328 (bss = ieee80211_bss_get(wpa_s, bssid))) {
2332 return ieee80211_sta_join_ibss(wpa_s, bss);
2341 if (wpa_s->mlme.state == IEEE80211_IBSS_JOINED &&
2342 !ieee80211_sta_active_ibss(wpa_s)) {
2343 ieee80211_reschedule_timer(wpa_s,
2345 } else if (time_after(jiffies, wpa_s->mlme.last_scan_completed +
2349 return ieee80211_sta_req_scan(wpa_s->mlme.ssid,
2350 wpa_s->mlme.ssid_len);
2351 } else if (wpa_s->mlme.state != IEEE80211_IBSS_JOINED) {
2354 if (time_after(jiffies, wpa_s->mlme.ibss_join_req +
2356 if (wpa_s->mlme.create_ibss &&
2357 ieee80211_ibss_allowed(wpa_s))
2358 return ieee80211_sta_create_ibss(wpa_s);
2359 if (wpa_s->mlme.create_ibss) {
2372 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2373 ieee80211_reschedule_timer(wpa_s, interval);
2382 int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid,
2385 os_memcpy(ssid, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2386 *len = wpa_s->mlme.ssid_len;
2391 int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
2396 wpa_s->mlme.bssid_set = 0;
2397 wpa_s->mlme.freq = params->freq;
2399 os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
2401 wpa_s->mlme.bssid_set = 1;
2402 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
2404 wpa_s->mlme.phymode = bss->hw_mode;
2405 wpa_s->mlme.channel = bss->channel;
2406 wpa_s->mlme.freq = bss->freq;
2426 local->hw->conf_tx(wpa_s, i + IEEE80211_TX_QUEUE_DATA0,
2433 local->hw->conf_tx(wpa_s, IEEE80211_TX_QUEUE_BEACON, &qparam);
2437 if (wpa_s->mlme.ssid_len != params->ssid_len ||
2438 os_memcmp(wpa_s->mlme.ssid, params->ssid, params->ssid_len) != 0)
2439 wpa_s->mlme.prev_bssid_set = 0;
2440 os_memcpy(wpa_s->mlme.ssid, params->ssid, params->ssid_len);
2441 os_memset(wpa_s->mlme.ssid + params->ssid_len, 0,
2443 wpa_s->mlme.ssid_len = params->ssid_len;
2444 wpa_s->mlme.ssid_set = 1;
2446 os_free(wpa_s->mlme.extra_ie);
2448 wpa_s->mlme.extra_ie = NULL;
2449 wpa_s->mlme.extra_ie_len = 0;
2451 wpa_s->mlme.extra_ie = os_malloc(params->wpa_ie_len);
2452 if (wpa_s->mlme.extra_ie == NULL) {
2453 wpa_s->mlme.extra_ie_len = 0;
2456 os_memcpy(wpa_s->mlme.extra_ie, params->wpa_ie,
2458 wpa_s->mlme.extra_ie_len = params->wpa_ie_len;
2461 wpa_s->mlme.key_mgmt = params->key_mgmt_suite;
2463 ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2464 wpa_s->mlme.channel, wpa_s->mlme.freq);
2466 if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
2467 os_get_time(&wpa_s->mlme.ibss_join_req);
2468 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2469 return ieee80211_sta_find_ibss(wpa_s);
2472 if (wpa_s->mlme.bssid_set)
2473 ieee80211_sta_new_auth(wpa_s);
2479 static void ieee80211_sta_save_oper_chan(struct wpa_supplicant *wpa_s)
2481 wpa_s->mlme.scan_oper_channel = wpa_s->mlme.channel;
2482 wpa_s->mlme.scan_oper_freq = wpa_s->mlme.freq;
2483 wpa_s->mlme.scan_oper_phymode = wpa_s->mlme.phymode;
2487 static int ieee80211_sta_restore_oper_chan(struct wpa_supplicant *wpa_s)
2489 wpa_s->mlme.channel = wpa_s->mlme.scan_oper_channel;
2490 wpa_s->mlme.freq = wpa_s->mlme.scan_oper_freq;
2491 wpa_s->mlme.phymode = wpa_s->mlme.scan_oper_phymode;
2492 if (wpa_s->mlme.freq == 0)
2494 return ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2495 wpa_s->mlme.channel,
2496 wpa_s->mlme.freq);
2500 static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
2505 for (m = 0; m < wpa_s->mlme.num_modes; m++) {
2506 struct wpa_hw_modes *mode = &wpa_s->mlme.modes[m];
2507 if ((int) mode->mode != (int) wpa_s->mlme.phymode)
2512 chan->chan == wpa_s->mlme.channel) {
2526 struct wpa_supplicant *wpa_s = eloop_ctx;
2531 struct wpa_ssid *ssid = wpa_s->current_ssid;
2534 if (!wpa_s->mlme.sta_scanning || wpa_s->mlme.modes == NULL)
2539 switch (wpa_s->mlme.scan_state) {
2541 mode = &wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx];
2542 if (wpa_s->mlme.scan_hw_mode_idx >=
2543 (int) wpa_s->mlme.num_modes ||
2544 (wpa_s->mlme.scan_hw_mode_idx + 1 ==
2545 (int) wpa_s->mlme.num_modes
2546 && wpa_s->mlme.scan_channel_idx >= mode->num_channels)) {
2547 if (ieee80211_sta_restore_oper_chan(wpa_s)) {
2553 wpa_s->mlme.sta_scanning = 0;
2554 os_get_time(&wpa_s->mlme.last_scan_completed);
2555 wpa_supplicant_event(wpa_s, EVENT_SCAN_RESULTS, NULL);
2557 if (!wpa_s->mlme.bssid_set ||
2558 (wpa_s->mlme.state ==
2560 !ieee80211_sta_active_ibss(wpa_s)))
2561 ieee80211_sta_find_ibss(wpa_s);
2565 skip = !(wpa_s->mlme.hw_modes & (1 << mode->mode));
2566 chan = &mode->channels[wpa_s->mlme.scan_channel_idx];
2569 (wpa_s->mlme.hw_modes & (1 << WPA_MODE_IEEE80211G) &&
2571 wpa_s->mlme.scan_skip_11b))
2579 wpa_s->mlme.channel = chan->chan;
2580 wpa_s->mlme.freq = chan->freq;
2581 wpa_s->mlme.phymode = mode->mode;
2582 if (ieee80211_sta_set_channel(wpa_s, mode->mode,
2592 wpa_s->mlme.scan_channel_idx++;
2593 if (wpa_s->mlme.scan_channel_idx >=
2594 wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx].
2596 wpa_s->mlme.scan_hw_mode_idx++;
2597 wpa_s->mlme.scan_channel_idx = 0;
2606 wpa_s->mlme.scan_state = SCAN_SEND_PROBE;
2609 if (ieee80211_active_scan(wpa_s)) {
2610 ieee80211_send_probe_req(wpa_s, NULL,
2611 wpa_s->mlme.scan_ssid,
2612 wpa_s->mlme.scan_ssid_len);
2617 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2622 ieee80211_sta_scan_timer, wpa_s, NULL);
2626 int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
2652 if (wpa_s->mlme.sta_scanning)
2657 ieee80211_sta_save_oper_chan(wpa_s);
2659 wpa_s->mlme.sta_scanning = 1;
2663 wpa_s->mlme.scan_ssid_len = ssid_len;
2664 os_memcpy(wpa_s->mlme.scan_ssid, ssid, ssid_len);
2666 wpa_s->mlme.scan_ssid_len = 0;
2667 wpa_s->mlme.scan_skip_11b = 1; /* FIX: clear this is 11g is not
2669 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2670 wpa_s->mlme.scan_hw_mode_idx = 0;
2671 wpa_s->mlme.scan_channel_idx = 0;
2672 eloop_register_timeout(0, 1, ieee80211_sta_scan_timer, wpa_s, NULL);
2679 ieee80211_sta_get_scan_results(struct wpa_supplicant *wpa_s)
2687 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next)
2695 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2718 struct sta_info * ieee80211_ibss_add_sta(struct wpa_supplicant *wpa_s,
2754 sta = sta_info_add(wpa_s, addr);
2760 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
2769 int ieee80211_sta_deauthenticate(struct wpa_supplicant *wpa_s, u16 reason)
2773 ieee80211_send_deauth(wpa_s, reason);
2774 ieee80211_set_associated(wpa_s, 0);
2779 int ieee80211_sta_disassociate(struct wpa_supplicant *wpa_s, u16 reason)
2783 if (!wpa_s->mlme.associated)
2786 ieee80211_send_disassoc(wpa_s, reason);
2787 ieee80211_set_associated(wpa_s, 0);
2792 void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
2801 if (wpa_s->mlme.sta_scanning) {
2802 ieee80211_sta_rx_scan(wpa_s, buf, len, rx_status);
2813 ieee80211_sta_rx_mgmt(wpa_s, buf, len, rx_status);
2819 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0)
2827 wpa_supplicant_rx_eapol(wpa_s, mgmt->bssid,
2850 int ieee80211_sta_init(struct wpa_supplicant *wpa_s)
2854 wpa_s->mlme.modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes,
2856 if (wpa_s->mlme.modes == NULL) {
2862 wpa_s->mlme.num_modes = num_modes;
2864 wpa_s->mlme.hw_modes = 1 << WPA_MODE_IEEE80211A;
2865 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211B;
2866 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211G;
2872 void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
2874 eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
2875 eloop_cancel_timeout(ieee80211_sta_scan_timer, wpa_s, NULL);
2876 os_free(wpa_s->mlme.extra_ie);
2877 wpa_s->mlme.extra_ie = NULL;
2878 os_free(wpa_s->mlme.extra_probe_ie);
2879 wpa_s->mlme.extra_probe_ie = NULL;
2880 os_free(wpa_s->mlme.assocreq_ies);
2881 wpa_s->mlme.assocreq_ies = NULL;
2882 os_free(wpa_s->mlme.assocresp_ies);
2883 wpa_s->mlme.assocresp_ies = NULL;
2884 ieee80211_bss_list_deinit(wpa_s);
2885 ieee80211_sta_free_hw_features(wpa_s->mlme.modes,
2886 wpa_s->mlme.num_modes);
2888 os_free(wpa_s->mlme.ft_ies);
2889 wpa_s->mlme.ft_ies = NULL;
2890 wpa_s->mlme.ft_ies_len = 0;
2897 int ieee80211_sta_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
2902 os_memset(wpa_s->mlme.current_md, 0, MOBILITY_DOMAIN_ID_LEN);
2906 os_memcpy(wpa_s->mlme.current_md, md, MOBILITY_DOMAIN_ID_LEN);
2910 os_free(wpa_s->mlme.ft_ies);
2911 wpa_s->mlme.ft_ies = os_malloc(ies_len);
2912 if (wpa_s->mlme.ft_ies == NULL)
2914 os_memcpy(wpa_s->mlme.ft_ies, ies, ies_len);
2915 wpa_s->mlme.ft_ies_len = ies_len;
2921 int ieee80211_sta_send_ft_action(struct wpa_supplicant *wpa_s, u8 action,
2948 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
2949 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
2950 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
2955 os_memcpy(mgmt->u.action.u.ft_action_req.sta_addr, wpa_s->own_addr,
2966 res = ieee80211_sta_tx(wpa_s, buf, len);
2975 int ieee80211_sta_set_probe_req_ie(struct wpa_supplicant *wpa_s, const u8 *ies,
2978 os_free(wpa_s->mlme.extra_probe_ie);
2979 wpa_s->mlme.extra_probe_ie = NULL;
2980 wpa_s->mlme.extra_probe_ie_len = 0;
2985 wpa_s->mlme.extra_probe_ie = os_malloc(ies_len);
2986 if (wpa_s->mlme.extra_probe_ie == NULL)
2989 os_memcpy(wpa_s->mlme.extra_probe_ie, ies, ies_len);
2990 wpa_s->mlme.extra_probe_ie_len = ies_len;