ibss.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /*
  2. * IBSS mode implementation
  3. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/slab.h>
  16. #include <linux/if_ether.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/rtnetlink.h>
  21. #include <net/mac80211.h>
  22. #include <asm/unaligned.h>
  23. #include "ieee80211_i.h"
  24. #include "driver-ops.h"
  25. #include "rate.h"
  26. #define IEEE80211_SCAN_INTERVAL (2 * HZ)
  27. #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
  28. #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
  29. #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
  30. #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
  31. #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
  32. static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
  33. struct ieee80211_mgmt *mgmt,
  34. size_t len)
  35. {
  36. u16 auth_alg, auth_transaction;
  37. lockdep_assert_held(&sdata->u.ibss.mtx);
  38. if (len < 24 + 6)
  39. return;
  40. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  41. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  42. /*
  43. * IEEE 802.11 standard does not require authentication in IBSS
  44. * networks and most implementations do not seem to use it.
  45. * However, try to reply to authentication attempts if someone
  46. * has actually implemented this.
  47. */
  48. if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1)
  49. ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0,
  50. sdata->u.ibss.bssid, NULL, 0, 0);
  51. }
  52. static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
  53. const u8 *bssid, const int beacon_int,
  54. struct ieee80211_channel *chan,
  55. const u32 basic_rates,
  56. const u16 capability, u64 tsf)
  57. {
  58. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  59. struct ieee80211_local *local = sdata->local;
  60. int rates, i;
  61. struct sk_buff *skb;
  62. struct ieee80211_mgmt *mgmt;
  63. u8 *pos;
  64. struct ieee80211_supported_band *sband;
  65. struct cfg80211_bss *bss;
  66. u32 bss_change;
  67. u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
  68. enum nl80211_channel_type channel_type;
  69. lockdep_assert_held(&ifibss->mtx);
  70. /* Reset own TSF to allow time synchronization work. */
  71. drv_reset_tsf(local, sdata);
  72. skb = ifibss->skb;
  73. RCU_INIT_POINTER(ifibss->presp, NULL);
  74. synchronize_rcu();
  75. skb->data = skb->head;
  76. skb->len = 0;
  77. skb_reset_tail_pointer(skb);
  78. skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
  79. if (memcmp(ifibss->bssid, bssid, ETH_ALEN))
  80. sta_info_flush(sdata->local, sdata);
  81. /* if merging, indicate to driver that we leave the old IBSS */
  82. if (sdata->vif.bss_conf.ibss_joined) {
  83. sdata->vif.bss_conf.ibss_joined = false;
  84. netif_carrier_off(sdata->dev);
  85. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IBSS);
  86. }
  87. memcpy(ifibss->bssid, bssid, ETH_ALEN);
  88. sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
  89. channel_type = ifibss->channel_type;
  90. if (channel_type > NL80211_CHAN_HT20 &&
  91. !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
  92. channel_type = NL80211_CHAN_HT20;
  93. if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
  94. /* can only fail due to HT40+/- mismatch */
  95. channel_type = NL80211_CHAN_HT20;
  96. WARN_ON(!ieee80211_set_channel_type(local, sdata,
  97. NL80211_CHAN_HT20));
  98. }
  99. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  100. sband = local->hw.wiphy->bands[chan->band];
  101. /* build supported rates array */
  102. pos = supp_rates;
  103. for (i = 0; i < sband->n_bitrates; i++) {
  104. int rate = sband->bitrates[i].bitrate;
  105. u8 basic = 0;
  106. if (basic_rates & BIT(i))
  107. basic = 0x80;
  108. *pos++ = basic | (u8) (rate / 5);
  109. }
  110. /* Build IBSS probe response */
  111. mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon));
  112. memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  113. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  114. IEEE80211_STYPE_PROBE_RESP);
  115. memset(mgmt->da, 0xff, ETH_ALEN);
  116. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  117. memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
  118. mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int);
  119. mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
  120. mgmt->u.beacon.capab_info = cpu_to_le16(capability);
  121. pos = skb_put(skb, 2 + ifibss->ssid_len);
  122. *pos++ = WLAN_EID_SSID;
  123. *pos++ = ifibss->ssid_len;
  124. memcpy(pos, ifibss->ssid, ifibss->ssid_len);
  125. rates = sband->n_bitrates;
  126. if (rates > 8)
  127. rates = 8;
  128. pos = skb_put(skb, 2 + rates);
  129. *pos++ = WLAN_EID_SUPP_RATES;
  130. *pos++ = rates;
  131. memcpy(pos, supp_rates, rates);
  132. if (sband->band == IEEE80211_BAND_2GHZ) {
  133. pos = skb_put(skb, 2 + 1);
  134. *pos++ = WLAN_EID_DS_PARAMS;
  135. *pos++ = 1;
  136. *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
  137. }
  138. pos = skb_put(skb, 2 + 2);
  139. *pos++ = WLAN_EID_IBSS_PARAMS;
  140. *pos++ = 2;
  141. /* FIX: set ATIM window based on scan results */
  142. *pos++ = 0;
  143. *pos++ = 0;
  144. if (sband->n_bitrates > 8) {
  145. rates = sband->n_bitrates - 8;
  146. pos = skb_put(skb, 2 + rates);
  147. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  148. *pos++ = rates;
  149. memcpy(pos, &supp_rates[8], rates);
  150. }
  151. if (ifibss->ie_len)
  152. memcpy(skb_put(skb, ifibss->ie_len),
  153. ifibss->ie, ifibss->ie_len);
  154. /* add HT capability and information IEs */
  155. if (channel_type && sband->ht_cap.ht_supported) {
  156. pos = skb_put(skb, 4 +
  157. sizeof(struct ieee80211_ht_cap) +
  158. sizeof(struct ieee80211_ht_info));
  159. pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
  160. sband->ht_cap.cap);
  161. pos = ieee80211_ie_build_ht_info(pos,
  162. &sband->ht_cap,
  163. chan,
  164. channel_type);
  165. }
  166. if (local->hw.queues >= 4) {
  167. pos = skb_put(skb, 9);
  168. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  169. *pos++ = 7; /* len */
  170. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  171. *pos++ = 0x50;
  172. *pos++ = 0xf2;
  173. *pos++ = 2; /* WME */
  174. *pos++ = 0; /* WME info */
  175. *pos++ = 1; /* WME ver */
  176. *pos++ = 0; /* U-APSD no in use */
  177. }
  178. rcu_assign_pointer(ifibss->presp, skb);
  179. sdata->vif.bss_conf.beacon_int = beacon_int;
  180. sdata->vif.bss_conf.basic_rates = basic_rates;
  181. bss_change = BSS_CHANGED_BEACON_INT;
  182. bss_change |= ieee80211_reset_erp_info(sdata);
  183. bss_change |= BSS_CHANGED_BSSID;
  184. bss_change |= BSS_CHANGED_BEACON;
  185. bss_change |= BSS_CHANGED_BEACON_ENABLED;
  186. bss_change |= BSS_CHANGED_BASIC_RATES;
  187. bss_change |= BSS_CHANGED_HT;
  188. bss_change |= BSS_CHANGED_IBSS;
  189. sdata->vif.bss_conf.ibss_joined = true;
  190. ieee80211_bss_info_change_notify(sdata, bss_change);
  191. ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
  192. ifibss->state = IEEE80211_IBSS_MLME_JOINED;
  193. mod_timer(&ifibss->timer,
  194. round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
  195. bss = cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
  196. mgmt, skb->len, 0, GFP_KERNEL);
  197. cfg80211_put_bss(bss);
  198. netif_carrier_on(sdata->dev);
  199. cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
  200. }
  201. static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
  202. struct ieee80211_bss *bss)
  203. {
  204. struct cfg80211_bss *cbss =
  205. container_of((void *)bss, struct cfg80211_bss, priv);
  206. struct ieee80211_supported_band *sband;
  207. u32 basic_rates;
  208. int i, j;
  209. u16 beacon_int = cbss->beacon_interval;
  210. lockdep_assert_held(&sdata->u.ibss.mtx);
  211. if (beacon_int < 10)
  212. beacon_int = 10;
  213. sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
  214. basic_rates = 0;
  215. for (i = 0; i < bss->supp_rates_len; i++) {
  216. int rate = (bss->supp_rates[i] & 0x7f) * 5;
  217. bool is_basic = !!(bss->supp_rates[i] & 0x80);
  218. for (j = 0; j < sband->n_bitrates; j++) {
  219. if (sband->bitrates[j].bitrate == rate) {
  220. if (is_basic)
  221. basic_rates |= BIT(j);
  222. break;
  223. }
  224. }
  225. }
  226. __ieee80211_sta_join_ibss(sdata, cbss->bssid,
  227. beacon_int,
  228. cbss->channel,
  229. basic_rates,
  230. cbss->capability,
  231. cbss->tsf);
  232. }
  233. static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta)
  234. __acquires(RCU)
  235. {
  236. struct ieee80211_sub_if_data *sdata = sta->sdata;
  237. u8 addr[ETH_ALEN];
  238. memcpy(addr, sta->sta.addr, ETH_ALEN);
  239. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  240. wiphy_debug(sdata->local->hw.wiphy,
  241. "Adding new IBSS station %pM (dev=%s)\n",
  242. addr, sdata->name);
  243. #endif
  244. sta_info_move_state(sta, IEEE80211_STA_AUTH);
  245. sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  246. sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  247. rate_control_rate_init(sta);
  248. /* If it fails, maybe we raced another insertion? */
  249. if (sta_info_insert_rcu(sta))
  250. return sta_info_get(sdata, addr);
  251. return sta;
  252. }
  253. static struct sta_info *
  254. ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
  255. const u8 *bssid, const u8 *addr,
  256. u32 supp_rates)
  257. __acquires(RCU)
  258. {
  259. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  260. struct ieee80211_local *local = sdata->local;
  261. struct sta_info *sta;
  262. int band = local->hw.conf.channel->band;
  263. /*
  264. * XXX: Consider removing the least recently used entry and
  265. * allow new one to be added.
  266. */
  267. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  268. if (net_ratelimit())
  269. printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
  270. sdata->name, addr);
  271. rcu_read_lock();
  272. return NULL;
  273. }
  274. if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH) {
  275. rcu_read_lock();
  276. return NULL;
  277. }
  278. if (compare_ether_addr(bssid, sdata->u.ibss.bssid)) {
  279. rcu_read_lock();
  280. return NULL;
  281. }
  282. sta = sta_info_alloc(sdata, addr, GFP_KERNEL);
  283. if (!sta) {
  284. rcu_read_lock();
  285. return NULL;
  286. }
  287. sta->last_rx = jiffies;
  288. /* make sure mandatory rates are always added */
  289. sta->sta.supp_rates[band] = supp_rates |
  290. ieee80211_mandatory_rates(local, band);
  291. return ieee80211_ibss_finish_sta(sta);
  292. }
  293. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  294. struct ieee80211_mgmt *mgmt,
  295. size_t len,
  296. struct ieee80211_rx_status *rx_status,
  297. struct ieee802_11_elems *elems,
  298. bool beacon)
  299. {
  300. struct ieee80211_local *local = sdata->local;
  301. int freq;
  302. struct cfg80211_bss *cbss;
  303. struct ieee80211_bss *bss;
  304. struct sta_info *sta;
  305. struct ieee80211_channel *channel;
  306. u64 beacon_timestamp, rx_timestamp;
  307. u32 supp_rates = 0;
  308. enum ieee80211_band band = rx_status->band;
  309. struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
  310. bool rates_updated = false;
  311. if (elems->ds_params && elems->ds_params_len == 1)
  312. freq = ieee80211_channel_to_frequency(elems->ds_params[0],
  313. band);
  314. else
  315. freq = rx_status->freq;
  316. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  317. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  318. return;
  319. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  320. memcmp(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0) {
  321. rcu_read_lock();
  322. sta = sta_info_get(sdata, mgmt->sa);
  323. if (elems->supp_rates) {
  324. supp_rates = ieee80211_sta_get_rates(local, elems,
  325. band);
  326. if (sta) {
  327. u32 prev_rates;
  328. prev_rates = sta->sta.supp_rates[band];
  329. /* make sure mandatory rates are always added */
  330. sta->sta.supp_rates[band] = supp_rates |
  331. ieee80211_mandatory_rates(local, band);
  332. if (sta->sta.supp_rates[band] != prev_rates) {
  333. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  334. printk(KERN_DEBUG
  335. "%s: updated supp_rates set "
  336. "for %pM based on beacon"
  337. "/probe_resp (0x%x -> 0x%x)\n",
  338. sdata->name, sta->sta.addr,
  339. prev_rates,
  340. sta->sta.supp_rates[band]);
  341. #endif
  342. rates_updated = true;
  343. }
  344. } else {
  345. rcu_read_unlock();
  346. sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid,
  347. mgmt->sa, supp_rates);
  348. }
  349. }
  350. if (sta && elems->wmm_info)
  351. set_sta_flag(sta, WLAN_STA_WME);
  352. if (sta && elems->ht_info_elem && elems->ht_cap_elem &&
  353. sdata->u.ibss.channel_type != NL80211_CHAN_NO_HT) {
  354. /* we both use HT */
  355. struct ieee80211_sta_ht_cap sta_ht_cap_new;
  356. enum nl80211_channel_type channel_type =
  357. ieee80211_ht_info_to_channel_type(
  358. elems->ht_info_elem);
  359. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  360. elems->ht_cap_elem,
  361. &sta_ht_cap_new);
  362. /*
  363. * fall back to HT20 if we don't use or use
  364. * the other extension channel
  365. */
  366. if ((channel_type == NL80211_CHAN_HT40MINUS ||
  367. channel_type == NL80211_CHAN_HT40PLUS) &&
  368. channel_type != sdata->u.ibss.channel_type)
  369. sta_ht_cap_new.cap &=
  370. ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  371. if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new,
  372. sizeof(sta_ht_cap_new))) {
  373. memcpy(&sta->sta.ht_cap, &sta_ht_cap_new,
  374. sizeof(sta_ht_cap_new));
  375. rates_updated = true;
  376. }
  377. }
  378. if (sta && rates_updated)
  379. rate_control_rate_init(sta);
  380. rcu_read_unlock();
  381. }
  382. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  383. channel, beacon);
  384. if (!bss)
  385. return;
  386. cbss = container_of((void *)bss, struct cfg80211_bss, priv);
  387. /* was just updated in ieee80211_bss_info_update */
  388. beacon_timestamp = cbss->tsf;
  389. /* check if we need to merge IBSS */
  390. /* we use a fixed BSSID */
  391. if (sdata->u.ibss.fixed_bssid)
  392. goto put_bss;
  393. /* not an IBSS */
  394. if (!(cbss->capability & WLAN_CAPABILITY_IBSS))
  395. goto put_bss;
  396. /* different channel */
  397. if (cbss->channel != local->oper_channel)
  398. goto put_bss;
  399. /* different SSID */
  400. if (elems->ssid_len != sdata->u.ibss.ssid_len ||
  401. memcmp(elems->ssid, sdata->u.ibss.ssid,
  402. sdata->u.ibss.ssid_len))
  403. goto put_bss;
  404. /* same BSSID */
  405. if (memcmp(cbss->bssid, sdata->u.ibss.bssid, ETH_ALEN) == 0)
  406. goto put_bss;
  407. if (rx_status->flag & RX_FLAG_MACTIME_MPDU) {
  408. /*
  409. * For correct IBSS merging we need mactime; since mactime is
  410. * defined as the time the first data symbol of the frame hits
  411. * the PHY, and the timestamp of the beacon is defined as "the
  412. * time that the data symbol containing the first bit of the
  413. * timestamp is transmitted to the PHY plus the transmitting
  414. * STA's delays through its local PHY from the MAC-PHY
  415. * interface to its interface with the WM" (802.11 11.1.2)
  416. * - equals the time this bit arrives at the receiver - we have
  417. * to take into account the offset between the two.
  418. *
  419. * E.g. at 1 MBit that means mactime is 192 usec earlier
  420. * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
  421. */
  422. int rate;
  423. if (rx_status->flag & RX_FLAG_HT)
  424. rate = 65; /* TODO: HT rates */
  425. else
  426. rate = local->hw.wiphy->bands[band]->
  427. bitrates[rx_status->rate_idx].bitrate;
  428. rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
  429. } else {
  430. /*
  431. * second best option: get current TSF
  432. * (will return -1 if not supported)
  433. */
  434. rx_timestamp = drv_get_tsf(local, sdata);
  435. }
  436. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  437. printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
  438. "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
  439. mgmt->sa, mgmt->bssid,
  440. (unsigned long long)rx_timestamp,
  441. (unsigned long long)beacon_timestamp,
  442. (unsigned long long)(rx_timestamp - beacon_timestamp),
  443. jiffies);
  444. #endif
  445. if (beacon_timestamp > rx_timestamp) {
  446. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  447. printk(KERN_DEBUG "%s: beacon TSF higher than "
  448. "local TSF - IBSS merge with BSSID %pM\n",
  449. sdata->name, mgmt->bssid);
  450. #endif
  451. ieee80211_sta_join_ibss(sdata, bss);
  452. supp_rates = ieee80211_sta_get_rates(local, elems, band);
  453. ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
  454. supp_rates);
  455. rcu_read_unlock();
  456. }
  457. put_bss:
  458. ieee80211_rx_bss_put(local, bss);
  459. }
  460. void ieee80211_ibss_rx_no_sta(struct ieee80211_sub_if_data *sdata,
  461. const u8 *bssid, const u8 *addr,
  462. u32 supp_rates)
  463. {
  464. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  465. struct ieee80211_local *local = sdata->local;
  466. struct sta_info *sta;
  467. int band = local->hw.conf.channel->band;
  468. /*
  469. * XXX: Consider removing the least recently used entry and
  470. * allow new one to be added.
  471. */
  472. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  473. if (net_ratelimit())
  474. printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
  475. sdata->name, addr);
  476. return;
  477. }
  478. if (ifibss->state == IEEE80211_IBSS_MLME_SEARCH)
  479. return;
  480. if (compare_ether_addr(bssid, sdata->u.ibss.bssid))
  481. return;
  482. sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
  483. if (!sta)
  484. return;
  485. sta->last_rx = jiffies;
  486. /* make sure mandatory rates are always added */
  487. sta->sta.supp_rates[band] = supp_rates |
  488. ieee80211_mandatory_rates(local, band);
  489. spin_lock(&ifibss->incomplete_lock);
  490. list_add(&sta->list, &ifibss->incomplete_stations);
  491. spin_unlock(&ifibss->incomplete_lock);
  492. ieee80211_queue_work(&local->hw, &sdata->work);
  493. }
  494. static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
  495. {
  496. struct ieee80211_local *local = sdata->local;
  497. int active = 0;
  498. struct sta_info *sta;
  499. lockdep_assert_held(&sdata->u.ibss.mtx);
  500. rcu_read_lock();
  501. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  502. if (sta->sdata == sdata &&
  503. time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
  504. jiffies)) {
  505. active++;
  506. break;
  507. }
  508. }
  509. rcu_read_unlock();
  510. return active;
  511. }
  512. /*
  513. * This function is called with state == IEEE80211_IBSS_MLME_JOINED
  514. */
  515. static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
  516. {
  517. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  518. lockdep_assert_held(&ifibss->mtx);
  519. mod_timer(&ifibss->timer,
  520. round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
  521. ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
  522. if (time_before(jiffies, ifibss->last_scan_completed +
  523. IEEE80211_IBSS_MERGE_INTERVAL))
  524. return;
  525. if (ieee80211_sta_active_ibss(sdata))
  526. return;
  527. if (ifibss->fixed_channel)
  528. return;
  529. printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
  530. "IBSS networks with same SSID (merge)\n", sdata->name);
  531. ieee80211_request_internal_scan(sdata,
  532. ifibss->ssid, ifibss->ssid_len,
  533. ifibss->fixed_channel ? ifibss->channel : NULL);
  534. }
  535. static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
  536. {
  537. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  538. u8 bssid[ETH_ALEN];
  539. u16 capability;
  540. int i;
  541. lockdep_assert_held(&ifibss->mtx);
  542. if (ifibss->fixed_bssid) {
  543. memcpy(bssid, ifibss->bssid, ETH_ALEN);
  544. } else {
  545. /* Generate random, not broadcast, locally administered BSSID. Mix in
  546. * own MAC address to make sure that devices that do not have proper
  547. * random number generator get different BSSID. */
  548. get_random_bytes(bssid, ETH_ALEN);
  549. for (i = 0; i < ETH_ALEN; i++)
  550. bssid[i] ^= sdata->vif.addr[i];
  551. bssid[0] &= ~0x01;
  552. bssid[0] |= 0x02;
  553. }
  554. printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
  555. sdata->name, bssid);
  556. capability = WLAN_CAPABILITY_IBSS;
  557. if (ifibss->privacy)
  558. capability |= WLAN_CAPABILITY_PRIVACY;
  559. else
  560. sdata->drop_unencrypted = 0;
  561. __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
  562. ifibss->channel, ifibss->basic_rates,
  563. capability, 0);
  564. }
  565. /*
  566. * This function is called with state == IEEE80211_IBSS_MLME_SEARCH
  567. */
  568. static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
  569. {
  570. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  571. struct ieee80211_local *local = sdata->local;
  572. struct cfg80211_bss *cbss;
  573. struct ieee80211_channel *chan = NULL;
  574. const u8 *bssid = NULL;
  575. int active_ibss;
  576. u16 capability;
  577. lockdep_assert_held(&ifibss->mtx);
  578. active_ibss = ieee80211_sta_active_ibss(sdata);
  579. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  580. printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
  581. sdata->name, active_ibss);
  582. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  583. if (active_ibss)
  584. return;
  585. capability = WLAN_CAPABILITY_IBSS;
  586. if (ifibss->privacy)
  587. capability |= WLAN_CAPABILITY_PRIVACY;
  588. if (ifibss->fixed_bssid)
  589. bssid = ifibss->bssid;
  590. if (ifibss->fixed_channel)
  591. chan = ifibss->channel;
  592. if (!is_zero_ether_addr(ifibss->bssid))
  593. bssid = ifibss->bssid;
  594. cbss = cfg80211_get_bss(local->hw.wiphy, chan, bssid,
  595. ifibss->ssid, ifibss->ssid_len,
  596. WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_PRIVACY,
  597. capability);
  598. if (cbss) {
  599. struct ieee80211_bss *bss;
  600. bss = (void *)cbss->priv;
  601. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  602. printk(KERN_DEBUG " sta_find_ibss: selected %pM current "
  603. "%pM\n", cbss->bssid, ifibss->bssid);
  604. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  605. printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
  606. " based on configured SSID\n",
  607. sdata->name, cbss->bssid);
  608. ieee80211_sta_join_ibss(sdata, bss);
  609. ieee80211_rx_bss_put(local, bss);
  610. return;
  611. }
  612. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  613. printk(KERN_DEBUG " did not try to join ibss\n");
  614. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  615. /* Selected IBSS not found in current scan results - try to scan */
  616. if (time_after(jiffies, ifibss->last_scan_completed +
  617. IEEE80211_SCAN_INTERVAL)) {
  618. printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
  619. "join\n", sdata->name);
  620. ieee80211_request_internal_scan(sdata,
  621. ifibss->ssid, ifibss->ssid_len,
  622. ifibss->fixed_channel ? ifibss->channel : NULL);
  623. } else {
  624. int interval = IEEE80211_SCAN_INTERVAL;
  625. if (time_after(jiffies, ifibss->ibss_join_req +
  626. IEEE80211_IBSS_JOIN_TIMEOUT)) {
  627. if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) {
  628. ieee80211_sta_create_ibss(sdata);
  629. return;
  630. }
  631. printk(KERN_DEBUG "%s: IBSS not allowed on"
  632. " %d MHz\n", sdata->name,
  633. local->hw.conf.channel->center_freq);
  634. /* No IBSS found - decrease scan interval and continue
  635. * scanning. */
  636. interval = IEEE80211_SCAN_INTERVAL_SLOW;
  637. }
  638. mod_timer(&ifibss->timer,
  639. round_jiffies(jiffies + interval));
  640. }
  641. }
  642. static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
  643. struct sk_buff *req)
  644. {
  645. struct ieee80211_mgmt *mgmt = (void *)req->data;
  646. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  647. struct ieee80211_local *local = sdata->local;
  648. int tx_last_beacon, len = req->len;
  649. struct sk_buff *skb;
  650. struct ieee80211_mgmt *resp;
  651. struct sk_buff *presp;
  652. u8 *pos, *end;
  653. lockdep_assert_held(&ifibss->mtx);
  654. presp = rcu_dereference_protected(ifibss->presp,
  655. lockdep_is_held(&ifibss->mtx));
  656. if (ifibss->state != IEEE80211_IBSS_MLME_JOINED ||
  657. len < 24 + 2 || !presp)
  658. return;
  659. tx_last_beacon = drv_tx_last_beacon(local);
  660. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  661. printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
  662. " (tx_last_beacon=%d)\n",
  663. sdata->name, mgmt->sa, mgmt->da,
  664. mgmt->bssid, tx_last_beacon);
  665. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  666. if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da))
  667. return;
  668. if (memcmp(mgmt->bssid, ifibss->bssid, ETH_ALEN) != 0 &&
  669. memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
  670. return;
  671. end = ((u8 *) mgmt) + len;
  672. pos = mgmt->u.probe_req.variable;
  673. if (pos[0] != WLAN_EID_SSID ||
  674. pos + 2 + pos[1] > end) {
  675. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  676. printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
  677. "from %pM\n",
  678. sdata->name, mgmt->sa);
  679. #endif
  680. return;
  681. }
  682. if (pos[1] != 0 &&
  683. (pos[1] != ifibss->ssid_len ||
  684. memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) {
  685. /* Ignore ProbeReq for foreign SSID */
  686. return;
  687. }
  688. /* Reply with ProbeResp */
  689. skb = skb_copy(presp, GFP_KERNEL);
  690. if (!skb)
  691. return;
  692. resp = (struct ieee80211_mgmt *) skb->data;
  693. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  694. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  695. printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
  696. sdata->name, resp->da);
  697. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  698. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  699. ieee80211_tx_skb(sdata, skb);
  700. }
  701. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  702. struct ieee80211_mgmt *mgmt,
  703. size_t len,
  704. struct ieee80211_rx_status *rx_status)
  705. {
  706. size_t baselen;
  707. struct ieee802_11_elems elems;
  708. if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
  709. return; /* ignore ProbeResp to foreign address */
  710. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  711. if (baselen > len)
  712. return;
  713. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  714. &elems);
  715. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  716. }
  717. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  718. struct ieee80211_mgmt *mgmt,
  719. size_t len,
  720. struct ieee80211_rx_status *rx_status)
  721. {
  722. size_t baselen;
  723. struct ieee802_11_elems elems;
  724. /* Process beacon from the current BSS */
  725. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  726. if (baselen > len)
  727. return;
  728. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  729. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  730. }
  731. void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  732. struct sk_buff *skb)
  733. {
  734. struct ieee80211_rx_status *rx_status;
  735. struct ieee80211_mgmt *mgmt;
  736. u16 fc;
  737. rx_status = IEEE80211_SKB_RXCB(skb);
  738. mgmt = (struct ieee80211_mgmt *) skb->data;
  739. fc = le16_to_cpu(mgmt->frame_control);
  740. mutex_lock(&sdata->u.ibss.mtx);
  741. if (!sdata->u.ibss.ssid_len)
  742. goto mgmt_out; /* not ready to merge yet */
  743. switch (fc & IEEE80211_FCTL_STYPE) {
  744. case IEEE80211_STYPE_PROBE_REQ:
  745. ieee80211_rx_mgmt_probe_req(sdata, skb);
  746. break;
  747. case IEEE80211_STYPE_PROBE_RESP:
  748. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
  749. rx_status);
  750. break;
  751. case IEEE80211_STYPE_BEACON:
  752. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  753. rx_status);
  754. break;
  755. case IEEE80211_STYPE_AUTH:
  756. ieee80211_rx_mgmt_auth_ibss(sdata, mgmt, skb->len);
  757. break;
  758. }
  759. mgmt_out:
  760. mutex_unlock(&sdata->u.ibss.mtx);
  761. }
  762. void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)
  763. {
  764. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  765. struct sta_info *sta;
  766. mutex_lock(&ifibss->mtx);
  767. /*
  768. * Work could be scheduled after scan or similar
  769. * when we aren't even joined (or trying) with a
  770. * network.
  771. */
  772. if (!ifibss->ssid_len)
  773. goto out;
  774. spin_lock_bh(&ifibss->incomplete_lock);
  775. while (!list_empty(&ifibss->incomplete_stations)) {
  776. sta = list_first_entry(&ifibss->incomplete_stations,
  777. struct sta_info, list);
  778. list_del(&sta->list);
  779. spin_unlock_bh(&ifibss->incomplete_lock);
  780. ieee80211_ibss_finish_sta(sta);
  781. rcu_read_unlock();
  782. spin_lock_bh(&ifibss->incomplete_lock);
  783. }
  784. spin_unlock_bh(&ifibss->incomplete_lock);
  785. switch (ifibss->state) {
  786. case IEEE80211_IBSS_MLME_SEARCH:
  787. ieee80211_sta_find_ibss(sdata);
  788. break;
  789. case IEEE80211_IBSS_MLME_JOINED:
  790. ieee80211_sta_merge_ibss(sdata);
  791. break;
  792. default:
  793. WARN_ON(1);
  794. break;
  795. }
  796. out:
  797. mutex_unlock(&ifibss->mtx);
  798. }
  799. static void ieee80211_ibss_timer(unsigned long data)
  800. {
  801. struct ieee80211_sub_if_data *sdata =
  802. (struct ieee80211_sub_if_data *) data;
  803. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  804. struct ieee80211_local *local = sdata->local;
  805. if (local->quiescing) {
  806. ifibss->timer_running = true;
  807. return;
  808. }
  809. ieee80211_queue_work(&local->hw, &sdata->work);
  810. }
  811. #ifdef CONFIG_PM
  812. void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata)
  813. {
  814. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  815. if (del_timer_sync(&ifibss->timer))
  816. ifibss->timer_running = true;
  817. }
  818. void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata)
  819. {
  820. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  821. if (ifibss->timer_running) {
  822. add_timer(&ifibss->timer);
  823. ifibss->timer_running = false;
  824. }
  825. }
  826. #endif
  827. void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
  828. {
  829. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  830. setup_timer(&ifibss->timer, ieee80211_ibss_timer,
  831. (unsigned long) sdata);
  832. mutex_init(&ifibss->mtx);
  833. INIT_LIST_HEAD(&ifibss->incomplete_stations);
  834. spin_lock_init(&ifibss->incomplete_lock);
  835. }
  836. /* scan finished notification */
  837. void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
  838. {
  839. struct ieee80211_sub_if_data *sdata;
  840. mutex_lock(&local->iflist_mtx);
  841. list_for_each_entry(sdata, &local->interfaces, list) {
  842. if (!ieee80211_sdata_running(sdata))
  843. continue;
  844. if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
  845. continue;
  846. sdata->u.ibss.last_scan_completed = jiffies;
  847. ieee80211_queue_work(&local->hw, &sdata->work);
  848. }
  849. mutex_unlock(&local->iflist_mtx);
  850. }
  851. int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
  852. struct cfg80211_ibss_params *params)
  853. {
  854. struct sk_buff *skb;
  855. u32 changed = 0;
  856. skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
  857. sizeof(struct ieee80211_hdr_3addr) +
  858. 12 /* struct ieee80211_mgmt.u.beacon */ +
  859. 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
  860. 2 + 8 /* max Supported Rates */ +
  861. 3 /* max DS params */ +
  862. 4 /* IBSS params */ +
  863. 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
  864. 2 + sizeof(struct ieee80211_ht_cap) +
  865. 2 + sizeof(struct ieee80211_ht_info) +
  866. params->ie_len);
  867. if (!skb)
  868. return -ENOMEM;
  869. mutex_lock(&sdata->u.ibss.mtx);
  870. if (params->bssid) {
  871. memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
  872. sdata->u.ibss.fixed_bssid = true;
  873. } else
  874. sdata->u.ibss.fixed_bssid = false;
  875. sdata->u.ibss.privacy = params->privacy;
  876. sdata->u.ibss.basic_rates = params->basic_rates;
  877. memcpy(sdata->vif.bss_conf.mcast_rate, params->mcast_rate,
  878. sizeof(params->mcast_rate));
  879. sdata->vif.bss_conf.beacon_int = params->beacon_interval;
  880. sdata->u.ibss.channel = params->channel;
  881. sdata->u.ibss.channel_type = params->channel_type;
  882. sdata->u.ibss.fixed_channel = params->channel_fixed;
  883. /* fix ourselves to that channel now already */
  884. if (params->channel_fixed) {
  885. sdata->local->oper_channel = params->channel;
  886. if (!ieee80211_set_channel_type(sdata->local, sdata,
  887. params->channel_type)) {
  888. mutex_unlock(&sdata->u.ibss.mtx);
  889. kfree_skb(skb);
  890. return -EINVAL;
  891. }
  892. }
  893. if (params->ie) {
  894. sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
  895. GFP_KERNEL);
  896. if (sdata->u.ibss.ie)
  897. sdata->u.ibss.ie_len = params->ie_len;
  898. }
  899. sdata->u.ibss.skb = skb;
  900. sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
  901. sdata->u.ibss.ibss_join_req = jiffies;
  902. memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
  903. sdata->u.ibss.ssid_len = params->ssid_len;
  904. mutex_unlock(&sdata->u.ibss.mtx);
  905. mutex_lock(&sdata->local->mtx);
  906. ieee80211_recalc_idle(sdata->local);
  907. mutex_unlock(&sdata->local->mtx);
  908. /*
  909. * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
  910. * reserved, but an HT STA shall protect HT transmissions as though
  911. * the HT Protection field were set to non-HT mixed mode.
  912. *
  913. * In an IBSS, the RIFS Mode field of the HT Operation element is
  914. * also reserved, but an HT STA shall operate as though this field
  915. * were set to 1.
  916. */
  917. sdata->vif.bss_conf.ht_operation_mode |=
  918. IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
  919. | IEEE80211_HT_PARAM_RIFS_MODE;
  920. changed |= BSS_CHANGED_HT;
  921. ieee80211_bss_info_change_notify(sdata, changed);
  922. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  923. return 0;
  924. }
  925. int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
  926. {
  927. struct sk_buff *skb;
  928. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  929. struct ieee80211_local *local = sdata->local;
  930. struct cfg80211_bss *cbss;
  931. u16 capability;
  932. int active_ibss;
  933. struct sta_info *sta;
  934. mutex_lock(&sdata->u.ibss.mtx);
  935. sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
  936. memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
  937. sdata->u.ibss.ssid_len = 0;
  938. active_ibss = ieee80211_sta_active_ibss(sdata);
  939. if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
  940. capability = WLAN_CAPABILITY_IBSS;
  941. if (ifibss->privacy)
  942. capability |= WLAN_CAPABILITY_PRIVACY;
  943. cbss = cfg80211_get_bss(local->hw.wiphy, ifibss->channel,
  944. ifibss->bssid, ifibss->ssid,
  945. ifibss->ssid_len, WLAN_CAPABILITY_IBSS |
  946. WLAN_CAPABILITY_PRIVACY,
  947. capability);
  948. if (cbss) {
  949. cfg80211_unlink_bss(local->hw.wiphy, cbss);
  950. cfg80211_put_bss(cbss);
  951. }
  952. }
  953. sta_info_flush(sdata->local, sdata);
  954. spin_lock_bh(&ifibss->incomplete_lock);
  955. while (!list_empty(&ifibss->incomplete_stations)) {
  956. sta = list_first_entry(&ifibss->incomplete_stations,
  957. struct sta_info, list);
  958. list_del(&sta->list);
  959. spin_unlock_bh(&ifibss->incomplete_lock);
  960. sta_info_free(local, sta);
  961. spin_lock_bh(&ifibss->incomplete_lock);
  962. }
  963. spin_unlock_bh(&ifibss->incomplete_lock);
  964. netif_carrier_off(sdata->dev);
  965. /* remove beacon */
  966. kfree(sdata->u.ibss.ie);
  967. skb = rcu_dereference_protected(sdata->u.ibss.presp,
  968. lockdep_is_held(&sdata->u.ibss.mtx));
  969. RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
  970. sdata->vif.bss_conf.ibss_joined = false;
  971. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
  972. BSS_CHANGED_IBSS);
  973. synchronize_rcu();
  974. kfree_skb(skb);
  975. skb_queue_purge(&sdata->skb_queue);
  976. del_timer_sync(&sdata->u.ibss.timer);
  977. mutex_unlock(&sdata->u.ibss.mtx);
  978. mutex_lock(&local->mtx);
  979. ieee80211_recalc_idle(sdata->local);
  980. mutex_unlock(&local->mtx);
  981. return 0;
  982. }