ibss.c 32 KB

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