ibss.c 31 KB

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