ibss.c 33 KB

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