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