mlme.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  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. printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
  799. "- sending probe request\n", sdata->dev->name,
  800. sdata->u.mgd.bssid);
  801. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  802. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  803. ifmgd->ssid_len, NULL, 0);
  804. mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
  805. }
  806. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  807. {
  808. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  809. queue_work(sdata->local->hw.workqueue,
  810. &sdata->u.mgd.beacon_loss_work);
  811. }
  812. EXPORT_SYMBOL(ieee80211_beacon_loss);
  813. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
  814. {
  815. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  816. struct ieee80211_local *local = sdata->local;
  817. struct sta_info *sta;
  818. bool disassoc = false;
  819. /* TODO: start monitoring current AP signal quality and number of
  820. * missed beacons. Scan other channels every now and then and search
  821. * for better APs. */
  822. /* TODO: remove expired BSSes */
  823. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
  824. rcu_read_lock();
  825. sta = sta_info_get(local, ifmgd->bssid);
  826. if (!sta) {
  827. printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
  828. sdata->dev->name, ifmgd->bssid);
  829. disassoc = true;
  830. goto unlock;
  831. }
  832. if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
  833. time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  834. printk(KERN_DEBUG "%s: no probe response from AP %pM "
  835. "- disassociating\n",
  836. sdata->dev->name, ifmgd->bssid);
  837. disassoc = true;
  838. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  839. goto unlock;
  840. }
  841. /*
  842. * Beacon filtering is only enabled with power save and then the
  843. * stack should not check for beacon loss.
  844. */
  845. if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
  846. (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
  847. time_after(jiffies,
  848. ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
  849. printk(KERN_DEBUG "%s: beacon loss from AP %pM "
  850. "- sending probe request\n",
  851. sdata->dev->name, ifmgd->bssid);
  852. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  853. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  854. ifmgd->ssid_len, NULL, 0);
  855. goto unlock;
  856. }
  857. if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
  858. ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
  859. ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
  860. ifmgd->ssid_len, NULL, 0);
  861. }
  862. unlock:
  863. rcu_read_unlock();
  864. if (disassoc)
  865. ieee80211_set_disassoc(sdata, true, true,
  866. WLAN_REASON_PREV_AUTH_NOT_VALID);
  867. else
  868. mod_timer(&ifmgd->timer, jiffies +
  869. IEEE80211_MONITORING_INTERVAL);
  870. }
  871. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
  872. {
  873. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  874. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  875. ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
  876. if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
  877. /* Wait for SME to request association */
  878. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  879. } else
  880. ieee80211_associate(sdata);
  881. }
  882. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  883. struct ieee80211_mgmt *mgmt,
  884. size_t len)
  885. {
  886. u8 *pos;
  887. struct ieee802_11_elems elems;
  888. pos = mgmt->u.auth.variable;
  889. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  890. if (!elems.challenge)
  891. return;
  892. ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
  893. elems.challenge - 2, elems.challenge_len + 2,
  894. sdata->u.mgd.bssid, 1);
  895. sdata->u.mgd.auth_transaction = 4;
  896. }
  897. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  898. struct ieee80211_mgmt *mgmt,
  899. size_t len)
  900. {
  901. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  902. u16 auth_alg, auth_transaction, status_code;
  903. if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
  904. return;
  905. if (len < 24 + 6)
  906. return;
  907. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  908. return;
  909. if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  910. return;
  911. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  912. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  913. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  914. if (auth_alg != ifmgd->auth_alg ||
  915. auth_transaction != ifmgd->auth_transaction)
  916. return;
  917. if (status_code != WLAN_STATUS_SUCCESS) {
  918. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  919. u8 algs[3];
  920. const int num_algs = ARRAY_SIZE(algs);
  921. int i, pos;
  922. algs[0] = algs[1] = algs[2] = 0xff;
  923. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  924. algs[0] = WLAN_AUTH_OPEN;
  925. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  926. algs[1] = WLAN_AUTH_SHARED_KEY;
  927. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  928. algs[2] = WLAN_AUTH_LEAP;
  929. if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
  930. pos = 0;
  931. else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
  932. pos = 1;
  933. else
  934. pos = 2;
  935. for (i = 0; i < num_algs; i++) {
  936. pos++;
  937. if (pos >= num_algs)
  938. pos = 0;
  939. if (algs[pos] == ifmgd->auth_alg ||
  940. algs[pos] == 0xff)
  941. continue;
  942. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  943. !ieee80211_sta_wep_configured(sdata))
  944. continue;
  945. ifmgd->auth_alg = algs[pos];
  946. break;
  947. }
  948. }
  949. return;
  950. }
  951. switch (ifmgd->auth_alg) {
  952. case WLAN_AUTH_OPEN:
  953. case WLAN_AUTH_LEAP:
  954. case WLAN_AUTH_FT:
  955. ieee80211_auth_completed(sdata);
  956. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  957. break;
  958. case WLAN_AUTH_SHARED_KEY:
  959. if (ifmgd->auth_transaction == 4) {
  960. ieee80211_auth_completed(sdata);
  961. cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
  962. } else
  963. ieee80211_auth_challenge(sdata, mgmt, len);
  964. break;
  965. }
  966. }
  967. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  968. struct ieee80211_mgmt *mgmt,
  969. size_t len)
  970. {
  971. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  972. u16 reason_code;
  973. if (len < 24 + 2)
  974. return;
  975. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  976. return;
  977. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  978. if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
  979. printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
  980. sdata->dev->name, reason_code);
  981. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  982. (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  983. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
  984. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
  985. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  986. mod_timer(&ifmgd->timer, jiffies +
  987. IEEE80211_RETRY_AUTH_INTERVAL);
  988. }
  989. ieee80211_set_disassoc(sdata, true, false, 0);
  990. ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
  991. cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len);
  992. }
  993. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  994. struct ieee80211_mgmt *mgmt,
  995. size_t len)
  996. {
  997. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  998. u16 reason_code;
  999. if (len < 24 + 2)
  1000. return;
  1001. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
  1002. return;
  1003. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1004. if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
  1005. printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
  1006. sdata->dev->name, reason_code);
  1007. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1008. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1009. ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
  1010. mod_timer(&ifmgd->timer, jiffies +
  1011. IEEE80211_RETRY_AUTH_INTERVAL);
  1012. }
  1013. ieee80211_set_disassoc(sdata, false, false, reason_code);
  1014. cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len);
  1015. }
  1016. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1017. struct ieee80211_mgmt *mgmt,
  1018. size_t len,
  1019. int reassoc)
  1020. {
  1021. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1022. struct ieee80211_local *local = sdata->local;
  1023. struct ieee80211_supported_band *sband;
  1024. struct sta_info *sta;
  1025. u32 rates, basic_rates;
  1026. u16 capab_info, status_code, aid;
  1027. struct ieee802_11_elems elems;
  1028. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1029. u8 *pos;
  1030. u32 changed = 0;
  1031. int i, j;
  1032. bool have_higher_than_11mbit = false, newsta = false;
  1033. u16 ap_ht_cap_flags;
  1034. /* AssocResp and ReassocResp have identical structure, so process both
  1035. * of them in this function. */
  1036. if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1037. return;
  1038. if (len < 24 + 6)
  1039. return;
  1040. if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
  1041. return;
  1042. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1043. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1044. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1045. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1046. "status=%d aid=%d)\n",
  1047. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1048. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1049. pos = mgmt->u.assoc_resp.variable;
  1050. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1051. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  1052. elems.timeout_int && elems.timeout_int_len == 5 &&
  1053. elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  1054. u32 tu, ms;
  1055. tu = get_unaligned_le32(elems.timeout_int + 1);
  1056. ms = tu * 1024 / 1000;
  1057. printk(KERN_DEBUG "%s: AP rejected association temporarily; "
  1058. "comeback duration %u TU (%u ms)\n",
  1059. sdata->dev->name, tu, ms);
  1060. if (ms > IEEE80211_ASSOC_TIMEOUT)
  1061. mod_timer(&ifmgd->timer,
  1062. jiffies + msecs_to_jiffies(ms));
  1063. return;
  1064. }
  1065. if (status_code != WLAN_STATUS_SUCCESS) {
  1066. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1067. sdata->dev->name, status_code);
  1068. /* if this was a reassociation, ensure we try a "full"
  1069. * association next time. This works around some broken APs
  1070. * which do not correctly reject reassociation requests. */
  1071. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1072. return;
  1073. }
  1074. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1075. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1076. "set\n", sdata->dev->name, aid);
  1077. aid &= ~(BIT(15) | BIT(14));
  1078. if (!elems.supp_rates) {
  1079. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1080. sdata->dev->name);
  1081. return;
  1082. }
  1083. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1084. ifmgd->aid = aid;
  1085. ifmgd->ap_capab = capab_info;
  1086. kfree(ifmgd->assocresp_ies);
  1087. ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1088. ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
  1089. if (ifmgd->assocresp_ies)
  1090. memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
  1091. rcu_read_lock();
  1092. /* Add STA entry for the AP */
  1093. sta = sta_info_get(local, ifmgd->bssid);
  1094. if (!sta) {
  1095. newsta = true;
  1096. sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
  1097. if (!sta) {
  1098. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1099. " the AP\n", sdata->dev->name);
  1100. rcu_read_unlock();
  1101. return;
  1102. }
  1103. /* update new sta with its last rx activity */
  1104. sta->last_rx = jiffies;
  1105. }
  1106. /*
  1107. * FIXME: Do we really need to update the sta_info's information here?
  1108. * We already know about the AP (we found it in our list) so it
  1109. * should already be filled with the right info, no?
  1110. * As is stands, all this is racy because typically we assume
  1111. * the information that is filled in here (except flags) doesn't
  1112. * change while a STA structure is alive. As such, it should move
  1113. * to between the sta_info_alloc() and sta_info_insert() above.
  1114. */
  1115. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1116. WLAN_STA_AUTHORIZED);
  1117. rates = 0;
  1118. basic_rates = 0;
  1119. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1120. for (i = 0; i < elems.supp_rates_len; i++) {
  1121. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1122. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1123. if (rate > 110)
  1124. have_higher_than_11mbit = true;
  1125. for (j = 0; j < sband->n_bitrates; j++) {
  1126. if (sband->bitrates[j].bitrate == rate) {
  1127. rates |= BIT(j);
  1128. if (is_basic)
  1129. basic_rates |= BIT(j);
  1130. break;
  1131. }
  1132. }
  1133. }
  1134. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1135. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1136. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1137. if (rate > 110)
  1138. have_higher_than_11mbit = true;
  1139. for (j = 0; j < sband->n_bitrates; j++) {
  1140. if (sband->bitrates[j].bitrate == rate) {
  1141. rates |= BIT(j);
  1142. if (is_basic)
  1143. basic_rates |= BIT(j);
  1144. break;
  1145. }
  1146. }
  1147. }
  1148. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1149. sdata->vif.bss_conf.basic_rates = basic_rates;
  1150. /* cf. IEEE 802.11 9.2.12 */
  1151. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1152. have_higher_than_11mbit)
  1153. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1154. else
  1155. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1156. /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
  1157. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1158. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1159. elems.ht_cap_elem, &sta->sta.ht_cap);
  1160. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1161. rate_control_rate_init(sta);
  1162. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
  1163. set_sta_flags(sta, WLAN_STA_MFP);
  1164. if (elems.wmm_param)
  1165. set_sta_flags(sta, WLAN_STA_WME);
  1166. if (newsta) {
  1167. int err = sta_info_insert(sta);
  1168. if (err) {
  1169. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1170. " the AP (error %d)\n", sdata->dev->name, err);
  1171. rcu_read_unlock();
  1172. return;
  1173. }
  1174. }
  1175. rcu_read_unlock();
  1176. if (elems.wmm_param)
  1177. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1178. elems.wmm_param_len);
  1179. if (elems.ht_info_elem && elems.wmm_param &&
  1180. (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
  1181. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
  1182. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1183. ap_ht_cap_flags);
  1184. /* set AID and assoc capability,
  1185. * ieee80211_set_associated() will tell the driver */
  1186. bss_conf->aid = aid;
  1187. bss_conf->assoc_capability = capab_info;
  1188. ieee80211_set_associated(sdata, changed);
  1189. /*
  1190. * initialise the time of last beacon to be the association time,
  1191. * otherwise beacon loss check will trigger immediately
  1192. */
  1193. ifmgd->last_beacon = jiffies;
  1194. ieee80211_associated(sdata);
  1195. cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
  1196. }
  1197. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1198. struct ieee80211_mgmt *mgmt,
  1199. size_t len,
  1200. struct ieee80211_rx_status *rx_status,
  1201. struct ieee802_11_elems *elems,
  1202. bool beacon)
  1203. {
  1204. struct ieee80211_local *local = sdata->local;
  1205. int freq;
  1206. struct ieee80211_bss *bss;
  1207. struct ieee80211_channel *channel;
  1208. if (elems->ds_params && elems->ds_params_len == 1)
  1209. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1210. else
  1211. freq = rx_status->freq;
  1212. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1213. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1214. return;
  1215. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1216. channel, beacon);
  1217. if (!bss)
  1218. return;
  1219. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1220. (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
  1221. struct ieee80211_channel_sw_ie *sw_elem =
  1222. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1223. ieee80211_process_chanswitch(sdata, sw_elem, bss);
  1224. }
  1225. ieee80211_rx_bss_put(local, bss);
  1226. }
  1227. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1228. struct ieee80211_mgmt *mgmt,
  1229. size_t len,
  1230. struct ieee80211_rx_status *rx_status)
  1231. {
  1232. struct ieee80211_if_managed *ifmgd;
  1233. size_t baselen;
  1234. struct ieee802_11_elems elems;
  1235. ifmgd = &sdata->u.mgd;
  1236. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1237. return; /* ignore ProbeResp to foreign address */
  1238. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1239. if (baselen > len)
  1240. return;
  1241. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1242. &elems);
  1243. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1244. /* direct probe may be part of the association flow */
  1245. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  1246. &ifmgd->request)) {
  1247. printk(KERN_DEBUG "%s direct probe responded\n",
  1248. sdata->dev->name);
  1249. ieee80211_authenticate(sdata);
  1250. }
  1251. if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
  1252. ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  1253. }
  1254. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1255. struct ieee80211_mgmt *mgmt,
  1256. size_t len,
  1257. struct ieee80211_rx_status *rx_status)
  1258. {
  1259. struct ieee80211_if_managed *ifmgd;
  1260. size_t baselen;
  1261. struct ieee802_11_elems elems;
  1262. struct ieee80211_local *local = sdata->local;
  1263. u32 changed = 0;
  1264. bool erp_valid, directed_tim;
  1265. u8 erp_value = 0;
  1266. /* Process beacon from the current BSS */
  1267. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1268. if (baselen > len)
  1269. return;
  1270. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  1271. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  1272. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1273. return;
  1274. ifmgd = &sdata->u.mgd;
  1275. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
  1276. memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1277. return;
  1278. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1279. return;
  1280. ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
  1281. elems.wmm_param_len);
  1282. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
  1283. directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
  1284. if (directed_tim) {
  1285. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1286. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1287. ieee80211_hw_config(local,
  1288. IEEE80211_CONF_CHANGE_PS);
  1289. ieee80211_send_nullfunc(local, sdata, 0);
  1290. } else {
  1291. local->pspolling = true;
  1292. /*
  1293. * Here is assumed that the driver will be
  1294. * able to send ps-poll frame and receive a
  1295. * response even though power save mode is
  1296. * enabled, but some drivers might require
  1297. * to disable power save here. This needs
  1298. * to be investigated.
  1299. */
  1300. ieee80211_send_pspoll(local, sdata);
  1301. }
  1302. }
  1303. }
  1304. if (elems.erp_info && elems.erp_info_len >= 1) {
  1305. erp_valid = true;
  1306. erp_value = elems.erp_info[0];
  1307. } else {
  1308. erp_valid = false;
  1309. }
  1310. changed |= ieee80211_handle_bss_capability(sdata,
  1311. le16_to_cpu(mgmt->u.beacon.capab_info),
  1312. erp_valid, erp_value);
  1313. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1314. !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
  1315. struct sta_info *sta;
  1316. struct ieee80211_supported_band *sband;
  1317. u16 ap_ht_cap_flags;
  1318. rcu_read_lock();
  1319. sta = sta_info_get(local, ifmgd->bssid);
  1320. if (!sta) {
  1321. rcu_read_unlock();
  1322. return;
  1323. }
  1324. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1325. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1326. elems.ht_cap_elem, &sta->sta.ht_cap);
  1327. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1328. rcu_read_unlock();
  1329. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1330. ap_ht_cap_flags);
  1331. }
  1332. if (elems.country_elem) {
  1333. /* Note we are only reviewing this on beacons
  1334. * for the BSSID we are associated to */
  1335. regulatory_hint_11d(local->hw.wiphy,
  1336. elems.country_elem, elems.country_elem_len);
  1337. /* TODO: IBSS also needs this */
  1338. if (elems.pwr_constr_elem)
  1339. ieee80211_handle_pwr_constr(sdata,
  1340. le16_to_cpu(mgmt->u.probe_resp.capab_info),
  1341. elems.pwr_constr_elem,
  1342. elems.pwr_constr_elem_len);
  1343. }
  1344. ieee80211_bss_info_change_notify(sdata, changed);
  1345. }
  1346. ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
  1347. struct sk_buff *skb,
  1348. struct ieee80211_rx_status *rx_status)
  1349. {
  1350. struct ieee80211_local *local = sdata->local;
  1351. struct ieee80211_mgmt *mgmt;
  1352. u16 fc;
  1353. if (skb->len < 24)
  1354. return RX_DROP_MONITOR;
  1355. mgmt = (struct ieee80211_mgmt *) skb->data;
  1356. fc = le16_to_cpu(mgmt->frame_control);
  1357. switch (fc & IEEE80211_FCTL_STYPE) {
  1358. case IEEE80211_STYPE_PROBE_REQ:
  1359. case IEEE80211_STYPE_PROBE_RESP:
  1360. case IEEE80211_STYPE_BEACON:
  1361. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  1362. case IEEE80211_STYPE_AUTH:
  1363. case IEEE80211_STYPE_ASSOC_RESP:
  1364. case IEEE80211_STYPE_REASSOC_RESP:
  1365. case IEEE80211_STYPE_DEAUTH:
  1366. case IEEE80211_STYPE_DISASSOC:
  1367. skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
  1368. queue_work(local->hw.workqueue, &sdata->u.mgd.work);
  1369. return RX_QUEUED;
  1370. }
  1371. return RX_DROP_MONITOR;
  1372. }
  1373. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1374. struct sk_buff *skb)
  1375. {
  1376. struct ieee80211_rx_status *rx_status;
  1377. struct ieee80211_mgmt *mgmt;
  1378. u16 fc;
  1379. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1380. mgmt = (struct ieee80211_mgmt *) skb->data;
  1381. fc = le16_to_cpu(mgmt->frame_control);
  1382. switch (fc & IEEE80211_FCTL_STYPE) {
  1383. case IEEE80211_STYPE_PROBE_RESP:
  1384. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
  1385. rx_status);
  1386. break;
  1387. case IEEE80211_STYPE_BEACON:
  1388. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
  1389. rx_status);
  1390. break;
  1391. case IEEE80211_STYPE_AUTH:
  1392. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  1393. break;
  1394. case IEEE80211_STYPE_ASSOC_RESP:
  1395. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
  1396. break;
  1397. case IEEE80211_STYPE_REASSOC_RESP:
  1398. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
  1399. break;
  1400. case IEEE80211_STYPE_DEAUTH:
  1401. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  1402. break;
  1403. case IEEE80211_STYPE_DISASSOC:
  1404. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  1405. break;
  1406. }
  1407. kfree_skb(skb);
  1408. }
  1409. static void ieee80211_sta_timer(unsigned long data)
  1410. {
  1411. struct ieee80211_sub_if_data *sdata =
  1412. (struct ieee80211_sub_if_data *) data;
  1413. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1414. struct ieee80211_local *local = sdata->local;
  1415. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1416. queue_work(local->hw.workqueue, &ifmgd->work);
  1417. }
  1418. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
  1419. {
  1420. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1421. struct ieee80211_local *local = sdata->local;
  1422. if (local->ops->reset_tsf) {
  1423. /* Reset own TSF to allow time synchronization work. */
  1424. local->ops->reset_tsf(local_to_hw(local));
  1425. }
  1426. ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
  1427. if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1428. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1429. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1430. ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
  1431. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1432. ifmgd->auth_alg = WLAN_AUTH_LEAP;
  1433. else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
  1434. ifmgd->auth_alg = WLAN_AUTH_FT;
  1435. else
  1436. ifmgd->auth_alg = WLAN_AUTH_OPEN;
  1437. ifmgd->auth_transaction = -1;
  1438. ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
  1439. ifmgd->assoc_scan_tries = 0;
  1440. ifmgd->direct_probe_tries = 0;
  1441. ifmgd->auth_tries = 0;
  1442. ifmgd->assoc_tries = 0;
  1443. netif_tx_stop_all_queues(sdata->dev);
  1444. netif_carrier_off(sdata->dev);
  1445. }
  1446. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
  1447. {
  1448. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1449. struct ieee80211_local *local = sdata->local;
  1450. struct ieee80211_bss *bss;
  1451. u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
  1452. u8 ssid_len = ifmgd->ssid_len;
  1453. u16 capa_mask = WLAN_CAPABILITY_ESS;
  1454. u16 capa_val = WLAN_CAPABILITY_ESS;
  1455. struct ieee80211_channel *chan = local->oper_channel;
  1456. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
  1457. ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  1458. IEEE80211_STA_AUTO_BSSID_SEL |
  1459. IEEE80211_STA_AUTO_CHANNEL_SEL)) {
  1460. capa_mask |= WLAN_CAPABILITY_PRIVACY;
  1461. if (sdata->default_key)
  1462. capa_val |= WLAN_CAPABILITY_PRIVACY;
  1463. }
  1464. if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  1465. chan = NULL;
  1466. if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  1467. bssid = NULL;
  1468. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
  1469. ssid = NULL;
  1470. ssid_len = 0;
  1471. }
  1472. bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
  1473. bssid, ssid, ssid_len,
  1474. capa_mask, capa_val);
  1475. if (bss) {
  1476. ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
  1477. if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
  1478. ieee80211_sta_set_ssid(sdata, bss->ssid,
  1479. bss->ssid_len);
  1480. ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
  1481. ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
  1482. bss->supp_rates);
  1483. if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
  1484. sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
  1485. else
  1486. sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
  1487. /* Send out direct probe if no probe resp was received or
  1488. * the one we have is outdated
  1489. */
  1490. if (!bss->last_probe_resp ||
  1491. time_after(jiffies, bss->last_probe_resp
  1492. + IEEE80211_SCAN_RESULT_EXPIRE))
  1493. ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1494. else
  1495. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1496. ieee80211_rx_bss_put(local, bss);
  1497. ieee80211_sta_reset_auth(sdata);
  1498. return 0;
  1499. } else {
  1500. if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  1501. ifmgd->assoc_scan_tries++;
  1502. /* XXX maybe racy? */
  1503. if (local->scan_req)
  1504. return -1;
  1505. memcpy(local->int_scan_req.ssids[0].ssid,
  1506. ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
  1507. if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
  1508. local->int_scan_req.ssids[0].ssid_len = 0;
  1509. else
  1510. local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
  1511. if (ieee80211_start_scan(sdata, &local->int_scan_req))
  1512. ieee80211_scan_failed(local);
  1513. ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1514. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1515. } else {
  1516. ifmgd->assoc_scan_tries = 0;
  1517. ifmgd->state = IEEE80211_STA_MLME_DISABLED;
  1518. }
  1519. }
  1520. return -1;
  1521. }
  1522. static void ieee80211_sta_work(struct work_struct *work)
  1523. {
  1524. struct ieee80211_sub_if_data *sdata =
  1525. container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
  1526. struct ieee80211_local *local = sdata->local;
  1527. struct ieee80211_if_managed *ifmgd;
  1528. struct sk_buff *skb;
  1529. if (!netif_running(sdata->dev))
  1530. return;
  1531. if (local->sw_scanning || local->hw_scanning)
  1532. return;
  1533. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1534. return;
  1535. ifmgd = &sdata->u.mgd;
  1536. while ((skb = skb_dequeue(&ifmgd->skb_queue)))
  1537. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1538. if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  1539. ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1540. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
  1541. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
  1542. /*
  1543. * The call to ieee80211_start_scan can fail but ieee80211_request_scan
  1544. * (which queued ieee80211_sta_work) did not return an error. Thus, call
  1545. * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
  1546. * notify the scan requester.
  1547. */
  1548. if (ieee80211_start_scan(sdata, local->scan_req))
  1549. ieee80211_scan_failed(local);
  1550. return;
  1551. }
  1552. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
  1553. if (ieee80211_sta_config_auth(sdata))
  1554. return;
  1555. clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1556. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
  1557. return;
  1558. switch (ifmgd->state) {
  1559. case IEEE80211_STA_MLME_DISABLED:
  1560. break;
  1561. case IEEE80211_STA_MLME_DIRECT_PROBE:
  1562. ieee80211_direct_probe(sdata);
  1563. break;
  1564. case IEEE80211_STA_MLME_AUTHENTICATE:
  1565. ieee80211_authenticate(sdata);
  1566. break;
  1567. case IEEE80211_STA_MLME_ASSOCIATE:
  1568. ieee80211_associate(sdata);
  1569. break;
  1570. case IEEE80211_STA_MLME_ASSOCIATED:
  1571. ieee80211_associated(sdata);
  1572. break;
  1573. default:
  1574. WARN_ON(1);
  1575. break;
  1576. }
  1577. if (ieee80211_privacy_mismatch(sdata)) {
  1578. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  1579. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  1580. ieee80211_set_disassoc(sdata, false, true,
  1581. WLAN_REASON_UNSPECIFIED);
  1582. }
  1583. }
  1584. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  1585. {
  1586. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1587. queue_work(sdata->local->hw.workqueue,
  1588. &sdata->u.mgd.work);
  1589. }
  1590. /* interface setup */
  1591. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  1592. {
  1593. struct ieee80211_if_managed *ifmgd;
  1594. ifmgd = &sdata->u.mgd;
  1595. INIT_WORK(&ifmgd->work, ieee80211_sta_work);
  1596. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  1597. INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
  1598. setup_timer(&ifmgd->timer, ieee80211_sta_timer,
  1599. (unsigned long) sdata);
  1600. setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
  1601. (unsigned long) sdata);
  1602. skb_queue_head_init(&ifmgd->skb_queue);
  1603. ifmgd->capab = WLAN_CAPABILITY_ESS;
  1604. ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
  1605. IEEE80211_AUTH_ALG_SHARED_KEY;
  1606. ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
  1607. IEEE80211_STA_AUTO_BSSID_SEL |
  1608. IEEE80211_STA_AUTO_CHANNEL_SEL;
  1609. if (sdata->local->hw.queues >= 4)
  1610. ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
  1611. }
  1612. /* configuration hooks */
  1613. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
  1614. {
  1615. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1616. struct ieee80211_local *local = sdata->local;
  1617. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1618. return;
  1619. if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
  1620. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  1621. (ifmgd->flags & (IEEE80211_STA_SSID_SET |
  1622. IEEE80211_STA_AUTO_SSID_SEL))) {
  1623. if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
  1624. ieee80211_set_disassoc(sdata, true, true,
  1625. WLAN_REASON_DEAUTH_LEAVING);
  1626. if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
  1627. ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
  1628. set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
  1629. else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
  1630. set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
  1631. queue_work(local->hw.workqueue, &ifmgd->work);
  1632. }
  1633. }
  1634. int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
  1635. {
  1636. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1637. if (ifmgd->ssid_len)
  1638. ifmgd->flags |= IEEE80211_STA_SSID_SET;
  1639. else
  1640. ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
  1641. return 0;
  1642. }
  1643. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  1644. {
  1645. struct ieee80211_if_managed *ifmgd;
  1646. if (len > IEEE80211_MAX_SSID_LEN)
  1647. return -EINVAL;
  1648. ifmgd = &sdata->u.mgd;
  1649. if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
  1650. /*
  1651. * Do not use reassociation if SSID is changed (different ESS).
  1652. */
  1653. ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1654. memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
  1655. memcpy(ifmgd->ssid, ssid, len);
  1656. ifmgd->ssid_len = len;
  1657. }
  1658. return ieee80211_sta_commit(sdata);
  1659. }
  1660. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  1661. {
  1662. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1663. memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
  1664. *len = ifmgd->ssid_len;
  1665. return 0;
  1666. }
  1667. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  1668. {
  1669. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1670. if (is_valid_ether_addr(bssid)) {
  1671. memcpy(ifmgd->bssid, bssid, ETH_ALEN);
  1672. ifmgd->flags |= IEEE80211_STA_BSSID_SET;
  1673. } else {
  1674. memset(ifmgd->bssid, 0, ETH_ALEN);
  1675. ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
  1676. }
  1677. if (netif_running(sdata->dev)) {
  1678. if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
  1679. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  1680. "the low-level driver\n", sdata->dev->name);
  1681. }
  1682. }
  1683. return ieee80211_sta_commit(sdata);
  1684. }
  1685. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
  1686. const char *ie, size_t len)
  1687. {
  1688. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1689. kfree(ifmgd->extra_ie);
  1690. if (len == 0) {
  1691. ifmgd->extra_ie = NULL;
  1692. ifmgd->extra_ie_len = 0;
  1693. return 0;
  1694. }
  1695. ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
  1696. if (!ifmgd->extra_ie) {
  1697. ifmgd->extra_ie_len = 0;
  1698. return -ENOMEM;
  1699. }
  1700. memcpy(ifmgd->extra_ie, ie, len);
  1701. ifmgd->extra_ie_len = len;
  1702. return 0;
  1703. }
  1704. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1705. {
  1706. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  1707. sdata->dev->name, reason);
  1708. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1709. return -EINVAL;
  1710. ieee80211_set_disassoc(sdata, true, true, reason);
  1711. return 0;
  1712. }
  1713. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  1714. {
  1715. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1716. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  1717. sdata->dev->name, reason);
  1718. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1719. return -EINVAL;
  1720. if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
  1721. return -ENOLINK;
  1722. ieee80211_set_disassoc(sdata, false, true, reason);
  1723. return 0;
  1724. }
  1725. /* scan finished notification */
  1726. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  1727. {
  1728. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1729. /* Restart STA timers */
  1730. rcu_read_lock();
  1731. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  1732. ieee80211_restart_sta_timer(sdata);
  1733. rcu_read_unlock();
  1734. }
  1735. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1736. {
  1737. struct ieee80211_local *local =
  1738. container_of(work, struct ieee80211_local,
  1739. dynamic_ps_disable_work);
  1740. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1741. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1742. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1743. }
  1744. ieee80211_wake_queues_by_reason(&local->hw,
  1745. IEEE80211_QUEUE_STOP_REASON_PS);
  1746. }
  1747. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1748. {
  1749. struct ieee80211_local *local =
  1750. container_of(work, struct ieee80211_local,
  1751. dynamic_ps_enable_work);
  1752. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  1753. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1754. return;
  1755. if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
  1756. ieee80211_send_nullfunc(local, sdata, 1);
  1757. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1758. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1759. }
  1760. void ieee80211_dynamic_ps_timer(unsigned long data)
  1761. {
  1762. struct ieee80211_local *local = (void *) data;
  1763. queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
  1764. }
  1765. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  1766. struct ieee80211_sub_if_data *sdata,
  1767. int powersave)
  1768. {
  1769. struct sk_buff *skb;
  1770. struct ieee80211_hdr *nullfunc;
  1771. __le16 fc;
  1772. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1773. return;
  1774. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
  1775. if (!skb) {
  1776. printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
  1777. "frame\n", sdata->dev->name);
  1778. return;
  1779. }
  1780. skb_reserve(skb, local->hw.extra_tx_headroom);
  1781. nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
  1782. memset(nullfunc, 0, 24);
  1783. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  1784. IEEE80211_FCTL_TODS);
  1785. if (powersave)
  1786. fc |= cpu_to_le16(IEEE80211_FCTL_PM);
  1787. nullfunc->frame_control = fc;
  1788. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1789. memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
  1790. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  1791. ieee80211_tx_skb(sdata, skb, 0);
  1792. }