work.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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. 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. ieee80211_ie_build_ht_cap(pos, sband, cap);
  136. }
  137. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  138. struct ieee80211_work *wk)
  139. {
  140. struct ieee80211_local *local = sdata->local;
  141. struct sk_buff *skb;
  142. struct ieee80211_mgmt *mgmt;
  143. u8 *pos, qos_info;
  144. size_t offset = 0, noffset;
  145. int i, count, rates_len, supp_rates_len;
  146. u16 capab;
  147. struct ieee80211_supported_band *sband;
  148. u32 rates = 0;
  149. sband = local->hw.wiphy->bands[wk->chan->band];
  150. if (wk->assoc.supp_rates_len) {
  151. /*
  152. * Get all rates supported by the device and the AP as
  153. * some APs don't like getting a superset of their rates
  154. * in the association request (e.g. D-Link DAP 1353 in
  155. * b-only mode)...
  156. */
  157. rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates,
  158. wk->assoc.supp_rates_len,
  159. sband, &rates);
  160. } else {
  161. /*
  162. * In case AP not provide any supported rates information
  163. * before association, we send information element(s) with
  164. * all rates that we support.
  165. */
  166. rates = ~0;
  167. rates_len = sband->n_bitrates;
  168. }
  169. skb = alloc_skb(local->hw.extra_tx_headroom +
  170. sizeof(*mgmt) + /* bit too much but doesn't matter */
  171. 2 + wk->assoc.ssid_len + /* SSID */
  172. 4 + rates_len + /* (extended) rates */
  173. 4 + /* power capability */
  174. 2 + 2 * sband->n_channels + /* supported channels */
  175. 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
  176. wk->ie_len + /* extra IEs */
  177. 9, /* WMM */
  178. GFP_KERNEL);
  179. if (!skb)
  180. return;
  181. skb_reserve(skb, local->hw.extra_tx_headroom);
  182. capab = WLAN_CAPABILITY_ESS;
  183. if (sband->band == IEEE80211_BAND_2GHZ) {
  184. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  185. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  186. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  187. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  188. }
  189. if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY)
  190. capab |= WLAN_CAPABILITY_PRIVACY;
  191. if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  192. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  193. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  194. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  195. memset(mgmt, 0, 24);
  196. memcpy(mgmt->da, wk->filter_ta, ETH_ALEN);
  197. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  198. memcpy(mgmt->bssid, wk->filter_ta, ETH_ALEN);
  199. if (!is_zero_ether_addr(wk->assoc.prev_bssid)) {
  200. skb_put(skb, 10);
  201. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  202. IEEE80211_STYPE_REASSOC_REQ);
  203. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  204. mgmt->u.reassoc_req.listen_interval =
  205. cpu_to_le16(local->hw.conf.listen_interval);
  206. memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid,
  207. ETH_ALEN);
  208. } else {
  209. skb_put(skb, 4);
  210. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  211. IEEE80211_STYPE_ASSOC_REQ);
  212. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  213. mgmt->u.assoc_req.listen_interval =
  214. cpu_to_le16(local->hw.conf.listen_interval);
  215. }
  216. /* SSID */
  217. pos = skb_put(skb, 2 + wk->assoc.ssid_len);
  218. *pos++ = WLAN_EID_SSID;
  219. *pos++ = wk->assoc.ssid_len;
  220. memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len);
  221. /* add all rates which were marked to be used above */
  222. supp_rates_len = rates_len;
  223. if (supp_rates_len > 8)
  224. supp_rates_len = 8;
  225. pos = skb_put(skb, supp_rates_len + 2);
  226. *pos++ = WLAN_EID_SUPP_RATES;
  227. *pos++ = supp_rates_len;
  228. count = 0;
  229. for (i = 0; i < sband->n_bitrates; i++) {
  230. if (BIT(i) & rates) {
  231. int rate = sband->bitrates[i].bitrate;
  232. *pos++ = (u8) (rate / 5);
  233. if (++count == 8)
  234. break;
  235. }
  236. }
  237. if (rates_len > count) {
  238. pos = skb_put(skb, rates_len - count + 2);
  239. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  240. *pos++ = rates_len - count;
  241. for (i++; i < sband->n_bitrates; i++) {
  242. if (BIT(i) & rates) {
  243. int rate = sband->bitrates[i].bitrate;
  244. *pos++ = (u8) (rate / 5);
  245. }
  246. }
  247. }
  248. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  249. /* 1. power capabilities */
  250. pos = skb_put(skb, 4);
  251. *pos++ = WLAN_EID_PWR_CAPABILITY;
  252. *pos++ = 2;
  253. *pos++ = 0; /* min tx power */
  254. *pos++ = wk->chan->max_power; /* max tx power */
  255. /* 2. supported channels */
  256. /* TODO: get this in reg domain format */
  257. pos = skb_put(skb, 2 * sband->n_channels + 2);
  258. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  259. *pos++ = 2 * sband->n_channels;
  260. for (i = 0; i < sband->n_channels; i++) {
  261. *pos++ = ieee80211_frequency_to_channel(
  262. sband->channels[i].center_freq);
  263. *pos++ = 1; /* one channel in the subband*/
  264. }
  265. }
  266. /* if present, add any custom IEs that go before HT */
  267. if (wk->ie_len && wk->ie) {
  268. static const u8 before_ht[] = {
  269. WLAN_EID_SSID,
  270. WLAN_EID_SUPP_RATES,
  271. WLAN_EID_EXT_SUPP_RATES,
  272. WLAN_EID_PWR_CAPABILITY,
  273. WLAN_EID_SUPPORTED_CHANNELS,
  274. WLAN_EID_RSN,
  275. WLAN_EID_QOS_CAPA,
  276. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  277. WLAN_EID_MOBILITY_DOMAIN,
  278. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  279. };
  280. noffset = ieee80211_ie_split(wk->ie, wk->ie_len,
  281. before_ht, ARRAY_SIZE(before_ht),
  282. offset);
  283. pos = skb_put(skb, noffset - offset);
  284. memcpy(pos, wk->ie + offset, noffset - offset);
  285. offset = noffset;
  286. }
  287. if (wk->assoc.use_11n && wk->assoc.wmm_used &&
  288. local->hw.queues >= 4)
  289. ieee80211_add_ht_ie(skb, wk->assoc.ht_information_ie,
  290. sband, wk->chan, wk->assoc.smps);
  291. /* if present, add any custom non-vendor IEs that go after HT */
  292. if (wk->ie_len && wk->ie) {
  293. noffset = ieee80211_ie_split_vendor(wk->ie, wk->ie_len,
  294. offset);
  295. pos = skb_put(skb, noffset - offset);
  296. memcpy(pos, wk->ie + offset, noffset - offset);
  297. offset = noffset;
  298. }
  299. if (wk->assoc.wmm_used && local->hw.queues >= 4) {
  300. if (wk->assoc.uapsd_used) {
  301. qos_info = local->uapsd_queues;
  302. qos_info |= (local->uapsd_max_sp_len <<
  303. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  304. } else {
  305. qos_info = 0;
  306. }
  307. pos = skb_put(skb, 9);
  308. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  309. *pos++ = 7; /* len */
  310. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  311. *pos++ = 0x50;
  312. *pos++ = 0xf2;
  313. *pos++ = 2; /* WME */
  314. *pos++ = 0; /* WME info */
  315. *pos++ = 1; /* WME ver */
  316. *pos++ = qos_info;
  317. }
  318. /* add any remaining custom (i.e. vendor specific here) IEs */
  319. if (wk->ie_len && wk->ie) {
  320. noffset = wk->ie_len;
  321. pos = skb_put(skb, noffset - offset);
  322. memcpy(pos, wk->ie + offset, noffset - offset);
  323. }
  324. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  325. ieee80211_tx_skb(sdata, skb);
  326. }
  327. static void ieee80211_remove_auth_bss(struct ieee80211_local *local,
  328. struct ieee80211_work *wk)
  329. {
  330. struct cfg80211_bss *cbss;
  331. u16 capa_val = WLAN_CAPABILITY_ESS;
  332. if (wk->probe_auth.privacy)
  333. capa_val |= WLAN_CAPABILITY_PRIVACY;
  334. cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->filter_ta,
  335. wk->probe_auth.ssid, wk->probe_auth.ssid_len,
  336. WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY,
  337. capa_val);
  338. if (!cbss)
  339. return;
  340. cfg80211_unlink_bss(local->hw.wiphy, cbss);
  341. cfg80211_put_bss(cbss);
  342. }
  343. static enum work_action __must_check
  344. ieee80211_direct_probe(struct ieee80211_work *wk)
  345. {
  346. struct ieee80211_sub_if_data *sdata = wk->sdata;
  347. struct ieee80211_local *local = sdata->local;
  348. if (!wk->probe_auth.synced) {
  349. int ret = drv_tx_sync(local, sdata, wk->filter_ta,
  350. IEEE80211_TX_SYNC_AUTH);
  351. if (ret)
  352. return WORK_ACT_TIMEOUT;
  353. }
  354. wk->probe_auth.synced = true;
  355. wk->probe_auth.tries++;
  356. if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
  357. printk(KERN_DEBUG "%s: direct probe to %pM timed out\n",
  358. sdata->name, wk->filter_ta);
  359. /*
  360. * Most likely AP is not in the range so remove the
  361. * bss struct for that AP.
  362. */
  363. ieee80211_remove_auth_bss(local, wk);
  364. return WORK_ACT_TIMEOUT;
  365. }
  366. printk(KERN_DEBUG "%s: direct probe to %pM (try %d/%i)\n",
  367. sdata->name, wk->filter_ta, wk->probe_auth.tries,
  368. IEEE80211_AUTH_MAX_TRIES);
  369. /*
  370. * Direct probe is sent to broadcast address as some APs
  371. * will not answer to direct packet in unassociated state.
  372. */
  373. ieee80211_send_probe_req(sdata, NULL, wk->probe_auth.ssid,
  374. wk->probe_auth.ssid_len, NULL, 0,
  375. (u32) -1, true, false);
  376. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  377. run_again(local, wk->timeout);
  378. return WORK_ACT_NONE;
  379. }
  380. static enum work_action __must_check
  381. ieee80211_authenticate(struct ieee80211_work *wk)
  382. {
  383. struct ieee80211_sub_if_data *sdata = wk->sdata;
  384. struct ieee80211_local *local = sdata->local;
  385. if (!wk->probe_auth.synced) {
  386. int ret = drv_tx_sync(local, sdata, wk->filter_ta,
  387. IEEE80211_TX_SYNC_AUTH);
  388. if (ret)
  389. return WORK_ACT_TIMEOUT;
  390. }
  391. wk->probe_auth.synced = true;
  392. wk->probe_auth.tries++;
  393. if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
  394. printk(KERN_DEBUG "%s: authentication with %pM"
  395. " timed out\n", sdata->name, wk->filter_ta);
  396. /*
  397. * Most likely AP is not in the range so remove the
  398. * bss struct for that AP.
  399. */
  400. ieee80211_remove_auth_bss(local, wk);
  401. return WORK_ACT_TIMEOUT;
  402. }
  403. printk(KERN_DEBUG "%s: authenticate with %pM (try %d)\n",
  404. sdata->name, wk->filter_ta, wk->probe_auth.tries);
  405. ieee80211_send_auth(sdata, 1, wk->probe_auth.algorithm, wk->ie,
  406. wk->ie_len, wk->filter_ta, NULL, 0, 0);
  407. wk->probe_auth.transaction = 2;
  408. wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  409. run_again(local, wk->timeout);
  410. return WORK_ACT_NONE;
  411. }
  412. static enum work_action __must_check
  413. ieee80211_associate(struct ieee80211_work *wk)
  414. {
  415. struct ieee80211_sub_if_data *sdata = wk->sdata;
  416. struct ieee80211_local *local = sdata->local;
  417. if (!wk->assoc.synced) {
  418. int ret = drv_tx_sync(local, sdata, wk->filter_ta,
  419. IEEE80211_TX_SYNC_ASSOC);
  420. if (ret)
  421. return WORK_ACT_TIMEOUT;
  422. }
  423. wk->assoc.synced = true;
  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, on_oper_chan2;
  797. enum nl80211_channel_type wk_ct;
  798. on_oper_chan = ieee80211_cfg_on_oper_channel(local);
  799. /* Work with existing channel type if possible. */
  800. wk_ct = wk->chan_type;
  801. if (wk->chan == local->hw.conf.channel)
  802. wk_ct = ieee80211_calc_ct(wk->chan_type,
  803. local->hw.conf.channel_type);
  804. local->tmp_channel = wk->chan;
  805. local->tmp_channel_type = wk_ct;
  806. /*
  807. * Leave the station vifs in awake mode if they
  808. * happen to be on the same channel as
  809. * the requested channel.
  810. */
  811. on_oper_chan2 = ieee80211_cfg_on_oper_channel(local);
  812. if (on_oper_chan != on_oper_chan2) {
  813. if (on_oper_chan2) {
  814. /* going off oper channel, PS too */
  815. ieee80211_offchannel_stop_vifs(local,
  816. true);
  817. ieee80211_hw_config(local, 0);
  818. } else {
  819. /* going on channel, but leave PS
  820. * off-channel. */
  821. ieee80211_hw_config(local, 0);
  822. ieee80211_offchannel_return(local,
  823. true,
  824. false);
  825. }
  826. }
  827. started = true;
  828. wk->timeout = jiffies;
  829. }
  830. /* don't try to work with items that aren't started */
  831. if (!started)
  832. continue;
  833. if (time_is_after_jiffies(wk->timeout)) {
  834. /*
  835. * This work item isn't supposed to be worked on
  836. * right now, but take care to adjust the timer
  837. * properly.
  838. */
  839. run_again(local, wk->timeout);
  840. continue;
  841. }
  842. switch (wk->type) {
  843. default:
  844. WARN_ON(1);
  845. /* nothing */
  846. rma = WORK_ACT_NONE;
  847. break;
  848. case IEEE80211_WORK_ABORT:
  849. rma = WORK_ACT_TIMEOUT;
  850. break;
  851. case IEEE80211_WORK_DIRECT_PROBE:
  852. rma = ieee80211_direct_probe(wk);
  853. break;
  854. case IEEE80211_WORK_AUTH:
  855. rma = ieee80211_authenticate(wk);
  856. break;
  857. case IEEE80211_WORK_ASSOC:
  858. rma = ieee80211_associate(wk);
  859. break;
  860. case IEEE80211_WORK_REMAIN_ON_CHANNEL:
  861. rma = ieee80211_remain_on_channel_timeout(wk);
  862. break;
  863. case IEEE80211_WORK_OFFCHANNEL_TX:
  864. rma = ieee80211_offchannel_tx(wk);
  865. break;
  866. case IEEE80211_WORK_ASSOC_BEACON_WAIT:
  867. rma = ieee80211_assoc_beacon_wait(wk);
  868. break;
  869. }
  870. wk->started = started;
  871. switch (rma) {
  872. case WORK_ACT_NONE:
  873. /* might have changed the timeout */
  874. run_again(local, wk->timeout);
  875. break;
  876. case WORK_ACT_TIMEOUT:
  877. list_del_rcu(&wk->list);
  878. synchronize_rcu();
  879. list_add(&wk->list, &free_work);
  880. break;
  881. default:
  882. WARN(1, "unexpected: %d", rma);
  883. }
  884. }
  885. list_for_each_entry(wk, &local->work_list, list) {
  886. if (!wk->started)
  887. continue;
  888. if (wk->chan != local->tmp_channel)
  889. continue;
  890. if (!ieee80211_work_ct_coexists(wk->chan_type,
  891. local->tmp_channel_type))
  892. continue;
  893. remain_off_channel = true;
  894. }
  895. if (!remain_off_channel && local->tmp_channel) {
  896. local->tmp_channel = NULL;
  897. /* If tmp_channel wasn't operating channel, then
  898. * we need to go back on-channel.
  899. * NOTE: If we can ever be here while scannning,
  900. * or if the hw_config() channel config logic changes,
  901. * then we may need to do a more thorough check to see if
  902. * we still need to do a hardware config. Currently,
  903. * we cannot be here while scanning, however.
  904. */
  905. if (!ieee80211_cfg_on_oper_channel(local))
  906. ieee80211_hw_config(local, 0);
  907. /* At the least, we need to disable offchannel_ps,
  908. * so just go ahead and run the entire offchannel
  909. * return logic here. We *could* skip enabling
  910. * beaconing if we were already on-oper-channel
  911. * as a future optimization.
  912. */
  913. ieee80211_offchannel_return(local, true, true);
  914. /* give connection some time to breathe */
  915. run_again(local, jiffies + HZ/2);
  916. }
  917. if (list_empty(&local->work_list) && local->scan_req &&
  918. !local->scanning)
  919. ieee80211_queue_delayed_work(&local->hw,
  920. &local->scan_work,
  921. round_jiffies_relative(0));
  922. ieee80211_recalc_idle(local);
  923. mutex_unlock(&local->mtx);
  924. list_for_each_entry_safe(wk, tmp, &free_work, list) {
  925. wk->done(wk, NULL);
  926. list_del(&wk->list);
  927. kfree(wk);
  928. }
  929. }
  930. void ieee80211_add_work(struct ieee80211_work *wk)
  931. {
  932. struct ieee80211_local *local;
  933. if (WARN_ON(!wk->chan))
  934. return;
  935. if (WARN_ON(!wk->sdata))
  936. return;
  937. if (WARN_ON(!wk->done))
  938. return;
  939. if (WARN_ON(!ieee80211_sdata_running(wk->sdata)))
  940. return;
  941. wk->started = false;
  942. local = wk->sdata->local;
  943. mutex_lock(&local->mtx);
  944. list_add_tail(&wk->list, &local->work_list);
  945. mutex_unlock(&local->mtx);
  946. ieee80211_queue_work(&local->hw, &local->work_work);
  947. }
  948. void ieee80211_work_init(struct ieee80211_local *local)
  949. {
  950. INIT_LIST_HEAD(&local->work_list);
  951. setup_timer(&local->work_timer, ieee80211_work_timer,
  952. (unsigned long)local);
  953. INIT_WORK(&local->work_work, ieee80211_work_work);
  954. skb_queue_head_init(&local->work_skb_queue);
  955. }
  956. void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata)
  957. {
  958. struct ieee80211_local *local = sdata->local;
  959. struct ieee80211_work *wk;
  960. bool cleanup = false;
  961. mutex_lock(&local->mtx);
  962. list_for_each_entry(wk, &local->work_list, list) {
  963. if (wk->sdata != sdata)
  964. continue;
  965. cleanup = true;
  966. wk->type = IEEE80211_WORK_ABORT;
  967. wk->started = true;
  968. wk->timeout = jiffies;
  969. }
  970. mutex_unlock(&local->mtx);
  971. /* run cleanups etc. */
  972. if (cleanup)
  973. ieee80211_work_work(&local->work_work);
  974. mutex_lock(&local->mtx);
  975. list_for_each_entry(wk, &local->work_list, list) {
  976. if (wk->sdata != sdata)
  977. continue;
  978. WARN_ON(1);
  979. break;
  980. }
  981. mutex_unlock(&local->mtx);
  982. }
  983. ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata,
  984. struct sk_buff *skb)
  985. {
  986. struct ieee80211_local *local = sdata->local;
  987. struct ieee80211_mgmt *mgmt;
  988. struct ieee80211_work *wk;
  989. u16 fc;
  990. if (skb->len < 24)
  991. return RX_DROP_MONITOR;
  992. mgmt = (struct ieee80211_mgmt *) skb->data;
  993. fc = le16_to_cpu(mgmt->frame_control);
  994. list_for_each_entry_rcu(wk, &local->work_list, list) {
  995. if (sdata != wk->sdata)
  996. continue;
  997. if (compare_ether_addr(wk->filter_ta, mgmt->sa))
  998. continue;
  999. if (compare_ether_addr(wk->filter_ta, mgmt->bssid))
  1000. continue;
  1001. switch (fc & IEEE80211_FCTL_STYPE) {
  1002. case IEEE80211_STYPE_AUTH:
  1003. case IEEE80211_STYPE_PROBE_RESP:
  1004. case IEEE80211_STYPE_ASSOC_RESP:
  1005. case IEEE80211_STYPE_REASSOC_RESP:
  1006. case IEEE80211_STYPE_BEACON:
  1007. skb_queue_tail(&local->work_skb_queue, skb);
  1008. ieee80211_queue_work(&local->hw, &local->work_work);
  1009. return RX_QUEUED;
  1010. }
  1011. }
  1012. return RX_CONTINUE;
  1013. }
  1014. static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk,
  1015. struct sk_buff *skb)
  1016. {
  1017. /*
  1018. * We are done serving the remain-on-channel command.
  1019. */
  1020. cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk,
  1021. wk->chan, wk->chan_type,
  1022. GFP_KERNEL);
  1023. return WORK_DONE_DESTROY;
  1024. }
  1025. int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
  1026. struct ieee80211_channel *chan,
  1027. enum nl80211_channel_type channel_type,
  1028. unsigned int duration, u64 *cookie)
  1029. {
  1030. struct ieee80211_work *wk;
  1031. wk = kzalloc(sizeof(*wk), GFP_KERNEL);
  1032. if (!wk)
  1033. return -ENOMEM;
  1034. wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL;
  1035. wk->chan = chan;
  1036. wk->chan_type = channel_type;
  1037. wk->sdata = sdata;
  1038. wk->done = ieee80211_remain_done;
  1039. wk->remain.duration = duration;
  1040. *cookie = (unsigned long) wk;
  1041. ieee80211_add_work(wk);
  1042. return 0;
  1043. }
  1044. int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
  1045. u64 cookie)
  1046. {
  1047. struct ieee80211_local *local = sdata->local;
  1048. struct ieee80211_work *wk, *tmp;
  1049. bool found = false;
  1050. mutex_lock(&local->mtx);
  1051. list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
  1052. if ((unsigned long) wk == cookie) {
  1053. wk->timeout = jiffies;
  1054. found = true;
  1055. break;
  1056. }
  1057. }
  1058. mutex_unlock(&local->mtx);
  1059. if (!found)
  1060. return -ENOENT;
  1061. ieee80211_queue_work(&local->hw, &local->work_work);
  1062. return 0;
  1063. }