mlme.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/rtnetlink.h>
  19. #include <net/mac80211.h>
  20. #include <asm/unaligned.h>
  21. #include "ieee80211_i.h"
  22. #include "rate.h"
  23. #include "led.h"
  24. #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
  25. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  26. #define IEEE80211_AUTH_MAX_TRIES 3
  27. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  28. #define IEEE80211_ASSOC_MAX_TRIES 3
  29. #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
  30. #define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
  31. #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
  32. /* utils */
  33. static int ecw2cw(int ecw)
  34. {
  35. return (1 << ecw) - 1;
  36. }
  37. static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
  38. {
  39. u8 *end, *pos;
  40. pos = bss->cbss.information_elements;
  41. if (pos == NULL)
  42. return NULL;
  43. end = pos + bss->cbss.len_information_elements;
  44. while (pos + 1 < end) {
  45. if (pos + 2 + pos[1] > end)
  46. break;
  47. if (pos[0] == ie)
  48. return pos;
  49. pos += 2 + pos[1];
  50. }
  51. return NULL;
  52. }
  53. static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
  54. struct ieee80211_supported_band *sband,
  55. u32 *rates)
  56. {
  57. int i, j, count;
  58. *rates = 0;
  59. count = 0;
  60. for (i = 0; i < bss->supp_rates_len; i++) {
  61. int rate = (bss->supp_rates[i] & 0x7F) * 5;
  62. for (j = 0; j < sband->n_bitrates; j++)
  63. if (sband->bitrates[j].bitrate == rate) {
  64. *rates |= BIT(j);
  65. count++;
  66. break;
  67. }
  68. }
  69. return count;
  70. }
  71. /* frame sending functions */
  72. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  73. {
  74. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  75. struct ieee80211_local *local = sdata->local;
  76. struct sk_buff *skb;
  77. struct ieee80211_mgmt *mgmt;
  78. u8 *pos, *ies, *ht_ie;
  79. int i, len, count, rates_len, supp_rates_len;
  80. u16 capab;
  81. struct ieee80211_bss *bss;
  82. int wmm = 0;
  83. struct ieee80211_supported_band *sband;
  84. u32 rates = 0;
  85. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  86. sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
  87. ifmgd->ssid_len);
  88. if (!skb) {
  89. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  90. "frame\n", sdata->dev->name);
  91. return;
  92. }
  93. skb_reserve(skb, local->hw.extra_tx_headroom);
  94. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  95. capab = ifmgd->capab;
  96. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
  97. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  98. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  99. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  100. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  101. }
  102. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  103. local->hw.conf.channel->center_freq,
  104. ifmgd->ssid, ifmgd->ssid_len);
  105. if (bss) {
  106. if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
  107. capab |= WLAN_CAPABILITY_PRIVACY;
  108. if (bss->wmm_used)
  109. wmm = 1;
  110. /* get all rates supported by the device and the AP as
  111. * some APs don't like getting a superset of their rates
  112. * in the association request (e.g. D-Link DAP 1353 in
  113. * b-only mode) */
  114. rates_len = ieee80211_compatible_rates(bss, sband, &rates);
  115. if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  116. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  117. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  118. ieee80211_rx_bss_put(local, bss);
  119. } else {
  120. rates = ~0;
  121. rates_len = sband->n_bitrates;
  122. }
  123. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  124. memset(mgmt, 0, 24);
  125. memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
  126. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  127. memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
  128. if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
  129. skb_put(skb, 10);
  130. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  131. IEEE80211_STYPE_REASSOC_REQ);
  132. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  133. mgmt->u.reassoc_req.listen_interval =
  134. cpu_to_le16(local->hw.conf.listen_interval);
  135. memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
  136. ETH_ALEN);
  137. } else {
  138. skb_put(skb, 4);
  139. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  140. IEEE80211_STYPE_ASSOC_REQ);
  141. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  142. mgmt->u.assoc_req.listen_interval =
  143. cpu_to_le16(local->hw.conf.listen_interval);
  144. }
  145. /* SSID */
  146. ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
  147. *pos++ = WLAN_EID_SSID;
  148. *pos++ = ifmgd->ssid_len;
  149. memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
  150. /* add all rates which were marked to be used above */
  151. supp_rates_len = rates_len;
  152. if (supp_rates_len > 8)
  153. supp_rates_len = 8;
  154. len = sband->n_bitrates;
  155. pos = skb_put(skb, supp_rates_len + 2);
  156. *pos++ = WLAN_EID_SUPP_RATES;
  157. *pos++ = supp_rates_len;
  158. count = 0;
  159. for (i = 0; i < sband->n_bitrates; i++) {
  160. if (BIT(i) & rates) {
  161. int rate = sband->bitrates[i].bitrate;
  162. *pos++ = (u8) (rate / 5);
  163. if (++count == 8)
  164. break;
  165. }
  166. }
  167. if (rates_len > count) {
  168. pos = skb_put(skb, rates_len - count + 2);
  169. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  170. *pos++ = rates_len - count;
  171. for (i++; i < sband->n_bitrates; i++) {
  172. if (BIT(i) & rates) {
  173. int rate = sband->bitrates[i].bitrate;
  174. *pos++ = (u8) (rate / 5);
  175. }
  176. }
  177. }
  178. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  179. /* 1. power capabilities */
  180. pos = skb_put(skb, 4);
  181. *pos++ = WLAN_EID_PWR_CAPABILITY;
  182. *pos++ = 2;
  183. *pos++ = 0; /* min tx power */
  184. *pos++ = local->hw.conf.channel->max_power; /* max tx power */
  185. /* 2. supported channels */
  186. /* TODO: get this in reg domain format */
  187. pos = skb_put(skb, 2 * sband->n_channels + 2);
  188. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  189. *pos++ = 2 * sband->n_channels;
  190. for (i = 0; i < sband->n_channels; i++) {
  191. *pos++ = ieee80211_frequency_to_channel(
  192. sband->channels[i].center_freq);
  193. *pos++ = 1; /* one channel in the subband*/
  194. }
  195. }
  196. if (ifmgd->extra_ie) {
  197. pos = skb_put(skb, ifmgd->extra_ie_len);
  198. memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
  199. }
  200. if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
  201. pos = skb_put(skb, 9);
  202. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  203. *pos++ = 7; /* len */
  204. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  205. *pos++ = 0x50;
  206. *pos++ = 0xf2;
  207. *pos++ = 2; /* WME */
  208. *pos++ = 0; /* WME info */
  209. *pos++ = 1; /* WME ver */
  210. *pos++ = 0;
  211. }
  212. /* wmm support is a must to HT */
  213. /*
  214. * IEEE802.11n does not allow TKIP/WEP as pairwise
  215. * ciphers in HT mode. We still associate in non-ht
  216. * mode (11a/b/g) if any one of these ciphers is
  217. * configured as pairwise.
  218. */
  219. if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  220. sband->ht_cap.ht_supported &&
  221. (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
  222. ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
  223. (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
  224. struct ieee80211_ht_info *ht_info =
  225. (struct ieee80211_ht_info *)(ht_ie + 2);
  226. u16 cap = sband->ht_cap.cap;
  227. __le16 tmp;
  228. u32 flags = local->hw.conf.channel->flags;
  229. switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  230. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  231. if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
  232. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  233. cap &= ~IEEE80211_HT_CAP_SGI_40;
  234. }
  235. break;
  236. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  237. if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
  238. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  239. cap &= ~IEEE80211_HT_CAP_SGI_40;
  240. }
  241. break;
  242. }
  243. tmp = cpu_to_le16(cap);
  244. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
  245. *pos++ = WLAN_EID_HT_CAPABILITY;
  246. *pos++ = sizeof(struct ieee80211_ht_cap);
  247. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  248. memcpy(pos, &tmp, sizeof(u16));
  249. pos += sizeof(u16);
  250. /* TODO: needs a define here for << 2 */
  251. *pos++ = sband->ht_cap.ampdu_factor |
  252. (sband->ht_cap.ampdu_density << 2);
  253. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  254. }
  255. kfree(ifmgd->assocreq_ies);
  256. ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
  257. ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
  258. if (ifmgd->assocreq_ies)
  259. memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
  260. ieee80211_tx_skb(sdata, skb, 0);
  261. }
  262. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  263. u16 stype, u16 reason)
  264. {
  265. struct ieee80211_local *local = sdata->local;
  266. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  267. struct sk_buff *skb;
  268. struct ieee80211_mgmt *mgmt;
  269. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  270. if (!skb) {
  271. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  272. "deauth/disassoc frame\n", sdata->dev->name);
  273. return;
  274. }
  275. skb_reserve(skb, local->hw.extra_tx_headroom);
  276. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  277. memset(mgmt, 0, 24);
  278. memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
  279. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  280. memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
  281. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  282. skb_put(skb, 2);
  283. /* u.deauth.reason_code == u.disassoc.reason_code */
  284. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  285. ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
  286. }
  287. void ieee80211_send_pspoll(struct ieee80211_local *local,
  288. struct ieee80211_sub_if_data *sdata)
  289. {
  290. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  291. struct ieee80211_pspoll *pspoll;
  292. struct sk_buff *skb;
  293. u16 fc;
  294. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
  295. if (!skb) {
  296. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  297. "pspoll frame\n", sdata->dev->name);
  298. return;
  299. }
  300. skb_reserve(skb, local->hw.extra_tx_headroom);
  301. pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
  302. memset(pspoll, 0, sizeof(*pspoll));
  303. fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
  304. pspoll->frame_control = cpu_to_le16(fc);
  305. pspoll->aid = cpu_to_le16(ifmgd->aid);
  306. /* aid in PS-Poll has its two MSBs each set to 1 */
  307. pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
  308. memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
  309. memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
  310. ieee80211_tx_skb(sdata, skb, 0);
  311. }
  312. /* MLME */
  313. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  314. struct ieee80211_if_managed *ifmgd,
  315. u8 *wmm_param, size_t wmm_param_len)
  316. {
  317. struct ieee80211_tx_queue_params params;
  318. size_t left;
  319. int count;
  320. u8 *pos;
  321. if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
  322. return;
  323. if (!wmm_param)
  324. return;
  325. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  326. return;
  327. count = wmm_param[6] & 0x0f;
  328. if (count == ifmgd->wmm_last_param_set)
  329. return;
  330. ifmgd->wmm_last_param_set = count;
  331. pos = wmm_param + 8;
  332. left = wmm_param_len - 8;
  333. memset(&params, 0, sizeof(params));
  334. local->wmm_acm = 0;
  335. for (; left >= 4; left -= 4, pos += 4) {
  336. int aci = (pos[0] >> 5) & 0x03;
  337. int acm = (pos[0] >> 4) & 0x01;
  338. int queue;
  339. switch (aci) {
  340. case 1: /* AC_BK */
  341. queue = 3;
  342. if (acm)
  343. local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  344. break;
  345. case 2: /* AC_VI */
  346. queue = 1;
  347. if (acm)
  348. local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  349. break;
  350. case 3: /* AC_VO */
  351. queue = 0;
  352. if (acm)
  353. local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  354. break;
  355. case 0: /* AC_BE */
  356. default:
  357. queue = 2;
  358. if (acm)
  359. local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  360. break;
  361. }
  362. params.aifs = pos[0] & 0x0f;
  363. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  364. params.cw_min = ecw2cw(pos[1] & 0x0f);
  365. params.txop = get_unaligned_le16(pos + 2);
  366. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  367. printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
  368. "cWmin=%d cWmax=%d txop=%d\n",
  369. local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
  370. params.cw_max, params.txop);
  371. #endif
  372. if (local->ops->conf_tx &&
  373. local->ops->conf_tx(local_to_hw(local), queue, &params)) {
  374. printk(KERN_DEBUG "%s: failed to set TX queue "
  375. "parameters for queue %d\n", local->mdev->name, queue);
  376. }
  377. }
  378. }
  379. static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
  380. {
  381. u8 mask;
  382. u8 index, indexn1, indexn2;
  383. struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
  384. if (unlikely(!tim || elems->tim_len < 4))
  385. return false;
  386. aid &= 0x3fff;
  387. index = aid / 8;
  388. mask = 1 << (aid & 7);
  389. indexn1 = tim->bitmap_ctrl & 0xfe;
  390. indexn2 = elems->tim_len + indexn1 - 4;
  391. if (index < indexn1 || index > indexn2)
  392. return false;
  393. index -= indexn1;
  394. return !!(tim->virtual_map[index] & mask);
  395. }
  396. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  397. u16 capab, bool erp_valid, u8 erp)
  398. {
  399. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  400. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  401. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  402. #endif
  403. u32 changed = 0;
  404. bool use_protection;
  405. bool use_short_preamble;
  406. bool use_short_slot;
  407. if (erp_valid) {
  408. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  409. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  410. } else {
  411. use_protection = false;
  412. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  413. }
  414. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  415. if (use_protection != bss_conf->use_cts_prot) {
  416. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  417. if (net_ratelimit()) {
  418. printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
  419. sdata->dev->name,
  420. use_protection ? "enabled" : "disabled",
  421. ifmgd->bssid);
  422. }
  423. #endif
  424. bss_conf->use_cts_prot = use_protection;
  425. changed |= BSS_CHANGED_ERP_CTS_PROT;
  426. }
  427. if (use_short_preamble != bss_conf->use_short_preamble) {
  428. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  429. if (net_ratelimit()) {
  430. printk(KERN_DEBUG "%s: switched to %s barker preamble"
  431. " (BSSID=%pM)\n",
  432. sdata->dev->name,
  433. use_short_preamble ? "short" : "long",
  434. ifmgd->bssid);
  435. }
  436. #endif
  437. bss_conf->use_short_preamble = use_short_preamble;
  438. changed |= BSS_CHANGED_ERP_PREAMBLE;
  439. }
  440. if (use_short_slot != bss_conf->use_short_slot) {
  441. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  442. if (net_ratelimit()) {
  443. printk(KERN_DEBUG "%s: switched to %s slot time"
  444. " (BSSID=%pM)\n",
  445. sdata->dev->name,
  446. use_short_slot ? "short" : "long",
  447. ifmgd->bssid);
  448. }
  449. #endif
  450. bss_conf->use_short_slot = use_short_slot;
  451. changed |= BSS_CHANGED_ERP_SLOT;
  452. }
  453. return changed;
  454. }
  455. static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
  456. {
  457. union iwreq_data wrqu;
  458. memset(&wrqu, 0, sizeof(wrqu));
  459. if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
  460. memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
  461. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  462. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  463. }
  464. static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
  465. {
  466. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  467. char *buf;
  468. size_t len;
  469. int i;
  470. union iwreq_data wrqu;
  471. if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
  472. return;
  473. buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
  474. ifmgd->assocresp_ies_len), GFP_KERNEL);
  475. if (!buf)
  476. return;
  477. len = sprintf(buf, "ASSOCINFO(");
  478. if (ifmgd->assocreq_ies) {
  479. len += sprintf(buf + len, "ReqIEs=");
  480. for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
  481. len += sprintf(buf + len, "%02x",
  482. ifmgd->assocreq_ies[i]);
  483. }
  484. }
  485. if (ifmgd->assocresp_ies) {
  486. if (ifmgd->assocreq_ies)
  487. len += sprintf(buf + len, " ");
  488. len += sprintf(buf + len, "RespIEs=");
  489. for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
  490. len += sprintf(buf + len, "%02x",
  491. ifmgd->assocresp_ies[i]);
  492. }
  493. }
  494. len += sprintf(buf + len, ")");
  495. if (len > IW_CUSTOM_MAX) {
  496. len = sprintf(buf, "ASSOCRESPIE=");
  497. for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
  498. len += sprintf(buf + len, "%02x",
  499. ifmgd->assocresp_ies[i]);
  500. }
  501. }
  502. if (len <= IW_CUSTOM_MAX) {
  503. memset(&wrqu, 0, sizeof(wrqu));
  504. wrqu.data.length = len;
  505. wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
  506. }
  507. kfree(buf);
  508. }
  509. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  510. u32 bss_info_changed)
  511. {
  512. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  513. struct ieee80211_local *local = sdata->local;
  514. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  515. struct ieee80211_bss *bss;
  516. bss_info_changed |= BSS_CHANGED_ASSOC;
  517. ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
  518. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  519. conf->channel->center_freq,
  520. ifmgd->ssid, ifmgd->ssid_len);
  521. if (bss) {
  522. /* set timing information */
  523. sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
  524. sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
  525. sdata->vif.bss_conf.dtim_period = bss->dtim_period;
  526. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  527. bss->cbss.capability, bss->has_erp_value, bss->erp_value);
  528. cfg80211_hold_bss(&bss->cbss);
  529. ieee80211_rx_bss_put(local, bss);
  530. }
  531. ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
  532. memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
  533. ieee80211_sta_send_associnfo(sdata);
  534. ifmgd->last_probe = jiffies;
  535. ieee80211_led_assoc(local, 1);
  536. sdata->vif.bss_conf.assoc = 1;
  537. /*
  538. * For now just always ask the driver to update the basic rateset
  539. * when we have associated, we aren't checking whether it actually
  540. * changed or not.
  541. */
  542. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  543. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  544. if (local->powersave) {
  545. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
  546. local->hw.conf.dynamic_ps_timeout > 0) {
  547. mod_timer(&local->dynamic_ps_timer, jiffies +
  548. msecs_to_jiffies(
  549. local->hw.conf.dynamic_ps_timeout));
  550. } else {
  551. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  552. ieee80211_send_nullfunc(local, sdata, 1);
  553. conf->flags |= IEEE80211_CONF_PS;
  554. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  555. }
  556. }
  557. netif_tx_start_all_queues(sdata->dev);
  558. netif_carrier_on(sdata->dev);
  559. ieee80211_sta_send_apinfo(sdata);
  560. }
  561. static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
  562. {
  563. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  564. struct ieee80211_local *local = sdata->local;
  565. ifmgd->direct_probe_tries++;
  566. if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
  567. printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
  568. sdata->dev->name, ifmgd->bssid);
  569. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  570. ieee80211_sta_send_apinfo(sdata);
  571. /*
  572. * Most likely AP is not in the range so remove the
  573. * bss information associated to the AP
  574. */
  575. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  576. sdata->local->hw.conf.channel->center_freq,
  577. ifmgd->ssid, ifmgd->ssid_len);
  578. /*
  579. * We might have a pending scan which had no chance to run yet
  580. * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
  581. * Hence, queue the STAs work again
  582. */
  583. queue_work(local->hw.workqueue, &ifmgd->work);
  584. return;
  585. }
  586. printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
  587. sdata->dev->name, ifmgd->bssid,
  588. ifmgd->direct_probe_tries);
  589. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  590. set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
  591. /* Direct probe is sent to broadcast address as some APs
  592. * will not answer to direct packet in unassociated state.
  593. */
  594. ieee80211_send_probe_req(sdata, NULL,
  595. ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
  596. mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  597. }
  598. static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
  599. {
  600. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  601. struct ieee80211_local *local = sdata->local;
  602. u8 *ies;
  603. size_t ies_len;
  604. ifmgd->auth_tries++;
  605. if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  606. printk(KERN_DEBUG "%s: authentication with AP %pM"
  607. " timed out\n",
  608. sdata->dev->name, ifmgd->bssid);
  609. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  610. ieee80211_sta_send_apinfo(sdata);
  611. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  612. sdata->local->hw.conf.channel->center_freq,
  613. ifmgd->ssid, ifmgd->ssid_len);
  614. /*
  615. * We might have a pending scan which had no chance to run yet
  616. * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
  617. * Hence, queue the STAs work again
  618. */
  619. queue_work(local->hw.workqueue, &ifmgd->work);
  620. return;
  621. }
  622. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  623. printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
  624. sdata->dev->name, ifmgd->bssid);
  625. if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
  626. ies = ifmgd->sme_auth_ie;
  627. ies_len = ifmgd->sme_auth_ie_len;
  628. } else {
  629. ies = NULL;
  630. ies_len = 0;
  631. }
  632. ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
  633. ifmgd->bssid, 0);
  634. ifmgd->auth_transaction = 2;
  635. mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  636. }
  637. /*
  638. * The disassoc 'reason' argument can be either our own reason
  639. * if self disconnected or a reason code from the AP.
  640. */
  641. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  642. bool deauth, bool self_disconnected,
  643. u16 reason)
  644. {
  645. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  646. struct ieee80211_local *local = sdata->local;
  647. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  648. struct ieee80211_bss *bss;
  649. struct sta_info *sta;
  650. u32 changed = 0, config_changed = 0;
  651. rcu_read_lock();
  652. sta = sta_info_get(local, ifmgd->bssid);
  653. if (!sta) {
  654. rcu_read_unlock();
  655. return;
  656. }
  657. if (deauth) {
  658. ifmgd->direct_probe_tries = 0;
  659. ifmgd->auth_tries = 0;
  660. }
  661. ifmgd->assoc_scan_tries = 0;
  662. ifmgd->assoc_tries = 0;
  663. netif_tx_stop_all_queues(sdata->dev);
  664. netif_carrier_off(sdata->dev);
  665. ieee80211_sta_tear_down_BA_sessions(sta);
  666. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  667. conf->channel->center_freq,
  668. ifmgd->ssid, ifmgd->ssid_len);
  669. if (bss) {
  670. cfg80211_unhold_bss(&bss->cbss);
  671. ieee80211_rx_bss_put(local, bss);
  672. }
  673. if (self_disconnected) {
  674. if (deauth)
  675. ieee80211_send_deauth_disassoc(sdata,
  676. IEEE80211_STYPE_DEAUTH, reason);
  677. else
  678. ieee80211_send_deauth_disassoc(sdata,
  679. IEEE80211_STYPE_DISASSOC, reason);
  680. }
  681. ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
  682. changed |= ieee80211_reset_erp_info(sdata);
  683. ieee80211_led_assoc(local, 0);
  684. changed |= BSS_CHANGED_ASSOC;
  685. sdata->vif.bss_conf.assoc = false;
  686. ieee80211_sta_send_apinfo(sdata);
  687. if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
  688. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  689. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  690. sdata->local->hw.conf.channel->center_freq,
  691. ifmgd->ssid, ifmgd->ssid_len);
  692. }
  693. rcu_read_unlock();
  694. /* channel(_type) changes are handled by ieee80211_hw_config */
  695. local->oper_channel_type = NL80211_CHAN_NO_HT;
  696. local->power_constr_level = 0;
  697. del_timer_sync(&local->dynamic_ps_timer);
  698. cancel_work_sync(&local->dynamic_ps_enable_work);
  699. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  700. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  701. config_changed |= IEEE80211_CONF_CHANGE_PS;
  702. }
  703. ieee80211_hw_config(local, config_changed);
  704. ieee80211_bss_info_change_notify(sdata, changed);
  705. rcu_read_lock();
  706. sta = sta_info_get(local, ifmgd->bssid);
  707. if (!sta) {
  708. rcu_read_unlock();
  709. return;
  710. }
  711. sta_info_unlink(&sta);
  712. rcu_read_unlock();
  713. sta_info_destroy(sta);
  714. }
  715. static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
  716. {
  717. if (!sdata || !sdata->default_key ||
  718. sdata->default_key->conf.alg != ALG_WEP)
  719. return 0;
  720. return 1;
  721. }
  722. static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
  723. {
  724. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  725. struct ieee80211_local *local = sdata->local;
  726. struct ieee80211_bss *bss;
  727. int bss_privacy;
  728. int wep_privacy;
  729. int privacy_invoked;
  730. if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
  731. return 0;
  732. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  733. local->hw.conf.channel->center_freq,
  734. ifmgd->ssid, ifmgd->ssid_len);
  735. if (!bss)
  736. return 0;
  737. bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
  738. wep_privacy = !!ieee80211_sta_wep_configured(sdata);
  739. privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
  740. ieee80211_rx_bss_put(local, bss);
  741. if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
  742. return 0;
  743. return 1;
  744. }
  745. static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
  746. {
  747. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  748. struct ieee80211_local *local = sdata->local;
  749. ifmgd->assoc_tries++;
  750. if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  751. printk(KERN_DEBUG "%s: association with AP %pM"
  752. " timed out\n",
  753. sdata->dev->name, ifmgd->bssid);
  754. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  755. ieee80211_sta_send_apinfo(sdata);
  756. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  757. sdata->local->hw.conf.channel->center_freq,
  758. ifmgd->ssid, ifmgd->ssid_len);
  759. /*
  760. * We might have a pending scan which had no chance to run yet
  761. * due to state == IEEE80211_STA_MLME_ASSOCIATE.
  762. * Hence, queue the STAs work again
  763. */
  764. queue_work(local->hw.workqueue, &ifmgd->work);
  765. return;
  766. }
  767. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
  768. printk(KERN_DEBUG "%s: associate with AP %pM\n",
  769. sdata->dev->name, ifmgd->bssid);
  770. if (ieee80211_privacy_mismatch(sdata)) {
  771. printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
  772. "mixed-cell disabled - abort association\n", sdata->dev->name);
  773. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  774. return;
  775. }
  776. ieee80211_send_assoc(sdata);
  777. mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
  778. }
  779. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  780. struct ieee80211_hdr *hdr)
  781. {
  782. /*
  783. * We can postpone the mgd.timer whenever receiving unicast frames
  784. * from AP because we know that the connection is working both ways
  785. * at that time. But multicast frames (and hence also beacons) must
  786. * be ignored here, because we need to trigger the timer during
  787. * data idle periods for sending the periodical probe request to
  788. * the AP.
  789. */
  790. if (!is_multicast_ether_addr(hdr->addr1))
  791. mod_timer(&sdata->u.mgd.timer,
  792. jiffies + IEEE80211_MONITORING_INTERVAL);
  793. }
  794. void ieee80211_beacon_loss_work(struct work_struct *work)
  795. {
  796. struct ieee80211_sub_if_data *sdata =
  797. container_of(work, struct ieee80211_sub_if_data,
  798. u.mgd.beacon_loss_work);
  799. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  800. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  801. if (net_ratelimit()) {
  802. printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
  803. "- sending probe request\n", sdata->dev->name,
  804. sdata->u.mgd.bssid);
  805. }
  806. #endif
  807. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  808. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  809. ifmgd->ssid_len, NULL, 0);
  810. mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
  811. }
  812. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  813. {
  814. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  815. queue_work(sdata->local->hw.workqueue,
  816. &sdata->u.mgd.beacon_loss_work);
  817. }
  818. EXPORT_SYMBOL(ieee80211_beacon_loss);
  819. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
  820. {
  821. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  822. struct ieee80211_local *local = sdata->local;
  823. struct sta_info *sta;
  824. bool disassoc = false;
  825. /* TODO: start monitoring current AP signal quality and number of
  826. * missed beacons. Scan other channels every now and then and search
  827. * for better APs. */
  828. /* TODO: remove expired BSSes */
  829. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
  830. rcu_read_lock();
  831. sta = sta_info_get(local, ifmgd->bssid);
  832. if (!sta) {
  833. printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
  834. sdata->dev->name, ifmgd->bssid);
  835. disassoc = true;
  836. goto unlock;
  837. }
  838. if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
  839. time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  840. printk(KERN_DEBUG "%s: no probe response from AP %pM "
  841. "- disassociating\n",
  842. sdata->dev->name, ifmgd->bssid);
  843. disassoc = true;
  844. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  845. goto unlock;
  846. }
  847. /*
  848. * Beacon filtering is only enabled with power save and then the
  849. * stack should not check for beacon loss.
  850. */
  851. if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
  852. (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
  853. time_after(jiffies,
  854. ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
  855. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  856. if (net_ratelimit()) {
  857. printk(KERN_DEBUG "%s: beacon loss from AP %pM "
  858. "- sending probe request\n",
  859. sdata->dev->name, ifmgd->bssid);
  860. }
  861. #endif
  862. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  863. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  864. ifmgd->ssid_len, NULL, 0);
  865. goto unlock;
  866. }
  867. if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
  868. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  869. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  870. ifmgd->ssid_len, NULL, 0);
  871. }
  872. unlock:
  873. rcu_read_unlock();
  874. if (disassoc)
  875. ieee80211_set_disassoc(sdata, true, true,
  876. WLAN_REASON_PREV_AUTH_NOT_VALID);
  877. else
  878. mod_timer(&ifmgd->timer, jiffies +
  879. IEEE80211_MONITORING_INTERVAL);
  880. }
  881. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
  882. {
  883. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  884. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  885. ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
  886. if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
  887. /* Wait for SME to request association */
  888. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  889. } else
  890. ieee80211_associate(sdata);
  891. }
  892. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  893. struct ieee80211_mgmt *mgmt,
  894. size_t len)
  895. {
  896. u8 *pos;
  897. struct ieee802_11_elems elems;
  898. pos = mgmt->u.auth.variable;
  899. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  900. if (!elems.challenge)
  901. return;
  902. ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
  903. elems.challenge - 2, elems.challenge_len + 2,
  904. sdata->u.mgd.bssid, 1);
  905. sdata->u.mgd.auth_transaction = 4;
  906. }
  907. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  908. struct ieee80211_mgmt *mgmt,
  909. size_t len)
  910. {
  911. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  912. u16 auth_alg, auth_transaction, status_code;
  913. if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
  914. return;
  915. if (len < 24 + 6)
  916. return;
  917. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  918. return;
  919. if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  920. return;
  921. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  922. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  923. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  924. if (auth_alg != ifmgd->auth_alg ||
  925. auth_transaction != ifmgd->auth_transaction)
  926. return;
  927. if (status_code != WLAN_STATUS_SUCCESS) {
  928. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  929. u8 algs[3];
  930. const int num_algs = ARRAY_SIZE(algs);
  931. int i, pos;
  932. algs[0] = algs[1] = algs[2] = 0xff;
  933. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  934. algs[0] = WLAN_AUTH_OPEN;
  935. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  936. algs[1] = WLAN_AUTH_SHARED_KEY;
  937. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  938. algs[2] = WLAN_AUTH_LEAP;
  939. if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
  940. pos = 0;
  941. else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
  942. pos = 1;
  943. else
  944. pos = 2;
  945. for (i = 0; i < num_algs; i++) {
  946. pos++;
  947. if (pos >= num_algs)
  948. pos = 0;
  949. if (algs[pos] == ifmgd->auth_alg ||
  950. algs[pos] == 0xff)
  951. continue;
  952. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  953. !ieee80211_sta_wep_configured(sdata))
  954. continue;
  955. ifmgd->auth_alg = algs[pos];
  956. break;
  957. }
  958. }
  959. return;
  960. }
  961. switch (ifmgd->auth_alg) {
  962. case WLAN_AUTH_OPEN:
  963. case WLAN_AUTH_LEAP:
  964. case WLAN_AUTH_FT:
  965. ieee80211_auth_completed(sdata);
  966. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  967. break;
  968. case WLAN_AUTH_SHARED_KEY:
  969. if (ifmgd->auth_transaction == 4) {
  970. ieee80211_auth_completed(sdata);
  971. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  972. } else
  973. ieee80211_auth_challenge(sdata, mgmt, len);
  974. break;
  975. }
  976. }
  977. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  978. struct ieee80211_mgmt *mgmt,
  979. size_t len)
  980. {
  981. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  982. u16 reason_code;
  983. if (len < 24 + 2)
  984. return;
  985. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  986. return;
  987. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  988. if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
  989. printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
  990. sdata->dev->name, reason_code);
  991. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  992. (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  993. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
  994. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
  995. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  996. mod_timer(&ifmgd->timer, jiffies +
  997. IEEE80211_RETRY_AUTH_INTERVAL);
  998. }
  999. ieee80211_set_disassoc(sdata, true, false, 0);
  1000. ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
  1001. cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len);
  1002. }
  1003. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1004. struct ieee80211_mgmt *mgmt,
  1005. size_t len)
  1006. {
  1007. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1008. u16 reason_code;
  1009. if (len < 24 + 2)
  1010. return;
  1011. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  1012. return;
  1013. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1014. if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
  1015. printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
  1016. sdata->dev->name, reason_code);
  1017. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1018. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1019. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
  1020. mod_timer(&ifmgd->timer, jiffies +
  1021. IEEE80211_RETRY_AUTH_INTERVAL);
  1022. }
  1023. ieee80211_set_disassoc(sdata, false, false, reason_code);
  1024. cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len);
  1025. }
  1026. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1027. struct ieee80211_mgmt *mgmt,
  1028. size_t len,
  1029. int reassoc)
  1030. {
  1031. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1032. struct ieee80211_local *local = sdata->local;
  1033. struct ieee80211_supported_band *sband;
  1034. struct sta_info *sta;
  1035. u32 rates, basic_rates;
  1036. u16 capab_info, status_code, aid;
  1037. struct ieee802_11_elems elems;
  1038. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1039. u8 *pos;
  1040. u32 changed = 0;
  1041. int i, j;
  1042. bool have_higher_than_11mbit = false, newsta = false;
  1043. u16 ap_ht_cap_flags;
  1044. /* AssocResp and ReassocResp have identical structure, so process both
  1045. * of them in this function. */
  1046. if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1047. return;
  1048. if (len < 24 + 6)
  1049. return;
  1050. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  1051. return;
  1052. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1053. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1054. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1055. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1056. "status=%d aid=%d)\n",
  1057. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1058. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1059. pos = mgmt->u.assoc_resp.variable;
  1060. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1061. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  1062. elems.timeout_int && elems.timeout_int_len == 5 &&
  1063. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  1064. u32 tu, ms;
  1065. tu = get_unaligned_le32(elems.timeout_int + 1);
  1066. ms = tu * 1024 / 1000;
  1067. printk(KERN_DEBUG "%s: AP rejected association temporarily; "
  1068. "comeback duration %u TU (%u ms)\n",
  1069. sdata->dev->name, tu, ms);
  1070. if (ms > IEEE80211_ASSOC_TIMEOUT)
  1071. mod_timer(&ifmgd->timer,
  1072. jiffies + msecs_to_jiffies(ms));
  1073. return;
  1074. }
  1075. if (status_code != WLAN_STATUS_SUCCESS) {
  1076. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1077. sdata->dev->name, status_code);
  1078. /* if this was a reassociation, ensure we try a "full"
  1079. * association next time. This works around some broken APs
  1080. * which do not correctly reject reassociation requests. */
  1081. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1082. return;
  1083. }
  1084. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1085. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1086. "set\n", sdata->dev->name, aid);
  1087. aid &= ~(BIT(15) | BIT(14));
  1088. if (!elems.supp_rates) {
  1089. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1090. sdata->dev->name);
  1091. return;
  1092. }
  1093. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1094. ifmgd->aid = aid;
  1095. ifmgd->ap_capab = capab_info;
  1096. kfree(ifmgd->assocresp_ies);
  1097. ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1098. ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
  1099. if (ifmgd->assocresp_ies)
  1100. memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
  1101. rcu_read_lock();
  1102. /* Add STA entry for the AP */
  1103. sta = sta_info_get(local, ifmgd->bssid);
  1104. if (!sta) {
  1105. newsta = true;
  1106. sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
  1107. if (!sta) {
  1108. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1109. " the AP\n", sdata->dev->name);
  1110. rcu_read_unlock();
  1111. return;
  1112. }
  1113. /* update new sta with its last rx activity */
  1114. sta->last_rx = jiffies;
  1115. }
  1116. /*
  1117. * FIXME: Do we really need to update the sta_info's information here?
  1118. * We already know about the AP (we found it in our list) so it
  1119. * should already be filled with the right info, no?
  1120. * As is stands, all this is racy because typically we assume
  1121. * the information that is filled in here (except flags) doesn't
  1122. * change while a STA structure is alive. As such, it should move
  1123. * to between the sta_info_alloc() and sta_info_insert() above.
  1124. */
  1125. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1126. WLAN_STA_AUTHORIZED);
  1127. rates = 0;
  1128. basic_rates = 0;
  1129. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1130. for (i = 0; i < elems.supp_rates_len; i++) {
  1131. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1132. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1133. if (rate > 110)
  1134. have_higher_than_11mbit = true;
  1135. for (j = 0; j < sband->n_bitrates; j++) {
  1136. if (sband->bitrates[j].bitrate == rate) {
  1137. rates |= BIT(j);
  1138. if (is_basic)
  1139. basic_rates |= BIT(j);
  1140. break;
  1141. }
  1142. }
  1143. }
  1144. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1145. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1146. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1147. if (rate > 110)
  1148. have_higher_than_11mbit = true;
  1149. for (j = 0; j < sband->n_bitrates; j++) {
  1150. if (sband->bitrates[j].bitrate == rate) {
  1151. rates |= BIT(j);
  1152. if (is_basic)
  1153. basic_rates |= BIT(j);
  1154. break;
  1155. }
  1156. }
  1157. }
  1158. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1159. sdata->vif.bss_conf.basic_rates = basic_rates;
  1160. /* cf. IEEE 802.11 9.2.12 */
  1161. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1162. have_higher_than_11mbit)
  1163. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1164. else
  1165. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1166. /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
  1167. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1168. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1169. elems.ht_cap_elem, &sta->sta.ht_cap);
  1170. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1171. rate_control_rate_init(sta);
  1172. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1173. set_sta_flags(sta, WLAN_STA_MFP);
  1174. if (elems.wmm_param)
  1175. set_sta_flags(sta, WLAN_STA_WME);
  1176. if (newsta) {
  1177. int err = sta_info_insert(sta);
  1178. if (err) {
  1179. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1180. " the AP (error %d)\n", sdata->dev->name, err);
  1181. rcu_read_unlock();
  1182. return;
  1183. }
  1184. }
  1185. rcu_read_unlock();
  1186. if (elems.wmm_param)
  1187. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1188. elems.wmm_param_len);
  1189. if (elems.ht_info_elem && elems.wmm_param &&
  1190. (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  1191. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1192. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1193. ap_ht_cap_flags);
  1194. /* set AID and assoc capability,
  1195. * ieee80211_set_associated() will tell the driver */
  1196. bss_conf->aid = aid;
  1197. bss_conf->assoc_capability = capab_info;
  1198. ieee80211_set_associated(sdata, changed);
  1199. /*
  1200. * initialise the time of last beacon to be the association time,
  1201. * otherwise beacon loss check will trigger immediately
  1202. */
  1203. ifmgd->last_beacon = jiffies;
  1204. ieee80211_associated(sdata);
  1205. cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
  1206. }
  1207. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1208. struct ieee80211_mgmt *mgmt,
  1209. size_t len,
  1210. struct ieee80211_rx_status *rx_status,
  1211. struct ieee802_11_elems *elems,
  1212. bool beacon)
  1213. {
  1214. struct ieee80211_local *local = sdata->local;
  1215. int freq;
  1216. struct ieee80211_bss *bss;
  1217. struct ieee80211_channel *channel;
  1218. if (elems->ds_params && elems->ds_params_len == 1)
  1219. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1220. else
  1221. freq = rx_status->freq;
  1222. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1223. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1224. return;
  1225. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1226. channel, beacon);
  1227. if (!bss)
  1228. return;
  1229. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1230. (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
  1231. struct ieee80211_channel_sw_ie *sw_elem =
  1232. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1233. ieee80211_process_chanswitch(sdata, sw_elem, bss);
  1234. }
  1235. ieee80211_rx_bss_put(local, bss);
  1236. }
  1237. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1238. struct ieee80211_mgmt *mgmt,
  1239. size_t len,
  1240. struct ieee80211_rx_status *rx_status)
  1241. {
  1242. struct ieee80211_if_managed *ifmgd;
  1243. size_t baselen;
  1244. struct ieee802_11_elems elems;
  1245. ifmgd = &sdata->u.mgd;
  1246. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1247. return; /* ignore ProbeResp to foreign address */
  1248. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1249. if (baselen > len)
  1250. return;
  1251. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1252. &elems);
  1253. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1254. /* direct probe may be part of the association flow */
  1255. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  1256. &ifmgd->request)) {
  1257. printk(KERN_DEBUG "%s direct probe responded\n",
  1258. sdata->dev->name);
  1259. ieee80211_authenticate(sdata);
  1260. }
  1261. if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
  1262. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  1263. }
  1264. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1265. struct ieee80211_mgmt *mgmt,
  1266. size_t len,
  1267. struct ieee80211_rx_status *rx_status)
  1268. {
  1269. struct ieee80211_if_managed *ifmgd;
  1270. size_t baselen;
  1271. struct ieee802_11_elems elems;
  1272. struct ieee80211_local *local = sdata->local;
  1273. u32 changed = 0;
  1274. bool erp_valid, directed_tim;
  1275. u8 erp_value = 0;
  1276. /* Process beacon from the current BSS */
  1277. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1278. if (baselen > len)
  1279. return;
  1280. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  1281. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  1282. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1283. return;
  1284. ifmgd = &sdata->u.mgd;
  1285. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
  1286. memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1287. return;
  1288. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1289. return;
  1290. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1291. elems.wmm_param_len);
  1292. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1293. directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
  1294. if (directed_tim) {
  1295. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1296. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1297. ieee80211_hw_config(local,
  1298. IEEE80211_CONF_CHANGE_PS);
  1299. ieee80211_send_nullfunc(local, sdata, 0);
  1300. } else {
  1301. local->pspolling = true;
  1302. /*
  1303. * Here is assumed that the driver will be
  1304. * able to send ps-poll frame and receive a
  1305. * response even though power save mode is
  1306. * enabled, but some drivers might require
  1307. * to disable power save here. This needs
  1308. * to be investigated.
  1309. */
  1310. ieee80211_send_pspoll(local, sdata);
  1311. }
  1312. }
  1313. }
  1314. if (elems.erp_info && elems.erp_info_len >= 1) {
  1315. erp_valid = true;
  1316. erp_value = elems.erp_info[0];
  1317. } else {
  1318. erp_valid = false;
  1319. }
  1320. changed |= ieee80211_handle_bss_capability(sdata,
  1321. le16_to_cpu(mgmt->u.beacon.capab_info),
  1322. erp_valid, erp_value);
  1323. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1324. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
  1325. struct sta_info *sta;
  1326. struct ieee80211_supported_band *sband;
  1327. u16 ap_ht_cap_flags;
  1328. rcu_read_lock();
  1329. sta = sta_info_get(local, ifmgd->bssid);
  1330. if (!sta) {
  1331. rcu_read_unlock();
  1332. return;
  1333. }
  1334. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1335. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1336. elems.ht_cap_elem, &sta->sta.ht_cap);
  1337. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1338. rcu_read_unlock();
  1339. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1340. ap_ht_cap_flags);
  1341. }
  1342. if (elems.country_elem) {
  1343. /* Note we are only reviewing this on beacons
  1344. * for the BSSID we are associated to */
  1345. regulatory_hint_11d(local->hw.wiphy,
  1346. elems.country_elem, elems.country_elem_len);
  1347. /* TODO: IBSS also needs this */
  1348. if (elems.pwr_constr_elem)
  1349. ieee80211_handle_pwr_constr(sdata,
  1350. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1351. elems.pwr_constr_elem,
  1352. elems.pwr_constr_elem_len);
  1353. }
  1354. ieee80211_bss_info_change_notify(sdata, changed);
  1355. }
  1356. ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
  1357. struct sk_buff *skb,
  1358. struct ieee80211_rx_status *rx_status)
  1359. {
  1360. struct ieee80211_local *local = sdata->local;
  1361. struct ieee80211_mgmt *mgmt;
  1362. u16 fc;
  1363. if (skb->len < 24)
  1364. return RX_DROP_MONITOR;
  1365. mgmt = (struct ieee80211_mgmt *) skb->data;
  1366. fc = le16_to_cpu(mgmt->frame_control);
  1367. switch (fc & IEEE80211_FCTL_STYPE) {
  1368. case IEEE80211_STYPE_PROBE_REQ:
  1369. case IEEE80211_STYPE_PROBE_RESP:
  1370. case IEEE80211_STYPE_BEACON:
  1371. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  1372. case IEEE80211_STYPE_AUTH:
  1373. case IEEE80211_STYPE_ASSOC_RESP:
  1374. case IEEE80211_STYPE_REASSOC_RESP:
  1375. case IEEE80211_STYPE_DEAUTH:
  1376. case IEEE80211_STYPE_DISASSOC:
  1377. skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
  1378. queue_work(local->hw.workqueue, &sdata->u.mgd.work);
  1379. return RX_QUEUED;
  1380. }
  1381. return RX_DROP_MONITOR;
  1382. }
  1383. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1384. struct sk_buff *skb)
  1385. {
  1386. struct ieee80211_rx_status *rx_status;
  1387. struct ieee80211_mgmt *mgmt;
  1388. u16 fc;
  1389. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1390. mgmt = (struct ieee80211_mgmt *) skb->data;
  1391. fc = le16_to_cpu(mgmt->frame_control);
  1392. switch (fc & IEEE80211_FCTL_STYPE) {
  1393. case IEEE80211_STYPE_PROBE_RESP:
  1394. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
  1395. rx_status);
  1396. break;
  1397. case IEEE80211_STYPE_BEACON:
  1398. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1399. rx_status);
  1400. break;
  1401. case IEEE80211_STYPE_AUTH:
  1402. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  1403. break;
  1404. case IEEE80211_STYPE_ASSOC_RESP:
  1405. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
  1406. break;
  1407. case IEEE80211_STYPE_REASSOC_RESP:
  1408. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
  1409. break;
  1410. case IEEE80211_STYPE_DEAUTH:
  1411. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1412. break;
  1413. case IEEE80211_STYPE_DISASSOC:
  1414. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1415. break;
  1416. }
  1417. kfree_skb(skb);
  1418. }
  1419. static void ieee80211_sta_timer(unsigned long data)
  1420. {
  1421. struct ieee80211_sub_if_data *sdata =
  1422. (struct ieee80211_sub_if_data *) data;
  1423. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1424. struct ieee80211_local *local = sdata->local;
  1425. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1426. queue_work(local->hw.workqueue, &ifmgd->work);
  1427. }
  1428. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
  1429. {
  1430. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1431. struct ieee80211_local *local = sdata->local;
  1432. if (local->ops->reset_tsf) {
  1433. /* Reset own TSF to allow time synchronization work. */
  1434. local->ops->reset_tsf(local_to_hw(local));
  1435. }
  1436. ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
  1437. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1438. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1439. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1440. ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
  1441. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1442. ifmgd->auth_alg = WLAN_AUTH_LEAP;
  1443. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
  1444. ifmgd->auth_alg = WLAN_AUTH_FT;
  1445. else
  1446. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1447. ifmgd->auth_transaction = -1;
  1448. ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
  1449. ifmgd->assoc_scan_tries = 0;
  1450. ifmgd->direct_probe_tries = 0;
  1451. ifmgd->auth_tries = 0;
  1452. ifmgd->assoc_tries = 0;
  1453. netif_tx_stop_all_queues(sdata->dev);
  1454. netif_carrier_off(sdata->dev);
  1455. }
  1456. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
  1457. {
  1458. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1459. struct ieee80211_local *local = sdata->local;
  1460. struct ieee80211_bss *bss;
  1461. u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
  1462. u8 ssid_len = ifmgd->ssid_len;
  1463. u16 capa_mask = WLAN_CAPABILITY_ESS;
  1464. u16 capa_val = WLAN_CAPABILITY_ESS;
  1465. struct ieee80211_channel *chan = local->oper_channel;
  1466. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1467. ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  1468. IEEE80211_STA_AUTO_BSSID_SEL |
  1469. IEEE80211_STA_AUTO_CHANNEL_SEL)) {
  1470. capa_mask |= WLAN_CAPABILITY_PRIVACY;
  1471. if (sdata->default_key)
  1472. capa_val |= WLAN_CAPABILITY_PRIVACY;
  1473. }
  1474. if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  1475. chan = NULL;
  1476. if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  1477. bssid = NULL;
  1478. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
  1479. ssid = NULL;
  1480. ssid_len = 0;
  1481. }
  1482. bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
  1483. bssid, ssid, ssid_len,
  1484. capa_mask, capa_val);
  1485. if (bss) {
  1486. ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
  1487. if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
  1488. ieee80211_sta_set_ssid(sdata, bss->ssid,
  1489. bss->ssid_len);
  1490. ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
  1491. ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
  1492. bss->supp_rates);
  1493. if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
  1494. sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
  1495. else
  1496. sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
  1497. /* Send out direct probe if no probe resp was received or
  1498. * the one we have is outdated
  1499. */
  1500. if (!bss->last_probe_resp ||
  1501. time_after(jiffies, bss->last_probe_resp
  1502. + IEEE80211_SCAN_RESULT_EXPIRE))
  1503. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1504. else
  1505. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1506. ieee80211_rx_bss_put(local, bss);
  1507. ieee80211_sta_reset_auth(sdata);
  1508. return 0;
  1509. } else {
  1510. if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  1511. ifmgd->assoc_scan_tries++;
  1512. /* XXX maybe racy? */
  1513. if (local->scan_req)
  1514. return -1;
  1515. memcpy(local->int_scan_req.ssids[0].ssid,
  1516. ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
  1517. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
  1518. local->int_scan_req.ssids[0].ssid_len = 0;
  1519. else
  1520. local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
  1521. if (ieee80211_start_scan(sdata, &local->int_scan_req))
  1522. ieee80211_scan_failed(local);
  1523. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1524. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1525. } else {
  1526. ifmgd->assoc_scan_tries = 0;
  1527. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  1528. }
  1529. }
  1530. return -1;
  1531. }
  1532. static void ieee80211_sta_work(struct work_struct *work)
  1533. {
  1534. struct ieee80211_sub_if_data *sdata =
  1535. container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
  1536. struct ieee80211_local *local = sdata->local;
  1537. struct ieee80211_if_managed *ifmgd;
  1538. struct sk_buff *skb;
  1539. if (!netif_running(sdata->dev))
  1540. return;
  1541. if (local->sw_scanning || local->hw_scanning)
  1542. return;
  1543. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1544. return;
  1545. ifmgd = &sdata->u.mgd;
  1546. while ((skb = skb_dequeue(&ifmgd->skb_queue)))
  1547. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1548. if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  1549. ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1550. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
  1551. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
  1552. /*
  1553. * The call to ieee80211_start_scan can fail but ieee80211_request_scan
  1554. * (which queued ieee80211_sta_work) did not return an error. Thus, call
  1555. * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
  1556. * notify the scan requester.
  1557. */
  1558. if (ieee80211_start_scan(sdata, local->scan_req))
  1559. ieee80211_scan_failed(local);
  1560. return;
  1561. }
  1562. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
  1563. if (ieee80211_sta_config_auth(sdata))
  1564. return;
  1565. clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1566. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
  1567. return;
  1568. switch (ifmgd->state) {
  1569. case IEEE80211_STA_MLME_DISABLED:
  1570. break;
  1571. case IEEE80211_STA_MLME_DIRECT_PROBE:
  1572. ieee80211_direct_probe(sdata);
  1573. break;
  1574. case IEEE80211_STA_MLME_AUTHENTICATE:
  1575. ieee80211_authenticate(sdata);
  1576. break;
  1577. case IEEE80211_STA_MLME_ASSOCIATE:
  1578. ieee80211_associate(sdata);
  1579. break;
  1580. case IEEE80211_STA_MLME_ASSOCIATED:
  1581. ieee80211_associated(sdata);
  1582. break;
  1583. default:
  1584. WARN_ON(1);
  1585. break;
  1586. }
  1587. if (ieee80211_privacy_mismatch(sdata)) {
  1588. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  1589. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  1590. ieee80211_set_disassoc(sdata, false, true,
  1591. WLAN_REASON_UNSPECIFIED);
  1592. }
  1593. }
  1594. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1595. {
  1596. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1597. queue_work(sdata->local->hw.workqueue,
  1598. &sdata->u.mgd.work);
  1599. }
  1600. /* interface setup */
  1601. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1602. {
  1603. struct ieee80211_if_managed *ifmgd;
  1604. ifmgd = &sdata->u.mgd;
  1605. INIT_WORK(&ifmgd->work, ieee80211_sta_work);
  1606. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1607. INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
  1608. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1609. (unsigned long) sdata);
  1610. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1611. (unsigned long) sdata);
  1612. skb_queue_head_init(&ifmgd->skb_queue);
  1613. ifmgd->capab = WLAN_CAPABILITY_ESS;
  1614. ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
  1615. IEEE80211_AUTH_ALG_SHARED_KEY;
  1616. ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
  1617. IEEE80211_STA_AUTO_BSSID_SEL |
  1618. IEEE80211_STA_AUTO_CHANNEL_SEL;
  1619. if (sdata->local->hw.queues >= 4)
  1620. ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
  1621. }
  1622. /* configuration hooks */
  1623. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
  1624. {
  1625. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1626. struct ieee80211_local *local = sdata->local;
  1627. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1628. return;
  1629. if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
  1630. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  1631. (ifmgd->flags & (IEEE80211_STA_SSID_SET |
  1632. IEEE80211_STA_AUTO_SSID_SEL))) {
  1633. if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
  1634. ieee80211_set_disassoc(sdata, true, true,
  1635. WLAN_REASON_DEAUTH_LEAVING);
  1636. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
  1637. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1638. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1639. else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
  1640. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1641. queue_work(local->hw.workqueue, &ifmgd->work);
  1642. }
  1643. }
  1644. int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
  1645. {
  1646. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1647. if (ifmgd->ssid_len)
  1648. ifmgd->flags |= IEEE80211_STA_SSID_SET;
  1649. else
  1650. ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
  1651. return 0;
  1652. }
  1653. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  1654. {
  1655. struct ieee80211_if_managed *ifmgd;
  1656. if (len > IEEE80211_MAX_SSID_LEN)
  1657. return -EINVAL;
  1658. ifmgd = &sdata->u.mgd;
  1659. if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
  1660. /*
  1661. * Do not use reassociation if SSID is changed (different ESS).
  1662. */
  1663. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1664. memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
  1665. memcpy(ifmgd->ssid, ssid, len);
  1666. ifmgd->ssid_len = len;
  1667. }
  1668. return ieee80211_sta_commit(sdata);
  1669. }
  1670. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  1671. {
  1672. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1673. memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
  1674. *len = ifmgd->ssid_len;
  1675. return 0;
  1676. }
  1677. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  1678. {
  1679. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1680. if (is_valid_ether_addr(bssid)) {
  1681. memcpy(ifmgd->bssid, bssid, ETH_ALEN);
  1682. ifmgd->flags |= IEEE80211_STA_BSSID_SET;
  1683. } else {
  1684. memset(ifmgd->bssid, 0, ETH_ALEN);
  1685. ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
  1686. }
  1687. if (netif_running(sdata->dev)) {
  1688. if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
  1689. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  1690. "the low-level driver\n", sdata->dev->name);
  1691. }
  1692. }
  1693. return ieee80211_sta_commit(sdata);
  1694. }
  1695. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
  1696. const char *ie, size_t len)
  1697. {
  1698. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1699. kfree(ifmgd->extra_ie);
  1700. if (len == 0) {
  1701. ifmgd->extra_ie = NULL;
  1702. ifmgd->extra_ie_len = 0;
  1703. return 0;
  1704. }
  1705. ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
  1706. if (!ifmgd->extra_ie) {
  1707. ifmgd->extra_ie_len = 0;
  1708. return -ENOMEM;
  1709. }
  1710. memcpy(ifmgd->extra_ie, ie, len);
  1711. ifmgd->extra_ie_len = len;
  1712. return 0;
  1713. }
  1714. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1715. {
  1716. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  1717. sdata->dev->name, reason);
  1718. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1719. return -EINVAL;
  1720. ieee80211_set_disassoc(sdata, true, true, reason);
  1721. return 0;
  1722. }
  1723. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1724. {
  1725. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1726. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  1727. sdata->dev->name, reason);
  1728. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1729. return -EINVAL;
  1730. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
  1731. return -ENOLINK;
  1732. ieee80211_set_disassoc(sdata, false, true, reason);
  1733. return 0;
  1734. }
  1735. /* scan finished notification */
  1736. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1737. {
  1738. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1739. /* Restart STA timers */
  1740. rcu_read_lock();
  1741. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1742. ieee80211_restart_sta_timer(sdata);
  1743. rcu_read_unlock();
  1744. }
  1745. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1746. {
  1747. struct ieee80211_local *local =
  1748. container_of(work, struct ieee80211_local,
  1749. dynamic_ps_disable_work);
  1750. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1751. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1752. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1753. }
  1754. ieee80211_wake_queues_by_reason(&local->hw,
  1755. IEEE80211_QUEUE_STOP_REASON_PS);
  1756. }
  1757. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1758. {
  1759. struct ieee80211_local *local =
  1760. container_of(work, struct ieee80211_local,
  1761. dynamic_ps_enable_work);
  1762. /* XXX: using scan_sdata is completely broken! */
  1763. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1764. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1765. return;
  1766. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
  1767. ieee80211_send_nullfunc(local, sdata, 1);
  1768. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1769. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1770. }
  1771. void ieee80211_dynamic_ps_timer(unsigned long data)
  1772. {
  1773. struct ieee80211_local *local = (void *) data;
  1774. queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
  1775. }
  1776. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  1777. struct ieee80211_sub_if_data *sdata,
  1778. int powersave)
  1779. {
  1780. struct sk_buff *skb;
  1781. struct ieee80211_hdr *nullfunc;
  1782. __le16 fc;
  1783. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1784. return;
  1785. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
  1786. if (!skb) {
  1787. printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
  1788. "frame\n", sdata->dev->name);
  1789. return;
  1790. }
  1791. skb_reserve(skb, local->hw.extra_tx_headroom);
  1792. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
  1793. memset(nullfunc, 0, 24);
  1794. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  1795. IEEE80211_FCTL_TODS);
  1796. if (powersave)
  1797. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  1798. nullfunc->frame_control = fc;
  1799. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1800. memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
  1801. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  1802. ieee80211_tx_skb(sdata, skb, 0);
  1803. }