mlme.c 57 KB

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