work.c 33 KB

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