ibss.c 32 KB

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