work.c 33 KB

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