work.c 33 KB

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