work.c 33 KB

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