ibss.c 33 KB

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