ibss.c 32 KB

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