work.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*
  2. * mac80211 work implementation
  3. *
  4. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  5. * Copyright 2004, Instant802 Networks, Inc.
  6. * Copyright 2005, Devicescape Software, Inc.
  7. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  8. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  9. * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/delay.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/crc32.h>
  21. #include <linux/slab.h>
  22. #include <net/mac80211.h>
  23. #include <asm/unaligned.h>
  24. #include "ieee80211_i.h"
  25. #include "rate.h"
  26. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  27. #define IEEE80211_AUTH_MAX_TRIES 3
  28. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  29. #define IEEE80211_ASSOC_MAX_TRIES 3
  30. enum work_action {
  31. WORK_ACT_MISMATCH,
  32. WORK_ACT_NONE,
  33. WORK_ACT_TIMEOUT,
  34. WORK_ACT_DONE,
  35. };
  36. /* utils */
  37. static inline void ASSERT_WORK_MTX(struct ieee80211_local *local)
  38. {
  39. lockdep_assert_held(&local->mtx);
  40. }
  41. /*
  42. * We can have multiple work items (and connection probing)
  43. * scheduling this timer, but we need to take care to only
  44. * reschedule it when it should fire _earlier_ than it was
  45. * asked for before, or if it's not pending right now. This
  46. * function ensures that. Note that it then is required to
  47. * run this function for all timeouts after the first one
  48. * has happened -- the work that runs from this timer will
  49. * do that.
  50. */
  51. static void run_again(struct ieee80211_local *local,
  52. unsigned long timeout)
  53. {
  54. ASSERT_WORK_MTX(local);
  55. if (!timer_pending(&local->work_timer) ||
  56. time_before(timeout, local->work_timer.expires))
  57. mod_timer(&local->work_timer, timeout);
  58. }
  59. static void work_free_rcu(struct rcu_head *head)
  60. {
  61. struct ieee80211_work *wk =
  62. container_of(head, struct ieee80211_work, rcu_head);
  63. kfree(wk);
  64. }
  65. void free_work(struct ieee80211_work *wk)
  66. {
  67. call_rcu(&wk->rcu_head, work_free_rcu);
  68. }
  69. static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
  70. struct ieee80211_supported_band *sband,
  71. u32 *rates)
  72. {
  73. int i, j, count;
  74. *rates = 0;
  75. count = 0;
  76. for (i = 0; i < supp_rates_len; i++) {
  77. int rate = (supp_rates[i] & 0x7F) * 5;
  78. for (j = 0; j < sband->n_bitrates; j++)
  79. if (sband->bitrates[j].bitrate == rate) {
  80. *rates |= BIT(j);
  81. count++;
  82. break;
  83. }
  84. }
  85. return count;
  86. }
  87. /* frame sending functions */
  88. static void ieee80211_add_ht_ie(struct sk_buff *skb, const u8 *ht_info_ie,
  89. struct ieee80211_supported_band *sband,
  90. struct ieee80211_channel *channel,
  91. enum ieee80211_smps_mode smps)
  92. {
  93. struct ieee80211_ht_info *ht_info;
  94. u8 *pos;
  95. u32 flags = channel->flags;
  96. u16 cap = sband->ht_cap.cap;
  97. __le16 tmp;
  98. if (!sband->ht_cap.ht_supported)
  99. return;
  100. if (!ht_info_ie)
  101. return;
  102. if (ht_info_ie[1] < sizeof(struct ieee80211_ht_info))
  103. return;
  104. ht_info = (struct ieee80211_ht_info *)(ht_info_ie + 2);
  105. /* determine capability flags */
  106. switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  107. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  108. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  109. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  110. cap &= ~IEEE80211_HT_CAP_SGI_40;
  111. }
  112. break;
  113. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  114. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  115. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  116. cap &= ~IEEE80211_HT_CAP_SGI_40;
  117. }
  118. break;
  119. }
  120. /* set SM PS mode properly */
  121. cap &= ~IEEE80211_HT_CAP_SM_PS;
  122. switch (smps) {
  123. case IEEE80211_SMPS_AUTOMATIC:
  124. case IEEE80211_SMPS_NUM_MODES:
  125. WARN_ON(1);
  126. case IEEE80211_SMPS_OFF:
  127. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  128. IEEE80211_HT_CAP_SM_PS_SHIFT;
  129. break;
  130. case IEEE80211_SMPS_STATIC:
  131. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  132. IEEE80211_HT_CAP_SM_PS_SHIFT;
  133. break;
  134. case IEEE80211_SMPS_DYNAMIC:
  135. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  136. IEEE80211_HT_CAP_SM_PS_SHIFT;
  137. break;
  138. }
  139. /* reserve and fill IE */
  140. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  141. *pos++ = WLAN_EID_HT_CAPABILITY;
  142. *pos++ = sizeof(struct ieee80211_ht_cap);
  143. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  144. /* capability flags */
  145. tmp = cpu_to_le16(cap);
  146. memcpy(pos, &tmp, sizeof(u16));
  147. pos += sizeof(u16);
  148. /* AMPDU parameters */
  149. *pos++ = sband->ht_cap.ampdu_factor |
  150. (sband->ht_cap.ampdu_density <<
  151. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  152. /* MCS set */
  153. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  154. pos += sizeof(sband->ht_cap.mcs);
  155. /* extended capabilities */
  156. pos += sizeof(__le16);
  157. /* BF capabilities */
  158. pos += sizeof(__le32);
  159. /* antenna selection */
  160. pos += sizeof(u8);
  161. }
  162. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  163. struct ieee80211_work *wk)
  164. {
  165. struct ieee80211_local *local = sdata->local;
  166. struct sk_buff *skb;
  167. struct ieee80211_mgmt *mgmt;
  168. u8 *pos, qos_info;
  169. size_t offset = 0, noffset;
  170. int i, count, rates_len, supp_rates_len;
  171. u16 capab;
  172. struct ieee80211_supported_band *sband;
  173. u32 rates = 0;
  174. sband = local->hw.wiphy->bands[wk->chan->band];
  175. if (wk->assoc.supp_rates_len) {
  176. /*
  177. * Get all rates supported by the device and the AP as
  178. * some APs don't like getting a superset of their rates
  179. * in the association request (e.g. D-Link DAP 1353 in
  180. * b-only mode)...
  181. */
  182. rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates,
  183. wk->assoc.supp_rates_len,
  184. sband, &rates);
  185. } else {
  186. /*
  187. * In case AP not provide any supported rates information
  188. * before association, we send information element(s) with
  189. * all rates that we support.
  190. */
  191. rates = ~0;
  192. rates_len = sband->n_bitrates;
  193. }
  194. skb = alloc_skb(local->hw.extra_tx_headroom +
  195. sizeof(*mgmt) + /* bit too much but doesn't matter */
  196. 2 + wk->assoc.ssid_len + /* SSID */
  197. 4 + rates_len + /* (extended) rates */
  198. 4 + /* power capability */
  199. 2 + 2 * sband->n_channels + /* supported channels */
  200. 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
  201. wk->ie_len + /* extra IEs */
  202. 9, /* WMM */
  203. GFP_KERNEL);
  204. if (!skb) {
  205. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  206. "frame\n", sdata->name);
  207. return;
  208. }
  209. skb_reserve(skb, local->hw.extra_tx_headroom);
  210. capab = WLAN_CAPABILITY_ESS;
  211. if (sband->band == IEEE80211_BAND_2GHZ) {
  212. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  213. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  214. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  215. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  216. }
  217. if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY)
  218. capab |= WLAN_CAPABILITY_PRIVACY;
  219. if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  220. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  221. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  222. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  223. memset(mgmt, 0, 24);
  224. memcpy(mgmt->da, wk->filter_ta, ETH_ALEN);
  225. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  226. memcpy(mgmt->bssid, wk->filter_ta, ETH_ALEN);
  227. if (!is_zero_ether_addr(wk->assoc.prev_bssid)) {
  228. skb_put(skb, 10);
  229. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  230. IEEE80211_STYPE_REASSOC_REQ);
  231. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  232. mgmt->u.reassoc_req.listen_interval =
  233. cpu_to_le16(local->hw.conf.listen_interval);
  234. memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid,
  235. ETH_ALEN);
  236. } else {
  237. skb_put(skb, 4);
  238. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  239. IEEE80211_STYPE_ASSOC_REQ);
  240. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  241. mgmt->u.assoc_req.listen_interval =
  242. cpu_to_le16(local->hw.conf.listen_interval);
  243. }
  244. /* SSID */
  245. pos = skb_put(skb, 2 + wk->assoc.ssid_len);
  246. *pos++ = WLAN_EID_SSID;
  247. *pos++ = wk->assoc.ssid_len;
  248. memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len);
  249. /* add all rates which were marked to be used above */
  250. supp_rates_len = rates_len;
  251. if (supp_rates_len > 8)
  252. supp_rates_len = 8;
  253. pos = skb_put(skb, supp_rates_len + 2);
  254. *pos++ = WLAN_EID_SUPP_RATES;
  255. *pos++ = supp_rates_len;
  256. count = 0;
  257. for (i = 0; i < sband->n_bitrates; i++) {
  258. if (BIT(i) & rates) {
  259. int rate = sband->bitrates[i].bitrate;
  260. *pos++ = (u8) (rate / 5);
  261. if (++count == 8)
  262. break;
  263. }
  264. }
  265. if (rates_len > count) {
  266. pos = skb_put(skb, rates_len - count + 2);
  267. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  268. *pos++ = rates_len - count;
  269. for (i++; i < sband->n_bitrates; i++) {
  270. if (BIT(i) & rates) {
  271. int rate = sband->bitrates[i].bitrate;
  272. *pos++ = (u8) (rate / 5);
  273. }
  274. }
  275. }
  276. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  277. /* 1. power capabilities */
  278. pos = skb_put(skb, 4);
  279. *pos++ = WLAN_EID_PWR_CAPABILITY;
  280. *pos++ = 2;
  281. *pos++ = 0; /* min tx power */
  282. *pos++ = wk->chan->max_power; /* max tx power */
  283. /* 2. supported channels */
  284. /* TODO: get this in reg domain format */
  285. pos = skb_put(skb, 2 * sband->n_channels + 2);
  286. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  287. *pos++ = 2 * sband->n_channels;
  288. for (i = 0; i < sband->n_channels; i++) {
  289. *pos++ = ieee80211_frequency_to_channel(
  290. sband->channels[i].center_freq);
  291. *pos++ = 1; /* one channel in the subband*/
  292. }
  293. }
  294. /* if present, add any custom IEs that go before HT */
  295. if (wk->ie_len && wk->ie) {
  296. static const u8 before_ht[] = {
  297. WLAN_EID_SSID,
  298. WLAN_EID_SUPP_RATES,
  299. WLAN_EID_EXT_SUPP_RATES,
  300. WLAN_EID_PWR_CAPABILITY,
  301. WLAN_EID_SUPPORTED_CHANNELS,
  302. WLAN_EID_RSN,
  303. WLAN_EID_QOS_CAPA,
  304. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  305. WLAN_EID_MOBILITY_DOMAIN,
  306. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  307. };
  308. noffset = ieee80211_ie_split(wk->ie, wk->ie_len,
  309. before_ht, ARRAY_SIZE(before_ht),
  310. offset);
  311. pos = skb_put(skb, noffset - offset);
  312. memcpy(pos, wk->ie + offset, noffset - offset);
  313. offset = noffset;
  314. }
  315. if (wk->assoc.use_11n && wk->assoc.wmm_used &&
  316. local->hw.queues >= 4)
  317. ieee80211_add_ht_ie(skb, wk->assoc.ht_information_ie,
  318. sband, wk->chan, wk->assoc.smps);
  319. /* if present, add any custom non-vendor IEs that go after HT */
  320. if (wk->ie_len && wk->ie) {
  321. noffset = ieee80211_ie_split_vendor(wk->ie, wk->ie_len,
  322. offset);
  323. pos = skb_put(skb, noffset - offset);
  324. memcpy(pos, wk->ie + offset, noffset - offset);
  325. offset = noffset;
  326. }
  327. if (wk->assoc.wmm_used && local->hw.queues >= 4) {
  328. if (wk->assoc.uapsd_used) {
  329. qos_info = local->uapsd_queues;
  330. qos_info |= (local->uapsd_max_sp_len <<
  331. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  332. } else {
  333. qos_info = 0;
  334. }
  335. pos = skb_put(skb, 9);
  336. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  337. *pos++ = 7; /* len */
  338. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  339. *pos++ = 0x50;
  340. *pos++ = 0xf2;
  341. *pos++ = 2; /* WME */
  342. *pos++ = 0; /* WME info */
  343. *pos++ = 1; /* WME ver */
  344. *pos++ = qos_info;
  345. }
  346. /* add any remaining custom (i.e. vendor specific here) IEs */
  347. if (wk->ie_len && wk->ie) {
  348. noffset = wk->ie_len;
  349. pos = skb_put(skb, noffset - offset);
  350. memcpy(pos, wk->ie + offset, noffset - offset);
  351. }
  352. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  353. ieee80211_tx_skb(sdata, skb);
  354. }
  355. static void ieee80211_remove_auth_bss(struct ieee80211_local *local,
  356. struct ieee80211_work *wk)
  357. {
  358. struct cfg80211_bss *cbss;
  359. u16 capa_val = WLAN_CAPABILITY_ESS;
  360. if (wk->probe_auth.privacy)
  361. capa_val |= WLAN_CAPABILITY_PRIVACY;
  362. cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->filter_ta,
  363. wk->probe_auth.ssid, wk->probe_auth.ssid_len,
  364. WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
  365. capa_val);
  366. if (!cbss)
  367. return;
  368. cfg80211_unlink_bss(local->hw.wiphy, cbss);
  369. cfg80211_put_bss(cbss);
  370. }
  371. static enum work_action __must_check
  372. ieee80211_direct_probe(struct ieee80211_work *wk)
  373. {
  374. struct ieee80211_sub_if_data *sdata = wk->sdata;
  375. struct ieee80211_local *local = sdata->local;
  376. wk->probe_auth.tries++;
  377. if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
  378. printk(KERN_DEBUG "%s: direct probe to %pM timed out\n",
  379. sdata->name, wk->filter_ta);
  380. /*
  381. * Most likely AP is not in the range so remove the
  382. * bss struct for that AP.
  383. */
  384. ieee80211_remove_auth_bss(local, wk);
  385. return WORK_ACT_TIMEOUT;
  386. }
  387. printk(KERN_DEBUG "%s: direct probe to %pM (try %d/%i)\n",
  388. sdata->name, wk->filter_ta, wk->probe_auth.tries,
  389. IEEE80211_AUTH_MAX_TRIES);
  390. /*
  391. * Direct probe is sent to broadcast address as some APs
  392. * will not answer to direct packet in unassociated state.
  393. */
  394. ieee80211_send_probe_req(sdata, NULL, wk->probe_auth.ssid,
  395. wk->probe_auth.ssid_len, NULL, 0);
  396. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  397. run_again(local, wk->timeout);
  398. return WORK_ACT_NONE;
  399. }
  400. static enum work_action __must_check
  401. ieee80211_authenticate(struct ieee80211_work *wk)
  402. {
  403. struct ieee80211_sub_if_data *sdata = wk->sdata;
  404. struct ieee80211_local *local = sdata->local;
  405. wk->probe_auth.tries++;
  406. if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
  407. printk(KERN_DEBUG "%s: authentication with %pM"
  408. " timed out\n", sdata->name, wk->filter_ta);
  409. /*
  410. * Most likely AP is not in the range so remove the
  411. * bss struct for that AP.
  412. */
  413. ieee80211_remove_auth_bss(local, wk);
  414. return WORK_ACT_TIMEOUT;
  415. }
  416. printk(KERN_DEBUG "%s: authenticate with %pM (try %d)\n",
  417. sdata->name, wk->filter_ta, wk->probe_auth.tries);
  418. ieee80211_send_auth(sdata, 1, wk->probe_auth.algorithm, wk->ie,
  419. wk->ie_len, wk->filter_ta, NULL, 0, 0);
  420. wk->probe_auth.transaction = 2;
  421. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  422. run_again(local, wk->timeout);
  423. return WORK_ACT_NONE;
  424. }
  425. static enum work_action __must_check
  426. ieee80211_associate(struct ieee80211_work *wk)
  427. {
  428. struct ieee80211_sub_if_data *sdata = wk->sdata;
  429. struct ieee80211_local *local = sdata->local;
  430. wk->assoc.tries++;
  431. if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) {
  432. printk(KERN_DEBUG "%s: association with %pM"
  433. " timed out\n",
  434. sdata->name, wk->filter_ta);
  435. /*
  436. * Most likely AP is not in the range so remove the
  437. * bss struct for that AP.
  438. */
  439. if (wk->assoc.bss)
  440. cfg80211_unlink_bss(local->hw.wiphy, wk->assoc.bss);
  441. return WORK_ACT_TIMEOUT;
  442. }
  443. printk(KERN_DEBUG "%s: associate with %pM (try %d)\n",
  444. sdata->name, wk->filter_ta, wk->assoc.tries);
  445. ieee80211_send_assoc(sdata, wk);
  446. wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  447. run_again(local, wk->timeout);
  448. return WORK_ACT_NONE;
  449. }
  450. static enum work_action __must_check
  451. ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk)
  452. {
  453. /*
  454. * First time we run, do nothing -- the generic code will
  455. * have switched to the right channel etc.
  456. */
  457. if (!wk->started) {
  458. wk->timeout = jiffies + msecs_to_jiffies(wk->remain.duration);
  459. cfg80211_ready_on_channel(wk->sdata->dev, (unsigned long) wk,
  460. wk->chan, wk->chan_type,
  461. wk->remain.duration, GFP_KERNEL);
  462. return WORK_ACT_NONE;
  463. }
  464. return WORK_ACT_TIMEOUT;
  465. }
  466. static enum work_action __must_check
  467. ieee80211_offchannel_tx(struct ieee80211_work *wk)
  468. {
  469. if (!wk->started) {
  470. wk->timeout = jiffies + msecs_to_jiffies(wk->offchan_tx.wait);
  471. /*
  472. * After this, offchan_tx.frame remains but now is no
  473. * longer a valid pointer -- we still need it as the
  474. * cookie for canceling this work.
  475. */
  476. ieee80211_tx_skb(wk->sdata, wk->offchan_tx.frame);
  477. return WORK_ACT_NONE;
  478. }
  479. return WORK_ACT_TIMEOUT;
  480. }
  481. static enum work_action __must_check
  482. ieee80211_assoc_beacon_wait(struct ieee80211_work *wk)
  483. {
  484. if (wk->started)
  485. return WORK_ACT_TIMEOUT;
  486. /*
  487. * Wait up to one beacon interval ...
  488. * should this be more if we miss one?
  489. */
  490. printk(KERN_DEBUG "%s: waiting for beacon from %pM\n",
  491. wk->sdata->name, wk->filter_ta);
  492. wk->timeout = TU_TO_EXP_TIME(wk->assoc.bss->beacon_interval);
  493. return WORK_ACT_NONE;
  494. }
  495. static void ieee80211_auth_challenge(struct ieee80211_work *wk,
  496. struct ieee80211_mgmt *mgmt,
  497. size_t len)
  498. {
  499. struct ieee80211_sub_if_data *sdata = wk->sdata;
  500. u8 *pos;
  501. struct ieee802_11_elems elems;
  502. pos = mgmt->u.auth.variable;
  503. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  504. if (!elems.challenge)
  505. return;
  506. ieee80211_send_auth(sdata, 3, wk->probe_auth.algorithm,
  507. elems.challenge - 2, elems.challenge_len + 2,
  508. wk->filter_ta, wk->probe_auth.key,
  509. wk->probe_auth.key_len, wk->probe_auth.key_idx);
  510. wk->probe_auth.transaction = 4;
  511. }
  512. static enum work_action __must_check
  513. ieee80211_rx_mgmt_auth(struct ieee80211_work *wk,
  514. struct ieee80211_mgmt *mgmt, size_t len)
  515. {
  516. u16 auth_alg, auth_transaction, status_code;
  517. if (wk->type != IEEE80211_WORK_AUTH)
  518. return WORK_ACT_MISMATCH;
  519. if (len < 24 + 6)
  520. return WORK_ACT_NONE;
  521. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  522. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  523. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  524. if (auth_alg != wk->probe_auth.algorithm ||
  525. auth_transaction != wk->probe_auth.transaction)
  526. return WORK_ACT_NONE;
  527. if (status_code != WLAN_STATUS_SUCCESS) {
  528. printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n",
  529. wk->sdata->name, mgmt->sa, status_code);
  530. return WORK_ACT_DONE;
  531. }
  532. switch (wk->probe_auth.algorithm) {
  533. case WLAN_AUTH_OPEN:
  534. case WLAN_AUTH_LEAP:
  535. case WLAN_AUTH_FT:
  536. break;
  537. case WLAN_AUTH_SHARED_KEY:
  538. if (wk->probe_auth.transaction != 4) {
  539. ieee80211_auth_challenge(wk, mgmt, len);
  540. /* need another frame */
  541. return WORK_ACT_NONE;
  542. }
  543. break;
  544. default:
  545. WARN_ON(1);
  546. return WORK_ACT_NONE;
  547. }
  548. printk(KERN_DEBUG "%s: authenticated\n", wk->sdata->name);
  549. return WORK_ACT_DONE;
  550. }
  551. static enum work_action __must_check
  552. ieee80211_rx_mgmt_assoc_resp(struct ieee80211_work *wk,
  553. struct ieee80211_mgmt *mgmt, size_t len,
  554. bool reassoc)
  555. {
  556. struct ieee80211_sub_if_data *sdata = wk->sdata;
  557. struct ieee80211_local *local = sdata->local;
  558. u16 capab_info, status_code, aid;
  559. struct ieee802_11_elems elems;
  560. u8 *pos;
  561. if (wk->type != IEEE80211_WORK_ASSOC)
  562. return WORK_ACT_MISMATCH;
  563. /*
  564. * AssocResp and ReassocResp have identical structure, so process both
  565. * of them in this function.
  566. */
  567. if (len < 24 + 6)
  568. return WORK_ACT_NONE;
  569. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  570. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  571. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  572. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  573. "status=%d aid=%d)\n",
  574. sdata->name, reassoc ? "Rea" : "A", mgmt->sa,
  575. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  576. pos = mgmt->u.assoc_resp.variable;
  577. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  578. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  579. elems.timeout_int && elems.timeout_int_len == 5 &&
  580. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  581. u32 tu, ms;
  582. tu = get_unaligned_le32(elems.timeout_int + 1);
  583. ms = tu * 1024 / 1000;
  584. printk(KERN_DEBUG "%s: %pM rejected association temporarily; "
  585. "comeback duration %u TU (%u ms)\n",
  586. sdata->name, mgmt->sa, tu, ms);
  587. wk->timeout = jiffies + msecs_to_jiffies(ms);
  588. if (ms > IEEE80211_ASSOC_TIMEOUT)
  589. run_again(local, wk->timeout);
  590. return WORK_ACT_NONE;
  591. }
  592. if (status_code != WLAN_STATUS_SUCCESS)
  593. printk(KERN_DEBUG "%s: %pM denied association (code=%d)\n",
  594. sdata->name, mgmt->sa, status_code);
  595. else
  596. printk(KERN_DEBUG "%s: associated\n", sdata->name);
  597. return WORK_ACT_DONE;
  598. }
  599. static enum work_action __must_check
  600. ieee80211_rx_mgmt_probe_resp(struct ieee80211_work *wk,
  601. struct ieee80211_mgmt *mgmt, size_t len,
  602. struct ieee80211_rx_status *rx_status)
  603. {
  604. struct ieee80211_sub_if_data *sdata = wk->sdata;
  605. struct ieee80211_local *local = sdata->local;
  606. size_t baselen;
  607. ASSERT_WORK_MTX(local);
  608. if (wk->type != IEEE80211_WORK_DIRECT_PROBE)
  609. return WORK_ACT_MISMATCH;
  610. if (len < 24 + 12)
  611. return WORK_ACT_NONE;
  612. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  613. if (baselen > len)
  614. return WORK_ACT_NONE;
  615. printk(KERN_DEBUG "%s: direct probe responded\n", sdata->name);
  616. return WORK_ACT_DONE;
  617. }
  618. static enum work_action __must_check
  619. ieee80211_rx_mgmt_beacon(struct ieee80211_work *wk,
  620. struct ieee80211_mgmt *mgmt, size_t len)
  621. {
  622. struct ieee80211_sub_if_data *sdata = wk->sdata;
  623. struct ieee80211_local *local = sdata->local;
  624. ASSERT_WORK_MTX(local);
  625. if (wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
  626. return WORK_ACT_MISMATCH;
  627. if (len < 24 + 12)
  628. return WORK_ACT_NONE;
  629. printk(KERN_DEBUG "%s: beacon received\n", sdata->name);
  630. return WORK_ACT_DONE;
  631. }
  632. static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local,
  633. struct sk_buff *skb)
  634. {
  635. struct ieee80211_rx_status *rx_status;
  636. struct ieee80211_mgmt *mgmt;
  637. struct ieee80211_work *wk;
  638. enum work_action rma = WORK_ACT_NONE;
  639. u16 fc;
  640. rx_status = (struct ieee80211_rx_status *) skb->cb;
  641. mgmt = (struct ieee80211_mgmt *) skb->data;
  642. fc = le16_to_cpu(mgmt->frame_control);
  643. mutex_lock(&local->mtx);
  644. list_for_each_entry(wk, &local->work_list, list) {
  645. const u8 *bssid = NULL;
  646. switch (wk->type) {
  647. case IEEE80211_WORK_DIRECT_PROBE:
  648. case IEEE80211_WORK_AUTH:
  649. case IEEE80211_WORK_ASSOC:
  650. case IEEE80211_WORK_ASSOC_BEACON_WAIT:
  651. bssid = wk->filter_ta;
  652. break;
  653. default:
  654. continue;
  655. }
  656. /*
  657. * Before queuing, we already verified mgmt->sa,
  658. * so this is needed just for matching.
  659. */
  660. if (compare_ether_addr(bssid, mgmt->bssid))
  661. continue;
  662. switch (fc & IEEE80211_FCTL_STYPE) {
  663. case IEEE80211_STYPE_BEACON:
  664. rma = ieee80211_rx_mgmt_beacon(wk, mgmt, skb->len);
  665. break;
  666. case IEEE80211_STYPE_PROBE_RESP:
  667. rma = ieee80211_rx_mgmt_probe_resp(wk, mgmt, skb->len,
  668. rx_status);
  669. break;
  670. case IEEE80211_STYPE_AUTH:
  671. rma = ieee80211_rx_mgmt_auth(wk, mgmt, skb->len);
  672. break;
  673. case IEEE80211_STYPE_ASSOC_RESP:
  674. rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt,
  675. skb->len, false);
  676. break;
  677. case IEEE80211_STYPE_REASSOC_RESP:
  678. rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt,
  679. skb->len, true);
  680. break;
  681. default:
  682. WARN_ON(1);
  683. rma = WORK_ACT_NONE;
  684. }
  685. /*
  686. * We've either received an unexpected frame, or we have
  687. * multiple work items and need to match the frame to the
  688. * right one.
  689. */
  690. if (rma == WORK_ACT_MISMATCH)
  691. continue;
  692. /*
  693. * We've processed this frame for that work, so it can't
  694. * belong to another work struct.
  695. * NB: this is also required for correctness for 'rma'!
  696. */
  697. break;
  698. }
  699. switch (rma) {
  700. case WORK_ACT_MISMATCH:
  701. /* ignore this unmatched frame */
  702. break;
  703. case WORK_ACT_NONE:
  704. break;
  705. case WORK_ACT_DONE:
  706. list_del_rcu(&wk->list);
  707. break;
  708. default:
  709. WARN(1, "unexpected: %d", rma);
  710. }
  711. mutex_unlock(&local->mtx);
  712. if (rma != WORK_ACT_DONE)
  713. goto out;
  714. switch (wk->done(wk, skb)) {
  715. case WORK_DONE_DESTROY:
  716. free_work(wk);
  717. break;
  718. case WORK_DONE_REQUEUE:
  719. synchronize_rcu();
  720. wk->started = false; /* restart */
  721. mutex_lock(&local->mtx);
  722. list_add_tail(&wk->list, &local->work_list);
  723. mutex_unlock(&local->mtx);
  724. }
  725. out:
  726. kfree_skb(skb);
  727. }
  728. static bool ieee80211_work_ct_coexists(enum nl80211_channel_type wk_ct,
  729. enum nl80211_channel_type oper_ct)
  730. {
  731. switch (wk_ct) {
  732. case NL80211_CHAN_NO_HT:
  733. return true;
  734. case NL80211_CHAN_HT20:
  735. if (oper_ct != NL80211_CHAN_NO_HT)
  736. return true;
  737. return false;
  738. case NL80211_CHAN_HT40MINUS:
  739. case NL80211_CHAN_HT40PLUS:
  740. return (wk_ct == oper_ct);
  741. }
  742. WARN_ON(1); /* shouldn't get here */
  743. return false;
  744. }
  745. static enum nl80211_channel_type
  746. ieee80211_calc_ct(enum nl80211_channel_type wk_ct,
  747. enum nl80211_channel_type oper_ct)
  748. {
  749. switch (wk_ct) {
  750. case NL80211_CHAN_NO_HT:
  751. return oper_ct;
  752. case NL80211_CHAN_HT20:
  753. if (oper_ct != NL80211_CHAN_NO_HT)
  754. return oper_ct;
  755. return wk_ct;
  756. case NL80211_CHAN_HT40MINUS:
  757. case NL80211_CHAN_HT40PLUS:
  758. return wk_ct;
  759. }
  760. WARN_ON(1); /* shouldn't get here */
  761. return wk_ct;
  762. }
  763. static void ieee80211_work_timer(unsigned long data)
  764. {
  765. struct ieee80211_local *local = (void *) data;
  766. if (local->quiescing)
  767. return;
  768. ieee80211_queue_work(&local->hw, &local->work_work);
  769. }
  770. static void ieee80211_work_work(struct work_struct *work)
  771. {
  772. struct ieee80211_local *local =
  773. container_of(work, struct ieee80211_local, work_work);
  774. struct sk_buff *skb;
  775. struct ieee80211_work *wk, *tmp;
  776. LIST_HEAD(free_work);
  777. enum work_action rma;
  778. bool remain_off_channel = false;
  779. if (local->scanning)
  780. return;
  781. /*
  782. * ieee80211_queue_work() should have picked up most cases,
  783. * here we'll pick the rest.
  784. */
  785. if (WARN(local->suspended, "work scheduled while going to suspend\n"))
  786. return;
  787. /* first process frames to avoid timing out while a frame is pending */
  788. while ((skb = skb_dequeue(&local->work_skb_queue)))
  789. ieee80211_work_rx_queued_mgmt(local, skb);
  790. mutex_lock(&local->mtx);
  791. ieee80211_recalc_idle(local);
  792. list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
  793. bool started = wk->started;
  794. /* mark work as started if it's on the current off-channel */
  795. if (!started && local->tmp_channel &&
  796. wk->chan == local->tmp_channel &&
  797. wk->chan_type == local->tmp_channel_type) {
  798. started = true;
  799. wk->timeout = jiffies;
  800. }
  801. if (!started && !local->tmp_channel) {
  802. bool on_oper_chan;
  803. bool tmp_chan_changed = false;
  804. bool on_oper_chan2;
  805. enum nl80211_channel_type wk_ct;
  806. on_oper_chan = ieee80211_cfg_on_oper_channel(local);
  807. /* Work with existing channel type if possible. */
  808. wk_ct = wk->chan_type;
  809. if (wk->chan == local->hw.conf.channel)
  810. wk_ct = ieee80211_calc_ct(wk->chan_type,
  811. local->hw.conf.channel_type);
  812. if (local->tmp_channel)
  813. if ((local->tmp_channel != wk->chan) ||
  814. (local->tmp_channel_type != wk_ct))
  815. tmp_chan_changed = true;
  816. local->tmp_channel = wk->chan;
  817. local->tmp_channel_type = wk_ct;
  818. /*
  819. * Leave the station vifs in awake mode if they
  820. * happen to be on the same channel as
  821. * the requested channel.
  822. */
  823. on_oper_chan2 = ieee80211_cfg_on_oper_channel(local);
  824. if (on_oper_chan != on_oper_chan2) {
  825. if (on_oper_chan2) {
  826. /* going off oper channel, PS too */
  827. ieee80211_offchannel_stop_vifs(local,
  828. true);
  829. ieee80211_hw_config(local, 0);
  830. } else {
  831. /* going on channel, but leave PS
  832. * off-channel. */
  833. ieee80211_hw_config(local, 0);
  834. ieee80211_offchannel_return(local,
  835. true,
  836. false);
  837. }
  838. } else if (tmp_chan_changed)
  839. /* Still off-channel, but on some other
  840. * channel, so update hardware.
  841. * PS should already be off-channel.
  842. */
  843. ieee80211_hw_config(local, 0);
  844. started = true;
  845. wk->timeout = jiffies;
  846. }
  847. /* don't try to work with items that aren't started */
  848. if (!started)
  849. continue;
  850. if (time_is_after_jiffies(wk->timeout)) {
  851. /*
  852. * This work item isn't supposed to be worked on
  853. * right now, but take care to adjust the timer
  854. * properly.
  855. */
  856. run_again(local, wk->timeout);
  857. continue;
  858. }
  859. switch (wk->type) {
  860. default:
  861. WARN_ON(1);
  862. /* nothing */
  863. rma = WORK_ACT_NONE;
  864. break;
  865. case IEEE80211_WORK_ABORT:
  866. rma = WORK_ACT_TIMEOUT;
  867. break;
  868. case IEEE80211_WORK_DIRECT_PROBE:
  869. rma = ieee80211_direct_probe(wk);
  870. break;
  871. case IEEE80211_WORK_AUTH:
  872. rma = ieee80211_authenticate(wk);
  873. break;
  874. case IEEE80211_WORK_ASSOC:
  875. rma = ieee80211_associate(wk);
  876. break;
  877. case IEEE80211_WORK_REMAIN_ON_CHANNEL:
  878. rma = ieee80211_remain_on_channel_timeout(wk);
  879. break;
  880. case IEEE80211_WORK_OFFCHANNEL_TX:
  881. rma = ieee80211_offchannel_tx(wk);
  882. break;
  883. case IEEE80211_WORK_ASSOC_BEACON_WAIT:
  884. rma = ieee80211_assoc_beacon_wait(wk);
  885. break;
  886. }
  887. wk->started = started;
  888. switch (rma) {
  889. case WORK_ACT_NONE:
  890. /* might have changed the timeout */
  891. run_again(local, wk->timeout);
  892. break;
  893. case WORK_ACT_TIMEOUT:
  894. list_del_rcu(&wk->list);
  895. synchronize_rcu();
  896. list_add(&wk->list, &free_work);
  897. break;
  898. default:
  899. WARN(1, "unexpected: %d", rma);
  900. }
  901. }
  902. list_for_each_entry(wk, &local->work_list, list) {
  903. if (!wk->started)
  904. continue;
  905. if (wk->chan != local->tmp_channel)
  906. continue;
  907. if (ieee80211_work_ct_coexists(wk->chan_type,
  908. local->tmp_channel_type))
  909. continue;
  910. remain_off_channel = true;
  911. }
  912. if (!remain_off_channel && local->tmp_channel) {
  913. bool on_oper_chan = ieee80211_cfg_on_oper_channel(local);
  914. local->tmp_channel = NULL;
  915. /* If tmp_channel wasn't operating channel, then
  916. * we need to go back on-channel.
  917. * NOTE: If we can ever be here while scannning,
  918. * or if the hw_config() channel config logic changes,
  919. * then we may need to do a more thorough check to see if
  920. * we still need to do a hardware config. Currently,
  921. * we cannot be here while scanning, however.
  922. */
  923. if (ieee80211_cfg_on_oper_channel(local) && !on_oper_chan)
  924. ieee80211_hw_config(local, 0);
  925. /* At the least, we need to disable offchannel_ps,
  926. * so just go ahead and run the entire offchannel
  927. * return logic here. We *could* skip enabling
  928. * beaconing if we were already on-oper-channel
  929. * as a future optimization.
  930. */
  931. ieee80211_offchannel_return(local, true, true);
  932. /* give connection some time to breathe */
  933. run_again(local, jiffies + HZ/2);
  934. }
  935. if (list_empty(&local->work_list) && local->scan_req &&
  936. !local->scanning)
  937. ieee80211_queue_delayed_work(&local->hw,
  938. &local->scan_work,
  939. round_jiffies_relative(0));
  940. ieee80211_recalc_idle(local);
  941. mutex_unlock(&local->mtx);
  942. list_for_each_entry_safe(wk, tmp, &free_work, list) {
  943. wk->done(wk, NULL);
  944. list_del(&wk->list);
  945. kfree(wk);
  946. }
  947. }
  948. void ieee80211_add_work(struct ieee80211_work *wk)
  949. {
  950. struct ieee80211_local *local;
  951. if (WARN_ON(!wk->chan))
  952. return;
  953. if (WARN_ON(!wk->sdata))
  954. return;
  955. if (WARN_ON(!wk->done))
  956. return;
  957. if (WARN_ON(!ieee80211_sdata_running(wk->sdata)))
  958. return;
  959. wk->started = false;
  960. local = wk->sdata->local;
  961. mutex_lock(&local->mtx);
  962. list_add_tail(&wk->list, &local->work_list);
  963. mutex_unlock(&local->mtx);
  964. ieee80211_queue_work(&local->hw, &local->work_work);
  965. }
  966. void ieee80211_work_init(struct ieee80211_local *local)
  967. {
  968. INIT_LIST_HEAD(&local->work_list);
  969. setup_timer(&local->work_timer, ieee80211_work_timer,
  970. (unsigned long)local);
  971. INIT_WORK(&local->work_work, ieee80211_work_work);
  972. skb_queue_head_init(&local->work_skb_queue);
  973. }
  974. void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata)
  975. {
  976. struct ieee80211_local *local = sdata->local;
  977. struct ieee80211_work *wk;
  978. bool cleanup = false;
  979. mutex_lock(&local->mtx);
  980. list_for_each_entry(wk, &local->work_list, list) {
  981. if (wk->sdata != sdata)
  982. continue;
  983. cleanup = true;
  984. wk->type = IEEE80211_WORK_ABORT;
  985. wk->started = true;
  986. wk->timeout = jiffies;
  987. }
  988. mutex_unlock(&local->mtx);
  989. /* run cleanups etc. */
  990. if (cleanup)
  991. ieee80211_work_work(&local->work_work);
  992. mutex_lock(&local->mtx);
  993. list_for_each_entry(wk, &local->work_list, list) {
  994. if (wk->sdata != sdata)
  995. continue;
  996. WARN_ON(1);
  997. break;
  998. }
  999. mutex_unlock(&local->mtx);
  1000. }
  1001. ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
  1002. struct sk_buff *skb)
  1003. {
  1004. struct ieee80211_local *local = sdata->local;
  1005. struct ieee80211_mgmt *mgmt;
  1006. struct ieee80211_work *wk;
  1007. u16 fc;
  1008. if (skb->len < 24)
  1009. return RX_DROP_MONITOR;
  1010. mgmt = (struct ieee80211_mgmt *) skb->data;
  1011. fc = le16_to_cpu(mgmt->frame_control);
  1012. list_for_each_entry_rcu(wk, &local->work_list, list) {
  1013. if (sdata != wk->sdata)
  1014. continue;
  1015. if (compare_ether_addr(wk->filter_ta, mgmt->sa))
  1016. continue;
  1017. if (compare_ether_addr(wk->filter_ta, mgmt->bssid))
  1018. continue;
  1019. switch (fc & IEEE80211_FCTL_STYPE) {
  1020. case IEEE80211_STYPE_AUTH:
  1021. case IEEE80211_STYPE_PROBE_RESP:
  1022. case IEEE80211_STYPE_ASSOC_RESP:
  1023. case IEEE80211_STYPE_REASSOC_RESP:
  1024. case IEEE80211_STYPE_BEACON:
  1025. skb_queue_tail(&local->work_skb_queue, skb);
  1026. ieee80211_queue_work(&local->hw, &local->work_work);
  1027. return RX_QUEUED;
  1028. }
  1029. }
  1030. return RX_CONTINUE;
  1031. }
  1032. static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk,
  1033. struct sk_buff *skb)
  1034. {
  1035. /*
  1036. * We are done serving the remain-on-channel command.
  1037. */
  1038. cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk,
  1039. wk->chan, wk->chan_type,
  1040. GFP_KERNEL);
  1041. return WORK_DONE_DESTROY;
  1042. }
  1043. int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
  1044. struct ieee80211_channel *chan,
  1045. enum nl80211_channel_type channel_type,
  1046. unsigned int duration, u64 *cookie)
  1047. {
  1048. struct ieee80211_work *wk;
  1049. wk = kzalloc(sizeof(*wk), GFP_KERNEL);
  1050. if (!wk)
  1051. return -ENOMEM;
  1052. wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL;
  1053. wk->chan = chan;
  1054. wk->chan_type = channel_type;
  1055. wk->sdata = sdata;
  1056. wk->done = ieee80211_remain_done;
  1057. wk->remain.duration = duration;
  1058. *cookie = (unsigned long) wk;
  1059. ieee80211_add_work(wk);
  1060. return 0;
  1061. }
  1062. int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
  1063. u64 cookie)
  1064. {
  1065. struct ieee80211_local *local = sdata->local;
  1066. struct ieee80211_work *wk, *tmp;
  1067. bool found = false;
  1068. mutex_lock(&local->mtx);
  1069. list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
  1070. if ((unsigned long) wk == cookie) {
  1071. wk->timeout = jiffies;
  1072. found = true;
  1073. break;
  1074. }
  1075. }
  1076. mutex_unlock(&local->mtx);
  1077. if (!found)
  1078. return -ENOENT;
  1079. ieee80211_queue_work(&local->hw, &local->work_work);
  1080. return 0;
  1081. }