16 #include <linux/slab.h>
17 #include <linux/if_ether.h>
19 #include <linux/if_arp.h>
21 #include <linux/rtnetlink.h>
28 #define IEEE80211_SCAN_INTERVAL (2 * HZ)
29 #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
30 #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
32 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
33 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
35 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
41 const u32 basic_rates,
59 drv_reset_tsf(local, sdata);
66 skb_reset_tail_pointer(skb);
67 skb_reserve(skb, sdata->
local->hw.extra_tx_headroom);
69 if (!ether_addr_equal(ifibss->bssid, bssid))
73 if (sdata->
vif.bss_conf.ibss_joined) {
74 sdata->
vif.bss_conf.ibss_joined =
false;
95 sband = local->
hw.wiphy->bands[chan->
band];
102 if (basic_rates &
BIT(i))
104 *pos++ = basic | (
u8) (rate / 5);
108 mgmt = (
void *)
skb_put(skb, 24 +
sizeof(mgmt->
u.beacon));
109 memset(mgmt, 0, 24 +
sizeof(mgmt->
u.beacon));
112 eth_broadcast_addr(mgmt->
da);
130 memcpy(pos, supp_rates, rates);
151 memcpy(pos, &supp_rates[8], rates);
159 if (channel_type && sband->
ht_cap.ht_supported) {
171 chan, channel_type, 0);
190 sdata->
vif.bss_conf.basic_rates = basic_rates;
199 sdata->
vif.bss_conf.ibss_joined =
true;
204 ifibss->
state = IEEE80211_IBSS_MLME_JOINED;
230 sband = sdata->
local->hw.wiphy->bands[cbss->
channel->band];
239 if (sband->
bitrates[j].bitrate == rate) {
241 basic_rates |=
BIT(j);
247 __ieee80211_sta_join_ibss(sdata, cbss->
bssid,
264 ibss_dbg(sdata,
"Adding new IBSS station %pM\n", addr);
270 if (!sta->sdata->u.ibss.control_port)
273 rate_control_rate_init(sta);
278 if (
auth && !sdata->
u.
ibss.auth_frame_registrations) {
280 "TX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=1)\n",
281 sdata->
vif.addr, addr, sdata->
u.
ibss.bssid);
310 if (ifibss->
state == IEEE80211_IBSS_MLME_SEARCH) {
315 if (!ether_addr_equal(
bssid, sdata->
u.
ibss.bssid)) {
329 sta->
sta.supp_rates[band] = supp_rates |
332 return ieee80211_ibss_finish_sta(sta,
auth);
344 ibss_dbg(sdata,
"RX DeAuth SA=%pM DA=%pM BSSID=%pM (reason: %d)\n",
345 mgmt->
sa, mgmt->
da, mgmt->
bssid, reason);
363 auth_transaction =
le16_to_cpu(mgmt->
u.auth.auth_transaction);
368 "RX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=%d)\n",
369 mgmt->
sa, mgmt->
da, mgmt->
bssid, auth_transaction);
371 sta = ieee80211_ibss_add_sta(sdata, mgmt->
bssid, mgmt->
sa, 0,
false);
409 u64 beacon_timestamp, rx_timestamp;
413 bool rates_updated =
false;
419 freq = rx_status->
freq;
421 channel = ieee80211_get_channel(local->
hw.wiphy, freq);
427 ether_addr_equal(mgmt->
bssid, sdata->
u.
ibss.bssid)) {
438 prev_rates = sta->
sta.supp_rates[
band];
440 sta->
sta.supp_rates[
band] = supp_rates |
443 if (sta->
sta.supp_rates[band] != prev_rates) {
445 "updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n",
446 sta->
sta.addr, prev_rates,
447 sta->
sta.supp_rates[band]);
448 rates_updated =
true;
452 sta = ieee80211_ibss_add_sta(sdata, mgmt->
bssid,
453 mgmt->
sa, supp_rates,
true);
478 channel_type != sdata->
u.
ibss.channel_type)
479 sta_ht_cap_new.cap &=
482 if (
memcmp(&sta->
sta.ht_cap, &sta_ht_cap_new,
483 sizeof(sta_ht_cap_new))) {
484 memcpy(&sta->
sta.ht_cap, &sta_ht_cap_new,
485 sizeof(sta_ht_cap_new));
486 rates_updated =
true;
490 if (sta && rates_updated) {
491 drv_sta_rc_update(local, sdata, &sta->
sta,
493 rate_control_rate_init(sta);
507 beacon_timestamp = cbss->
tsf;
512 if (sdata->
u.
ibss.fixed_bssid)
526 sdata->
u.
ibss.ssid_len))
530 if (ether_addr_equal(cbss->
bssid, sdata->
u.
ibss.bssid))
553 rate = local->
hw.wiphy->bands[band]->
554 bitrates[rx_status->
rate_idx].bitrate;
556 rx_timestamp = rx_status->
mactime + (24 * 8 * 10 /
rate);
562 rx_timestamp = drv_get_tsf(local, sdata);
566 "RX beacon SA=%pM BSSID=%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
568 (
unsigned long long)rx_timestamp,
569 (
unsigned long long)beacon_timestamp,
570 (
unsigned long long)(rx_timestamp - beacon_timestamp),
573 if (beacon_timestamp > rx_timestamp) {
575 "beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n",
577 ieee80211_sta_join_ibss(sdata, bss);
579 ieee80211_ibss_add_sta(sdata, mgmt->
bssid, mgmt->
sa,
607 if (ifibss->
state == IEEE80211_IBSS_MLME_SEARCH)
610 if (!ether_addr_equal(bssid, sdata->
u.
ibss.bssid))
620 sta->
sta.supp_rates[band] = supp_rates |
640 if (sta->
sdata == sdata &&
672 if (ieee80211_sta_active_ibss(sdata))
679 "No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n");
702 bssid[i] ^= sdata->
vif.addr[i];
707 sdata_info(sdata,
"Creating new IBSS network, BSSID %pM\n", bssid);
716 __ieee80211_sta_join_ibss(sdata, bssid, sdata->
vif.bss_conf.beacon_int,
737 active_ibss = ieee80211_sta_active_ibss(sdata);
738 ibss_dbg(sdata,
"sta_find_ibss (active_ibss=%d)\n", active_ibss);
747 bssid = ifibss->bssid;
750 if (!is_zero_ether_addr(ifibss->bssid))
751 bssid = ifibss->bssid;
760 bss = (
void *)cbss->priv;
762 "sta_find_ibss: selected %pM current %pM\n",
763 cbss->
bssid, ifibss->bssid);
765 "Selected IBSS BSSID %pM based on configured SSID\n",
768 ieee80211_sta_join_ibss(sdata, bss);
773 ibss_dbg(sdata,
"sta_find_ibss: did not try to join ibss\n");
778 sdata_info(sdata,
"Trigger new scan to find an IBSS to join\n");
789 ieee80211_sta_create_ibss(sdata);
792 sdata_info(sdata,
"IBSS not allowed on %d MHz\n",
811 int tx_last_beacon, len = req->
len;
820 lockdep_is_held(&ifibss->
mtx));
822 if (ifibss->
state != IEEE80211_IBSS_MLME_JOINED ||
823 len < 24 + 2 || !presp)
826 tx_last_beacon = drv_tx_last_beacon(local);
829 "RX ProbeReq SA=%pM DA=%pM BSSID=%pM (tx_last_beacon=%d)\n",
830 mgmt->
sa, mgmt->
da, mgmt->
bssid, tx_last_beacon);
832 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->
da))
835 if (!ether_addr_equal(mgmt->
bssid, ifibss->bssid) &&
836 !is_broadcast_ether_addr(mgmt->
bssid))
839 end = ((
u8 *) mgmt) + len;
840 pos = mgmt->
u.probe_req.variable;
842 pos + 2 + pos[1] >
end) {
843 ibss_dbg(sdata,
"Invalid SSID IE in ProbeReq from %pM\n",
861 ibss_dbg(sdata,
"Sending ProbeResp to %pM\n",
resp->da);
863 ieee80211_tx_skb(sdata,
skb);
874 baselen = (
u8 *) mgmt->
u.probe_resp.variable - (
u8 *)
mgmt;
881 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
false);
893 baselen = (
u8 *) mgmt->
u.beacon.variable - (
u8 *)
mgmt;
899 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
true);
909 rx_status = IEEE80211_SKB_RXCB(skb);
915 if (!sdata->
u.
ibss.ssid_len)
920 ieee80211_rx_mgmt_probe_req(sdata, skb);
923 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->
len,
927 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->
len,
931 ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->
len);
934 ieee80211_rx_mgmt_deauth_ibss(sdata, mgmt, skb->
len);
964 ieee80211_ibss_finish_sta(sta,
true);
970 switch (ifibss->
state) {
971 case IEEE80211_IBSS_MLME_SEARCH:
972 ieee80211_sta_find_ibss(sdata);
974 case IEEE80211_IBSS_MLME_JOINED:
975 ieee80211_sta_merge_ibss(sdata);
986 static void ieee80211_ibss_timer(
unsigned long data)
1026 (
unsigned long) sdata);
1039 if (!ieee80211_sdata_running(sdata))
1055 skb = dev_alloc_skb(sdata->
local->hw.extra_tx_headroom +
1071 if (params->
bssid) {
1073 sdata->
u.
ibss.fixed_bssid =
true;
1075 sdata->
u.
ibss.fixed_bssid =
false;
1103 if (sdata->
u.
ibss.ie)
1108 sdata->
u.
ibss.state = IEEE80211_IBSS_MLME_SEARCH;
1130 sdata->
vif.bss_conf.ht_operation_mode |=
1154 active_ibss = ieee80211_sta_active_ibss(sdata);
1156 if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
1163 ifibss->bssid, ifibss->
ssid,
1174 ifibss->
state = IEEE80211_IBSS_MLME_SEARCH;
1197 lockdep_is_held(&sdata->
u.
ibss.mtx));
1199 sdata->
vif.bss_conf.ibss_joined =
false;