work.c 32 KB

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