Home | History | Annotate | Download | only in wpa_supplicant

Lines Matching refs:wpa_s

302 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
306 ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid);
307 static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s);
308 static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s);
458 static int ieee80211_sta_set_channel(struct wpa_supplicant *wpa_s,
465 for (i = 0; i < wpa_s->mlme.num_modes; i++) {
466 mode = &wpa_s->mlme.modes[i];
468 wpa_s->mlme.curr_rates = mode->rates;
469 wpa_s->mlme.num_curr_rates = mode->num_rates;
474 return wpa_drv_set_channel(wpa_s, phymode, chan, freq);
492 static void ieee80211_sta_wmm_params(struct wpa_supplicant *wpa_s,
502 if (count == wpa_s->mlme.wmm_last_param_set)
504 wpa_s->mlme.wmm_last_param_set = count;
536 wpa_s->mlme.wmm_acm |= BIT(0) | BIT(3);
560 static void ieee80211_set_associated(struct wpa_supplicant *wpa_s, int assoc)
562 if (wpa_s->mlme.associated == assoc)
565 wpa_s->mlme.associated = assoc;
570 wpa_s->mlme.prev_bssid_set = 1;
571 os_memcpy(wpa_s->mlme.prev_bssid, wpa_s->bssid, ETH_ALEN);
572 data.assoc_info.req_ies = wpa_s->mlme.assocreq_ies;
573 data.assoc_info.req_ies_len = wpa_s->mlme.assocreq_ies_len;
574 data.assoc_info.resp_ies = wpa_s->mlme.assocresp_ies;
575 data.assoc_info.resp_ies_len = wpa_s->mlme.assocresp_ies_len;
576 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data);
578 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
580 os_get_time(&wpa_s->mlme.last_probe);
584 static void ieee80211_sta_tx(struct wpa_supplicant *wpa_s, const u8 *buf,
587 wpa_drv_send_mlme(wpa_s, buf, len);
591 static void ieee80211_send_auth(struct wpa_supplicant *wpa_s,
613 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
614 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
615 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
616 mgmt->u.auth.auth_alg = host_to_le16(wpa_s->mlme.auth_alg);
618 wpa_s->mlme.auth_transaction = transaction + 1;
625 ieee80211_sta_tx(wpa_s, buf, len);
630 static void ieee80211_reschedule_timer(struct wpa_supplicant *wpa_s, int ms)
632 eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
634 ieee80211_sta_timer, wpa_s, NULL);
638 static void ieee80211_authenticate(struct wpa_supplicant *wpa_s)
640 wpa_s->mlme.auth_tries++;
641 if (wpa_s->mlme.auth_tries > IEEE80211_AUTH_MAX_TRIES) {
643 " timed out", MAC2STR(wpa_s->bssid));
647 wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
649 MAC2STR(wpa_s->bssid));
651 ieee80211_send_auth(wpa_s, 1, NULL, 0, 0);
653 ieee80211_reschedule_timer(wpa_s
657 static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
667 if (wpa_s->mlme.curr_rates == NULL) {
672 buf = os_malloc(sizeof(*mgmt) + 200 + wpa_s->mlme.extra_ie_len +
673 wpa_s->mlme.ssid_len);
681 capab = wpa_s->mlme.capab;
682 if (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G) {
686 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
698 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
699 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
700 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
702 if (wpa_s->mlme.prev_bssid_set) {
709 wpa_s->mlme.prev_bssid,
721 blen += 2 + wpa_s->mlme.ssid_len;
723 *pos++ = wpa_s->mlme.ssid_len;
724 os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
726 len = wpa_s->mlme.num_curr_rates;
734 int rate = wpa_s->mlme.curr_rates[i].rate;
738 if (wpa_s->mlme.num_curr_rates > len) {
740 blen += wpa_s->mlme.num_curr_rates - len + 2;
742 *pos++ = wpa_s->mlme.num_curr_rates - len;
743 for (i = len; i < wpa_s->mlme.num_curr_rates; i++) {
744 int rate = wpa_s->mlme.curr_rates[i].rate;
749 if (wpa_s->mlme.extra_ie) {
751 blen += wpa_s->mlme.extra_ie_len;
752 os_memcpy(pos, wpa_s->mlme.extra_ie, wpa_s->mlme.extra_ie_len);
755 if (wmm && wpa_s->mlme.wmm_enabled) {
769 os_free(wpa_s->mlme.assocreq_ies);
770 wpa_s->mlme.assocreq_ies_len = (buf + blen) - ies;
771 wpa_s->mlme.assocreq_ies = os_malloc(wpa_s->mlme.assocreq_ies_len);
772 if (wpa_s->mlme.assocreq_ies) {
773 os_memcpy(wpa_s->mlme.assocreq_ies, ies,
774 wpa_s->mlme.assocreq_ies_len);
777 ieee80211_sta_tx(wpa_s, buf, blen);
782 static void ieee80211_send_deauth(struct wpa_supplicant *wpa_s, u16 reason)
797 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
798 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
799 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
805 ieee80211_sta_tx(wpa_s, buf, len);
810 static void ieee80211_send_disassoc(struct wpa_supplicant *wpa_s, u16 reason)
825 os_memcpy(mgmt->da, wpa_s->bssid, ETH_ALEN);
826 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
827 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
833 ieee80211_sta_tx(wpa_s, buf, len);
838 static int ieee80211_privacy_mismatch(struct wpa_supplicant *wpa_s)
843 if (wpa_s->mlme.mixed_cell ||
844 wpa_s->mlme.key_mgmt != KEY_MGMT_NONE)
847 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
851 if (ieee80211_sta_wep_configured(wpa_s) !=
859 static void ieee80211_associate(struct wpa_supplicant *wpa_s)
861 wpa_s->mlme.assoc_tries++;
862 if (wpa_s->mlme.assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
864 " timed out", MAC2STR(wpa_s->bssid));
868 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
870 MAC2STR(wpa_s->bssid));
871 if (ieee80211_privacy_mismatch(wpa_s)) {
878 ieee80211_send_assoc(wpa_s);
880 ieee80211_reschedule_timer(wpa_s, IEEE80211_ASSOC_TIMEOUT);
884 static void ieee80211_associated(struct wpa_supplicant *wpa_s)
893 wpa_s->mlme.state = IEEE80211_ASSOCIATED;
896 sta = sta_info_get(local, wpa_s->bssid);
899 MAC2STR(wpa_s->bssid));
905 if (wpa_s->mlme.probereq_poll) {
909 MAC2STR(wpa_s->bssid));
913 wpa_s->bssid,
914 wpa_s->mlme.scan_ssid,
915 wpa_s->mlme.scan_ssid_len);
916 wpa_s->mlme.probereq_poll = 1;
919 wpa_s->mlme.probereq_poll = 0;
920 if (time_after(jiffies, wpa_s->mlme.last_probe +
922 wpa_s->mlme.last_probe = jiffies;
923 ieee80211_send_probe_req(wpa_s->bssid,
924 wpa_s->mlme.ssid,
925 wpa_s->mlme.ssid_len);
934 wpa_supplicant_event(wpa_s, EVENT_DISASSOC, NULL);
935 ieee80211_reschedule_timer(wpa_s,
939 ieee80211_reschedule_timer(wpa_s,
945 static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
968 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
986 for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
987 struct wpa_rate_data *rate = &wpa_s->mlme.curr_rates[i];
1006 ieee80211_sta_tx(wpa_s, buf, len);
1011 static int ieee80211_sta_wep_configured(struct wpa_supplicant *wpa_s)
1024 static void ieee80211_auth_completed(struct wpa_supplicant *wpa_s)
1027 wpa_s->mlme.authenticated = 1;
1028 ieee80211_associate(wpa_s);
1032 static void ieee80211_auth_challenge(struct wpa_supplicant *wpa_s,
1052 ieee80211_send_auth(wpa_s, 3, elems.challenge - 2,
1057 static void ieee80211_rx_mgmt_auth(struct wpa_supplicant *wpa_s,
1062 struct wpa_ssid *ssid = wpa_s->current_ssid;
1068 if (wpa_s->mlme.state != IEEE80211_AUTHENTICATE && !adhoc) {
1082 if (!adhoc && os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1090 if (adhoc && os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0) {
1119 ieee80211_send_auth(wpa_s, 2, NULL, 0, 0);
1122 if (auth_alg != wpa_s->mlme.auth_alg ||
1123 auth_transaction != wpa_s->mlme.auth_transaction) {
1132 "(auth_alg=%d code=%d)", wpa_s->mlme.auth_alg,
1139 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
1141 if (wpa_s->mlme.auth_algs &
1144 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
1146 if (wpa_s->mlme.auth_alg == WLAN_AUTH_OPEN)
1148 else if (wpa_s->mlme.auth_alg == WLAN_AUTH_SHARED_KEY)
1156 if (algs[pos] == wpa_s->mlme.auth_alg ||
1160 !ieee80211_sta_wep_configured(wpa_s))
1162 wpa_s->mlme.auth_alg = algs[pos];
1165 wpa_s->mlme.auth_alg);
1172 switch (wpa_s->mlme.auth_alg) {
1175 ieee80211_auth_completed(wpa_s);
1178 if (wpa_s->mlme.auth_transaction == 4)
1179 ieee80211_auth_completed(wpa_s);
1181 ieee80211_auth_challenge(wpa_s, mgmt, len,
1188 static void ieee80211_rx_mgmt_deauth(struct wpa_supplicant *wpa_s,
1202 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1215 if (wpa_s->mlme.authenticated)
1218 if (wpa_s->mlme.state == IEEE80211_AUTHENTICATE ||
1219 wpa_s->mlme.state == IEEE80211_ASSOCIATE ||
1220 wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
1221 wpa_s->mlme.state = IEEE80211_AUTHENTICATE;
1222 ieee80211_reschedule_timer(wpa_s,
1226 ieee80211_set_associated(wpa_s, 0);
1227 wpa_s->mlme.authenticated = 0;
1231 static void ieee80211_rx_mgmt_disassoc(struct wpa_supplicant *wpa_s,
1245 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1258 if (wpa_s->mlme.associated)
1261 if (wpa_s->mlme.state == IEEE80211_ASSOCIATED) {
1262 wpa_s->mlme.state = IEEE80211_ASSOCIATE;
1263 ieee80211_reschedule_timer(wpa_s,
1267 ieee80211_set_associated(wpa_s, 0);
1271 static void ieee80211_rx_mgmt_assoc_resp(struct wpa_supplicant *wpa_s,
1286 if (wpa_s->mlme.state != IEEE80211_ASSOCIATE) {
1300 if (os_memcmp(wpa_s->bssid, mgmt->sa, ETH_ALEN) != 0) {
1340 wpa_s->mlme.aid = aid;
1341 wpa_s->mlme.ap_capab = capab_info;
1343 os_free(wpa_s->mlme.assocresp_ies);
1344 wpa_s->mlme.assocresp_ies_len = len - (pos - (u8 *) mgmt);
1345 wpa_s->mlme.assocresp_ies = os_malloc(wpa_s->mlme.assocresp_ies_len);
1346 if (wpa_s->mlme.assocresp_ies) {
1347 os_memcpy(wpa_s->mlme.assocresp_ies, pos,
1348 wpa_s->mlme.assocresp_ies_len);
1351 ieee80211_set_associated(wpa_s, 1);
1365 if (wpa_drv_set_bssid(wpa_s, wpa_s->bssid) < 0) {
1369 if (wpa_drv_set_ssid(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) <
1377 wpa_drv_mlme_remove_sta(wpa_s, wpa_s->bssid);
1378 if (wpa_drv_mlme_add_sta(wpa_s, wpa_s->bssid, rates, rates_len) < 0) {
1386 if (elems.wmm_param && wpa_s->mlme.wmm_enabled) {
1388 ieee80211_sta_wmm_params(wpa_s, elems.wmm_param,
1393 ieee80211_associated(wpa_s);
1398 static void __ieee80211_bss_hash_add(struct wpa_supplicant *wpa_s,
1401 bss->hnext = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
1402 wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)] = bss;
1407 static void __ieee80211_bss_hash_del(struct wpa_supplicant *wpa_s,
1411 b = wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)];
1415 wpa_s->mlme.sta_bss_hash[STA_HASH(bss->bssid)]
1429 ieee80211_bss_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
1439 bss->next = wpa_s->mlme.sta_bss_list;
1440 wpa_s->mlme.sta_bss_list = bss;
1441 __ieee80211_bss_hash_add(wpa_s, bss);
1447 ieee80211_bss_get(struct wpa_supplicant *wpa_s, const u8 *bssid)
1451 bss = wpa_s->mlme.sta_bss_hash[STA_HASH(bssid)];
1461 static void ieee80211_bss_free(struct wpa_supplicant *wpa_s,
1464 __ieee80211_bss_hash_del(wpa_s, bss);
1472 static void ieee80211_bss_list_deinit(struct wpa_supplicant *wpa_s)
1476 bss = wpa_s->mlme.sta_bss_list;
1477 wpa_s->mlme.sta_bss_list = NULL;
1481 ieee80211_bss_free(wpa_s, prev);
1486 static void ieee80211_bss_info(struct wpa_supplicant *wpa_s,
1499 if (!beacon && os_memcmp(mgmt->da, wpa_s->own_addr, ETH_ALEN))
1555 oper_mode = wpa_s->mlme.sta_scanning ?
1590 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
1611 bss = ieee80211_bss_get(wpa_s, mgmt->bssid);
1613 bss = ieee80211_bss_add(wpa_s, mgmt->bssid);
1707 bss->hw_mode = wpa_s->mlme.phymode;
1709 bss->freq = wpa_s->mlme.freq;
1710 if (channel != wpa_s->mlme.channel &&
1711 (wpa_s->mlme.phymode == WPA_MODE_IEEE80211G ||
1712 wpa_s->mlme.phymode == WPA_MODE_IEEE80211B) &&
1730 static void ieee80211_rx_mgmt_probe_resp(struct wpa_supplicant *wpa_s,
1735 ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 0);
1739 static void ieee80211_rx_mgmt_beacon(struct wpa_supplicant *wpa_s,
1748 ieee80211_bss_info(wpa_s, mgmt, len, rx_status, 1);
1750 if (!wpa_s->mlme.associated ||
1751 os_memcmp(wpa_s->bssid, mgmt->bssid, ETH_ALEN) != 0)
1769 if (use_protection != !!wpa_s->mlme.use_protection) {
1773 MAC2STR(wpa_s->bssid));
1774 wpa_s->mlme.use_protection = use_protection ? 1 : 0;
1775 wpa_s->mlme.cts_protect_erp_frames = use_protection;
1778 if (elems.wmm_param && wpa_s->mlme.wmm_enabled) {
1779 ieee80211_sta_wmm_params(wpa_s, elems.wmm_param,
1785 static void ieee80211_rx_mgmt_probe_req(struct wpa_supplicant *wpa_s,
1795 struct wpa_ssid *ssid = wpa_s->current_ssid;
1799 if (!adhoc || wpa_s->mlme.state != IEEE80211_IBSS_JOINED ||
1800 len < 24 + 2 || wpa_s->mlme.probe_resp == NULL)
1820 if (os_memcmp(mgmt->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1833 (pos[1] != wpa_s->mlme.ssid_len ||
1834 os_memcmp(pos + 2, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len) != 0))
1842 skb = skb_copy(wpa_s->mlme.probe_resp, GFP_ATOMIC);
1852 ieee80211_sta_tx(wpa_s, skb, 0, 1);
1857 static void ieee80211_sta_rx_mgmt(struct wpa_supplicant *wpa_s,
1872 ieee80211_rx_mgmt_probe_req(wpa_s, mgmt, len, rx_status);
1875 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt, len, rx_status);
1878 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1881 ieee80211_rx_mgmt_auth(wpa_s, mgmt, len, rx_status);
1884 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 0);
1887 ieee80211_rx_mgmt_assoc_resp(wpa_s, mgmt, len, rx_status, 1);
1890 ieee80211_rx_mgmt_deauth(wpa_s, mgmt, len, rx_status);
1893 ieee80211_rx_mgmt_disassoc(wpa_s, mgmt, len, rx_status);
1903 static void ieee80211_sta_rx_scan(struct wpa_supplicant *wpa_s,
1918 ieee80211_rx_mgmt_probe_resp(wpa_s, mgmt,
1921 ieee80211_rx_mgmt_beacon(wpa_s, mgmt, len, rx_status);
1927 static int ieee80211_sta_active_ibss(struct wpa_supplicant *wpa_s)
1947 static void ieee80211_sta_expire(struct wpa_supplicant *wpa_s)
1963 static void ieee80211_sta_merge_ibss(struct wpa_supplicant *wpa_s)
1965 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
1967 ieee80211_sta_expire(wpa_s);
1968 if (ieee80211_sta_active_ibss(wpa_s))
1973 ieee80211_sta_req_scan(wpa_s, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
1979 struct wpa_supplicant *wpa_s = eloop_ctx;
1981 switch (wpa_s->mlme.state) {
1985 ieee80211_authenticate(wpa_s);
1988 ieee80211_associate(wpa_s);
1991 ieee80211_associated(wpa_s);
1994 ieee80211_sta_find_ibss(wpa_s);
1997 ieee80211_sta_merge_ibss(wpa_s);
2001 wpa_s->mlme.state);
2005 if (ieee80211_privacy_mismatch(wpa_s)) {
2009 ieee80211_send_disassoc(wpa_s, WLAN_REASON_UNSPECIFIED);
2010 ieee80211_set_associated(wpa_s, 0);
2015 static void ieee80211_sta_new_auth(struct wpa_supplicant *wpa_s)
2017 struct wpa_ssid *ssid = wpa_s->current_ssid;
2028 wpa_s->mlme.wmm_last_param_set = -1; /* allow any WMM update */
2031 if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_OPEN)
2032 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2033 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2034 wpa_s->mlme.auth_alg = WLAN_AUTH_SHARED_KEY;
2035 else if (wpa_s->mlme.auth_algs & IEEE80211_AUTH_ALG_LEAP)
2036 wpa_s->mlme.auth_alg = WLAN_AUTH_LEAP;
2038 wpa_s->mlme.auth_alg = WLAN_AUTH_OPEN;
2040 wpa_s->mlme.auth_alg);
2041 wpa_s->mlme.auth_transaction = -1;
2042 wpa_s->mlme.auth_tries = wpa_s->mlme.assoc_tries = 0;
2043 ieee80211_authenticate(wpa_s);
2047 static int ieee80211_ibss_allowed(struct wpa_supplicant *wpa_s)
2072 static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
2094 os_memcpy(wpa_s->bssid, bss->bssid, ETH_ALEN);
2107 res = ieee80211_ioctl_siwfreq(wpa_s, NULL, &rq, NULL);
2110 if (!ieee80211_ibss_allowed(wpa_s)) {
2132 os_memcpy(mgmt->sa, wpa_s->own_addr, ETH_ALEN);
2133 os_memcpy(mgmt->bssid, wpa_s->bssid, ETH_ALEN);
2141 len += 2 + wpa_s->mlme.ssid_len;
2143 *pos++ = wpa_s->mlme.ssid_len;
2144 os_memcpy(pos, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2183 rate = rate_control_get_rate(wpa_s, skb, &extra);
2189 control.tx_rate = (wpa_s->mlme.short_preamble &&
2200 wpa_s->mlme.probe_resp = skb_copy(skb, GFP_ATOMIC);
2201 if (wpa_s->mlme.probe_resp) {
2203 wpa_s->mlme.probe_resp->data;
2213 local->hw->beacon_update(wpa_s, skb, &control) == 0) {
2228 wpa_s->mlme.supp_rates_bits = rates;
2239 wpa_s->mlme.state = IEEE80211_IBSS_JOINED;
2240 ieee80211_reschedule_timer(wpa_s, IEEE80211_IBSS_MERGE_INTERVAL);
2247 static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
2262 bssid[i] ^= wpa_s->own_addr[i];
2270 bss = ieee80211_bss_add(wpa_s, bssid);
2301 return ieee80211_sta_join_ibss(wpa_s, bss);
2306 static int ieee80211_sta_find_ibss(struct wpa_supplicant *wpa_s)
2314 if (wpa_s->mlme.ssid_len == 0)
2317 active_ibss = ieee80211_sta_active_ibss(wpa_s);
2322 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2323 if (wpa_s->mlme.ssid_len != bss->ssid_len ||
2324 os_memcmp(wpa_s->mlme.ssid, bss->ssid, bss->ssid_len) != 0
2334 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)
2340 MACSTR, MAC2STR(bssid), MAC2STR(wpa_s->bssid));
2342 if (found && os_memcmp(wpa_s->bssid, bssid, ETH_ALEN) != 0 &&
2343 (bss = ieee80211_bss_get(wpa_s, bssid))) {
2347 return ieee80211_sta_join_ibss(wpa_s, bss);
2356 if (wpa_s->mlme.state == IEEE80211_IBSS_JOINED &&
2357 !ieee80211_sta_active_ibss(wpa_s)) {
2358 ieee80211_reschedule_timer(wpa_s,
2360 } else if (time_after(jiffies, wpa_s->mlme.last_scan_completed +
2364 return ieee80211_sta_req_scan(wpa_s->mlme.ssid,
2365 wpa_s->mlme.ssid_len);
2366 } else if (wpa_s->mlme.state != IEEE80211_IBSS_JOINED) {
2369 if (time_after(jiffies, wpa_s->mlme.ibss_join_req +
2371 if (wpa_s->mlme.create_ibss &&
2372 ieee80211_ibss_allowed(wpa_s))
2373 return ieee80211_sta_create_ibss(wpa_s);
2374 if (wpa_s->mlme.create_ibss) {
2387 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2388 ieee80211_reschedule_timer(wpa_s, interval);
2397 int ieee80211_sta_get_ssid(struct wpa_supplicant *wpa_s, u8 *ssid,
2400 os_memcpy(ssid, wpa_s->mlme.ssid, wpa_s->mlme.ssid_len);
2401 *len = wpa_s->mlme.ssid_len;
2406 int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
2411 wpa_s->mlme.bssid_set = 0;
2412 wpa_s->mlme.freq = params->freq;
2414 os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
2417 wpa_s->mlme.bssid_set = 1;
2418 bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
2420 wpa_s->mlme.phymode = bss->hw_mode;
2421 wpa_s->mlme.channel = bss->channel;
2422 wpa_s->mlme.freq = bss->freq;
2442 local->hw->conf_tx(wpa_s, i + IEEE80211_TX_QUEUE_DATA0,
2449 local->hw->conf_tx(wpa_s, IEEE80211_TX_QUEUE_BEACON, &qparam);
2453 if (wpa_s->mlme.ssid_len != params->ssid_len ||
2454 os_memcmp(wpa_s->mlme.ssid, params->ssid, params->ssid_len) != 0)
2455 wpa_s->mlme.prev_bssid_set = 0;
2456 os_memcpy(wpa_s->mlme.ssid, params->ssid, params->ssid_len);
2457 os_memset(wpa_s->mlme.ssid + params->ssid_len, 0,
2459 wpa_s->mlme.ssid_len = params->ssid_len;
2460 wpa_s->mlme.ssid_set = 1;
2462 os_free(wpa_s->mlme.extra_ie);
2464 wpa_s->mlme.extra_ie = NULL;
2465 wpa_s->mlme.extra_ie_len = 0;
2468 wpa_s->mlme.extra_ie = os_malloc(params->wpa_ie_len);
2469 if (wpa_s->mlme.extra_ie == NULL) {
2470 wpa_s->mlme.extra_ie_len = 0;
2473 os_memcpy(wpa_s->mlme.extra_ie, params->wpa_ie, params->wpa_ie_len);
2474 wpa_s->mlme.extra_ie_len = params->wpa_ie_len;
2476 wpa_s
2478 ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2479 wpa_s->mlme.channel, wpa_s->mlme.freq);
2481 if (params->mode == 1 && !wpa_s->mlme.bssid_set) {
2482 os_get_time(&wpa_s->mlme.ibss_join_req);
2483 wpa_s->mlme.state = IEEE80211_IBSS_SEARCH;
2484 return ieee80211_sta_find_ibss(wpa_s);
2487 if (wpa_s->mlme.bssid_set)
2488 ieee80211_sta_new_auth(wpa_s);
2494 static void ieee80211_sta_save_oper_chan(struct wpa_supplicant *wpa_s)
2496 wpa_s->mlme.scan_oper_channel = wpa_s->mlme.channel;
2497 wpa_s->mlme.scan_oper_freq = wpa_s->mlme.freq;
2498 wpa_s->mlme.scan_oper_phymode = wpa_s->mlme.phymode;
2502 static int ieee80211_sta_restore_oper_chan(struct wpa_supplicant *wpa_s)
2504 wpa_s->mlme.channel = wpa_s->mlme.scan_oper_channel;
2505 wpa_s->mlme.freq = wpa_s->mlme.scan_oper_freq;
2506 wpa_s->mlme.phymode = wpa_s->mlme.scan_oper_phymode;
2507 if (wpa_s->mlme.freq == 0)
2509 return ieee80211_sta_set_channel(wpa_s, wpa_s->mlme.phymode,
2510 wpa_s->mlme.channel,
2511 wpa_s->mlme.freq);
2515 static int ieee80211_active_scan(struct wpa_supplicant *wpa_s)
2520 for (m = 0; m < wpa_s->mlme.num_modes; m++) {
2521 struct wpa_hw_modes *mode = &wpa_s->mlme.modes[m];
2522 if ((int) mode->mode != (int) wpa_s->mlme.phymode)
2527 chan->chan == wpa_s->mlme.channel) {
2541 struct wpa_supplicant *wpa_s = eloop_ctx;
2546 struct wpa_ssid *ssid = wpa_s->current_ssid;
2549 if (!wpa_s->mlme.sta_scanning || wpa_s->mlme.modes == NULL)
2554 switch (wpa_s->mlme.scan_state) {
2556 mode = &wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx];
2557 if (wpa_s->mlme.scan_hw_mode_idx >=
2558 (int) wpa_s->mlme.num_modes ||
2559 (wpa_s->mlme.scan_hw_mode_idx + 1 ==
2560 (int) wpa_s->mlme.num_modes
2561 && wpa_s->mlme.scan_channel_idx >= mode->num_channels)) {
2562 if (ieee80211_sta_restore_oper_chan(wpa_s)) {
2568 wpa_s->mlme.sta_scanning = 0;
2569 os_get_time(&wpa_s->mlme.last_scan_completed);
2570 wpa_supplicant_event(wpa_s, EVENT_SCAN_RESULTS, NULL);
2572 if (!wpa_s->mlme.bssid_set ||
2573 (wpa_s->mlme.state ==
2575 !ieee80211_sta_active_ibss(wpa_s)))
2576 ieee80211_sta_find_ibss(wpa_s);
2580 skip = !(wpa_s->mlme.hw_modes & (1 << mode->mode));
2581 chan = &mode->channels[wpa_s->mlme.scan_channel_idx];
2584 (wpa_s->mlme.hw_modes & (1 << WPA_MODE_IEEE80211G) &&
2586 wpa_s->mlme.scan_skip_11b))
2594 wpa_s->mlme.channel = chan->chan;
2595 wpa_s->mlme.freq = chan->freq;
2596 wpa_s->mlme.phymode = mode->mode;
2597 if (ieee80211_sta_set_channel(wpa_s, mode->mode,
2607 wpa_s->mlme.scan_channel_idx++;
2608 if (wpa_s->mlme.scan_channel_idx >=
2609 wpa_s->mlme.modes[wpa_s->mlme.scan_hw_mode_idx].
2611 wpa_s->mlme.scan_hw_mode_idx++;
2612 wpa_s->mlme.scan_channel_idx = 0;
2621 wpa_s->mlme.scan_state = SCAN_SEND_PROBE;
2624 if (ieee80211_active_scan(wpa_s)) {
2625 ieee80211_send_probe_req(wpa_s, NULL,
2626 wpa_s->mlme.scan_ssid,
2627 wpa_s->mlme.scan_ssid_len);
2632 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2637 ieee80211_sta_scan_timer, wpa_s, NULL);
2641 int ieee80211_sta_req_scan(struct wpa_supplicant *wpa_s, const u8 *ssid,
2667 if (wpa_s->mlme.sta_scanning)
2672 ieee80211_sta_save_oper_chan(wpa_s);
2674 wpa_s->mlme.sta_scanning = 1;
2678 wpa_s->mlme.scan_ssid_len = ssid_len;
2679 os_memcpy(wpa_s->mlme.scan_ssid, ssid, ssid_len);
2681 wpa_s->mlme.scan_ssid_len = 0;
2682 wpa_s->mlme.scan_skip_11b = 1; /* FIX: clear this is 11g is not
2684 wpa_s->mlme.scan_state = SCAN_SET_CHANNEL;
2685 wpa_s->mlme.scan_hw_mode_idx = 0;
2686 wpa_s->mlme.scan_channel_idx = 0;
2687 eloop_register_timeout(0, 1, ieee80211_sta_scan_timer, wpa_s, NULL);
2693 int ieee80211_sta_get_scan_results(struct wpa_supplicant *wpa_s,
2702 for (bss = wpa_s->mlme.sta_bss_list; bss; bss = bss->next) {
2729 struct sta_info * ieee80211_ibss_add_sta(struct wpa_supplicant *wpa_s,
2765 sta = sta_info_add(wpa_s, addr);
2771 sta->supp_rates = wpa_s->mlme.supp_rates_bits;
2780 int ieee80211_sta_deauthenticate(struct wpa_supplicant *wpa_s, u16 reason)
2784 ieee80211_send_deauth(wpa_s, reason);
2785 ieee80211_set_associated(wpa_s, 0);
2790 int ieee80211_sta_disassociate(struct wpa_supplicant *wpa_s, u16 reason)
2794 if (!wpa_s->mlme.associated)
2797 ieee80211_send_disassoc(wpa_s, reason);
2798 ieee80211_set_associated(wpa_s, 0);
2803 void ieee80211_sta_rx(struct wpa_supplicant *wpa_s, const u8 *buf, size_t len,
2812 if (wpa_s->mlme.sta_scanning) {
2813 ieee80211_sta_rx_scan(wpa_s, buf, len, rx_status);
2824 ieee80211_sta_rx_mgmt(wpa_s, buf, len, rx_status);
2830 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) != 0)
2838 wpa_supplicant_rx_eapol(wpa_s, mgmt->bssid,
2861 int ieee80211_sta_init(struct wpa_supplicant *wpa_s)
2865 wpa_s->mlme.modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes,
2867 if (wpa_s->mlme.modes == NULL) {
2873 wpa_s->mlme.num_modes = num_modes;
2875 wpa_s->mlme.hw_modes = 1 << WPA_MODE_IEEE80211A;
2876 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211B;
2877 wpa_s->mlme.hw_modes |= 1 << WPA_MODE_IEEE80211G;
2883 void ieee80211_sta_deinit(struct wpa_supplicant *wpa_s)
2885 eloop_cancel_timeout(ieee80211_sta_timer, wpa_s, NULL);
2886 eloop_cancel_timeout(ieee80211_sta_scan_timer, wpa_s, NULL);
2887 os_free(wpa_s->mlme.extra_ie);
2888 wpa_s->mlme.extra_ie = NULL;
2889 os_free(wpa_s->mlme.assocreq_ies);
2890 wpa_s->mlme.assocreq_ies = NULL;
2891 os_free(wpa_s->mlme.assocresp_ies);
2892 wpa_s->mlme.assocresp_ies = NULL;
2893 ieee80211_bss_list_deinit(wpa_s);
2894 ieee80211_sta_free_hw_features(wpa_s->mlme.modes,
2895 wpa_s->mlme.num_modes);