mlme.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.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/wireless.h>
  18. #include <linux/random.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/rtnetlink.h>
  21. #include <net/iw_handler.h>
  22. #include <net/mac80211.h>
  23. #include <asm/unaligned.h>
  24. #include "ieee80211_i.h"
  25. #include "rate.h"
  26. #include "led.h"
  27. #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
  28. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  29. #define IEEE80211_AUTH_MAX_TRIES 3
  30. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  31. #define IEEE80211_ASSOC_MAX_TRIES 3
  32. #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
  33. #define IEEE80211_PROBE_INTERVAL (60 * HZ)
  34. #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
  35. #define IEEE80211_SCAN_INTERVAL (2 * HZ)
  36. #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
  37. #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
  38. #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
  39. #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
  40. #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
  41. /* utils */
  42. static int ecw2cw(int ecw)
  43. {
  44. return (1 << ecw) - 1;
  45. }
  46. static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
  47. {
  48. u8 *end, *pos;
  49. pos = bss->ies;
  50. if (pos == NULL)
  51. return NULL;
  52. end = pos + bss->ies_len;
  53. while (pos + 1 < end) {
  54. if (pos + 2 + pos[1] > end)
  55. break;
  56. if (pos[0] == ie)
  57. return pos;
  58. pos += 2 + pos[1];
  59. }
  60. return NULL;
  61. }
  62. static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
  63. struct ieee80211_supported_band *sband,
  64. u64 *rates)
  65. {
  66. int i, j, count;
  67. *rates = 0;
  68. count = 0;
  69. for (i = 0; i < bss->supp_rates_len; i++) {
  70. int rate = (bss->supp_rates[i] & 0x7F) * 5;
  71. for (j = 0; j < sband->n_bitrates; j++)
  72. if (sband->bitrates[j].bitrate == rate) {
  73. *rates |= BIT(j);
  74. count++;
  75. break;
  76. }
  77. }
  78. return count;
  79. }
  80. /* also used by mesh code */
  81. u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
  82. struct ieee802_11_elems *elems,
  83. enum ieee80211_band band)
  84. {
  85. struct ieee80211_supported_band *sband;
  86. struct ieee80211_rate *bitrates;
  87. size_t num_rates;
  88. u64 supp_rates;
  89. int i, j;
  90. sband = local->hw.wiphy->bands[band];
  91. if (!sband) {
  92. WARN_ON(1);
  93. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  94. }
  95. bitrates = sband->bitrates;
  96. num_rates = sband->n_bitrates;
  97. supp_rates = 0;
  98. for (i = 0; i < elems->supp_rates_len +
  99. elems->ext_supp_rates_len; i++) {
  100. u8 rate = 0;
  101. int own_rate;
  102. if (i < elems->supp_rates_len)
  103. rate = elems->supp_rates[i];
  104. else if (elems->ext_supp_rates)
  105. rate = elems->ext_supp_rates
  106. [i - elems->supp_rates_len];
  107. own_rate = 5 * (rate & 0x7f);
  108. for (j = 0; j < num_rates; j++)
  109. if (bitrates[j].bitrate == own_rate)
  110. supp_rates |= BIT(j);
  111. }
  112. return supp_rates;
  113. }
  114. /* frame sending functions */
  115. /* also used by scanning code */
  116. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  117. u8 *ssid, size_t ssid_len)
  118. {
  119. struct ieee80211_local *local = sdata->local;
  120. struct ieee80211_supported_band *sband;
  121. struct sk_buff *skb;
  122. struct ieee80211_mgmt *mgmt;
  123. u8 *pos, *supp_rates, *esupp_rates = NULL;
  124. int i;
  125. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
  126. if (!skb) {
  127. printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
  128. "request\n", sdata->dev->name);
  129. return;
  130. }
  131. skb_reserve(skb, local->hw.extra_tx_headroom);
  132. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  133. memset(mgmt, 0, 24);
  134. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  135. IEEE80211_STYPE_PROBE_REQ);
  136. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  137. if (dst) {
  138. memcpy(mgmt->da, dst, ETH_ALEN);
  139. memcpy(mgmt->bssid, dst, ETH_ALEN);
  140. } else {
  141. memset(mgmt->da, 0xff, ETH_ALEN);
  142. memset(mgmt->bssid, 0xff, ETH_ALEN);
  143. }
  144. pos = skb_put(skb, 2 + ssid_len);
  145. *pos++ = WLAN_EID_SSID;
  146. *pos++ = ssid_len;
  147. memcpy(pos, ssid, ssid_len);
  148. supp_rates = skb_put(skb, 2);
  149. supp_rates[0] = WLAN_EID_SUPP_RATES;
  150. supp_rates[1] = 0;
  151. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  152. for (i = 0; i < sband->n_bitrates; i++) {
  153. struct ieee80211_rate *rate = &sband->bitrates[i];
  154. if (esupp_rates) {
  155. pos = skb_put(skb, 1);
  156. esupp_rates[1]++;
  157. } else if (supp_rates[1] == 8) {
  158. esupp_rates = skb_put(skb, 3);
  159. esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
  160. esupp_rates[1] = 1;
  161. pos = &esupp_rates[2];
  162. } else {
  163. pos = skb_put(skb, 1);
  164. supp_rates[1]++;
  165. }
  166. *pos = rate->bitrate / 5;
  167. }
  168. ieee80211_tx_skb(sdata, skb, 0);
  169. }
  170. static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  171. struct ieee80211_if_sta *ifsta,
  172. int transaction, u8 *extra, size_t extra_len,
  173. int encrypt)
  174. {
  175. struct ieee80211_local *local = sdata->local;
  176. struct sk_buff *skb;
  177. struct ieee80211_mgmt *mgmt;
  178. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  179. sizeof(*mgmt) + 6 + extra_len);
  180. if (!skb) {
  181. printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
  182. "frame\n", sdata->dev->name);
  183. return;
  184. }
  185. skb_reserve(skb, local->hw.extra_tx_headroom);
  186. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  187. memset(mgmt, 0, 24 + 6);
  188. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  189. IEEE80211_STYPE_AUTH);
  190. if (encrypt)
  191. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  192. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  193. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  194. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  195. mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
  196. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  197. ifsta->auth_transaction = transaction + 1;
  198. mgmt->u.auth.status_code = cpu_to_le16(0);
  199. if (extra)
  200. memcpy(skb_put(skb, extra_len), extra, extra_len);
  201. ieee80211_tx_skb(sdata, skb, encrypt);
  202. }
  203. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  204. struct ieee80211_if_sta *ifsta)
  205. {
  206. struct ieee80211_local *local = sdata->local;
  207. struct sk_buff *skb;
  208. struct ieee80211_mgmt *mgmt;
  209. u8 *pos, *ies, *ht_ie;
  210. int i, len, count, rates_len, supp_rates_len;
  211. u16 capab;
  212. struct ieee80211_bss *bss;
  213. int wmm = 0;
  214. struct ieee80211_supported_band *sband;
  215. u64 rates = 0;
  216. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  217. sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
  218. ifsta->ssid_len);
  219. if (!skb) {
  220. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  221. "frame\n", sdata->dev->name);
  222. return;
  223. }
  224. skb_reserve(skb, local->hw.extra_tx_headroom);
  225. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  226. capab = ifsta->capab;
  227. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
  228. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  229. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  230. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  231. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  232. }
  233. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  234. local->hw.conf.channel->center_freq,
  235. ifsta->ssid, ifsta->ssid_len);
  236. if (bss) {
  237. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  238. capab |= WLAN_CAPABILITY_PRIVACY;
  239. if (bss->wmm_used)
  240. wmm = 1;
  241. /* get all rates supported by the device and the AP as
  242. * some APs don't like getting a superset of their rates
  243. * in the association request (e.g. D-Link DAP 1353 in
  244. * b-only mode) */
  245. rates_len = ieee80211_compatible_rates(bss, sband, &rates);
  246. if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  247. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  248. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  249. ieee80211_rx_bss_put(local, bss);
  250. } else {
  251. rates = ~0;
  252. rates_len = sband->n_bitrates;
  253. }
  254. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  255. memset(mgmt, 0, 24);
  256. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  257. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  258. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  259. if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
  260. skb_put(skb, 10);
  261. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  262. IEEE80211_STYPE_REASSOC_REQ);
  263. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  264. mgmt->u.reassoc_req.listen_interval =
  265. cpu_to_le16(local->hw.conf.listen_interval);
  266. memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
  267. ETH_ALEN);
  268. } else {
  269. skb_put(skb, 4);
  270. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  271. IEEE80211_STYPE_ASSOC_REQ);
  272. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  273. mgmt->u.assoc_req.listen_interval =
  274. cpu_to_le16(local->hw.conf.listen_interval);
  275. }
  276. /* SSID */
  277. ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
  278. *pos++ = WLAN_EID_SSID;
  279. *pos++ = ifsta->ssid_len;
  280. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  281. /* add all rates which were marked to be used above */
  282. supp_rates_len = rates_len;
  283. if (supp_rates_len > 8)
  284. supp_rates_len = 8;
  285. len = sband->n_bitrates;
  286. pos = skb_put(skb, supp_rates_len + 2);
  287. *pos++ = WLAN_EID_SUPP_RATES;
  288. *pos++ = supp_rates_len;
  289. count = 0;
  290. for (i = 0; i < sband->n_bitrates; i++) {
  291. if (BIT(i) & rates) {
  292. int rate = sband->bitrates[i].bitrate;
  293. *pos++ = (u8) (rate / 5);
  294. if (++count == 8)
  295. break;
  296. }
  297. }
  298. if (rates_len > count) {
  299. pos = skb_put(skb, rates_len - count + 2);
  300. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  301. *pos++ = rates_len - count;
  302. for (i++; i < sband->n_bitrates; i++) {
  303. if (BIT(i) & rates) {
  304. int rate = sband->bitrates[i].bitrate;
  305. *pos++ = (u8) (rate / 5);
  306. }
  307. }
  308. }
  309. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  310. /* 1. power capabilities */
  311. pos = skb_put(skb, 4);
  312. *pos++ = WLAN_EID_PWR_CAPABILITY;
  313. *pos++ = 2;
  314. *pos++ = 0; /* min tx power */
  315. *pos++ = local->hw.conf.channel->max_power; /* max tx power */
  316. /* 2. supported channels */
  317. /* TODO: get this in reg domain format */
  318. pos = skb_put(skb, 2 * sband->n_channels + 2);
  319. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  320. *pos++ = 2 * sband->n_channels;
  321. for (i = 0; i < sband->n_channels; i++) {
  322. *pos++ = ieee80211_frequency_to_channel(
  323. sband->channels[i].center_freq);
  324. *pos++ = 1; /* one channel in the subband*/
  325. }
  326. }
  327. if (ifsta->extra_ie) {
  328. pos = skb_put(skb, ifsta->extra_ie_len);
  329. memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
  330. }
  331. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
  332. pos = skb_put(skb, 9);
  333. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  334. *pos++ = 7; /* len */
  335. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  336. *pos++ = 0x50;
  337. *pos++ = 0xf2;
  338. *pos++ = 2; /* WME */
  339. *pos++ = 0; /* WME info */
  340. *pos++ = 1; /* WME ver */
  341. *pos++ = 0;
  342. }
  343. /* wmm support is a must to HT */
  344. /*
  345. * IEEE802.11n does not allow TKIP/WEP as pairwise
  346. * ciphers in HT mode. We still associate in non-ht
  347. * mode (11a/b/g) if any one of these ciphers is
  348. * configured as pairwise.
  349. */
  350. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
  351. sband->ht_cap.ht_supported &&
  352. (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
  353. ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
  354. (!(ifsta->flags & IEEE80211_STA_TKIP_WEP_USED))) {
  355. struct ieee80211_ht_info *ht_info =
  356. (struct ieee80211_ht_info *)(ht_ie + 2);
  357. u16 cap = sband->ht_cap.cap;
  358. __le16 tmp;
  359. u32 flags = local->hw.conf.channel->flags;
  360. switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  361. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  362. if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
  363. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  364. cap &= ~IEEE80211_HT_CAP_SGI_40;
  365. }
  366. break;
  367. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  368. if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
  369. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  370. cap &= ~IEEE80211_HT_CAP_SGI_40;
  371. }
  372. break;
  373. }
  374. tmp = cpu_to_le16(cap);
  375. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
  376. *pos++ = WLAN_EID_HT_CAPABILITY;
  377. *pos++ = sizeof(struct ieee80211_ht_cap);
  378. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  379. memcpy(pos, &tmp, sizeof(u16));
  380. pos += sizeof(u16);
  381. /* TODO: needs a define here for << 2 */
  382. *pos++ = sband->ht_cap.ampdu_factor |
  383. (sband->ht_cap.ampdu_density << 2);
  384. memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
  385. }
  386. kfree(ifsta->assocreq_ies);
  387. ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
  388. ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
  389. if (ifsta->assocreq_ies)
  390. memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
  391. ieee80211_tx_skb(sdata, skb, 0);
  392. }
  393. static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  394. u16 stype, u16 reason)
  395. {
  396. struct ieee80211_local *local = sdata->local;
  397. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  398. struct sk_buff *skb;
  399. struct ieee80211_mgmt *mgmt;
  400. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  401. if (!skb) {
  402. printk(KERN_DEBUG "%s: failed to allocate buffer for "
  403. "deauth/disassoc frame\n", sdata->dev->name);
  404. return;
  405. }
  406. skb_reserve(skb, local->hw.extra_tx_headroom);
  407. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  408. memset(mgmt, 0, 24);
  409. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  410. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  411. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  412. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  413. skb_put(skb, 2);
  414. /* u.deauth.reason_code == u.disassoc.reason_code */
  415. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  416. ieee80211_tx_skb(sdata, skb, 0);
  417. }
  418. /* MLME */
  419. static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
  420. struct ieee80211_bss *bss)
  421. {
  422. struct ieee80211_local *local = sdata->local;
  423. int i, have_higher_than_11mbit = 0;
  424. /* cf. IEEE 802.11 9.2.12 */
  425. for (i = 0; i < bss->supp_rates_len; i++)
  426. if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
  427. have_higher_than_11mbit = 1;
  428. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  429. have_higher_than_11mbit)
  430. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  431. else
  432. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  433. ieee80211_set_wmm_default(sdata);
  434. }
  435. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  436. struct ieee80211_if_sta *ifsta,
  437. u8 *wmm_param, size_t wmm_param_len)
  438. {
  439. struct ieee80211_tx_queue_params params;
  440. size_t left;
  441. int count;
  442. u8 *pos;
  443. if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED))
  444. return;
  445. if (!wmm_param)
  446. return;
  447. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  448. return;
  449. count = wmm_param[6] & 0x0f;
  450. if (count == ifsta->wmm_last_param_set)
  451. return;
  452. ifsta->wmm_last_param_set = count;
  453. pos = wmm_param + 8;
  454. left = wmm_param_len - 8;
  455. memset(&params, 0, sizeof(params));
  456. if (!local->ops->conf_tx)
  457. return;
  458. local->wmm_acm = 0;
  459. for (; left >= 4; left -= 4, pos += 4) {
  460. int aci = (pos[0] >> 5) & 0x03;
  461. int acm = (pos[0] >> 4) & 0x01;
  462. int queue;
  463. switch (aci) {
  464. case 1:
  465. queue = 3;
  466. if (acm)
  467. local->wmm_acm |= BIT(0) | BIT(3);
  468. break;
  469. case 2:
  470. queue = 1;
  471. if (acm)
  472. local->wmm_acm |= BIT(4) | BIT(5);
  473. break;
  474. case 3:
  475. queue = 0;
  476. if (acm)
  477. local->wmm_acm |= BIT(6) | BIT(7);
  478. break;
  479. case 0:
  480. default:
  481. queue = 2;
  482. if (acm)
  483. local->wmm_acm |= BIT(1) | BIT(2);
  484. break;
  485. }
  486. params.aifs = pos[0] & 0x0f;
  487. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  488. params.cw_min = ecw2cw(pos[1] & 0x0f);
  489. params.txop = get_unaligned_le16(pos + 2);
  490. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  491. printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
  492. "cWmin=%d cWmax=%d txop=%d\n",
  493. local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
  494. params.cw_max, params.txop);
  495. #endif
  496. /* TODO: handle ACM (block TX, fallback to next lowest allowed
  497. * AC for now) */
  498. if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
  499. printk(KERN_DEBUG "%s: failed to set TX queue "
  500. "parameters for queue %d\n", local->mdev->name, queue);
  501. }
  502. }
  503. }
  504. static bool check_tim(struct ieee802_11_elems *elems, u16 aid, bool *is_mc)
  505. {
  506. u8 mask;
  507. u8 index, indexn1, indexn2;
  508. struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
  509. aid &= 0x3fff;
  510. index = aid / 8;
  511. mask = 1 << (aid & 7);
  512. if (tim->bitmap_ctrl & 0x01)
  513. *is_mc = true;
  514. indexn1 = tim->bitmap_ctrl & 0xfe;
  515. indexn2 = elems->tim_len + indexn1 - 4;
  516. if (index < indexn1 || index > indexn2)
  517. return false;
  518. index -= indexn1;
  519. return !!(tim->virtual_map[index] & mask);
  520. }
  521. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  522. u16 capab, bool erp_valid, u8 erp)
  523. {
  524. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  525. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  526. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  527. #endif
  528. u32 changed = 0;
  529. bool use_protection;
  530. bool use_short_preamble;
  531. bool use_short_slot;
  532. if (erp_valid) {
  533. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  534. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  535. } else {
  536. use_protection = false;
  537. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  538. }
  539. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  540. if (use_protection != bss_conf->use_cts_prot) {
  541. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  542. if (net_ratelimit()) {
  543. printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
  544. sdata->dev->name,
  545. use_protection ? "enabled" : "disabled",
  546. ifsta->bssid);
  547. }
  548. #endif
  549. bss_conf->use_cts_prot = use_protection;
  550. changed |= BSS_CHANGED_ERP_CTS_PROT;
  551. }
  552. if (use_short_preamble != bss_conf->use_short_preamble) {
  553. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  554. if (net_ratelimit()) {
  555. printk(KERN_DEBUG "%s: switched to %s barker preamble"
  556. " (BSSID=%pM)\n",
  557. sdata->dev->name,
  558. use_short_preamble ? "short" : "long",
  559. ifsta->bssid);
  560. }
  561. #endif
  562. bss_conf->use_short_preamble = use_short_preamble;
  563. changed |= BSS_CHANGED_ERP_PREAMBLE;
  564. }
  565. if (use_short_slot != bss_conf->use_short_slot) {
  566. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  567. if (net_ratelimit()) {
  568. printk(KERN_DEBUG "%s: switched to %s slot time"
  569. " (BSSID=%pM)\n",
  570. sdata->dev->name,
  571. use_short_slot ? "short" : "long",
  572. ifsta->bssid);
  573. }
  574. #endif
  575. bss_conf->use_short_slot = use_short_slot;
  576. changed |= BSS_CHANGED_ERP_SLOT;
  577. }
  578. return changed;
  579. }
  580. static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata,
  581. struct ieee80211_if_sta *ifsta)
  582. {
  583. union iwreq_data wrqu;
  584. memset(&wrqu, 0, sizeof(wrqu));
  585. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  586. memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
  587. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  588. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  589. }
  590. static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata,
  591. struct ieee80211_if_sta *ifsta)
  592. {
  593. char *buf;
  594. size_t len;
  595. int i;
  596. union iwreq_data wrqu;
  597. if (!ifsta->assocreq_ies && !ifsta->assocresp_ies)
  598. return;
  599. buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
  600. ifsta->assocresp_ies_len), GFP_KERNEL);
  601. if (!buf)
  602. return;
  603. len = sprintf(buf, "ASSOCINFO(");
  604. if (ifsta->assocreq_ies) {
  605. len += sprintf(buf + len, "ReqIEs=");
  606. for (i = 0; i < ifsta->assocreq_ies_len; i++) {
  607. len += sprintf(buf + len, "%02x",
  608. ifsta->assocreq_ies[i]);
  609. }
  610. }
  611. if (ifsta->assocresp_ies) {
  612. if (ifsta->assocreq_ies)
  613. len += sprintf(buf + len, " ");
  614. len += sprintf(buf + len, "RespIEs=");
  615. for (i = 0; i < ifsta->assocresp_ies_len; i++) {
  616. len += sprintf(buf + len, "%02x",
  617. ifsta->assocresp_ies[i]);
  618. }
  619. }
  620. len += sprintf(buf + len, ")");
  621. if (len > IW_CUSTOM_MAX) {
  622. len = sprintf(buf, "ASSOCRESPIE=");
  623. for (i = 0; i < ifsta->assocresp_ies_len; i++) {
  624. len += sprintf(buf + len, "%02x",
  625. ifsta->assocresp_ies[i]);
  626. }
  627. }
  628. if (len <= IW_CUSTOM_MAX) {
  629. memset(&wrqu, 0, sizeof(wrqu));
  630. wrqu.data.length = len;
  631. wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
  632. }
  633. kfree(buf);
  634. }
  635. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  636. struct ieee80211_if_sta *ifsta,
  637. u32 bss_info_changed)
  638. {
  639. struct ieee80211_local *local = sdata->local;
  640. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  641. struct ieee80211_bss *bss;
  642. bss_info_changed |= BSS_CHANGED_ASSOC;
  643. ifsta->flags |= IEEE80211_STA_ASSOCIATED;
  644. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  645. return;
  646. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  647. conf->channel->center_freq,
  648. ifsta->ssid, ifsta->ssid_len);
  649. if (bss) {
  650. /* set timing information */
  651. sdata->vif.bss_conf.beacon_int = bss->beacon_int;
  652. sdata->vif.bss_conf.timestamp = bss->timestamp;
  653. sdata->vif.bss_conf.dtim_period = bss->dtim_period;
  654. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  655. bss->capability, bss->has_erp_value, bss->erp_value);
  656. ieee80211_rx_bss_put(local, bss);
  657. }
  658. ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
  659. memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
  660. ieee80211_sta_send_associnfo(sdata, ifsta);
  661. ifsta->last_probe = jiffies;
  662. ieee80211_led_assoc(local, 1);
  663. sdata->vif.bss_conf.assoc = 1;
  664. /*
  665. * For now just always ask the driver to update the basic rateset
  666. * when we have associated, we aren't checking whether it actually
  667. * changed or not.
  668. */
  669. bss_info_changed |= BSS_CHANGED_BASIC_RATES;
  670. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  671. if (local->powersave &&
  672. !(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS)) {
  673. if (local->hw.conf.dynamic_ps_timeout > 0)
  674. mod_timer(&local->dynamic_ps_timer, jiffies +
  675. msecs_to_jiffies(
  676. local->hw.conf.dynamic_ps_timeout));
  677. else {
  678. ieee80211_send_nullfunc(local, sdata, 1);
  679. conf->flags |= IEEE80211_CONF_PS;
  680. ieee80211_hw_config(local,
  681. IEEE80211_CONF_CHANGE_PS);
  682. }
  683. }
  684. netif_tx_start_all_queues(sdata->dev);
  685. netif_carrier_on(sdata->dev);
  686. ieee80211_sta_send_apinfo(sdata, ifsta);
  687. }
  688. static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
  689. struct ieee80211_if_sta *ifsta)
  690. {
  691. ifsta->direct_probe_tries++;
  692. if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
  693. printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
  694. sdata->dev->name, ifsta->bssid);
  695. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  696. ieee80211_sta_send_apinfo(sdata, ifsta);
  697. return;
  698. }
  699. printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
  700. sdata->dev->name, ifsta->bssid,
  701. ifsta->direct_probe_tries);
  702. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  703. set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request);
  704. /* Direct probe is sent to broadcast address as some APs
  705. * will not answer to direct packet in unassociated state.
  706. */
  707. ieee80211_send_probe_req(sdata, NULL,
  708. ifsta->ssid, ifsta->ssid_len);
  709. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  710. }
  711. static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
  712. struct ieee80211_if_sta *ifsta)
  713. {
  714. ifsta->auth_tries++;
  715. if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  716. printk(KERN_DEBUG "%s: authentication with AP %pM"
  717. " timed out\n",
  718. sdata->dev->name, ifsta->bssid);
  719. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  720. ieee80211_sta_send_apinfo(sdata, ifsta);
  721. return;
  722. }
  723. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  724. printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
  725. sdata->dev->name, ifsta->bssid);
  726. ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0);
  727. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  728. }
  729. /*
  730. * The disassoc 'reason' argument can be either our own reason
  731. * if self disconnected or a reason code from the AP.
  732. */
  733. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  734. struct ieee80211_if_sta *ifsta, bool deauth,
  735. bool self_disconnected, u16 reason)
  736. {
  737. struct ieee80211_local *local = sdata->local;
  738. struct sta_info *sta;
  739. u32 changed = 0, config_changed = 0;
  740. rcu_read_lock();
  741. sta = sta_info_get(local, ifsta->bssid);
  742. if (!sta) {
  743. rcu_read_unlock();
  744. return;
  745. }
  746. if (deauth) {
  747. ifsta->direct_probe_tries = 0;
  748. ifsta->auth_tries = 0;
  749. }
  750. ifsta->assoc_scan_tries = 0;
  751. ifsta->assoc_tries = 0;
  752. netif_tx_stop_all_queues(sdata->dev);
  753. netif_carrier_off(sdata->dev);
  754. ieee80211_sta_tear_down_BA_sessions(sdata, sta->sta.addr);
  755. if (self_disconnected) {
  756. if (deauth)
  757. ieee80211_send_deauth_disassoc(sdata,
  758. IEEE80211_STYPE_DEAUTH, reason);
  759. else
  760. ieee80211_send_deauth_disassoc(sdata,
  761. IEEE80211_STYPE_DISASSOC, reason);
  762. }
  763. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  764. changed |= ieee80211_reset_erp_info(sdata);
  765. ieee80211_led_assoc(local, 0);
  766. changed |= BSS_CHANGED_ASSOC;
  767. sdata->vif.bss_conf.assoc = false;
  768. ieee80211_sta_send_apinfo(sdata, ifsta);
  769. if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT)
  770. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  771. rcu_read_unlock();
  772. /* channel(_type) changes are handled by ieee80211_hw_config */
  773. local->oper_channel_type = NL80211_CHAN_NO_HT;
  774. del_timer_sync(&local->dynamic_ps_timer);
  775. cancel_work_sync(&local->dynamic_ps_enable_work);
  776. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  777. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  778. config_changed |= IEEE80211_CONF_CHANGE_PS;
  779. }
  780. ieee80211_hw_config(local, config_changed);
  781. ieee80211_bss_info_change_notify(sdata, changed);
  782. rcu_read_lock();
  783. sta = sta_info_get(local, ifsta->bssid);
  784. if (!sta) {
  785. rcu_read_unlock();
  786. return;
  787. }
  788. sta_info_unlink(&sta);
  789. rcu_read_unlock();
  790. sta_info_destroy(sta);
  791. }
  792. static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
  793. {
  794. if (!sdata || !sdata->default_key ||
  795. sdata->default_key->conf.alg != ALG_WEP)
  796. return 0;
  797. return 1;
  798. }
  799. static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
  800. struct ieee80211_if_sta *ifsta)
  801. {
  802. struct ieee80211_local *local = sdata->local;
  803. struct ieee80211_bss *bss;
  804. int bss_privacy;
  805. int wep_privacy;
  806. int privacy_invoked;
  807. if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
  808. return 0;
  809. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  810. local->hw.conf.channel->center_freq,
  811. ifsta->ssid, ifsta->ssid_len);
  812. if (!bss)
  813. return 0;
  814. bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
  815. wep_privacy = !!ieee80211_sta_wep_configured(sdata);
  816. privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
  817. ieee80211_rx_bss_put(local, bss);
  818. if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
  819. return 0;
  820. return 1;
  821. }
  822. static void ieee80211_associate(struct ieee80211_sub_if_data *sdata,
  823. struct ieee80211_if_sta *ifsta)
  824. {
  825. ifsta->assoc_tries++;
  826. if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  827. printk(KERN_DEBUG "%s: association with AP %pM"
  828. " timed out\n",
  829. sdata->dev->name, ifsta->bssid);
  830. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  831. ieee80211_sta_send_apinfo(sdata, ifsta);
  832. return;
  833. }
  834. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  835. printk(KERN_DEBUG "%s: associate with AP %pM\n",
  836. sdata->dev->name, ifsta->bssid);
  837. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  838. printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
  839. "mixed-cell disabled - abort association\n", sdata->dev->name);
  840. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  841. return;
  842. }
  843. ieee80211_send_assoc(sdata, ifsta);
  844. mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
  845. }
  846. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
  847. struct ieee80211_if_sta *ifsta)
  848. {
  849. struct ieee80211_local *local = sdata->local;
  850. struct sta_info *sta;
  851. int disassoc;
  852. /* TODO: start monitoring current AP signal quality and number of
  853. * missed beacons. Scan other channels every now and then and search
  854. * for better APs. */
  855. /* TODO: remove expired BSSes */
  856. ifsta->state = IEEE80211_STA_MLME_ASSOCIATED;
  857. rcu_read_lock();
  858. sta = sta_info_get(local, ifsta->bssid);
  859. if (!sta) {
  860. printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
  861. sdata->dev->name, ifsta->bssid);
  862. disassoc = 1;
  863. } else {
  864. disassoc = 0;
  865. if (time_after(jiffies,
  866. sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  867. if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
  868. printk(KERN_DEBUG "%s: No ProbeResp from "
  869. "current AP %pM - assume out of "
  870. "range\n",
  871. sdata->dev->name, ifsta->bssid);
  872. disassoc = 1;
  873. } else
  874. ieee80211_send_probe_req(sdata, ifsta->bssid,
  875. ifsta->ssid,
  876. ifsta->ssid_len);
  877. ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
  878. } else {
  879. ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  880. if (time_after(jiffies, ifsta->last_probe +
  881. IEEE80211_PROBE_INTERVAL)) {
  882. ifsta->last_probe = jiffies;
  883. ieee80211_send_probe_req(sdata, ifsta->bssid,
  884. ifsta->ssid,
  885. ifsta->ssid_len);
  886. }
  887. }
  888. }
  889. rcu_read_unlock();
  890. if (disassoc)
  891. ieee80211_set_disassoc(sdata, ifsta, true, true,
  892. WLAN_REASON_PREV_AUTH_NOT_VALID);
  893. else
  894. mod_timer(&ifsta->timer, jiffies +
  895. IEEE80211_MONITORING_INTERVAL);
  896. }
  897. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
  898. struct ieee80211_if_sta *ifsta)
  899. {
  900. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  901. ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
  902. ieee80211_associate(sdata, ifsta);
  903. }
  904. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  905. struct ieee80211_if_sta *ifsta,
  906. struct ieee80211_mgmt *mgmt,
  907. size_t len)
  908. {
  909. u8 *pos;
  910. struct ieee802_11_elems elems;
  911. pos = mgmt->u.auth.variable;
  912. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  913. if (!elems.challenge)
  914. return;
  915. ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2,
  916. elems.challenge_len + 2, 1);
  917. }
  918. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  919. struct ieee80211_if_sta *ifsta,
  920. struct ieee80211_mgmt *mgmt,
  921. size_t len)
  922. {
  923. u16 auth_alg, auth_transaction, status_code;
  924. if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  925. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  926. return;
  927. if (len < 24 + 6)
  928. return;
  929. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  930. memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  931. return;
  932. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  933. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  934. return;
  935. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  936. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  937. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  938. if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  939. /*
  940. * IEEE 802.11 standard does not require authentication in IBSS
  941. * networks and most implementations do not seem to use it.
  942. * However, try to reply to authentication attempts if someone
  943. * has actually implemented this.
  944. */
  945. if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
  946. return;
  947. ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0);
  948. }
  949. if (auth_alg != ifsta->auth_alg ||
  950. auth_transaction != ifsta->auth_transaction)
  951. return;
  952. if (status_code != WLAN_STATUS_SUCCESS) {
  953. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  954. u8 algs[3];
  955. const int num_algs = ARRAY_SIZE(algs);
  956. int i, pos;
  957. algs[0] = algs[1] = algs[2] = 0xff;
  958. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  959. algs[0] = WLAN_AUTH_OPEN;
  960. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  961. algs[1] = WLAN_AUTH_SHARED_KEY;
  962. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  963. algs[2] = WLAN_AUTH_LEAP;
  964. if (ifsta->auth_alg == WLAN_AUTH_OPEN)
  965. pos = 0;
  966. else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
  967. pos = 1;
  968. else
  969. pos = 2;
  970. for (i = 0; i < num_algs; i++) {
  971. pos++;
  972. if (pos >= num_algs)
  973. pos = 0;
  974. if (algs[pos] == ifsta->auth_alg ||
  975. algs[pos] == 0xff)
  976. continue;
  977. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  978. !ieee80211_sta_wep_configured(sdata))
  979. continue;
  980. ifsta->auth_alg = algs[pos];
  981. break;
  982. }
  983. }
  984. return;
  985. }
  986. switch (ifsta->auth_alg) {
  987. case WLAN_AUTH_OPEN:
  988. case WLAN_AUTH_LEAP:
  989. ieee80211_auth_completed(sdata, ifsta);
  990. break;
  991. case WLAN_AUTH_SHARED_KEY:
  992. if (ifsta->auth_transaction == 4)
  993. ieee80211_auth_completed(sdata, ifsta);
  994. else
  995. ieee80211_auth_challenge(sdata, ifsta, mgmt, len);
  996. break;
  997. }
  998. }
  999. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1000. struct ieee80211_if_sta *ifsta,
  1001. struct ieee80211_mgmt *mgmt,
  1002. size_t len)
  1003. {
  1004. u16 reason_code;
  1005. if (len < 24 + 2)
  1006. return;
  1007. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1008. return;
  1009. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1010. if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
  1011. printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
  1012. sdata->dev->name, reason_code);
  1013. if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  1014. ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
  1015. ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1016. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1017. mod_timer(&ifsta->timer, jiffies +
  1018. IEEE80211_RETRY_AUTH_INTERVAL);
  1019. }
  1020. ieee80211_set_disassoc(sdata, ifsta, true, false, 0);
  1021. ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
  1022. }
  1023. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1024. struct ieee80211_if_sta *ifsta,
  1025. struct ieee80211_mgmt *mgmt,
  1026. size_t len)
  1027. {
  1028. u16 reason_code;
  1029. if (len < 24 + 2)
  1030. return;
  1031. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1032. return;
  1033. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1034. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  1035. printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
  1036. sdata->dev->name, reason_code);
  1037. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1038. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  1039. mod_timer(&ifsta->timer, jiffies +
  1040. IEEE80211_RETRY_AUTH_INTERVAL);
  1041. }
  1042. ieee80211_set_disassoc(sdata, ifsta, false, false, reason_code);
  1043. }
  1044. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1045. struct ieee80211_if_sta *ifsta,
  1046. struct ieee80211_mgmt *mgmt,
  1047. size_t len,
  1048. int reassoc)
  1049. {
  1050. struct ieee80211_local *local = sdata->local;
  1051. struct ieee80211_supported_band *sband;
  1052. struct sta_info *sta;
  1053. u64 rates, basic_rates;
  1054. u16 capab_info, status_code, aid;
  1055. struct ieee802_11_elems elems;
  1056. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1057. u8 *pos;
  1058. u32 changed = 0;
  1059. int i, j;
  1060. bool have_higher_than_11mbit = false, newsta = false;
  1061. u16 ap_ht_cap_flags;
  1062. /* AssocResp and ReassocResp have identical structure, so process both
  1063. * of them in this function. */
  1064. if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE)
  1065. return;
  1066. if (len < 24 + 6)
  1067. return;
  1068. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  1069. return;
  1070. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1071. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1072. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1073. printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
  1074. "status=%d aid=%d)\n",
  1075. sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
  1076. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1077. if (status_code != WLAN_STATUS_SUCCESS) {
  1078. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1079. sdata->dev->name, status_code);
  1080. /* if this was a reassociation, ensure we try a "full"
  1081. * association next time. This works around some broken APs
  1082. * which do not correctly reject reassociation requests. */
  1083. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1084. return;
  1085. }
  1086. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1087. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1088. "set\n", sdata->dev->name, aid);
  1089. aid &= ~(BIT(15) | BIT(14));
  1090. pos = mgmt->u.assoc_resp.variable;
  1091. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1092. if (!elems.supp_rates) {
  1093. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1094. sdata->dev->name);
  1095. return;
  1096. }
  1097. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1098. ifsta->aid = aid;
  1099. ifsta->ap_capab = capab_info;
  1100. kfree(ifsta->assocresp_ies);
  1101. ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1102. ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
  1103. if (ifsta->assocresp_ies)
  1104. memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
  1105. rcu_read_lock();
  1106. /* Add STA entry for the AP */
  1107. sta = sta_info_get(local, ifsta->bssid);
  1108. if (!sta) {
  1109. struct ieee80211_bss *bss;
  1110. newsta = true;
  1111. sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
  1112. if (!sta) {
  1113. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1114. " the AP\n", sdata->dev->name);
  1115. rcu_read_unlock();
  1116. return;
  1117. }
  1118. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  1119. local->hw.conf.channel->center_freq,
  1120. ifsta->ssid, ifsta->ssid_len);
  1121. if (bss) {
  1122. sta->last_signal = bss->signal;
  1123. sta->last_qual = bss->qual;
  1124. sta->last_noise = bss->noise;
  1125. ieee80211_rx_bss_put(local, bss);
  1126. }
  1127. /* update new sta with its last rx activity */
  1128. sta->last_rx = jiffies;
  1129. }
  1130. /*
  1131. * FIXME: Do we really need to update the sta_info's information here?
  1132. * We already know about the AP (we found it in our list) so it
  1133. * should already be filled with the right info, no?
  1134. * As is stands, all this is racy because typically we assume
  1135. * the information that is filled in here (except flags) doesn't
  1136. * change while a STA structure is alive. As such, it should move
  1137. * to between the sta_info_alloc() and sta_info_insert() above.
  1138. */
  1139. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1140. WLAN_STA_AUTHORIZED);
  1141. rates = 0;
  1142. basic_rates = 0;
  1143. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1144. for (i = 0; i < elems.supp_rates_len; i++) {
  1145. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1146. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1147. if (rate > 110)
  1148. have_higher_than_11mbit = true;
  1149. for (j = 0; j < sband->n_bitrates; j++) {
  1150. if (sband->bitrates[j].bitrate == rate) {
  1151. rates |= BIT(j);
  1152. if (is_basic)
  1153. basic_rates |= BIT(j);
  1154. break;
  1155. }
  1156. }
  1157. }
  1158. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1159. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1160. bool is_basic = !!(elems.supp_rates[i] & 0x80);
  1161. if (rate > 110)
  1162. have_higher_than_11mbit = true;
  1163. for (j = 0; j < sband->n_bitrates; j++) {
  1164. if (sband->bitrates[j].bitrate == rate) {
  1165. rates |= BIT(j);
  1166. if (is_basic)
  1167. basic_rates |= BIT(j);
  1168. break;
  1169. }
  1170. }
  1171. }
  1172. sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
  1173. sdata->vif.bss_conf.basic_rates = basic_rates;
  1174. /* cf. IEEE 802.11 9.2.12 */
  1175. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1176. have_higher_than_11mbit)
  1177. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1178. else
  1179. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1180. if (elems.ht_cap_elem)
  1181. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1182. elems.ht_cap_elem, &sta->sta.ht_cap);
  1183. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1184. rate_control_rate_init(sta);
  1185. if (elems.wmm_param)
  1186. set_sta_flags(sta, WLAN_STA_WME);
  1187. if (newsta) {
  1188. int err = sta_info_insert(sta);
  1189. if (err) {
  1190. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1191. " the AP (error %d)\n", sdata->dev->name, err);
  1192. rcu_read_unlock();
  1193. return;
  1194. }
  1195. }
  1196. rcu_read_unlock();
  1197. if (elems.wmm_param)
  1198. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  1199. elems.wmm_param_len);
  1200. if (elems.ht_info_elem && elems.wmm_param &&
  1201. (ifsta->flags & IEEE80211_STA_WMM_ENABLED))
  1202. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1203. ap_ht_cap_flags);
  1204. /* set AID and assoc capability,
  1205. * ieee80211_set_associated() will tell the driver */
  1206. bss_conf->aid = aid;
  1207. bss_conf->assoc_capability = capab_info;
  1208. ieee80211_set_associated(sdata, ifsta, changed);
  1209. ieee80211_associated(sdata, ifsta);
  1210. }
  1211. static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
  1212. struct ieee80211_if_sta *ifsta,
  1213. struct ieee80211_bss *bss)
  1214. {
  1215. struct ieee80211_local *local = sdata->local;
  1216. int res, rates, i, j;
  1217. struct sk_buff *skb;
  1218. struct ieee80211_mgmt *mgmt;
  1219. u8 *pos;
  1220. struct ieee80211_supported_band *sband;
  1221. union iwreq_data wrqu;
  1222. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
  1223. if (!skb) {
  1224. printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
  1225. "response\n", sdata->dev->name);
  1226. return -ENOMEM;
  1227. }
  1228. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1229. /* Remove possible STA entries from other IBSS networks. */
  1230. sta_info_flush_delayed(sdata);
  1231. if (local->ops->reset_tsf) {
  1232. /* Reset own TSF to allow time synchronization work. */
  1233. local->ops->reset_tsf(local_to_hw(local));
  1234. }
  1235. memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
  1236. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  1237. if (res)
  1238. return res;
  1239. local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
  1240. sdata->drop_unencrypted = bss->capability &
  1241. WLAN_CAPABILITY_PRIVACY ? 1 : 0;
  1242. res = ieee80211_set_freq(sdata, bss->freq);
  1243. if (res)
  1244. return res;
  1245. /* Build IBSS probe response */
  1246. skb_reserve(skb, local->hw.extra_tx_headroom);
  1247. mgmt = (struct ieee80211_mgmt *)
  1248. skb_put(skb, 24 + sizeof(mgmt->u.beacon));
  1249. memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  1250. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1251. IEEE80211_STYPE_PROBE_RESP);
  1252. memset(mgmt->da, 0xff, ETH_ALEN);
  1253. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1254. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1255. mgmt->u.beacon.beacon_int =
  1256. cpu_to_le16(local->hw.conf.beacon_int);
  1257. mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
  1258. mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
  1259. pos = skb_put(skb, 2 + ifsta->ssid_len);
  1260. *pos++ = WLAN_EID_SSID;
  1261. *pos++ = ifsta->ssid_len;
  1262. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  1263. rates = bss->supp_rates_len;
  1264. if (rates > 8)
  1265. rates = 8;
  1266. pos = skb_put(skb, 2 + rates);
  1267. *pos++ = WLAN_EID_SUPP_RATES;
  1268. *pos++ = rates;
  1269. memcpy(pos, bss->supp_rates, rates);
  1270. if (bss->band == IEEE80211_BAND_2GHZ) {
  1271. pos = skb_put(skb, 2 + 1);
  1272. *pos++ = WLAN_EID_DS_PARAMS;
  1273. *pos++ = 1;
  1274. *pos++ = ieee80211_frequency_to_channel(bss->freq);
  1275. }
  1276. pos = skb_put(skb, 2 + 2);
  1277. *pos++ = WLAN_EID_IBSS_PARAMS;
  1278. *pos++ = 2;
  1279. /* FIX: set ATIM window based on scan results */
  1280. *pos++ = 0;
  1281. *pos++ = 0;
  1282. if (bss->supp_rates_len > 8) {
  1283. rates = bss->supp_rates_len - 8;
  1284. pos = skb_put(skb, 2 + rates);
  1285. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1286. *pos++ = rates;
  1287. memcpy(pos, &bss->supp_rates[8], rates);
  1288. }
  1289. ifsta->probe_resp = skb;
  1290. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  1291. rates = 0;
  1292. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1293. for (i = 0; i < bss->supp_rates_len; i++) {
  1294. int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
  1295. for (j = 0; j < sband->n_bitrates; j++)
  1296. if (sband->bitrates[j].bitrate == bitrate)
  1297. rates |= BIT(j);
  1298. }
  1299. ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
  1300. ieee80211_sta_def_wmm_params(sdata, bss);
  1301. ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED;
  1302. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  1303. ieee80211_led_assoc(local, true);
  1304. memset(&wrqu, 0, sizeof(wrqu));
  1305. memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  1306. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  1307. return res;
  1308. }
  1309. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  1310. struct ieee80211_mgmt *mgmt,
  1311. size_t len,
  1312. struct ieee80211_rx_status *rx_status,
  1313. struct ieee802_11_elems *elems,
  1314. bool beacon)
  1315. {
  1316. struct ieee80211_local *local = sdata->local;
  1317. int freq;
  1318. struct ieee80211_bss *bss;
  1319. struct sta_info *sta;
  1320. struct ieee80211_channel *channel;
  1321. u64 beacon_timestamp, rx_timestamp;
  1322. u64 supp_rates = 0;
  1323. enum ieee80211_band band = rx_status->band;
  1324. if (elems->ds_params && elems->ds_params_len == 1)
  1325. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  1326. else
  1327. freq = rx_status->freq;
  1328. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  1329. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  1330. return;
  1331. if (sdata->vif.type == NL80211_IFTYPE_ADHOC && elems->supp_rates &&
  1332. memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
  1333. supp_rates = ieee80211_sta_get_rates(local, elems, band);
  1334. rcu_read_lock();
  1335. sta = sta_info_get(local, mgmt->sa);
  1336. if (sta) {
  1337. u64 prev_rates;
  1338. prev_rates = sta->sta.supp_rates[band];
  1339. /* make sure mandatory rates are always added */
  1340. sta->sta.supp_rates[band] = supp_rates |
  1341. ieee80211_mandatory_rates(local, band);
  1342. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1343. if (sta->sta.supp_rates[band] != prev_rates)
  1344. printk(KERN_DEBUG "%s: updated supp_rates set "
  1345. "for %pM based on beacon info (0x%llx | "
  1346. "0x%llx -> 0x%llx)\n",
  1347. sdata->dev->name,
  1348. sta->sta.addr,
  1349. (unsigned long long) prev_rates,
  1350. (unsigned long long) supp_rates,
  1351. (unsigned long long) sta->sta.supp_rates[band]);
  1352. #endif
  1353. } else {
  1354. ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
  1355. }
  1356. rcu_read_unlock();
  1357. }
  1358. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  1359. freq, beacon);
  1360. if (!bss)
  1361. return;
  1362. if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
  1363. (memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0)) {
  1364. struct ieee80211_channel_sw_ie *sw_elem =
  1365. (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
  1366. ieee80211_process_chanswitch(sdata, sw_elem, bss);
  1367. }
  1368. /* was just updated in ieee80211_bss_info_update */
  1369. beacon_timestamp = bss->timestamp;
  1370. /*
  1371. * In STA mode, the remaining parameters should not be overridden
  1372. * by beacons because they're not necessarily accurate there.
  1373. */
  1374. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1375. bss->last_probe_resp && beacon) {
  1376. ieee80211_rx_bss_put(local, bss);
  1377. return;
  1378. }
  1379. /* check if we need to merge IBSS */
  1380. if (sdata->vif.type == NL80211_IFTYPE_ADHOC && beacon &&
  1381. (!(sdata->u.sta.flags & IEEE80211_STA_BSSID_SET)) &&
  1382. bss->capability & WLAN_CAPABILITY_IBSS &&
  1383. bss->freq == local->oper_channel->center_freq &&
  1384. elems->ssid_len == sdata->u.sta.ssid_len &&
  1385. memcmp(elems->ssid, sdata->u.sta.ssid,
  1386. sdata->u.sta.ssid_len) == 0) {
  1387. if (rx_status->flag & RX_FLAG_TSFT) {
  1388. /* in order for correct IBSS merging we need mactime
  1389. *
  1390. * since mactime is defined as the time the first data
  1391. * symbol of the frame hits the PHY, and the timestamp
  1392. * of the beacon is defined as "the time that the data
  1393. * symbol containing the first bit of the timestamp is
  1394. * transmitted to the PHY plus the transmitting STA’s
  1395. * delays through its local PHY from the MAC-PHY
  1396. * interface to its interface with the WM"
  1397. * (802.11 11.1.2) - equals the time this bit arrives at
  1398. * the receiver - we have to take into account the
  1399. * offset between the two.
  1400. * e.g: at 1 MBit that means mactime is 192 usec earlier
  1401. * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
  1402. */
  1403. int rate;
  1404. if (rx_status->flag & RX_FLAG_HT) {
  1405. rate = 65; /* TODO: HT rates */
  1406. } else {
  1407. rate = local->hw.wiphy->bands[band]->
  1408. bitrates[rx_status->rate_idx].bitrate;
  1409. }
  1410. rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
  1411. } else if (local && local->ops && local->ops->get_tsf)
  1412. /* second best option: get current TSF */
  1413. rx_timestamp = local->ops->get_tsf(local_to_hw(local));
  1414. else
  1415. /* can't merge without knowing the TSF */
  1416. rx_timestamp = -1LLU;
  1417. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1418. printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
  1419. "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
  1420. mgmt->sa, mgmt->bssid,
  1421. (unsigned long long)rx_timestamp,
  1422. (unsigned long long)beacon_timestamp,
  1423. (unsigned long long)(rx_timestamp - beacon_timestamp),
  1424. jiffies);
  1425. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1426. if (beacon_timestamp > rx_timestamp) {
  1427. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1428. printk(KERN_DEBUG "%s: beacon TSF higher than "
  1429. "local TSF - IBSS merge with BSSID %pM\n",
  1430. sdata->dev->name, mgmt->bssid);
  1431. #endif
  1432. ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss);
  1433. ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, supp_rates);
  1434. }
  1435. }
  1436. ieee80211_rx_bss_put(local, bss);
  1437. }
  1438. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  1439. struct ieee80211_mgmt *mgmt,
  1440. size_t len,
  1441. struct ieee80211_rx_status *rx_status)
  1442. {
  1443. size_t baselen;
  1444. struct ieee802_11_elems elems;
  1445. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1446. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  1447. return; /* ignore ProbeResp to foreign address */
  1448. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  1449. if (baselen > len)
  1450. return;
  1451. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  1452. &elems);
  1453. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  1454. /* direct probe may be part of the association flow */
  1455. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  1456. &ifsta->request)) {
  1457. printk(KERN_DEBUG "%s direct probe responded\n",
  1458. sdata->dev->name);
  1459. ieee80211_authenticate(sdata, ifsta);
  1460. }
  1461. }
  1462. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  1463. struct ieee80211_mgmt *mgmt,
  1464. size_t len,
  1465. struct ieee80211_rx_status *rx_status)
  1466. {
  1467. struct ieee80211_if_sta *ifsta;
  1468. size_t baselen;
  1469. struct ieee802_11_elems elems;
  1470. struct ieee80211_local *local = sdata->local;
  1471. u32 changed = 0;
  1472. bool erp_valid, directed_tim, is_mc = false;
  1473. u8 erp_value = 0;
  1474. /* Process beacon from the current BSS */
  1475. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  1476. if (baselen > len)
  1477. return;
  1478. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  1479. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  1480. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1481. return;
  1482. ifsta = &sdata->u.sta;
  1483. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
  1484. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1485. return;
  1486. if (rx_status->freq != local->hw.conf.channel->center_freq)
  1487. return;
  1488. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  1489. elems.wmm_param_len);
  1490. if (!(local->hw.flags & IEEE80211_HW_NO_STACK_DYNAMIC_PS)) {
  1491. directed_tim = check_tim(&elems, ifsta->aid, &is_mc);
  1492. if (directed_tim || is_mc) {
  1493. if (local->hw.conf.flags && IEEE80211_CONF_PS) {
  1494. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1495. ieee80211_hw_config(local,
  1496. IEEE80211_CONF_CHANGE_PS);
  1497. ieee80211_send_nullfunc(local, sdata, 0);
  1498. }
  1499. }
  1500. }
  1501. if (elems.erp_info && elems.erp_info_len >= 1) {
  1502. erp_valid = true;
  1503. erp_value = elems.erp_info[0];
  1504. } else {
  1505. erp_valid = false;
  1506. }
  1507. changed |= ieee80211_handle_bss_capability(sdata,
  1508. le16_to_cpu(mgmt->u.beacon.capab_info),
  1509. erp_valid, erp_value);
  1510. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param) {
  1511. struct sta_info *sta;
  1512. struct ieee80211_supported_band *sband;
  1513. u16 ap_ht_cap_flags;
  1514. rcu_read_lock();
  1515. sta = sta_info_get(local, ifsta->bssid);
  1516. if (!sta) {
  1517. rcu_read_unlock();
  1518. return;
  1519. }
  1520. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1521. ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
  1522. elems.ht_cap_elem, &sta->sta.ht_cap);
  1523. ap_ht_cap_flags = sta->sta.ht_cap.cap;
  1524. rcu_read_unlock();
  1525. changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
  1526. ap_ht_cap_flags);
  1527. }
  1528. if (elems.country_elem) {
  1529. /* Note we are only reviewing this on beacons
  1530. * for the BSSID we are associated to */
  1531. regulatory_hint_11d(local->hw.wiphy,
  1532. elems.country_elem, elems.country_elem_len);
  1533. }
  1534. ieee80211_bss_info_change_notify(sdata, changed);
  1535. }
  1536. static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
  1537. struct ieee80211_if_sta *ifsta,
  1538. struct ieee80211_mgmt *mgmt,
  1539. size_t len)
  1540. {
  1541. struct ieee80211_local *local = sdata->local;
  1542. int tx_last_beacon;
  1543. struct sk_buff *skb;
  1544. struct ieee80211_mgmt *resp;
  1545. u8 *pos, *end;
  1546. if (sdata->vif.type != NL80211_IFTYPE_ADHOC ||
  1547. ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
  1548. len < 24 + 2 || !ifsta->probe_resp)
  1549. return;
  1550. if (local->ops->tx_last_beacon)
  1551. tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
  1552. else
  1553. tx_last_beacon = 1;
  1554. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1555. printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
  1556. " (tx_last_beacon=%d)\n",
  1557. sdata->dev->name, mgmt->sa, mgmt->da,
  1558. mgmt->bssid, tx_last_beacon);
  1559. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1560. if (!tx_last_beacon)
  1561. return;
  1562. if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
  1563. memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
  1564. return;
  1565. end = ((u8 *) mgmt) + len;
  1566. pos = mgmt->u.probe_req.variable;
  1567. if (pos[0] != WLAN_EID_SSID ||
  1568. pos + 2 + pos[1] > end) {
  1569. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1570. printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
  1571. "from %pM\n",
  1572. sdata->dev->name, mgmt->sa);
  1573. #endif
  1574. return;
  1575. }
  1576. if (pos[1] != 0 &&
  1577. (pos[1] != ifsta->ssid_len ||
  1578. memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
  1579. /* Ignore ProbeReq for foreign SSID */
  1580. return;
  1581. }
  1582. /* Reply with ProbeResp */
  1583. skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
  1584. if (!skb)
  1585. return;
  1586. resp = (struct ieee80211_mgmt *) skb->data;
  1587. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1588. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1589. printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
  1590. sdata->dev->name, resp->da);
  1591. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1592. ieee80211_tx_skb(sdata, skb, 0);
  1593. }
  1594. void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  1595. struct ieee80211_rx_status *rx_status)
  1596. {
  1597. struct ieee80211_local *local = sdata->local;
  1598. struct ieee80211_if_sta *ifsta;
  1599. struct ieee80211_mgmt *mgmt;
  1600. u16 fc;
  1601. if (skb->len < 24)
  1602. goto fail;
  1603. ifsta = &sdata->u.sta;
  1604. mgmt = (struct ieee80211_mgmt *) skb->data;
  1605. fc = le16_to_cpu(mgmt->frame_control);
  1606. switch (fc & IEEE80211_FCTL_STYPE) {
  1607. case IEEE80211_STYPE_PROBE_REQ:
  1608. case IEEE80211_STYPE_PROBE_RESP:
  1609. case IEEE80211_STYPE_BEACON:
  1610. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  1611. case IEEE80211_STYPE_AUTH:
  1612. case IEEE80211_STYPE_ASSOC_RESP:
  1613. case IEEE80211_STYPE_REASSOC_RESP:
  1614. case IEEE80211_STYPE_DEAUTH:
  1615. case IEEE80211_STYPE_DISASSOC:
  1616. skb_queue_tail(&ifsta->skb_queue, skb);
  1617. queue_work(local->hw.workqueue, &ifsta->work);
  1618. return;
  1619. }
  1620. fail:
  1621. kfree_skb(skb);
  1622. }
  1623. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  1624. struct sk_buff *skb)
  1625. {
  1626. struct ieee80211_rx_status *rx_status;
  1627. struct ieee80211_if_sta *ifsta;
  1628. struct ieee80211_mgmt *mgmt;
  1629. u16 fc;
  1630. ifsta = &sdata->u.sta;
  1631. rx_status = (struct ieee80211_rx_status *) skb->cb;
  1632. mgmt = (struct ieee80211_mgmt *) skb->data;
  1633. fc = le16_to_cpu(mgmt->frame_control);
  1634. switch (fc & IEEE80211_FCTL_STYPE) {
  1635. case IEEE80211_STYPE_PROBE_REQ:
  1636. ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len);
  1637. break;
  1638. case IEEE80211_STYPE_PROBE_RESP:
  1639. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status);
  1640. break;
  1641. case IEEE80211_STYPE_BEACON:
  1642. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  1643. break;
  1644. case IEEE80211_STYPE_AUTH:
  1645. ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len);
  1646. break;
  1647. case IEEE80211_STYPE_ASSOC_RESP:
  1648. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
  1649. break;
  1650. case IEEE80211_STYPE_REASSOC_RESP:
  1651. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
  1652. break;
  1653. case IEEE80211_STYPE_DEAUTH:
  1654. ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len);
  1655. break;
  1656. case IEEE80211_STYPE_DISASSOC:
  1657. ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len);
  1658. break;
  1659. }
  1660. kfree_skb(skb);
  1661. }
  1662. static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
  1663. {
  1664. struct ieee80211_local *local = sdata->local;
  1665. int active = 0;
  1666. struct sta_info *sta;
  1667. rcu_read_lock();
  1668. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  1669. if (sta->sdata == sdata &&
  1670. time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
  1671. jiffies)) {
  1672. active++;
  1673. break;
  1674. }
  1675. }
  1676. rcu_read_unlock();
  1677. return active;
  1678. }
  1679. static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
  1680. struct ieee80211_if_sta *ifsta)
  1681. {
  1682. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  1683. ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
  1684. if (ieee80211_sta_active_ibss(sdata))
  1685. return;
  1686. if ((sdata->u.sta.flags & IEEE80211_STA_BSSID_SET) &&
  1687. (!(sdata->u.sta.flags & IEEE80211_STA_AUTO_CHANNEL_SEL)))
  1688. return;
  1689. printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
  1690. "IBSS networks with same SSID (merge)\n", sdata->dev->name);
  1691. ieee80211_request_scan(sdata, ifsta->ssid, ifsta->ssid_len);
  1692. }
  1693. static void ieee80211_sta_timer(unsigned long data)
  1694. {
  1695. struct ieee80211_sub_if_data *sdata =
  1696. (struct ieee80211_sub_if_data *) data;
  1697. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1698. struct ieee80211_local *local = sdata->local;
  1699. set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  1700. queue_work(local->hw.workqueue, &ifsta->work);
  1701. }
  1702. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata,
  1703. struct ieee80211_if_sta *ifsta)
  1704. {
  1705. struct ieee80211_local *local = sdata->local;
  1706. if (local->ops->reset_tsf) {
  1707. /* Reset own TSF to allow time synchronization work. */
  1708. local->ops->reset_tsf(local_to_hw(local));
  1709. }
  1710. ifsta->wmm_last_param_set = -1; /* allow any WMM update */
  1711. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1712. ifsta->auth_alg = WLAN_AUTH_OPEN;
  1713. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1714. ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
  1715. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1716. ifsta->auth_alg = WLAN_AUTH_LEAP;
  1717. else
  1718. ifsta->auth_alg = WLAN_AUTH_OPEN;
  1719. ifsta->auth_transaction = -1;
  1720. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  1721. ifsta->assoc_scan_tries = 0;
  1722. ifsta->direct_probe_tries = 0;
  1723. ifsta->auth_tries = 0;
  1724. ifsta->assoc_tries = 0;
  1725. netif_tx_stop_all_queues(sdata->dev);
  1726. netif_carrier_off(sdata->dev);
  1727. }
  1728. static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
  1729. const char *ssid, int ssid_len)
  1730. {
  1731. int tmp, hidden_ssid;
  1732. if (ssid_len == ifsta->ssid_len &&
  1733. !memcmp(ifsta->ssid, ssid, ssid_len))
  1734. return 1;
  1735. if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  1736. return 0;
  1737. hidden_ssid = 1;
  1738. tmp = ssid_len;
  1739. while (tmp--) {
  1740. if (ssid[tmp] != '\0') {
  1741. hidden_ssid = 0;
  1742. break;
  1743. }
  1744. }
  1745. if (hidden_ssid && (ifsta->ssid_len == ssid_len || ssid_len == 0))
  1746. return 1;
  1747. if (ssid_len == 1 && ssid[0] == ' ')
  1748. return 1;
  1749. return 0;
  1750. }
  1751. static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
  1752. struct ieee80211_if_sta *ifsta)
  1753. {
  1754. struct ieee80211_local *local = sdata->local;
  1755. struct ieee80211_bss *bss;
  1756. struct ieee80211_supported_band *sband;
  1757. u8 bssid[ETH_ALEN], *pos;
  1758. int i;
  1759. int ret;
  1760. #if 0
  1761. /* Easier testing, use fixed BSSID. */
  1762. memset(bssid, 0xfe, ETH_ALEN);
  1763. #else
  1764. /* Generate random, not broadcast, locally administered BSSID. Mix in
  1765. * own MAC address to make sure that devices that do not have proper
  1766. * random number generator get different BSSID. */
  1767. get_random_bytes(bssid, ETH_ALEN);
  1768. for (i = 0; i < ETH_ALEN; i++)
  1769. bssid[i] ^= sdata->dev->dev_addr[i];
  1770. bssid[0] &= ~0x01;
  1771. bssid[0] |= 0x02;
  1772. #endif
  1773. printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
  1774. sdata->dev->name, bssid);
  1775. bss = ieee80211_rx_bss_add(local, bssid,
  1776. local->hw.conf.channel->center_freq,
  1777. sdata->u.sta.ssid, sdata->u.sta.ssid_len);
  1778. if (!bss)
  1779. return -ENOMEM;
  1780. bss->band = local->hw.conf.channel->band;
  1781. sband = local->hw.wiphy->bands[bss->band];
  1782. if (local->hw.conf.beacon_int == 0)
  1783. local->hw.conf.beacon_int = 100;
  1784. bss->beacon_int = local->hw.conf.beacon_int;
  1785. bss->last_update = jiffies;
  1786. bss->capability = WLAN_CAPABILITY_IBSS;
  1787. if (sdata->default_key)
  1788. bss->capability |= WLAN_CAPABILITY_PRIVACY;
  1789. else
  1790. sdata->drop_unencrypted = 0;
  1791. bss->supp_rates_len = sband->n_bitrates;
  1792. pos = bss->supp_rates;
  1793. for (i = 0; i < sband->n_bitrates; i++) {
  1794. int rate = sband->bitrates[i].bitrate;
  1795. *pos++ = (u8) (rate / 5);
  1796. }
  1797. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  1798. ieee80211_rx_bss_put(local, bss);
  1799. return ret;
  1800. }
  1801. static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
  1802. struct ieee80211_if_sta *ifsta)
  1803. {
  1804. struct ieee80211_local *local = sdata->local;
  1805. struct ieee80211_bss *bss;
  1806. int found = 0;
  1807. u8 bssid[ETH_ALEN];
  1808. int active_ibss;
  1809. if (ifsta->ssid_len == 0)
  1810. return -EINVAL;
  1811. active_ibss = ieee80211_sta_active_ibss(sdata);
  1812. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1813. printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
  1814. sdata->dev->name, active_ibss);
  1815. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1816. spin_lock_bh(&local->bss_lock);
  1817. list_for_each_entry(bss, &local->bss_list, list) {
  1818. if (ifsta->ssid_len != bss->ssid_len ||
  1819. memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
  1820. || !(bss->capability & WLAN_CAPABILITY_IBSS))
  1821. continue;
  1822. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1823. printk(KERN_DEBUG " bssid=%pM found\n", bss->bssid);
  1824. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1825. memcpy(bssid, bss->bssid, ETH_ALEN);
  1826. found = 1;
  1827. if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
  1828. break;
  1829. }
  1830. spin_unlock_bh(&local->bss_lock);
  1831. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1832. if (found)
  1833. printk(KERN_DEBUG " sta_find_ibss: selected %pM current "
  1834. "%pM\n", bssid, ifsta->bssid);
  1835. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1836. if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  1837. int ret;
  1838. int search_freq;
  1839. if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  1840. search_freq = bss->freq;
  1841. else
  1842. search_freq = local->hw.conf.channel->center_freq;
  1843. bss = ieee80211_rx_bss_get(local, bssid, search_freq,
  1844. ifsta->ssid, ifsta->ssid_len);
  1845. if (!bss)
  1846. goto dont_join;
  1847. printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
  1848. " based on configured SSID\n",
  1849. sdata->dev->name, bssid);
  1850. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  1851. ieee80211_rx_bss_put(local, bss);
  1852. return ret;
  1853. }
  1854. dont_join:
  1855. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  1856. printk(KERN_DEBUG " did not try to join ibss\n");
  1857. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  1858. /* Selected IBSS not found in current scan results - try to scan */
  1859. if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED &&
  1860. !ieee80211_sta_active_ibss(sdata)) {
  1861. mod_timer(&ifsta->timer, jiffies +
  1862. IEEE80211_IBSS_MERGE_INTERVAL);
  1863. } else if (time_after(jiffies, local->last_scan_completed +
  1864. IEEE80211_SCAN_INTERVAL)) {
  1865. printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
  1866. "join\n", sdata->dev->name);
  1867. return ieee80211_request_scan(sdata, ifsta->ssid,
  1868. ifsta->ssid_len);
  1869. } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) {
  1870. int interval = IEEE80211_SCAN_INTERVAL;
  1871. if (time_after(jiffies, ifsta->ibss_join_req +
  1872. IEEE80211_IBSS_JOIN_TIMEOUT)) {
  1873. if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
  1874. (!(local->oper_channel->flags &
  1875. IEEE80211_CHAN_NO_IBSS)))
  1876. return ieee80211_sta_create_ibss(sdata, ifsta);
  1877. if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
  1878. printk(KERN_DEBUG "%s: IBSS not allowed on"
  1879. " %d MHz\n", sdata->dev->name,
  1880. local->hw.conf.channel->center_freq);
  1881. }
  1882. /* No IBSS found - decrease scan interval and continue
  1883. * scanning. */
  1884. interval = IEEE80211_SCAN_INTERVAL_SLOW;
  1885. }
  1886. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  1887. mod_timer(&ifsta->timer, jiffies + interval);
  1888. return 0;
  1889. }
  1890. return 0;
  1891. }
  1892. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
  1893. struct ieee80211_if_sta *ifsta)
  1894. {
  1895. struct ieee80211_local *local = sdata->local;
  1896. struct ieee80211_bss *bss, *selected = NULL;
  1897. int top_rssi = 0, freq;
  1898. spin_lock_bh(&local->bss_lock);
  1899. freq = local->oper_channel->center_freq;
  1900. list_for_each_entry(bss, &local->bss_list, list) {
  1901. if (!(bss->capability & WLAN_CAPABILITY_ESS))
  1902. continue;
  1903. if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  1904. IEEE80211_STA_AUTO_BSSID_SEL |
  1905. IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
  1906. (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
  1907. !!sdata->default_key))
  1908. continue;
  1909. if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
  1910. bss->freq != freq)
  1911. continue;
  1912. if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
  1913. memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
  1914. continue;
  1915. if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
  1916. !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
  1917. continue;
  1918. if (!selected || top_rssi < bss->signal) {
  1919. selected = bss;
  1920. top_rssi = bss->signal;
  1921. }
  1922. }
  1923. if (selected)
  1924. atomic_inc(&selected->users);
  1925. spin_unlock_bh(&local->bss_lock);
  1926. if (selected) {
  1927. ieee80211_set_freq(sdata, selected->freq);
  1928. if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
  1929. ieee80211_sta_set_ssid(sdata, selected->ssid,
  1930. selected->ssid_len);
  1931. ieee80211_sta_set_bssid(sdata, selected->bssid);
  1932. ieee80211_sta_def_wmm_params(sdata, selected);
  1933. /* Send out direct probe if no probe resp was received or
  1934. * the one we have is outdated
  1935. */
  1936. if (!selected->last_probe_resp ||
  1937. time_after(jiffies, selected->last_probe_resp
  1938. + IEEE80211_SCAN_RESULT_EXPIRE))
  1939. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1940. else
  1941. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1942. ieee80211_rx_bss_put(local, selected);
  1943. ieee80211_sta_reset_auth(sdata, ifsta);
  1944. return 0;
  1945. } else {
  1946. if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  1947. ifsta->assoc_scan_tries++;
  1948. if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
  1949. ieee80211_start_scan(sdata, NULL, 0);
  1950. else
  1951. ieee80211_start_scan(sdata, ifsta->ssid,
  1952. ifsta->ssid_len);
  1953. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  1954. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  1955. } else
  1956. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  1957. }
  1958. return -1;
  1959. }
  1960. static void ieee80211_sta_work(struct work_struct *work)
  1961. {
  1962. struct ieee80211_sub_if_data *sdata =
  1963. container_of(work, struct ieee80211_sub_if_data, u.sta.work);
  1964. struct ieee80211_local *local = sdata->local;
  1965. struct ieee80211_if_sta *ifsta;
  1966. struct sk_buff *skb;
  1967. if (!netif_running(sdata->dev))
  1968. return;
  1969. if (local->sw_scanning || local->hw_scanning)
  1970. return;
  1971. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION &&
  1972. sdata->vif.type != NL80211_IFTYPE_ADHOC))
  1973. return;
  1974. ifsta = &sdata->u.sta;
  1975. while ((skb = skb_dequeue(&ifsta->skb_queue)))
  1976. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  1977. if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  1978. ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1979. ifsta->state != IEEE80211_STA_MLME_ASSOCIATE &&
  1980. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
  1981. ieee80211_start_scan(sdata, ifsta->scan_ssid,
  1982. ifsta->scan_ssid_len);
  1983. return;
  1984. }
  1985. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
  1986. if (ieee80211_sta_config_auth(sdata, ifsta))
  1987. return;
  1988. clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  1989. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
  1990. return;
  1991. switch (ifsta->state) {
  1992. case IEEE80211_STA_MLME_DISABLED:
  1993. break;
  1994. case IEEE80211_STA_MLME_DIRECT_PROBE:
  1995. ieee80211_direct_probe(sdata, ifsta);
  1996. break;
  1997. case IEEE80211_STA_MLME_AUTHENTICATE:
  1998. ieee80211_authenticate(sdata, ifsta);
  1999. break;
  2000. case IEEE80211_STA_MLME_ASSOCIATE:
  2001. ieee80211_associate(sdata, ifsta);
  2002. break;
  2003. case IEEE80211_STA_MLME_ASSOCIATED:
  2004. ieee80211_associated(sdata, ifsta);
  2005. break;
  2006. case IEEE80211_STA_MLME_IBSS_SEARCH:
  2007. ieee80211_sta_find_ibss(sdata, ifsta);
  2008. break;
  2009. case IEEE80211_STA_MLME_IBSS_JOINED:
  2010. ieee80211_sta_merge_ibss(sdata, ifsta);
  2011. break;
  2012. default:
  2013. WARN_ON(1);
  2014. break;
  2015. }
  2016. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  2017. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  2018. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  2019. ieee80211_set_disassoc(sdata, ifsta, false, true,
  2020. WLAN_REASON_UNSPECIFIED);
  2021. }
  2022. }
  2023. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  2024. {
  2025. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  2026. queue_work(sdata->local->hw.workqueue,
  2027. &sdata->u.sta.work);
  2028. }
  2029. /* interface setup */
  2030. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  2031. {
  2032. struct ieee80211_if_sta *ifsta;
  2033. ifsta = &sdata->u.sta;
  2034. INIT_WORK(&ifsta->work, ieee80211_sta_work);
  2035. INIT_WORK(&ifsta->chswitch_work, ieee80211_chswitch_work);
  2036. setup_timer(&ifsta->timer, ieee80211_sta_timer,
  2037. (unsigned long) sdata);
  2038. setup_timer(&ifsta->chswitch_timer, ieee80211_chswitch_timer,
  2039. (unsigned long) sdata);
  2040. skb_queue_head_init(&ifsta->skb_queue);
  2041. ifsta->capab = WLAN_CAPABILITY_ESS;
  2042. ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
  2043. IEEE80211_AUTH_ALG_SHARED_KEY;
  2044. ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
  2045. IEEE80211_STA_AUTO_BSSID_SEL |
  2046. IEEE80211_STA_AUTO_CHANNEL_SEL;
  2047. if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
  2048. ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
  2049. }
  2050. /*
  2051. * Add a new IBSS station, will also be called by the RX code when,
  2052. * in IBSS mode, receiving a frame from a yet-unknown station, hence
  2053. * must be callable in atomic context.
  2054. */
  2055. struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
  2056. u8 *bssid,u8 *addr, u64 supp_rates)
  2057. {
  2058. struct ieee80211_local *local = sdata->local;
  2059. struct sta_info *sta;
  2060. int band = local->hw.conf.channel->band;
  2061. /* TODO: Could consider removing the least recently used entry and
  2062. * allow new one to be added. */
  2063. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  2064. if (net_ratelimit()) {
  2065. printk(KERN_DEBUG "%s: No room for a new IBSS STA "
  2066. "entry %pM\n", sdata->dev->name, addr);
  2067. }
  2068. return NULL;
  2069. }
  2070. if (compare_ether_addr(bssid, sdata->u.sta.bssid))
  2071. return NULL;
  2072. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  2073. printk(KERN_DEBUG "%s: Adding new IBSS station %pM (dev=%s)\n",
  2074. wiphy_name(local->hw.wiphy), addr, sdata->dev->name);
  2075. #endif
  2076. sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
  2077. if (!sta)
  2078. return NULL;
  2079. set_sta_flags(sta, WLAN_STA_AUTHORIZED);
  2080. /* make sure mandatory rates are always added */
  2081. sta->sta.supp_rates[band] = supp_rates |
  2082. ieee80211_mandatory_rates(local, band);
  2083. rate_control_rate_init(sta);
  2084. if (sta_info_insert(sta))
  2085. return NULL;
  2086. return sta;
  2087. }
  2088. /* configuration hooks */
  2089. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
  2090. struct ieee80211_if_sta *ifsta)
  2091. {
  2092. struct ieee80211_local *local = sdata->local;
  2093. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2094. return;
  2095. if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
  2096. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  2097. (ifsta->flags & (IEEE80211_STA_SSID_SET |
  2098. IEEE80211_STA_AUTO_SSID_SEL))) {
  2099. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED)
  2100. ieee80211_set_disassoc(sdata, ifsta, true, true,
  2101. WLAN_REASON_DEAUTH_LEAVING);
  2102. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  2103. queue_work(local->hw.workqueue, &ifsta->work);
  2104. }
  2105. }
  2106. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  2107. {
  2108. struct ieee80211_if_sta *ifsta;
  2109. if (len > IEEE80211_MAX_SSID_LEN)
  2110. return -EINVAL;
  2111. ifsta = &sdata->u.sta;
  2112. if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
  2113. memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
  2114. memcpy(ifsta->ssid, ssid, len);
  2115. ifsta->ssid_len = len;
  2116. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  2117. }
  2118. if (len)
  2119. ifsta->flags |= IEEE80211_STA_SSID_SET;
  2120. else
  2121. ifsta->flags &= ~IEEE80211_STA_SSID_SET;
  2122. if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  2123. !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
  2124. ifsta->ibss_join_req = jiffies;
  2125. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  2126. return ieee80211_sta_find_ibss(sdata, ifsta);
  2127. }
  2128. return 0;
  2129. }
  2130. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  2131. {
  2132. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2133. memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
  2134. *len = ifsta->ssid_len;
  2135. return 0;
  2136. }
  2137. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  2138. {
  2139. struct ieee80211_if_sta *ifsta;
  2140. int res;
  2141. bool valid;
  2142. ifsta = &sdata->u.sta;
  2143. valid = is_valid_ether_addr(bssid);
  2144. if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  2145. if(valid)
  2146. memcpy(ifsta->bssid, bssid, ETH_ALEN);
  2147. else
  2148. memset(ifsta->bssid, 0, ETH_ALEN);
  2149. res = 0;
  2150. /*
  2151. * Hack! See also ieee80211_sta_set_ssid.
  2152. */
  2153. if (netif_running(sdata->dev))
  2154. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  2155. if (res) {
  2156. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  2157. "the low-level driver\n", sdata->dev->name);
  2158. return res;
  2159. }
  2160. }
  2161. if (valid)
  2162. ifsta->flags |= IEEE80211_STA_BSSID_SET;
  2163. else
  2164. ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
  2165. return 0;
  2166. }
  2167. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
  2168. {
  2169. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2170. kfree(ifsta->extra_ie);
  2171. if (len == 0) {
  2172. ifsta->extra_ie = NULL;
  2173. ifsta->extra_ie_len = 0;
  2174. return 0;
  2175. }
  2176. ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
  2177. if (!ifsta->extra_ie) {
  2178. ifsta->extra_ie_len = 0;
  2179. return -ENOMEM;
  2180. }
  2181. memcpy(ifsta->extra_ie, ie, len);
  2182. ifsta->extra_ie_len = len;
  2183. return 0;
  2184. }
  2185. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  2186. {
  2187. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2188. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  2189. sdata->dev->name, reason);
  2190. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2191. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2192. return -EINVAL;
  2193. ieee80211_set_disassoc(sdata, ifsta, true, true, reason);
  2194. return 0;
  2195. }
  2196. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  2197. {
  2198. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2199. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  2200. sdata->dev->name, reason);
  2201. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2202. return -EINVAL;
  2203. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
  2204. return -1;
  2205. ieee80211_set_disassoc(sdata, ifsta, false, true, reason);
  2206. return 0;
  2207. }
  2208. /* scan finished notification */
  2209. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  2210. {
  2211. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  2212. struct ieee80211_if_sta *ifsta;
  2213. if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2214. ifsta = &sdata->u.sta;
  2215. if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
  2216. (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) &&
  2217. !ieee80211_sta_active_ibss(sdata)))
  2218. ieee80211_sta_find_ibss(sdata, ifsta);
  2219. }
  2220. /* Restart STA timers */
  2221. rcu_read_lock();
  2222. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  2223. ieee80211_restart_sta_timer(sdata);
  2224. rcu_read_unlock();
  2225. }
  2226. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  2227. {
  2228. struct ieee80211_local *local =
  2229. container_of(work, struct ieee80211_local,
  2230. dynamic_ps_disable_work);
  2231. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2232. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2233. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2234. }
  2235. ieee80211_wake_queues_by_reason(&local->hw,
  2236. IEEE80211_QUEUE_STOP_REASON_PS);
  2237. }
  2238. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  2239. {
  2240. struct ieee80211_local *local =
  2241. container_of(work, struct ieee80211_local,
  2242. dynamic_ps_enable_work);
  2243. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  2244. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  2245. return;
  2246. ieee80211_send_nullfunc(local, sdata, 1);
  2247. local->hw.conf.flags |= IEEE80211_CONF_PS;
  2248. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2249. }
  2250. void ieee80211_dynamic_ps_timer(unsigned long data)
  2251. {
  2252. struct ieee80211_local *local = (void *) data;
  2253. queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
  2254. }