ibss.c 32 KB

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