ibss.c 32 KB

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