ibss.c 33 KB

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