work.c 32 KB

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