work.c 33 KB

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