mlme.c 63 KB

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