ibss.c 32 KB

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