mlme.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167
  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. aid &= 0x3fff;
  385. index = aid / 8;
  386. mask = 1 << (aid & 7);
  387. indexn1 = tim->bitmap_ctrl & 0xfe;
  388. indexn2 = elems->tim_len + indexn1 - 4;
  389. if (index < indexn1 || index > indexn2)
  390. return false;
  391. index -= indexn1;
  392. return !!(tim->virtual_map[index] & mask);
  393. }
  394. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  395. u16 capab, bool erp_valid, u8 erp)
  396. {
  397. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  398. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  399. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  400. #endif
  401. u32 changed = 0;
  402. bool use_protection;
  403. bool use_short_preamble;
  404. bool use_short_slot;
  405. if (erp_valid) {
  406. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  407. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  408. } else {
  409. use_protection = false;
  410. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  411. }
  412. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  413. if (use_protection != bss_conf->use_cts_prot) {
  414. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  415. if (net_ratelimit()) {
  416. printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
  417. sdata->dev->name,
  418. use_protection ? "enabled" : "disabled",
  419. ifmgd->bssid);
  420. }
  421. #endif
  422. bss_conf->use_cts_prot = use_protection;
  423. changed |= BSS_CHANGED_ERP_CTS_PROT;
  424. }
  425. if (use_short_preamble != bss_conf->use_short_preamble) {
  426. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  427. if (net_ratelimit()) {
  428. printk(KERN_DEBUG "%s: switched to %s barker preamble"
  429. " (BSSID=%pM)\n",
  430. sdata->dev->name,
  431. use_short_preamble ? "short" : "long",
  432. ifmgd->bssid);
  433. }
  434. #endif
  435. bss_conf->use_short_preamble = use_short_preamble;
  436. changed |= BSS_CHANGED_ERP_PREAMBLE;
  437. }
  438. if (use_short_slot != bss_conf->use_short_slot) {
  439. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  440. if (net_ratelimit()) {
  441. printk(KERN_DEBUG "%s: switched to %s slot time"
  442. " (BSSID=%pM)\n",
  443. sdata->dev->name,
  444. use_short_slot ? "short" : "long",
  445. ifmgd->bssid);
  446. }
  447. #endif
  448. bss_conf->use_short_slot = use_short_slot;
  449. changed |= BSS_CHANGED_ERP_SLOT;
  450. }
  451. return changed;
  452. }
  453. static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
  454. {
  455. union iwreq_data wrqu;
  456. memset(&wrqu, 0, sizeof(wrqu));
  457. if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
  458. memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
  459. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  460. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  461. }
  462. static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
  463. {
  464. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  465. char *buf;
  466. size_t len;
  467. int i;
  468. union iwreq_data wrqu;
  469. if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
  470. return;
  471. buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
  472. ifmgd->assocresp_ies_len), GFP_KERNEL);
  473. if (!buf)
  474. return;
  475. len = sprintf(buf, "ASSOCINFO(");
  476. if (ifmgd->assocreq_ies) {
  477. len += sprintf(buf + len, "ReqIEs=");
  478. for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
  479. len += sprintf(buf + len, "%02x",
  480. ifmgd->assocreq_ies[i]);
  481. }
  482. }
  483. if (ifmgd->assocresp_ies) {
  484. if (ifmgd->assocreq_ies)
  485. len += sprintf(buf + len, " ");
  486. len += sprintf(buf + len, "RespIEs=");
  487. for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
  488. len += sprintf(buf + len, "%02x",
  489. ifmgd->assocresp_ies[i]);
  490. }
  491. }
  492. len += sprintf(buf + len, ")");
  493. if (len > IW_CUSTOM_MAX) {
  494. len = sprintf(buf, "ASSOCRESPIE=");
  495. for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
  496. len += sprintf(buf + len, "%02x",
  497. ifmgd->assocresp_ies[i]);
  498. }
  499. }
  500. if (len <= IW_CUSTOM_MAX) {
  501. memset(&wrqu, 0, sizeof(wrqu));
  502. wrqu.data.length = len;
  503. wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
  504. }
  505. kfree(buf);
  506. }
  507. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  508. u32 bss_info_changed)
  509. {
  510. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  511. struct ieee80211_local *local = sdata->local;
  512. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  513. struct ieee80211_bss *bss;
  514. bss_info_changed |= BSS_CHANGED_ASSOC;
  515. ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
  516. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  517. conf->channel->center_freq,
  518. ifmgd->ssid, ifmgd->ssid_len);
  519. if (bss) {
  520. /* set timing information */
  521. sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
  522. sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
  523. sdata->vif.bss_conf.dtim_period = bss->dtim_period;
  524. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  525. bss->cbss.capability, bss->has_erp_value, bss->erp_value);
  526. cfg80211_hold_bss(&bss->cbss);
  527. ieee80211_rx_bss_put(local, bss);
  528. }
  529. ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
  530. memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
  531. ieee80211_sta_send_associnfo(sdata);
  532. ifmgd->last_probe = jiffies;
  533. ieee80211_led_assoc(local, 1);
  534. sdata->vif.bss_conf.assoc = 1;
  535. /*
  536. * For now just always ask the driver to update the basic rateset
  537. * when we have associated, we aren't checking whether it actually
  538. * changed or not.
  539. */
  540. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  541. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  542. if (local->powersave) {
  543. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
  544. local->hw.conf.dynamic_ps_timeout > 0) {
  545. mod_timer(&local->dynamic_ps_timer, jiffies +
  546. msecs_to_jiffies(
  547. local->hw.conf.dynamic_ps_timeout));
  548. } else {
  549. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  550. ieee80211_send_nullfunc(local, sdata, 1);
  551. conf->flags |= IEEE80211_CONF_PS;
  552. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  553. }
  554. }
  555. netif_tx_start_all_queues(sdata->dev);
  556. netif_carrier_on(sdata->dev);
  557. ieee80211_sta_send_apinfo(sdata);
  558. }
  559. static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
  560. {
  561. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  562. struct ieee80211_local *local = sdata->local;
  563. ifmgd->direct_probe_tries++;
  564. if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
  565. printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
  566. sdata->dev->name, ifmgd->bssid);
  567. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  568. ieee80211_sta_send_apinfo(sdata);
  569. /*
  570. * Most likely AP is not in the range so remove the
  571. * bss information associated to the AP
  572. */
  573. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  574. sdata->local->hw.conf.channel->center_freq,
  575. ifmgd->ssid, ifmgd->ssid_len);
  576. /*
  577. * We might have a pending scan which had no chance to run yet
  578. * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
  579. * Hence, queue the STAs work again
  580. */
  581. queue_work(local->hw.workqueue, &ifmgd->work);
  582. return;
  583. }
  584. printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
  585. sdata->dev->name, ifmgd->bssid,
  586. ifmgd->direct_probe_tries);
  587. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  588. set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
  589. /* Direct probe is sent to broadcast address as some APs
  590. * will not answer to direct packet in unassociated state.
  591. */
  592. ieee80211_send_probe_req(sdata, NULL,
  593. ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
  594. mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  595. }
  596. static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
  597. {
  598. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  599. struct ieee80211_local *local = sdata->local;
  600. u8 *ies;
  601. size_t ies_len;
  602. ifmgd->auth_tries++;
  603. if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  604. printk(KERN_DEBUG "%s: authentication with AP %pM"
  605. " timed out\n",
  606. sdata->dev->name, ifmgd->bssid);
  607. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  608. ieee80211_sta_send_apinfo(sdata);
  609. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  610. sdata->local->hw.conf.channel->center_freq,
  611. ifmgd->ssid, ifmgd->ssid_len);
  612. /*
  613. * We might have a pending scan which had no chance to run yet
  614. * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
  615. * Hence, queue the STAs work again
  616. */
  617. queue_work(local->hw.workqueue, &ifmgd->work);
  618. return;
  619. }
  620. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  621. printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
  622. sdata->dev->name, ifmgd->bssid);
  623. if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
  624. ies = ifmgd->sme_auth_ie;
  625. ies_len = ifmgd->sme_auth_ie_len;
  626. } else {
  627. ies = NULL;
  628. ies_len = 0;
  629. }
  630. ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
  631. ifmgd->bssid, 0);
  632. ifmgd->auth_transaction = 2;
  633. mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  634. }
  635. /*
  636. * The disassoc 'reason' argument can be either our own reason
  637. * if self disconnected or a reason code from the AP.
  638. */
  639. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  640. bool deauth, bool self_disconnected,
  641. u16 reason)
  642. {
  643. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  644. struct ieee80211_local *local = sdata->local;
  645. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  646. struct ieee80211_bss *bss;
  647. struct sta_info *sta;
  648. u32 changed = 0, config_changed = 0;
  649. rcu_read_lock();
  650. sta = sta_info_get(local, ifmgd->bssid);
  651. if (!sta) {
  652. rcu_read_unlock();
  653. return;
  654. }
  655. if (deauth) {
  656. ifmgd->direct_probe_tries = 0;
  657. ifmgd->auth_tries = 0;
  658. }
  659. ifmgd->assoc_scan_tries = 0;
  660. ifmgd->assoc_tries = 0;
  661. netif_tx_stop_all_queues(sdata->dev);
  662. netif_carrier_off(sdata->dev);
  663. ieee80211_sta_tear_down_BA_sessions(sta);
  664. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  665. conf->channel->center_freq,
  666. ifmgd->ssid, ifmgd->ssid_len);
  667. if (bss) {
  668. cfg80211_unhold_bss(&bss->cbss);
  669. ieee80211_rx_bss_put(local, bss);
  670. }
  671. if (self_disconnected) {
  672. if (deauth)
  673. ieee80211_send_deauth_disassoc(sdata,
  674. IEEE80211_STYPE_DEAUTH, reason);
  675. else
  676. ieee80211_send_deauth_disassoc(sdata,
  677. IEEE80211_STYPE_DISASSOC, reason);
  678. }
  679. ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
  680. changed |= ieee80211_reset_erp_info(sdata);
  681. ieee80211_led_assoc(local, 0);
  682. changed |= BSS_CHANGED_ASSOC;
  683. sdata->vif.bss_conf.assoc = false;
  684. ieee80211_sta_send_apinfo(sdata);
  685. if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
  686. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  687. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  688. sdata->local->hw.conf.channel->center_freq,
  689. ifmgd->ssid, ifmgd->ssid_len);
  690. }
  691. rcu_read_unlock();
  692. /* channel(_type) changes are handled by ieee80211_hw_config */
  693. local->oper_channel_type = NL80211_CHAN_NO_HT;
  694. local->power_constr_level = 0;
  695. del_timer_sync(&local->dynamic_ps_timer);
  696. cancel_work_sync(&local->dynamic_ps_enable_work);
  697. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  698. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  699. config_changed |= IEEE80211_CONF_CHANGE_PS;
  700. }
  701. ieee80211_hw_config(local, config_changed);
  702. ieee80211_bss_info_change_notify(sdata, changed);
  703. rcu_read_lock();
  704. sta = sta_info_get(local, ifmgd->bssid);
  705. if (!sta) {
  706. rcu_read_unlock();
  707. return;
  708. }
  709. sta_info_unlink(&sta);
  710. rcu_read_unlock();
  711. sta_info_destroy(sta);
  712. }
  713. static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
  714. {
  715. if (!sdata || !sdata->default_key ||
  716. sdata->default_key->conf.alg != ALG_WEP)
  717. return 0;
  718. return 1;
  719. }
  720. static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
  721. {
  722. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  723. struct ieee80211_local *local = sdata->local;
  724. struct ieee80211_bss *bss;
  725. int bss_privacy;
  726. int wep_privacy;
  727. int privacy_invoked;
  728. if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
  729. return 0;
  730. bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
  731. local->hw.conf.channel->center_freq,
  732. ifmgd->ssid, ifmgd->ssid_len);
  733. if (!bss)
  734. return 0;
  735. bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
  736. wep_privacy = !!ieee80211_sta_wep_configured(sdata);
  737. privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
  738. ieee80211_rx_bss_put(local, bss);
  739. if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
  740. return 0;
  741. return 1;
  742. }
  743. static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
  744. {
  745. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  746. struct ieee80211_local *local = sdata->local;
  747. ifmgd->assoc_tries++;
  748. if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  749. printk(KERN_DEBUG "%s: association with AP %pM"
  750. " timed out\n",
  751. sdata->dev->name, ifmgd->bssid);
  752. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  753. ieee80211_sta_send_apinfo(sdata);
  754. ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
  755. sdata->local->hw.conf.channel->center_freq,
  756. ifmgd->ssid, ifmgd->ssid_len);
  757. /*
  758. * We might have a pending scan which had no chance to run yet
  759. * due to state == IEEE80211_STA_MLME_ASSOCIATE.
  760. * Hence, queue the STAs work again
  761. */
  762. queue_work(local->hw.workqueue, &ifmgd->work);
  763. return;
  764. }
  765. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
  766. printk(KERN_DEBUG "%s: associate with AP %pM\n",
  767. sdata->dev->name, ifmgd->bssid);
  768. if (ieee80211_privacy_mismatch(sdata)) {
  769. printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
  770. "mixed-cell disabled - abort association\n", sdata->dev->name);
  771. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  772. return;
  773. }
  774. ieee80211_send_assoc(sdata);
  775. mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
  776. }
  777. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  778. struct ieee80211_hdr *hdr)
  779. {
  780. /*
  781. * We can postpone the mgd.timer whenever receiving unicast frames
  782. * from AP because we know that the connection is working both ways
  783. * at that time. But multicast frames (and hence also beacons) must
  784. * be ignored here, because we need to trigger the timer during
  785. * data idle periods for sending the periodical probe request to
  786. * the AP.
  787. */
  788. if (!is_multicast_ether_addr(hdr->addr1))
  789. mod_timer(&sdata->u.mgd.timer,
  790. jiffies + IEEE80211_MONITORING_INTERVAL);
  791. }
  792. void ieee80211_beacon_loss_work(struct work_struct *work)
  793. {
  794. struct ieee80211_sub_if_data *sdata =
  795. container_of(work, struct ieee80211_sub_if_data,
  796. u.mgd.beacon_loss_work);
  797. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  798. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  799. if (net_ratelimit()) {
  800. printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
  801. "- sending probe request\n", sdata->dev->name,
  802. sdata->u.mgd.bssid);
  803. }
  804. #endif
  805. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  806. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  807. ifmgd->ssid_len, NULL, 0);
  808. mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
  809. }
  810. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  811. {
  812. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  813. queue_work(sdata->local->hw.workqueue,
  814. &sdata->u.mgd.beacon_loss_work);
  815. }
  816. EXPORT_SYMBOL(ieee80211_beacon_loss);
  817. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
  818. {
  819. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  820. struct ieee80211_local *local = sdata->local;
  821. struct sta_info *sta;
  822. bool disassoc = false;
  823. /* TODO: start monitoring current AP signal quality and number of
  824. * missed beacons. Scan other channels every now and then and search
  825. * for better APs. */
  826. /* TODO: remove expired BSSes */
  827. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
  828. rcu_read_lock();
  829. sta = sta_info_get(local, ifmgd->bssid);
  830. if (!sta) {
  831. printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
  832. sdata->dev->name, ifmgd->bssid);
  833. disassoc = true;
  834. goto unlock;
  835. }
  836. if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
  837. time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  838. printk(KERN_DEBUG "%s: no probe response from AP %pM "
  839. "- disassociating\n",
  840. sdata->dev->name, ifmgd->bssid);
  841. disassoc = true;
  842. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  843. goto unlock;
  844. }
  845. /*
  846. * Beacon filtering is only enabled with power save and then the
  847. * stack should not check for beacon loss.
  848. */
  849. if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
  850. (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
  851. time_after(jiffies,
  852. ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
  853. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  854. if (net_ratelimit()) {
  855. printk(KERN_DEBUG "%s: beacon loss from AP %pM "
  856. "- sending probe request\n",
  857. sdata->dev->name, ifmgd->bssid);
  858. }
  859. #endif
  860. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  861. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  862. ifmgd->ssid_len, NULL, 0);
  863. goto unlock;
  864. }
  865. if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
  866. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  867. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  868. ifmgd->ssid_len, NULL, 0);
  869. }
  870. unlock:
  871. rcu_read_unlock();
  872. if (disassoc)
  873. ieee80211_set_disassoc(sdata, true, true,
  874. WLAN_REASON_PREV_AUTH_NOT_VALID);
  875. else
  876. mod_timer(&ifmgd->timer, jiffies +
  877. IEEE80211_MONITORING_INTERVAL);
  878. }
  879. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
  880. {
  881. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  882. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  883. ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
  884. if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
  885. /* Wait for SME to request association */
  886. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  887. } else
  888. ieee80211_associate(sdata);
  889. }
  890. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  891. struct ieee80211_mgmt *mgmt,
  892. size_t len)
  893. {
  894. u8 *pos;
  895. struct ieee802_11_elems elems;
  896. pos = mgmt->u.auth.variable;
  897. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  898. if (!elems.challenge)
  899. return;
  900. ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
  901. elems.challenge - 2, elems.challenge_len + 2,
  902. sdata->u.mgd.bssid, 1);
  903. sdata->u.mgd.auth_transaction = 4;
  904. }
  905. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  906. struct ieee80211_mgmt *mgmt,
  907. size_t len)
  908. {
  909. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  910. u16 auth_alg, auth_transaction, status_code;
  911. if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
  912. return;
  913. if (len < 24 + 6)
  914. return;
  915. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  916. return;
  917. if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  918. return;
  919. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  920. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  921. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  922. if (auth_alg != ifmgd->auth_alg ||
  923. auth_transaction != ifmgd->auth_transaction)
  924. return;
  925. if (status_code != WLAN_STATUS_SUCCESS) {
  926. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  927. u8 algs[3];
  928. const int num_algs = ARRAY_SIZE(algs);
  929. int i, pos;
  930. algs[0] = algs[1] = algs[2] = 0xff;
  931. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  932. algs[0] = WLAN_AUTH_OPEN;
  933. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  934. algs[1] = WLAN_AUTH_SHARED_KEY;
  935. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  936. algs[2] = WLAN_AUTH_LEAP;
  937. if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
  938. pos = 0;
  939. else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
  940. pos = 1;
  941. else
  942. pos = 2;
  943. for (i = 0; i < num_algs; i++) {
  944. pos++;
  945. if (pos >= num_algs)
  946. pos = 0;
  947. if (algs[pos] == ifmgd->auth_alg ||
  948. algs[pos] == 0xff)
  949. continue;
  950. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  951. !ieee80211_sta_wep_configured(sdata))
  952. continue;
  953. ifmgd->auth_alg = algs[pos];
  954. break;
  955. }
  956. }
  957. return;
  958. }
  959. switch (ifmgd->auth_alg) {
  960. case WLAN_AUTH_OPEN:
  961. case WLAN_AUTH_LEAP:
  962. case WLAN_AUTH_FT:
  963. ieee80211_auth_completed(sdata);
  964. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  965. break;
  966. case WLAN_AUTH_SHARED_KEY:
  967. if (ifmgd->auth_transaction == 4) {
  968. ieee80211_auth_completed(sdata);
  969. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  970. } else
  971. ieee80211_auth_challenge(sdata, mgmt, len);
  972. break;
  973. }
  974. }
  975. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  976. struct ieee80211_mgmt *mgmt,
  977. size_t len)
  978. {
  979. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  980. u16 reason_code;
  981. if (len < 24 + 2)
  982. return;
  983. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  984. return;
  985. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  986. if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
  987. printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
  988. sdata->dev->name, reason_code);
  989. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  990. (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  991. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
  992. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
  993. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  994. mod_timer(&ifmgd->timer, jiffies +
  995. IEEE80211_RETRY_AUTH_INTERVAL);
  996. }
  997. ieee80211_set_disassoc(sdata, true, false, 0);
  998. ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
  999. cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len);
  1000. }
  1001. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1002. struct ieee80211_mgmt *mgmt,
  1003. size_t len)
  1004. {
  1005. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1006. u16 reason_code;
  1007. if (len < 24 + 2)
  1008. return;
  1009. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  1010. return;
  1011. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1012. if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
  1013. printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
  1014. sdata->dev->name, reason_code);
  1015. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1016. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1017. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
  1018. mod_timer(&ifmgd->timer, jiffies +
  1019. IEEE80211_RETRY_AUTH_INTERVAL);
  1020. }
  1021. ieee80211_set_disassoc(sdata, false, false, reason_code);
  1022. cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len);
  1023. }
  1024. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1025. struct ieee80211_mgmt *mgmt,
  1026. size_t len,
  1027. int reassoc)
  1028. {
  1029. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1030. struct ieee80211_local *local = sdata->local;
  1031. struct ieee80211_supported_band *sband;
  1032. struct sta_info *sta;
  1033. u32 rates, basic_rates;
  1034. u16 capab_info, status_code, aid;
  1035. struct ieee802_11_elems elems;
  1036. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1037. u8 *pos;
  1038. u32 changed = 0;
  1039. int i, j;
  1040. bool have_higher_than_11mbit = false, newsta = false;
  1041. u16 ap_ht_cap_flags;
  1042. /* AssocResp and ReassocResp have identical structure, so process both
  1043. * of them in this function. */
  1044. if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1045. return;
  1046. if (len < 24 + 6)
  1047. return;
  1048. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  1049. return;
  1050. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1051. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1052. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1053. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1054. "status=%d aid=%d)\n",
  1055. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1056. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1057. pos = mgmt->u.assoc_resp.variable;
  1058. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1059. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  1060. elems.timeout_int && elems.timeout_int_len == 5 &&
  1061. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  1062. u32 tu, ms;
  1063. tu = get_unaligned_le32(elems.timeout_int + 1);
  1064. ms = tu * 1024 / 1000;
  1065. printk(KERN_DEBUG "%s: AP rejected association temporarily; "
  1066. "comeback duration %u TU (%u ms)\n",
  1067. sdata->dev->name, tu, ms);
  1068. if (ms > IEEE80211_ASSOC_TIMEOUT)
  1069. mod_timer(&ifmgd->timer,
  1070. jiffies + msecs_to_jiffies(ms));
  1071. return;
  1072. }
  1073. if (status_code != WLAN_STATUS_SUCCESS) {
  1074. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1075. sdata->dev->name, status_code);
  1076. /* if this was a reassociation, ensure we try a "full"
  1077. * association next time. This works around some broken APs
  1078. * which do not correctly reject reassociation requests. */
  1079. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1080. return;
  1081. }
  1082. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1083. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1084. "set\n", sdata->dev->name, aid);
  1085. aid &= ~(BIT(15) | BIT(14));
  1086. if (!elems.supp_rates) {
  1087. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1088. sdata->dev->name);
  1089. return;
  1090. }
  1091. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1092. ifmgd->aid = aid;
  1093. ifmgd->ap_capab = capab_info;
  1094. kfree(ifmgd->assocresp_ies);
  1095. ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1096. ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
  1097. if (ifmgd->assocresp_ies)
  1098. memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
  1099. rcu_read_lock();
  1100. /* Add STA entry for the AP */
  1101. sta = sta_info_get(local, ifmgd->bssid);
  1102. if (!sta) {
  1103. newsta = true;
  1104. sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
  1105. if (!sta) {
  1106. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1107. " the AP\n", sdata->dev->name);
  1108. rcu_read_unlock();
  1109. return;
  1110. }
  1111. /* update new sta with its last rx activity */
  1112. sta->last_rx = jiffies;
  1113. }
  1114. /*
  1115. * FIXME: Do we really need to update the sta_info's information here?
  1116. * We already know about the AP (we found it in our list) so it
  1117. * should already be filled with the right info, no?
  1118. * As is stands, all this is racy because typically we assume
  1119. * the information that is filled in here (except flags) doesn't
  1120. * change while a STA structure is alive. As such, it should move
  1121. * to between the sta_info_alloc() and sta_info_insert() above.
  1122. */
  1123. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1124. WLAN_STA_AUTHORIZED);
  1125. rates = 0;
  1126. basic_rates = 0;
  1127. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1128. for (i = 0; i < elems.supp_rates_len; i++) {
  1129. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1130. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1131. if (rate > 110)
  1132. have_higher_than_11mbit = true;
  1133. for (j = 0; j < sband->n_bitrates; j++) {
  1134. if (sband->bitrates[j].bitrate == rate) {
  1135. rates |= BIT(j);
  1136. if (is_basic)
  1137. basic_rates |= BIT(j);
  1138. break;
  1139. }
  1140. }
  1141. }
  1142. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1143. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1144. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1145. if (rate > 110)
  1146. have_higher_than_11mbit = true;
  1147. for (j = 0; j < sband->n_bitrates; j++) {
  1148. if (sband->bitrates[j].bitrate == rate) {
  1149. rates |= BIT(j);
  1150. if (is_basic)
  1151. basic_rates |= BIT(j);
  1152. break;
  1153. }
  1154. }
  1155. }
  1156. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1157. sdata->vif.bss_conf.basic_rates = basic_rates;
  1158. /* cf. IEEE 802.11 9.2.12 */
  1159. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1160. have_higher_than_11mbit)
  1161. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1162. else
  1163. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1164. /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
  1165. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1166. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1167. elems.ht_cap_elem, &sta->sta.ht_cap);
  1168. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1169. rate_control_rate_init(sta);
  1170. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1171. set_sta_flags(sta, WLAN_STA_MFP);
  1172. if (elems.wmm_param)
  1173. set_sta_flags(sta, WLAN_STA_WME);
  1174. if (newsta) {
  1175. int err = sta_info_insert(sta);
  1176. if (err) {
  1177. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1178. " the AP (error %d)\n", sdata->dev->name, err);
  1179. rcu_read_unlock();
  1180. return;
  1181. }
  1182. }
  1183. rcu_read_unlock();
  1184. if (elems.wmm_param)
  1185. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1186. elems.wmm_param_len);
  1187. if (elems.ht_info_elem && elems.wmm_param &&
  1188. (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  1189. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1190. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1191. ap_ht_cap_flags);
  1192. /* set AID and assoc capability,
  1193. * ieee80211_set_associated() will tell the driver */
  1194. bss_conf->aid = aid;
  1195. bss_conf->assoc_capability = capab_info;
  1196. ieee80211_set_associated(sdata, changed);
  1197. /*
  1198. * initialise the time of last beacon to be the association time,
  1199. * otherwise beacon loss check will trigger immediately
  1200. */
  1201. ifmgd->last_beacon = jiffies;
  1202. ieee80211_associated(sdata);
  1203. cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
  1204. }
  1205. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1206. struct ieee80211_mgmt *mgmt,
  1207. size_t len,
  1208. struct ieee80211_rx_status *rx_status,
  1209. struct ieee802_11_elems *elems,
  1210. bool beacon)
  1211. {
  1212. struct ieee80211_local *local = sdata->local;
  1213. int freq;
  1214. struct ieee80211_bss *bss;
  1215. struct ieee80211_channel *channel;
  1216. if (elems->ds_params && elems->ds_params_len == 1)
  1217. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1218. else
  1219. freq = rx_status->freq;
  1220. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1221. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1222. return;
  1223. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1224. channel, beacon);
  1225. if (!bss)
  1226. return;
  1227. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1228. (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
  1229. struct ieee80211_channel_sw_ie *sw_elem =
  1230. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1231. ieee80211_process_chanswitch(sdata, sw_elem, bss);
  1232. }
  1233. ieee80211_rx_bss_put(local, bss);
  1234. }
  1235. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1236. struct ieee80211_mgmt *mgmt,
  1237. size_t len,
  1238. struct ieee80211_rx_status *rx_status)
  1239. {
  1240. struct ieee80211_if_managed *ifmgd;
  1241. size_t baselen;
  1242. struct ieee802_11_elems elems;
  1243. ifmgd = &sdata->u.mgd;
  1244. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1245. return; /* ignore ProbeResp to foreign address */
  1246. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1247. if (baselen > len)
  1248. return;
  1249. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1250. &elems);
  1251. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1252. /* direct probe may be part of the association flow */
  1253. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  1254. &ifmgd->request)) {
  1255. printk(KERN_DEBUG "%s direct probe responded\n",
  1256. sdata->dev->name);
  1257. ieee80211_authenticate(sdata);
  1258. }
  1259. if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
  1260. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  1261. }
  1262. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1263. struct ieee80211_mgmt *mgmt,
  1264. size_t len,
  1265. struct ieee80211_rx_status *rx_status)
  1266. {
  1267. struct ieee80211_if_managed *ifmgd;
  1268. size_t baselen;
  1269. struct ieee802_11_elems elems;
  1270. struct ieee80211_local *local = sdata->local;
  1271. u32 changed = 0;
  1272. bool erp_valid, directed_tim;
  1273. u8 erp_value = 0;
  1274. /* Process beacon from the current BSS */
  1275. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1276. if (baselen > len)
  1277. return;
  1278. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  1279. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  1280. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1281. return;
  1282. ifmgd = &sdata->u.mgd;
  1283. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
  1284. memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1285. return;
  1286. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1287. return;
  1288. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1289. elems.wmm_param_len);
  1290. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1291. directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
  1292. if (directed_tim) {
  1293. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1294. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1295. ieee80211_hw_config(local,
  1296. IEEE80211_CONF_CHANGE_PS);
  1297. ieee80211_send_nullfunc(local, sdata, 0);
  1298. } else {
  1299. local->pspolling = true;
  1300. /*
  1301. * Here is assumed that the driver will be
  1302. * able to send ps-poll frame and receive a
  1303. * response even though power save mode is
  1304. * enabled, but some drivers might require
  1305. * to disable power save here. This needs
  1306. * to be investigated.
  1307. */
  1308. ieee80211_send_pspoll(local, sdata);
  1309. }
  1310. }
  1311. }
  1312. if (elems.erp_info && elems.erp_info_len >= 1) {
  1313. erp_valid = true;
  1314. erp_value = elems.erp_info[0];
  1315. } else {
  1316. erp_valid = false;
  1317. }
  1318. changed |= ieee80211_handle_bss_capability(sdata,
  1319. le16_to_cpu(mgmt->u.beacon.capab_info),
  1320. erp_valid, erp_value);
  1321. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1322. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
  1323. struct sta_info *sta;
  1324. struct ieee80211_supported_band *sband;
  1325. u16 ap_ht_cap_flags;
  1326. rcu_read_lock();
  1327. sta = sta_info_get(local, ifmgd->bssid);
  1328. if (!sta) {
  1329. rcu_read_unlock();
  1330. return;
  1331. }
  1332. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1333. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1334. elems.ht_cap_elem, &sta->sta.ht_cap);
  1335. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1336. rcu_read_unlock();
  1337. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1338. ap_ht_cap_flags);
  1339. }
  1340. if (elems.country_elem) {
  1341. /* Note we are only reviewing this on beacons
  1342. * for the BSSID we are associated to */
  1343. regulatory_hint_11d(local->hw.wiphy,
  1344. elems.country_elem, elems.country_elem_len);
  1345. /* TODO: IBSS also needs this */
  1346. if (elems.pwr_constr_elem)
  1347. ieee80211_handle_pwr_constr(sdata,
  1348. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1349. elems.pwr_constr_elem,
  1350. elems.pwr_constr_elem_len);
  1351. }
  1352. ieee80211_bss_info_change_notify(sdata, changed);
  1353. }
  1354. ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
  1355. struct sk_buff *skb,
  1356. struct ieee80211_rx_status *rx_status)
  1357. {
  1358. struct ieee80211_local *local = sdata->local;
  1359. struct ieee80211_mgmt *mgmt;
  1360. u16 fc;
  1361. if (skb->len < 24)
  1362. return RX_DROP_MONITOR;
  1363. mgmt = (struct ieee80211_mgmt *) skb->data;
  1364. fc = le16_to_cpu(mgmt->frame_control);
  1365. switch (fc & IEEE80211_FCTL_STYPE) {
  1366. case IEEE80211_STYPE_PROBE_REQ:
  1367. case IEEE80211_STYPE_PROBE_RESP:
  1368. case IEEE80211_STYPE_BEACON:
  1369. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  1370. case IEEE80211_STYPE_AUTH:
  1371. case IEEE80211_STYPE_ASSOC_RESP:
  1372. case IEEE80211_STYPE_REASSOC_RESP:
  1373. case IEEE80211_STYPE_DEAUTH:
  1374. case IEEE80211_STYPE_DISASSOC:
  1375. skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
  1376. queue_work(local->hw.workqueue, &sdata->u.mgd.work);
  1377. return RX_QUEUED;
  1378. }
  1379. return RX_DROP_MONITOR;
  1380. }
  1381. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1382. struct sk_buff *skb)
  1383. {
  1384. struct ieee80211_rx_status *rx_status;
  1385. struct ieee80211_mgmt *mgmt;
  1386. u16 fc;
  1387. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1388. mgmt = (struct ieee80211_mgmt *) skb->data;
  1389. fc = le16_to_cpu(mgmt->frame_control);
  1390. switch (fc & IEEE80211_FCTL_STYPE) {
  1391. case IEEE80211_STYPE_PROBE_RESP:
  1392. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
  1393. rx_status);
  1394. break;
  1395. case IEEE80211_STYPE_BEACON:
  1396. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1397. rx_status);
  1398. break;
  1399. case IEEE80211_STYPE_AUTH:
  1400. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  1401. break;
  1402. case IEEE80211_STYPE_ASSOC_RESP:
  1403. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
  1404. break;
  1405. case IEEE80211_STYPE_REASSOC_RESP:
  1406. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
  1407. break;
  1408. case IEEE80211_STYPE_DEAUTH:
  1409. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1410. break;
  1411. case IEEE80211_STYPE_DISASSOC:
  1412. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1413. break;
  1414. }
  1415. kfree_skb(skb);
  1416. }
  1417. static void ieee80211_sta_timer(unsigned long data)
  1418. {
  1419. struct ieee80211_sub_if_data *sdata =
  1420. (struct ieee80211_sub_if_data *) data;
  1421. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1422. struct ieee80211_local *local = sdata->local;
  1423. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1424. queue_work(local->hw.workqueue, &ifmgd->work);
  1425. }
  1426. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
  1427. {
  1428. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1429. struct ieee80211_local *local = sdata->local;
  1430. if (local->ops->reset_tsf) {
  1431. /* Reset own TSF to allow time synchronization work. */
  1432. local->ops->reset_tsf(local_to_hw(local));
  1433. }
  1434. ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
  1435. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1436. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1437. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1438. ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
  1439. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1440. ifmgd->auth_alg = WLAN_AUTH_LEAP;
  1441. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
  1442. ifmgd->auth_alg = WLAN_AUTH_FT;
  1443. else
  1444. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1445. ifmgd->auth_transaction = -1;
  1446. ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
  1447. ifmgd->assoc_scan_tries = 0;
  1448. ifmgd->direct_probe_tries = 0;
  1449. ifmgd->auth_tries = 0;
  1450. ifmgd->assoc_tries = 0;
  1451. netif_tx_stop_all_queues(sdata->dev);
  1452. netif_carrier_off(sdata->dev);
  1453. }
  1454. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
  1455. {
  1456. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1457. struct ieee80211_local *local = sdata->local;
  1458. struct ieee80211_bss *bss;
  1459. u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
  1460. u8 ssid_len = ifmgd->ssid_len;
  1461. u16 capa_mask = WLAN_CAPABILITY_ESS;
  1462. u16 capa_val = WLAN_CAPABILITY_ESS;
  1463. struct ieee80211_channel *chan = local->oper_channel;
  1464. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1465. ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  1466. IEEE80211_STA_AUTO_BSSID_SEL |
  1467. IEEE80211_STA_AUTO_CHANNEL_SEL)) {
  1468. capa_mask |= WLAN_CAPABILITY_PRIVACY;
  1469. if (sdata->default_key)
  1470. capa_val |= WLAN_CAPABILITY_PRIVACY;
  1471. }
  1472. if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  1473. chan = NULL;
  1474. if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  1475. bssid = NULL;
  1476. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
  1477. ssid = NULL;
  1478. ssid_len = 0;
  1479. }
  1480. bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
  1481. bssid, ssid, ssid_len,
  1482. capa_mask, capa_val);
  1483. if (bss) {
  1484. ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
  1485. if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
  1486. ieee80211_sta_set_ssid(sdata, bss->ssid,
  1487. bss->ssid_len);
  1488. ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
  1489. ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
  1490. bss->supp_rates);
  1491. if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
  1492. sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
  1493. else
  1494. sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
  1495. /* Send out direct probe if no probe resp was received or
  1496. * the one we have is outdated
  1497. */
  1498. if (!bss->last_probe_resp ||
  1499. time_after(jiffies, bss->last_probe_resp
  1500. + IEEE80211_SCAN_RESULT_EXPIRE))
  1501. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1502. else
  1503. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1504. ieee80211_rx_bss_put(local, bss);
  1505. ieee80211_sta_reset_auth(sdata);
  1506. return 0;
  1507. } else {
  1508. if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  1509. ifmgd->assoc_scan_tries++;
  1510. /* XXX maybe racy? */
  1511. if (local->scan_req)
  1512. return -1;
  1513. memcpy(local->int_scan_req.ssids[0].ssid,
  1514. ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
  1515. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
  1516. local->int_scan_req.ssids[0].ssid_len = 0;
  1517. else
  1518. local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
  1519. if (ieee80211_start_scan(sdata, &local->int_scan_req))
  1520. ieee80211_scan_failed(local);
  1521. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1522. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1523. } else {
  1524. ifmgd->assoc_scan_tries = 0;
  1525. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  1526. }
  1527. }
  1528. return -1;
  1529. }
  1530. static void ieee80211_sta_work(struct work_struct *work)
  1531. {
  1532. struct ieee80211_sub_if_data *sdata =
  1533. container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
  1534. struct ieee80211_local *local = sdata->local;
  1535. struct ieee80211_if_managed *ifmgd;
  1536. struct sk_buff *skb;
  1537. if (!netif_running(sdata->dev))
  1538. return;
  1539. if (local->sw_scanning || local->hw_scanning)
  1540. return;
  1541. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1542. return;
  1543. ifmgd = &sdata->u.mgd;
  1544. while ((skb = skb_dequeue(&ifmgd->skb_queue)))
  1545. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1546. if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  1547. ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1548. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
  1549. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
  1550. /*
  1551. * The call to ieee80211_start_scan can fail but ieee80211_request_scan
  1552. * (which queued ieee80211_sta_work) did not return an error. Thus, call
  1553. * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
  1554. * notify the scan requester.
  1555. */
  1556. if (ieee80211_start_scan(sdata, local->scan_req))
  1557. ieee80211_scan_failed(local);
  1558. return;
  1559. }
  1560. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
  1561. if (ieee80211_sta_config_auth(sdata))
  1562. return;
  1563. clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1564. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
  1565. return;
  1566. switch (ifmgd->state) {
  1567. case IEEE80211_STA_MLME_DISABLED:
  1568. break;
  1569. case IEEE80211_STA_MLME_DIRECT_PROBE:
  1570. ieee80211_direct_probe(sdata);
  1571. break;
  1572. case IEEE80211_STA_MLME_AUTHENTICATE:
  1573. ieee80211_authenticate(sdata);
  1574. break;
  1575. case IEEE80211_STA_MLME_ASSOCIATE:
  1576. ieee80211_associate(sdata);
  1577. break;
  1578. case IEEE80211_STA_MLME_ASSOCIATED:
  1579. ieee80211_associated(sdata);
  1580. break;
  1581. default:
  1582. WARN_ON(1);
  1583. break;
  1584. }
  1585. if (ieee80211_privacy_mismatch(sdata)) {
  1586. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  1587. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  1588. ieee80211_set_disassoc(sdata, false, true,
  1589. WLAN_REASON_UNSPECIFIED);
  1590. }
  1591. }
  1592. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1593. {
  1594. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1595. queue_work(sdata->local->hw.workqueue,
  1596. &sdata->u.mgd.work);
  1597. }
  1598. /* interface setup */
  1599. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1600. {
  1601. struct ieee80211_if_managed *ifmgd;
  1602. ifmgd = &sdata->u.mgd;
  1603. INIT_WORK(&ifmgd->work, ieee80211_sta_work);
  1604. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1605. INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
  1606. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1607. (unsigned long) sdata);
  1608. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1609. (unsigned long) sdata);
  1610. skb_queue_head_init(&ifmgd->skb_queue);
  1611. ifmgd->capab = WLAN_CAPABILITY_ESS;
  1612. ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
  1613. IEEE80211_AUTH_ALG_SHARED_KEY;
  1614. ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
  1615. IEEE80211_STA_AUTO_BSSID_SEL |
  1616. IEEE80211_STA_AUTO_CHANNEL_SEL;
  1617. if (sdata->local->hw.queues >= 4)
  1618. ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
  1619. }
  1620. /* configuration hooks */
  1621. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
  1622. {
  1623. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1624. struct ieee80211_local *local = sdata->local;
  1625. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1626. return;
  1627. if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
  1628. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  1629. (ifmgd->flags & (IEEE80211_STA_SSID_SET |
  1630. IEEE80211_STA_AUTO_SSID_SEL))) {
  1631. if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
  1632. ieee80211_set_disassoc(sdata, true, true,
  1633. WLAN_REASON_DEAUTH_LEAVING);
  1634. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
  1635. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1636. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1637. else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
  1638. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1639. queue_work(local->hw.workqueue, &ifmgd->work);
  1640. }
  1641. }
  1642. int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
  1643. {
  1644. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1645. if (ifmgd->ssid_len)
  1646. ifmgd->flags |= IEEE80211_STA_SSID_SET;
  1647. else
  1648. ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
  1649. return 0;
  1650. }
  1651. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  1652. {
  1653. struct ieee80211_if_managed *ifmgd;
  1654. if (len > IEEE80211_MAX_SSID_LEN)
  1655. return -EINVAL;
  1656. ifmgd = &sdata->u.mgd;
  1657. if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
  1658. /*
  1659. * Do not use reassociation if SSID is changed (different ESS).
  1660. */
  1661. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1662. memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
  1663. memcpy(ifmgd->ssid, ssid, len);
  1664. ifmgd->ssid_len = len;
  1665. }
  1666. return ieee80211_sta_commit(sdata);
  1667. }
  1668. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  1669. {
  1670. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1671. memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
  1672. *len = ifmgd->ssid_len;
  1673. return 0;
  1674. }
  1675. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  1676. {
  1677. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1678. if (is_valid_ether_addr(bssid)) {
  1679. memcpy(ifmgd->bssid, bssid, ETH_ALEN);
  1680. ifmgd->flags |= IEEE80211_STA_BSSID_SET;
  1681. } else {
  1682. memset(ifmgd->bssid, 0, ETH_ALEN);
  1683. ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
  1684. }
  1685. if (netif_running(sdata->dev)) {
  1686. if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
  1687. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  1688. "the low-level driver\n", sdata->dev->name);
  1689. }
  1690. }
  1691. return ieee80211_sta_commit(sdata);
  1692. }
  1693. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
  1694. const char *ie, size_t len)
  1695. {
  1696. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1697. kfree(ifmgd->extra_ie);
  1698. if (len == 0) {
  1699. ifmgd->extra_ie = NULL;
  1700. ifmgd->extra_ie_len = 0;
  1701. return 0;
  1702. }
  1703. ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
  1704. if (!ifmgd->extra_ie) {
  1705. ifmgd->extra_ie_len = 0;
  1706. return -ENOMEM;
  1707. }
  1708. memcpy(ifmgd->extra_ie, ie, len);
  1709. ifmgd->extra_ie_len = len;
  1710. return 0;
  1711. }
  1712. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1713. {
  1714. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  1715. sdata->dev->name, reason);
  1716. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1717. return -EINVAL;
  1718. ieee80211_set_disassoc(sdata, true, true, reason);
  1719. return 0;
  1720. }
  1721. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1722. {
  1723. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1724. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  1725. sdata->dev->name, reason);
  1726. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1727. return -EINVAL;
  1728. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
  1729. return -ENOLINK;
  1730. ieee80211_set_disassoc(sdata, false, true, reason);
  1731. return 0;
  1732. }
  1733. /* scan finished notification */
  1734. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1735. {
  1736. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1737. /* Restart STA timers */
  1738. rcu_read_lock();
  1739. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1740. ieee80211_restart_sta_timer(sdata);
  1741. rcu_read_unlock();
  1742. }
  1743. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1744. {
  1745. struct ieee80211_local *local =
  1746. container_of(work, struct ieee80211_local,
  1747. dynamic_ps_disable_work);
  1748. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1749. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1750. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1751. }
  1752. ieee80211_wake_queues_by_reason(&local->hw,
  1753. IEEE80211_QUEUE_STOP_REASON_PS);
  1754. }
  1755. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1756. {
  1757. struct ieee80211_local *local =
  1758. container_of(work, struct ieee80211_local,
  1759. dynamic_ps_enable_work);
  1760. /* XXX: using scan_sdata is completely broken! */
  1761. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1762. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1763. return;
  1764. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
  1765. ieee80211_send_nullfunc(local, sdata, 1);
  1766. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1767. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1768. }
  1769. void ieee80211_dynamic_ps_timer(unsigned long data)
  1770. {
  1771. struct ieee80211_local *local = (void *) data;
  1772. queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
  1773. }
  1774. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  1775. struct ieee80211_sub_if_data *sdata,
  1776. int powersave)
  1777. {
  1778. struct sk_buff *skb;
  1779. struct ieee80211_hdr *nullfunc;
  1780. __le16 fc;
  1781. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1782. return;
  1783. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
  1784. if (!skb) {
  1785. printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
  1786. "frame\n", sdata->dev->name);
  1787. return;
  1788. }
  1789. skb_reserve(skb, local->hw.extra_tx_headroom);
  1790. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
  1791. memset(nullfunc, 0, 24);
  1792. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  1793. IEEE80211_FCTL_TODS);
  1794. if (powersave)
  1795. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  1796. nullfunc->frame_control = fc;
  1797. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1798. memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
  1799. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  1800. ieee80211_tx_skb(sdata, skb, 0);
  1801. }