mlme.c 60 KB

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