mlme.c 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746
  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. /* TODO:
  14. * order BSS list by RSSI(?) ("quality of AP")
  15. * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
  16. * SSID)
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/if_ether.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/if_arp.h>
  23. #include <linux/wireless.h>
  24. #include <linux/random.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/rtnetlink.h>
  27. #include <net/iw_handler.h>
  28. #include <net/mac80211.h>
  29. #include "ieee80211_i.h"
  30. #include "rate.h"
  31. #include "led.h"
  32. #include "mesh.h"
  33. #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
  34. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  35. #define IEEE80211_AUTH_MAX_TRIES 3
  36. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  37. #define IEEE80211_ASSOC_MAX_TRIES 3
  38. #define IEEE80211_MONITORING_INTERVAL (2 * HZ)
  39. #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
  40. #define IEEE80211_PROBE_INTERVAL (60 * HZ)
  41. #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
  42. #define IEEE80211_SCAN_INTERVAL (2 * HZ)
  43. #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
  44. #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ)
  45. #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
  46. #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
  47. #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
  48. #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
  49. /* mgmt header + 1 byte category code */
  50. #define IEEE80211_MIN_ACTION_SIZE (24 + 1)
  51. #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
  52. #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
  53. #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
  54. #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
  55. #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
  56. /* next values represent the buffer size for A-MPDU frame.
  57. * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */
  58. #define IEEE80211_MIN_AMPDU_BUF 0x8
  59. #define IEEE80211_MAX_AMPDU_BUF 0x40
  60. /* BSS handling */
  61. static struct ieee80211_sta_bss *
  62. ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
  63. u8 *ssid, u8 ssid_len)
  64. {
  65. struct ieee80211_sta_bss *bss;
  66. spin_lock_bh(&local->sta_bss_lock);
  67. bss = local->sta_bss_hash[STA_HASH(bssid)];
  68. while (bss) {
  69. if (!bss_mesh_cfg(bss) &&
  70. !memcmp(bss->bssid, bssid, ETH_ALEN) &&
  71. bss->freq == freq &&
  72. bss->ssid_len == ssid_len &&
  73. (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
  74. atomic_inc(&bss->users);
  75. break;
  76. }
  77. bss = bss->hnext;
  78. }
  79. spin_unlock_bh(&local->sta_bss_lock);
  80. return bss;
  81. }
  82. /* Caller must hold local->sta_bss_lock */
  83. static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local,
  84. struct ieee80211_sta_bss *bss)
  85. {
  86. u8 hash_idx;
  87. if (bss_mesh_cfg(bss))
  88. hash_idx = mesh_id_hash(bss_mesh_id(bss),
  89. bss_mesh_id_len(bss));
  90. else
  91. hash_idx = STA_HASH(bss->bssid);
  92. bss->hnext = local->sta_bss_hash[hash_idx];
  93. local->sta_bss_hash[hash_idx] = bss;
  94. }
  95. /* Caller must hold local->sta_bss_lock */
  96. static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local,
  97. struct ieee80211_sta_bss *bss)
  98. {
  99. struct ieee80211_sta_bss *b, *prev = NULL;
  100. b = local->sta_bss_hash[STA_HASH(bss->bssid)];
  101. while (b) {
  102. if (b == bss) {
  103. if (!prev)
  104. local->sta_bss_hash[STA_HASH(bss->bssid)] =
  105. bss->hnext;
  106. else
  107. prev->hnext = bss->hnext;
  108. break;
  109. }
  110. prev = b;
  111. b = b->hnext;
  112. }
  113. }
  114. static struct ieee80211_sta_bss *
  115. ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq,
  116. u8 *ssid, u8 ssid_len)
  117. {
  118. struct ieee80211_sta_bss *bss;
  119. bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
  120. if (!bss)
  121. return NULL;
  122. atomic_inc(&bss->users);
  123. atomic_inc(&bss->users);
  124. memcpy(bss->bssid, bssid, ETH_ALEN);
  125. bss->freq = freq;
  126. if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
  127. memcpy(bss->ssid, ssid, ssid_len);
  128. bss->ssid_len = ssid_len;
  129. }
  130. spin_lock_bh(&local->sta_bss_lock);
  131. /* TODO: order by RSSI? */
  132. list_add_tail(&bss->list, &local->sta_bss_list);
  133. __ieee80211_rx_bss_hash_add(local, bss);
  134. spin_unlock_bh(&local->sta_bss_lock);
  135. return bss;
  136. }
  137. #ifdef CONFIG_MAC80211_MESH
  138. static struct ieee80211_sta_bss *
  139. ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
  140. u8 *mesh_cfg, int freq)
  141. {
  142. struct ieee80211_sta_bss *bss;
  143. spin_lock_bh(&local->sta_bss_lock);
  144. bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
  145. while (bss) {
  146. if (bss_mesh_cfg(bss) &&
  147. !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
  148. bss->freq == freq &&
  149. mesh_id_len == bss->mesh_id_len &&
  150. (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
  151. mesh_id_len))) {
  152. atomic_inc(&bss->users);
  153. break;
  154. }
  155. bss = bss->hnext;
  156. }
  157. spin_unlock_bh(&local->sta_bss_lock);
  158. return bss;
  159. }
  160. static struct ieee80211_sta_bss *
  161. ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
  162. u8 *mesh_cfg, int mesh_config_len, int freq)
  163. {
  164. struct ieee80211_sta_bss *bss;
  165. if (mesh_config_len != MESH_CFG_LEN)
  166. return NULL;
  167. bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
  168. if (!bss)
  169. return NULL;
  170. bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
  171. if (!bss->mesh_cfg) {
  172. kfree(bss);
  173. return NULL;
  174. }
  175. if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
  176. bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
  177. if (!bss->mesh_id) {
  178. kfree(bss->mesh_cfg);
  179. kfree(bss);
  180. return NULL;
  181. }
  182. memcpy(bss->mesh_id, mesh_id, mesh_id_len);
  183. }
  184. atomic_inc(&bss->users);
  185. atomic_inc(&bss->users);
  186. memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
  187. bss->mesh_id_len = mesh_id_len;
  188. bss->freq = freq;
  189. spin_lock_bh(&local->sta_bss_lock);
  190. /* TODO: order by RSSI? */
  191. list_add_tail(&bss->list, &local->sta_bss_list);
  192. __ieee80211_rx_bss_hash_add(local, bss);
  193. spin_unlock_bh(&local->sta_bss_lock);
  194. return bss;
  195. }
  196. #endif
  197. static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
  198. {
  199. kfree(bss->ies);
  200. kfree(bss_mesh_id(bss));
  201. kfree(bss_mesh_cfg(bss));
  202. kfree(bss);
  203. }
  204. void ieee80211_rx_bss_put(struct ieee80211_local *local,
  205. struct ieee80211_sta_bss *bss)
  206. {
  207. local_bh_disable();
  208. if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
  209. local_bh_enable();
  210. return;
  211. }
  212. __ieee80211_rx_bss_hash_del(local, bss);
  213. list_del(&bss->list);
  214. spin_unlock_bh(&local->sta_bss_lock);
  215. ieee80211_rx_bss_free(bss);
  216. }
  217. void ieee80211_rx_bss_list_init(struct ieee80211_local *local)
  218. {
  219. spin_lock_init(&local->sta_bss_lock);
  220. INIT_LIST_HEAD(&local->sta_bss_list);
  221. }
  222. void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local)
  223. {
  224. struct ieee80211_sta_bss *bss, *tmp;
  225. list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list)
  226. ieee80211_rx_bss_put(local, bss);
  227. }
  228. static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie)
  229. {
  230. u8 *end, *pos;
  231. pos = bss->ies;
  232. if (pos == NULL)
  233. return NULL;
  234. end = pos + bss->ies_len;
  235. while (pos + 1 < end) {
  236. if (pos + 2 + pos[1] > end)
  237. break;
  238. if (pos[0] == ie)
  239. return pos;
  240. pos += 2 + pos[1];
  241. }
  242. return NULL;
  243. }
  244. /* utils */
  245. static int ecw2cw(int ecw)
  246. {
  247. return (1 << ecw) - 1;
  248. }
  249. /* frame sending functions */
  250. void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  251. int encrypt)
  252. {
  253. skb->dev = sdata->local->mdev;
  254. skb_set_mac_header(skb, 0);
  255. skb_set_network_header(skb, 0);
  256. skb_set_transport_header(skb, 0);
  257. skb->iif = sdata->dev->ifindex;
  258. skb->do_not_encrypt = !encrypt;
  259. dev_queue_xmit(skb);
  260. }
  261. static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  262. struct ieee80211_if_sta *ifsta,
  263. int transaction, u8 *extra, size_t extra_len,
  264. int encrypt)
  265. {
  266. struct ieee80211_local *local = sdata->local;
  267. struct sk_buff *skb;
  268. struct ieee80211_mgmt *mgmt;
  269. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  270. sizeof(*mgmt) + 6 + extra_len);
  271. if (!skb) {
  272. printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
  273. "frame\n", sdata->dev->name);
  274. return;
  275. }
  276. skb_reserve(skb, local->hw.extra_tx_headroom);
  277. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  278. memset(mgmt, 0, 24 + 6);
  279. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  280. IEEE80211_STYPE_AUTH);
  281. if (encrypt)
  282. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  283. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  284. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  285. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  286. mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
  287. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  288. ifsta->auth_transaction = transaction + 1;
  289. mgmt->u.auth.status_code = cpu_to_le16(0);
  290. if (extra)
  291. memcpy(skb_put(skb, extra_len), extra, extra_len);
  292. ieee80211_sta_tx(sdata, skb, encrypt);
  293. }
  294. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  295. u8 *ssid, size_t ssid_len)
  296. {
  297. struct ieee80211_local *local = sdata->local;
  298. struct ieee80211_supported_band *sband;
  299. struct sk_buff *skb;
  300. struct ieee80211_mgmt *mgmt;
  301. u8 *pos, *supp_rates, *esupp_rates = NULL;
  302. int i;
  303. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200);
  304. if (!skb) {
  305. printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
  306. "request\n", sdata->dev->name);
  307. return;
  308. }
  309. skb_reserve(skb, local->hw.extra_tx_headroom);
  310. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  311. memset(mgmt, 0, 24);
  312. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  313. IEEE80211_STYPE_PROBE_REQ);
  314. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  315. if (dst) {
  316. memcpy(mgmt->da, dst, ETH_ALEN);
  317. memcpy(mgmt->bssid, dst, ETH_ALEN);
  318. } else {
  319. memset(mgmt->da, 0xff, ETH_ALEN);
  320. memset(mgmt->bssid, 0xff, ETH_ALEN);
  321. }
  322. pos = skb_put(skb, 2 + ssid_len);
  323. *pos++ = WLAN_EID_SSID;
  324. *pos++ = ssid_len;
  325. memcpy(pos, ssid, ssid_len);
  326. supp_rates = skb_put(skb, 2);
  327. supp_rates[0] = WLAN_EID_SUPP_RATES;
  328. supp_rates[1] = 0;
  329. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  330. for (i = 0; i < sband->n_bitrates; i++) {
  331. struct ieee80211_rate *rate = &sband->bitrates[i];
  332. if (esupp_rates) {
  333. pos = skb_put(skb, 1);
  334. esupp_rates[1]++;
  335. } else if (supp_rates[1] == 8) {
  336. esupp_rates = skb_put(skb, 3);
  337. esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
  338. esupp_rates[1] = 1;
  339. pos = &esupp_rates[2];
  340. } else {
  341. pos = skb_put(skb, 1);
  342. supp_rates[1]++;
  343. }
  344. *pos = rate->bitrate / 5;
  345. }
  346. ieee80211_sta_tx(sdata, skb, 0);
  347. }
  348. /* MLME */
  349. static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
  350. struct ieee80211_sta_bss *bss,
  351. int ibss)
  352. {
  353. struct ieee80211_local *local = sdata->local;
  354. int i, have_higher_than_11mbit = 0;
  355. /* cf. IEEE 802.11 9.2.12 */
  356. for (i = 0; i < bss->supp_rates_len; i++)
  357. if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
  358. have_higher_than_11mbit = 1;
  359. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  360. have_higher_than_11mbit)
  361. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  362. else
  363. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  364. if (local->ops->conf_tx) {
  365. struct ieee80211_tx_queue_params qparam;
  366. memset(&qparam, 0, sizeof(qparam));
  367. qparam.aifs = 2;
  368. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  369. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
  370. qparam.cw_min = 31;
  371. else
  372. qparam.cw_min = 15;
  373. qparam.cw_max = 1023;
  374. qparam.txop = 0;
  375. for (i = 0; i < local_to_hw(local)->queues; i++)
  376. local->ops->conf_tx(local_to_hw(local), i, &qparam);
  377. }
  378. }
  379. static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
  380. struct ieee80211_if_sta *ifsta,
  381. u8 *wmm_param, size_t wmm_param_len)
  382. {
  383. struct ieee80211_tx_queue_params params;
  384. size_t left;
  385. int count;
  386. u8 *pos;
  387. if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED))
  388. return;
  389. if (!wmm_param)
  390. return;
  391. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  392. return;
  393. count = wmm_param[6] & 0x0f;
  394. if (count == ifsta->wmm_last_param_set)
  395. return;
  396. ifsta->wmm_last_param_set = count;
  397. pos = wmm_param + 8;
  398. left = wmm_param_len - 8;
  399. memset(&params, 0, sizeof(params));
  400. if (!local->ops->conf_tx)
  401. return;
  402. local->wmm_acm = 0;
  403. for (; left >= 4; left -= 4, pos += 4) {
  404. int aci = (pos[0] >> 5) & 0x03;
  405. int acm = (pos[0] >> 4) & 0x01;
  406. int queue;
  407. switch (aci) {
  408. case 1:
  409. queue = 3;
  410. if (acm)
  411. local->wmm_acm |= BIT(0) | BIT(3);
  412. break;
  413. case 2:
  414. queue = 1;
  415. if (acm)
  416. local->wmm_acm |= BIT(4) | BIT(5);
  417. break;
  418. case 3:
  419. queue = 0;
  420. if (acm)
  421. local->wmm_acm |= BIT(6) | BIT(7);
  422. break;
  423. case 0:
  424. default:
  425. queue = 2;
  426. if (acm)
  427. local->wmm_acm |= BIT(1) | BIT(2);
  428. break;
  429. }
  430. params.aifs = pos[0] & 0x0f;
  431. params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  432. params.cw_min = ecw2cw(pos[1] & 0x0f);
  433. params.txop = get_unaligned_le16(pos + 2);
  434. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  435. printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
  436. "cWmin=%d cWmax=%d txop=%d\n",
  437. local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
  438. params.cw_max, params.txop);
  439. #endif
  440. /* TODO: handle ACM (block TX, fallback to next lowest allowed
  441. * AC for now) */
  442. if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
  443. printk(KERN_DEBUG "%s: failed to set TX queue "
  444. "parameters for queue %d\n", local->mdev->name, queue);
  445. }
  446. }
  447. }
  448. static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata,
  449. bool use_protection,
  450. bool use_short_preamble)
  451. {
  452. struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
  453. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  454. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  455. DECLARE_MAC_BUF(mac);
  456. #endif
  457. u32 changed = 0;
  458. if (use_protection != bss_conf->use_cts_prot) {
  459. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  460. if (net_ratelimit()) {
  461. printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
  462. "%s)\n",
  463. sdata->dev->name,
  464. use_protection ? "enabled" : "disabled",
  465. print_mac(mac, ifsta->bssid));
  466. }
  467. #endif
  468. bss_conf->use_cts_prot = use_protection;
  469. changed |= BSS_CHANGED_ERP_CTS_PROT;
  470. }
  471. if (use_short_preamble != bss_conf->use_short_preamble) {
  472. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  473. if (net_ratelimit()) {
  474. printk(KERN_DEBUG "%s: switched to %s barker preamble"
  475. " (BSSID=%s)\n",
  476. sdata->dev->name,
  477. use_short_preamble ? "short" : "long",
  478. print_mac(mac, ifsta->bssid));
  479. }
  480. #endif
  481. bss_conf->use_short_preamble = use_short_preamble;
  482. changed |= BSS_CHANGED_ERP_PREAMBLE;
  483. }
  484. return changed;
  485. }
  486. static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
  487. u8 erp_value)
  488. {
  489. bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0;
  490. bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0;
  491. return ieee80211_handle_protect_preamb(sdata,
  492. use_protection, use_short_preamble);
  493. }
  494. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  495. struct ieee80211_sta_bss *bss)
  496. {
  497. u32 changed = 0;
  498. if (bss->has_erp_value)
  499. changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value);
  500. else {
  501. u16 capab = bss->capability;
  502. changed |= ieee80211_handle_protect_preamb(sdata, false,
  503. (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
  504. }
  505. return changed;
  506. }
  507. int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
  508. struct ieee80211_ht_info *ht_info)
  509. {
  510. if (ht_info == NULL)
  511. return -EINVAL;
  512. memset(ht_info, 0, sizeof(*ht_info));
  513. if (ht_cap_ie) {
  514. u8 ampdu_info = ht_cap_ie->ampdu_params_info;
  515. ht_info->ht_supported = 1;
  516. ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info);
  517. ht_info->ampdu_factor =
  518. ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR;
  519. ht_info->ampdu_density =
  520. (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2;
  521. memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16);
  522. } else
  523. ht_info->ht_supported = 0;
  524. return 0;
  525. }
  526. int ieee80211_ht_addt_info_ie_to_ht_bss_info(
  527. struct ieee80211_ht_addt_info *ht_add_info_ie,
  528. struct ieee80211_ht_bss_info *bss_info)
  529. {
  530. if (bss_info == NULL)
  531. return -EINVAL;
  532. memset(bss_info, 0, sizeof(*bss_info));
  533. if (ht_add_info_ie) {
  534. u16 op_mode;
  535. op_mode = le16_to_cpu(ht_add_info_ie->operation_mode);
  536. bss_info->primary_channel = ht_add_info_ie->control_chan;
  537. bss_info->bss_cap = ht_add_info_ie->ht_param;
  538. bss_info->bss_op_mode = (u8)(op_mode & 0xff);
  539. }
  540. return 0;
  541. }
  542. static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata,
  543. struct ieee80211_if_sta *ifsta)
  544. {
  545. union iwreq_data wrqu;
  546. memset(&wrqu, 0, sizeof(wrqu));
  547. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  548. memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
  549. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  550. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  551. }
  552. static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata,
  553. struct ieee80211_if_sta *ifsta)
  554. {
  555. union iwreq_data wrqu;
  556. if (ifsta->assocreq_ies) {
  557. memset(&wrqu, 0, sizeof(wrqu));
  558. wrqu.data.length = ifsta->assocreq_ies_len;
  559. wireless_send_event(sdata->dev, IWEVASSOCREQIE, &wrqu,
  560. ifsta->assocreq_ies);
  561. }
  562. if (ifsta->assocresp_ies) {
  563. memset(&wrqu, 0, sizeof(wrqu));
  564. wrqu.data.length = ifsta->assocresp_ies_len;
  565. wireless_send_event(sdata->dev, IWEVASSOCRESPIE, &wrqu,
  566. ifsta->assocresp_ies);
  567. }
  568. }
  569. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  570. struct ieee80211_if_sta *ifsta)
  571. {
  572. struct ieee80211_local *local = sdata->local;
  573. struct ieee80211_conf *conf = &local_to_hw(local)->conf;
  574. u32 changed = BSS_CHANGED_ASSOC;
  575. struct ieee80211_sta_bss *bss;
  576. ifsta->flags |= IEEE80211_STA_ASSOCIATED;
  577. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  578. return;
  579. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  580. conf->channel->center_freq,
  581. ifsta->ssid, ifsta->ssid_len);
  582. if (bss) {
  583. /* set timing information */
  584. sdata->bss_conf.beacon_int = bss->beacon_int;
  585. sdata->bss_conf.timestamp = bss->timestamp;
  586. sdata->bss_conf.dtim_period = bss->dtim_period;
  587. changed |= ieee80211_handle_bss_capability(sdata, bss);
  588. ieee80211_rx_bss_put(local, bss);
  589. }
  590. if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
  591. changed |= BSS_CHANGED_HT;
  592. sdata->bss_conf.assoc_ht = 1;
  593. sdata->bss_conf.ht_conf = &conf->ht_conf;
  594. sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
  595. }
  596. ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
  597. memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
  598. ieee80211_sta_send_associnfo(sdata, ifsta);
  599. ifsta->last_probe = jiffies;
  600. ieee80211_led_assoc(local, 1);
  601. sdata->bss_conf.assoc = 1;
  602. ieee80211_bss_info_change_notify(sdata, changed);
  603. netif_tx_start_all_queues(sdata->dev);
  604. netif_carrier_on(sdata->dev);
  605. ieee80211_sta_send_apinfo(sdata, ifsta);
  606. }
  607. static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
  608. struct ieee80211_if_sta *ifsta)
  609. {
  610. DECLARE_MAC_BUF(mac);
  611. ifsta->direct_probe_tries++;
  612. if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
  613. printk(KERN_DEBUG "%s: direct probe to AP %s timed out\n",
  614. sdata->dev->name, print_mac(mac, ifsta->bssid));
  615. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  616. return;
  617. }
  618. printk(KERN_DEBUG "%s: direct probe to AP %s try %d\n",
  619. sdata->dev->name, print_mac(mac, ifsta->bssid),
  620. ifsta->direct_probe_tries);
  621. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  622. set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request);
  623. /* Direct probe is sent to broadcast address as some APs
  624. * will not answer to direct packet in unassociated state.
  625. */
  626. ieee80211_send_probe_req(sdata, NULL,
  627. ifsta->ssid, ifsta->ssid_len);
  628. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  629. }
  630. static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
  631. struct ieee80211_if_sta *ifsta)
  632. {
  633. DECLARE_MAC_BUF(mac);
  634. ifsta->auth_tries++;
  635. if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
  636. printk(KERN_DEBUG "%s: authentication with AP %s"
  637. " timed out\n",
  638. sdata->dev->name, print_mac(mac, ifsta->bssid));
  639. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  640. return;
  641. }
  642. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  643. printk(KERN_DEBUG "%s: authenticate with AP %s\n",
  644. sdata->dev->name, print_mac(mac, ifsta->bssid));
  645. ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0);
  646. mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
  647. }
  648. static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss,
  649. struct ieee80211_supported_band *sband,
  650. u64 *rates)
  651. {
  652. int i, j, count;
  653. *rates = 0;
  654. count = 0;
  655. for (i = 0; i < bss->supp_rates_len; i++) {
  656. int rate = (bss->supp_rates[i] & 0x7F) * 5;
  657. for (j = 0; j < sband->n_bitrates; j++)
  658. if (sband->bitrates[j].bitrate == rate) {
  659. *rates |= BIT(j);
  660. count++;
  661. break;
  662. }
  663. }
  664. return count;
  665. }
  666. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
  667. struct ieee80211_if_sta *ifsta)
  668. {
  669. struct ieee80211_local *local = sdata->local;
  670. struct sk_buff *skb;
  671. struct ieee80211_mgmt *mgmt;
  672. u8 *pos, *ies, *ht_add_ie;
  673. int i, len, count, rates_len, supp_rates_len;
  674. u16 capab;
  675. struct ieee80211_sta_bss *bss;
  676. int wmm = 0;
  677. struct ieee80211_supported_band *sband;
  678. u64 rates = 0;
  679. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  680. sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
  681. ifsta->ssid_len);
  682. if (!skb) {
  683. printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
  684. "frame\n", sdata->dev->name);
  685. return;
  686. }
  687. skb_reserve(skb, local->hw.extra_tx_headroom);
  688. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  689. capab = ifsta->capab;
  690. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
  691. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
  692. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  693. if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
  694. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  695. }
  696. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  697. local->hw.conf.channel->center_freq,
  698. ifsta->ssid, ifsta->ssid_len);
  699. if (bss) {
  700. if (bss->capability & WLAN_CAPABILITY_PRIVACY)
  701. capab |= WLAN_CAPABILITY_PRIVACY;
  702. if (bss->wmm_used)
  703. wmm = 1;
  704. /* get all rates supported by the device and the AP as
  705. * some APs don't like getting a superset of their rates
  706. * in the association request (e.g. D-Link DAP 1353 in
  707. * b-only mode) */
  708. rates_len = ieee80211_compatible_rates(bss, sband, &rates);
  709. if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  710. (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
  711. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  712. ieee80211_rx_bss_put(local, bss);
  713. } else {
  714. rates = ~0;
  715. rates_len = sband->n_bitrates;
  716. }
  717. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  718. memset(mgmt, 0, 24);
  719. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  720. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  721. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  722. if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) {
  723. skb_put(skb, 10);
  724. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  725. IEEE80211_STYPE_REASSOC_REQ);
  726. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  727. mgmt->u.reassoc_req.listen_interval =
  728. cpu_to_le16(local->hw.conf.listen_interval);
  729. memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
  730. ETH_ALEN);
  731. } else {
  732. skb_put(skb, 4);
  733. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  734. IEEE80211_STYPE_ASSOC_REQ);
  735. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  736. mgmt->u.reassoc_req.listen_interval =
  737. cpu_to_le16(local->hw.conf.listen_interval);
  738. }
  739. /* SSID */
  740. ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
  741. *pos++ = WLAN_EID_SSID;
  742. *pos++ = ifsta->ssid_len;
  743. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  744. /* add all rates which were marked to be used above */
  745. supp_rates_len = rates_len;
  746. if (supp_rates_len > 8)
  747. supp_rates_len = 8;
  748. len = sband->n_bitrates;
  749. pos = skb_put(skb, supp_rates_len + 2);
  750. *pos++ = WLAN_EID_SUPP_RATES;
  751. *pos++ = supp_rates_len;
  752. count = 0;
  753. for (i = 0; i < sband->n_bitrates; i++) {
  754. if (BIT(i) & rates) {
  755. int rate = sband->bitrates[i].bitrate;
  756. *pos++ = (u8) (rate / 5);
  757. if (++count == 8)
  758. break;
  759. }
  760. }
  761. if (rates_len > count) {
  762. pos = skb_put(skb, rates_len - count + 2);
  763. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  764. *pos++ = rates_len - count;
  765. for (i++; i < sband->n_bitrates; i++) {
  766. if (BIT(i) & rates) {
  767. int rate = sband->bitrates[i].bitrate;
  768. *pos++ = (u8) (rate / 5);
  769. }
  770. }
  771. }
  772. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  773. /* 1. power capabilities */
  774. pos = skb_put(skb, 4);
  775. *pos++ = WLAN_EID_PWR_CAPABILITY;
  776. *pos++ = 2;
  777. *pos++ = 0; /* min tx power */
  778. *pos++ = local->hw.conf.channel->max_power; /* max tx power */
  779. /* 2. supported channels */
  780. /* TODO: get this in reg domain format */
  781. pos = skb_put(skb, 2 * sband->n_channels + 2);
  782. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  783. *pos++ = 2 * sband->n_channels;
  784. for (i = 0; i < sband->n_channels; i++) {
  785. *pos++ = ieee80211_frequency_to_channel(
  786. sband->channels[i].center_freq);
  787. *pos++ = 1; /* one channel in the subband*/
  788. }
  789. }
  790. if (ifsta->extra_ie) {
  791. pos = skb_put(skb, ifsta->extra_ie_len);
  792. memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
  793. }
  794. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
  795. pos = skb_put(skb, 9);
  796. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  797. *pos++ = 7; /* len */
  798. *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
  799. *pos++ = 0x50;
  800. *pos++ = 0xf2;
  801. *pos++ = 2; /* WME */
  802. *pos++ = 0; /* WME info */
  803. *pos++ = 1; /* WME ver */
  804. *pos++ = 0;
  805. }
  806. /* wmm support is a must to HT */
  807. if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) &&
  808. sband->ht_info.ht_supported &&
  809. (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) {
  810. struct ieee80211_ht_addt_info *ht_add_info =
  811. (struct ieee80211_ht_addt_info *)ht_add_ie;
  812. u16 cap = sband->ht_info.cap;
  813. __le16 tmp;
  814. u32 flags = local->hw.conf.channel->flags;
  815. switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) {
  816. case IEEE80211_HT_IE_CHA_SEC_ABOVE:
  817. if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
  818. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
  819. cap &= ~IEEE80211_HT_CAP_SGI_40;
  820. }
  821. break;
  822. case IEEE80211_HT_IE_CHA_SEC_BELOW:
  823. if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
  824. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH;
  825. cap &= ~IEEE80211_HT_CAP_SGI_40;
  826. }
  827. break;
  828. }
  829. tmp = cpu_to_le16(cap);
  830. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
  831. *pos++ = WLAN_EID_HT_CAPABILITY;
  832. *pos++ = sizeof(struct ieee80211_ht_cap);
  833. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  834. memcpy(pos, &tmp, sizeof(u16));
  835. pos += sizeof(u16);
  836. /* TODO: needs a define here for << 2 */
  837. *pos++ = sband->ht_info.ampdu_factor |
  838. (sband->ht_info.ampdu_density << 2);
  839. memcpy(pos, sband->ht_info.supp_mcs_set, 16);
  840. }
  841. kfree(ifsta->assocreq_ies);
  842. ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
  843. ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL);
  844. if (ifsta->assocreq_ies)
  845. memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
  846. ieee80211_sta_tx(sdata, skb, 0);
  847. }
  848. static void ieee80211_send_deauth(struct ieee80211_sub_if_data *sdata,
  849. struct ieee80211_if_sta *ifsta, u16 reason)
  850. {
  851. struct ieee80211_local *local = sdata->local;
  852. struct sk_buff *skb;
  853. struct ieee80211_mgmt *mgmt;
  854. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  855. if (!skb) {
  856. printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
  857. "frame\n", sdata->dev->name);
  858. return;
  859. }
  860. skb_reserve(skb, local->hw.extra_tx_headroom);
  861. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  862. memset(mgmt, 0, 24);
  863. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  864. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  865. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  866. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  867. IEEE80211_STYPE_DEAUTH);
  868. skb_put(skb, 2);
  869. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  870. ieee80211_sta_tx(sdata, skb, 0);
  871. }
  872. static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
  873. {
  874. if (!sdata || !sdata->default_key ||
  875. sdata->default_key->conf.alg != ALG_WEP)
  876. return 0;
  877. return 1;
  878. }
  879. static void ieee80211_send_disassoc(struct ieee80211_sub_if_data *sdata,
  880. struct ieee80211_if_sta *ifsta, u16 reason)
  881. {
  882. struct ieee80211_local *local = sdata->local;
  883. struct sk_buff *skb;
  884. struct ieee80211_mgmt *mgmt;
  885. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
  886. if (!skb) {
  887. printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
  888. "frame\n", sdata->dev->name);
  889. return;
  890. }
  891. skb_reserve(skb, local->hw.extra_tx_headroom);
  892. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  893. memset(mgmt, 0, 24);
  894. memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
  895. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  896. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  897. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  898. IEEE80211_STYPE_DISASSOC);
  899. skb_put(skb, 2);
  900. mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
  901. ieee80211_sta_tx(sdata, skb, 0);
  902. }
  903. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  904. struct ieee80211_if_sta *ifsta, bool deauth,
  905. bool self_disconnected, u16 reason)
  906. {
  907. struct ieee80211_local *local = sdata->local;
  908. struct sta_info *sta;
  909. u32 changed = BSS_CHANGED_ASSOC;
  910. rcu_read_lock();
  911. sta = sta_info_get(local, ifsta->bssid);
  912. if (!sta) {
  913. rcu_read_unlock();
  914. return;
  915. }
  916. if (deauth) {
  917. ifsta->direct_probe_tries = 0;
  918. ifsta->auth_tries = 0;
  919. }
  920. ifsta->assoc_scan_tries = 0;
  921. ifsta->assoc_tries = 0;
  922. netif_tx_stop_all_queues(sdata->dev);
  923. netif_carrier_off(sdata->dev);
  924. ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr);
  925. if (self_disconnected) {
  926. if (deauth)
  927. ieee80211_send_deauth(sdata, ifsta, reason);
  928. else
  929. ieee80211_send_disassoc(sdata, ifsta, reason);
  930. }
  931. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  932. changed |= ieee80211_reset_erp_info(sdata);
  933. if (sdata->bss_conf.assoc_ht)
  934. changed |= BSS_CHANGED_HT;
  935. sdata->bss_conf.assoc_ht = 0;
  936. sdata->bss_conf.ht_conf = NULL;
  937. sdata->bss_conf.ht_bss_conf = NULL;
  938. ieee80211_led_assoc(local, 0);
  939. sdata->bss_conf.assoc = 0;
  940. ieee80211_sta_send_apinfo(sdata, ifsta);
  941. if (self_disconnected)
  942. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  943. sta_info_unlink(&sta);
  944. rcu_read_unlock();
  945. sta_info_destroy(sta);
  946. }
  947. static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
  948. struct ieee80211_if_sta *ifsta)
  949. {
  950. struct ieee80211_local *local = sdata->local;
  951. struct ieee80211_sta_bss *bss;
  952. int bss_privacy;
  953. int wep_privacy;
  954. int privacy_invoked;
  955. if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
  956. return 0;
  957. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  958. local->hw.conf.channel->center_freq,
  959. ifsta->ssid, ifsta->ssid_len);
  960. if (!bss)
  961. return 0;
  962. bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY);
  963. wep_privacy = !!ieee80211_sta_wep_configured(sdata);
  964. privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED);
  965. ieee80211_rx_bss_put(local, bss);
  966. if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
  967. return 0;
  968. return 1;
  969. }
  970. static void ieee80211_associate(struct ieee80211_sub_if_data *sdata,
  971. struct ieee80211_if_sta *ifsta)
  972. {
  973. DECLARE_MAC_BUF(mac);
  974. ifsta->assoc_tries++;
  975. if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
  976. printk(KERN_DEBUG "%s: association with AP %s"
  977. " timed out\n",
  978. sdata->dev->name, print_mac(mac, ifsta->bssid));
  979. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  980. return;
  981. }
  982. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  983. printk(KERN_DEBUG "%s: associate with AP %s\n",
  984. sdata->dev->name, print_mac(mac, ifsta->bssid));
  985. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  986. printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
  987. "mixed-cell disabled - abort association\n", sdata->dev->name);
  988. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  989. return;
  990. }
  991. ieee80211_send_assoc(sdata, ifsta);
  992. mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
  993. }
  994. static void ieee80211_associated(struct ieee80211_sub_if_data *sdata,
  995. struct ieee80211_if_sta *ifsta)
  996. {
  997. struct ieee80211_local *local = sdata->local;
  998. struct sta_info *sta;
  999. int disassoc;
  1000. DECLARE_MAC_BUF(mac);
  1001. /* TODO: start monitoring current AP signal quality and number of
  1002. * missed beacons. Scan other channels every now and then and search
  1003. * for better APs. */
  1004. /* TODO: remove expired BSSes */
  1005. ifsta->state = IEEE80211_STA_MLME_ASSOCIATED;
  1006. rcu_read_lock();
  1007. sta = sta_info_get(local, ifsta->bssid);
  1008. if (!sta) {
  1009. printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
  1010. sdata->dev->name, print_mac(mac, ifsta->bssid));
  1011. disassoc = 1;
  1012. } else {
  1013. disassoc = 0;
  1014. if (time_after(jiffies,
  1015. sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
  1016. if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) {
  1017. printk(KERN_DEBUG "%s: No ProbeResp from "
  1018. "current AP %s - assume out of "
  1019. "range\n",
  1020. sdata->dev->name, print_mac(mac, ifsta->bssid));
  1021. disassoc = 1;
  1022. } else
  1023. ieee80211_send_probe_req(sdata, ifsta->bssid,
  1024. local->scan_ssid,
  1025. local->scan_ssid_len);
  1026. ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL;
  1027. } else {
  1028. ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
  1029. if (time_after(jiffies, ifsta->last_probe +
  1030. IEEE80211_PROBE_INTERVAL)) {
  1031. ifsta->last_probe = jiffies;
  1032. ieee80211_send_probe_req(sdata, ifsta->bssid,
  1033. ifsta->ssid,
  1034. ifsta->ssid_len);
  1035. }
  1036. }
  1037. }
  1038. rcu_read_unlock();
  1039. if (disassoc)
  1040. ieee80211_set_disassoc(sdata, ifsta, true, true,
  1041. WLAN_REASON_PREV_AUTH_NOT_VALID);
  1042. else
  1043. mod_timer(&ifsta->timer, jiffies +
  1044. IEEE80211_MONITORING_INTERVAL);
  1045. }
  1046. static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
  1047. struct ieee80211_if_sta *ifsta)
  1048. {
  1049. printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
  1050. ifsta->flags |= IEEE80211_STA_AUTHENTICATED;
  1051. ieee80211_associate(sdata, ifsta);
  1052. }
  1053. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  1054. struct ieee80211_if_sta *ifsta,
  1055. struct ieee80211_mgmt *mgmt,
  1056. size_t len)
  1057. {
  1058. u8 *pos;
  1059. struct ieee802_11_elems elems;
  1060. pos = mgmt->u.auth.variable;
  1061. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1062. if (!elems.challenge)
  1063. return;
  1064. ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2,
  1065. elems.challenge_len + 2, 1);
  1066. }
  1067. static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
  1068. u8 dialog_token, u16 status, u16 policy,
  1069. u16 buf_size, u16 timeout)
  1070. {
  1071. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1072. struct ieee80211_local *local = sdata->local;
  1073. struct sk_buff *skb;
  1074. struct ieee80211_mgmt *mgmt;
  1075. u16 capab;
  1076. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  1077. if (!skb) {
  1078. printk(KERN_DEBUG "%s: failed to allocate buffer "
  1079. "for addba resp frame\n", sdata->dev->name);
  1080. return;
  1081. }
  1082. skb_reserve(skb, local->hw.extra_tx_headroom);
  1083. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1084. memset(mgmt, 0, 24);
  1085. memcpy(mgmt->da, da, ETH_ALEN);
  1086. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1087. if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
  1088. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  1089. else
  1090. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1091. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1092. IEEE80211_STYPE_ACTION);
  1093. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
  1094. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  1095. mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
  1096. mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
  1097. capab = (u16)(policy << 1); /* bit 1 aggregation policy */
  1098. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  1099. capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
  1100. mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
  1101. mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
  1102. mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
  1103. ieee80211_sta_tx(sdata, skb, 0);
  1104. return;
  1105. }
  1106. void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, const u8 *da,
  1107. u16 tid, u8 dialog_token, u16 start_seq_num,
  1108. u16 agg_size, u16 timeout)
  1109. {
  1110. struct ieee80211_local *local = sdata->local;
  1111. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1112. struct sk_buff *skb;
  1113. struct ieee80211_mgmt *mgmt;
  1114. u16 capab;
  1115. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  1116. if (!skb) {
  1117. printk(KERN_ERR "%s: failed to allocate buffer "
  1118. "for addba request frame\n", sdata->dev->name);
  1119. return;
  1120. }
  1121. skb_reserve(skb, local->hw.extra_tx_headroom);
  1122. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1123. memset(mgmt, 0, 24);
  1124. memcpy(mgmt->da, da, ETH_ALEN);
  1125. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1126. if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
  1127. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  1128. else
  1129. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1130. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1131. IEEE80211_STYPE_ACTION);
  1132. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
  1133. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  1134. mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
  1135. mgmt->u.action.u.addba_req.dialog_token = dialog_token;
  1136. capab = (u16)(1 << 1); /* bit 1 aggregation policy */
  1137. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  1138. capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
  1139. mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
  1140. mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
  1141. mgmt->u.action.u.addba_req.start_seq_num =
  1142. cpu_to_le16(start_seq_num << 4);
  1143. ieee80211_sta_tx(sdata, skb, 0);
  1144. }
  1145. /*
  1146. * After accepting the AddBA Request we activated a timer,
  1147. * resetting it after each frame that arrives from the originator.
  1148. * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
  1149. */
  1150. static void sta_rx_agg_session_timer_expired(unsigned long data)
  1151. {
  1152. /* not an elegant detour, but there is no choice as the timer passes
  1153. * only one argument, and various sta_info are needed here, so init
  1154. * flow in sta_info_create gives the TID as data, while the timer_to_id
  1155. * array gives the sta through container_of */
  1156. u8 *ptid = (u8 *)data;
  1157. u8 *timer_to_id = ptid - *ptid;
  1158. struct sta_info *sta = container_of(timer_to_id, struct sta_info,
  1159. timer_to_tid[0]);
  1160. #ifdef CONFIG_MAC80211_HT_DEBUG
  1161. printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
  1162. #endif
  1163. ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr,
  1164. (u16)*ptid, WLAN_BACK_TIMER,
  1165. WLAN_REASON_QSTA_TIMEOUT);
  1166. }
  1167. static void ieee80211_sta_process_addba_request(struct ieee80211_local *local,
  1168. struct ieee80211_mgmt *mgmt,
  1169. size_t len)
  1170. {
  1171. struct ieee80211_hw *hw = &local->hw;
  1172. struct ieee80211_conf *conf = &hw->conf;
  1173. struct sta_info *sta;
  1174. struct tid_ampdu_rx *tid_agg_rx;
  1175. u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
  1176. u8 dialog_token;
  1177. int ret = -EOPNOTSUPP;
  1178. DECLARE_MAC_BUF(mac);
  1179. rcu_read_lock();
  1180. sta = sta_info_get(local, mgmt->sa);
  1181. if (!sta) {
  1182. rcu_read_unlock();
  1183. return;
  1184. }
  1185. /* extract session parameters from addba request frame */
  1186. dialog_token = mgmt->u.action.u.addba_req.dialog_token;
  1187. timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
  1188. start_seq_num =
  1189. le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
  1190. capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1191. ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
  1192. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1193. buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
  1194. status = WLAN_STATUS_REQUEST_DECLINED;
  1195. /* sanity check for incoming parameters:
  1196. * check if configuration can support the BA policy
  1197. * and if buffer size does not exceeds max value */
  1198. if (((ba_policy != 1)
  1199. && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA)))
  1200. || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
  1201. status = WLAN_STATUS_INVALID_QOS_PARAM;
  1202. #ifdef CONFIG_MAC80211_HT_DEBUG
  1203. if (net_ratelimit())
  1204. printk(KERN_DEBUG "AddBA Req with bad params from "
  1205. "%s on tid %u. policy %d, buffer size %d\n",
  1206. print_mac(mac, mgmt->sa), tid, ba_policy,
  1207. buf_size);
  1208. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1209. goto end_no_lock;
  1210. }
  1211. /* determine default buffer size */
  1212. if (buf_size == 0) {
  1213. struct ieee80211_supported_band *sband;
  1214. sband = local->hw.wiphy->bands[conf->channel->band];
  1215. buf_size = IEEE80211_MIN_AMPDU_BUF;
  1216. buf_size = buf_size << sband->ht_info.ampdu_factor;
  1217. }
  1218. /* examine state machine */
  1219. spin_lock_bh(&sta->lock);
  1220. if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
  1221. #ifdef CONFIG_MAC80211_HT_DEBUG
  1222. if (net_ratelimit())
  1223. printk(KERN_DEBUG "unexpected AddBA Req from "
  1224. "%s on tid %u\n",
  1225. print_mac(mac, mgmt->sa), tid);
  1226. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1227. goto end;
  1228. }
  1229. /* prepare A-MPDU MLME for Rx aggregation */
  1230. sta->ampdu_mlme.tid_rx[tid] =
  1231. kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
  1232. if (!sta->ampdu_mlme.tid_rx[tid]) {
  1233. #ifdef CONFIG_MAC80211_HT_DEBUG
  1234. if (net_ratelimit())
  1235. printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
  1236. tid);
  1237. #endif
  1238. goto end;
  1239. }
  1240. /* rx timer */
  1241. sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
  1242. sta_rx_agg_session_timer_expired;
  1243. sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
  1244. (unsigned long)&sta->timer_to_tid[tid];
  1245. init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
  1246. tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
  1247. /* prepare reordering buffer */
  1248. tid_agg_rx->reorder_buf =
  1249. kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
  1250. if (!tid_agg_rx->reorder_buf) {
  1251. #ifdef CONFIG_MAC80211_HT_DEBUG
  1252. if (net_ratelimit())
  1253. printk(KERN_ERR "can not allocate reordering buffer "
  1254. "to tid %d\n", tid);
  1255. #endif
  1256. kfree(sta->ampdu_mlme.tid_rx[tid]);
  1257. goto end;
  1258. }
  1259. memset(tid_agg_rx->reorder_buf, 0,
  1260. buf_size * sizeof(struct sk_buff *));
  1261. if (local->ops->ampdu_action)
  1262. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
  1263. sta->addr, tid, &start_seq_num);
  1264. #ifdef CONFIG_MAC80211_HT_DEBUG
  1265. printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
  1266. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1267. if (ret) {
  1268. kfree(tid_agg_rx->reorder_buf);
  1269. kfree(tid_agg_rx);
  1270. sta->ampdu_mlme.tid_rx[tid] = NULL;
  1271. goto end;
  1272. }
  1273. /* change state and send addba resp */
  1274. sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
  1275. tid_agg_rx->dialog_token = dialog_token;
  1276. tid_agg_rx->ssn = start_seq_num;
  1277. tid_agg_rx->head_seq_num = start_seq_num;
  1278. tid_agg_rx->buf_size = buf_size;
  1279. tid_agg_rx->timeout = timeout;
  1280. tid_agg_rx->stored_mpdu_num = 0;
  1281. status = WLAN_STATUS_SUCCESS;
  1282. end:
  1283. spin_unlock_bh(&sta->lock);
  1284. end_no_lock:
  1285. ieee80211_send_addba_resp(sta->sdata, sta->addr, tid,
  1286. dialog_token, status, 1, buf_size, timeout);
  1287. rcu_read_unlock();
  1288. }
  1289. static void ieee80211_sta_process_addba_resp(struct ieee80211_local *local,
  1290. struct ieee80211_mgmt *mgmt,
  1291. size_t len)
  1292. {
  1293. struct ieee80211_hw *hw = &local->hw;
  1294. struct sta_info *sta;
  1295. u16 capab;
  1296. u16 tid;
  1297. u8 *state;
  1298. rcu_read_lock();
  1299. sta = sta_info_get(local, mgmt->sa);
  1300. if (!sta) {
  1301. rcu_read_unlock();
  1302. return;
  1303. }
  1304. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  1305. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1306. state = &sta->ampdu_mlme.tid_state_tx[tid];
  1307. spin_lock_bh(&sta->lock);
  1308. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  1309. spin_unlock_bh(&sta->lock);
  1310. goto addba_resp_exit;
  1311. }
  1312. if (mgmt->u.action.u.addba_resp.dialog_token !=
  1313. sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
  1314. spin_unlock_bh(&sta->lock);
  1315. #ifdef CONFIG_MAC80211_HT_DEBUG
  1316. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  1317. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1318. goto addba_resp_exit;
  1319. }
  1320. del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  1321. #ifdef CONFIG_MAC80211_HT_DEBUG
  1322. printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
  1323. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1324. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  1325. == WLAN_STATUS_SUCCESS) {
  1326. *state |= HT_ADDBA_RECEIVED_MSK;
  1327. sta->ampdu_mlme.addba_req_num[tid] = 0;
  1328. if (*state == HT_AGG_STATE_OPERATIONAL)
  1329. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  1330. spin_unlock_bh(&sta->lock);
  1331. } else {
  1332. sta->ampdu_mlme.addba_req_num[tid]++;
  1333. /* this will allow the state check in stop_BA_session */
  1334. *state = HT_AGG_STATE_OPERATIONAL;
  1335. spin_unlock_bh(&sta->lock);
  1336. ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
  1337. WLAN_BACK_INITIATOR);
  1338. }
  1339. addba_resp_exit:
  1340. rcu_read_unlock();
  1341. }
  1342. void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, const u8 *da, u16 tid,
  1343. u16 initiator, u16 reason_code)
  1344. {
  1345. struct ieee80211_local *local = sdata->local;
  1346. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  1347. struct sk_buff *skb;
  1348. struct ieee80211_mgmt *mgmt;
  1349. u16 params;
  1350. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  1351. if (!skb) {
  1352. printk(KERN_ERR "%s: failed to allocate buffer "
  1353. "for delba frame\n", sdata->dev->name);
  1354. return;
  1355. }
  1356. skb_reserve(skb, local->hw.extra_tx_headroom);
  1357. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1358. memset(mgmt, 0, 24);
  1359. memcpy(mgmt->da, da, ETH_ALEN);
  1360. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1361. if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
  1362. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  1363. else
  1364. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1365. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1366. IEEE80211_STYPE_ACTION);
  1367. skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
  1368. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  1369. mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  1370. params = (u16)(initiator << 11); /* bit 11 initiator */
  1371. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  1372. mgmt->u.action.u.delba.params = cpu_to_le16(params);
  1373. mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
  1374. ieee80211_sta_tx(sdata, skb, 0);
  1375. }
  1376. void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
  1377. {
  1378. struct ieee80211_local *local = sdata->local;
  1379. struct sk_buff *skb;
  1380. struct ieee80211_bar *bar;
  1381. u16 bar_control = 0;
  1382. skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
  1383. if (!skb) {
  1384. printk(KERN_ERR "%s: failed to allocate buffer for "
  1385. "bar frame\n", sdata->dev->name);
  1386. return;
  1387. }
  1388. skb_reserve(skb, local->hw.extra_tx_headroom);
  1389. bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
  1390. memset(bar, 0, sizeof(*bar));
  1391. bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  1392. IEEE80211_STYPE_BACK_REQ);
  1393. memcpy(bar->ra, ra, ETH_ALEN);
  1394. memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
  1395. bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
  1396. bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
  1397. bar_control |= (u16)(tid << 12);
  1398. bar->control = cpu_to_le16(bar_control);
  1399. bar->start_seq_num = cpu_to_le16(ssn);
  1400. ieee80211_sta_tx(sdata, skb, 0);
  1401. }
  1402. void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
  1403. u16 initiator, u16 reason)
  1404. {
  1405. struct ieee80211_local *local = sdata->local;
  1406. struct ieee80211_hw *hw = &local->hw;
  1407. struct sta_info *sta;
  1408. int ret, i;
  1409. DECLARE_MAC_BUF(mac);
  1410. rcu_read_lock();
  1411. sta = sta_info_get(local, ra);
  1412. if (!sta) {
  1413. rcu_read_unlock();
  1414. return;
  1415. }
  1416. /* check if TID is in operational state */
  1417. spin_lock_bh(&sta->lock);
  1418. if (sta->ampdu_mlme.tid_state_rx[tid]
  1419. != HT_AGG_STATE_OPERATIONAL) {
  1420. spin_unlock_bh(&sta->lock);
  1421. rcu_read_unlock();
  1422. return;
  1423. }
  1424. sta->ampdu_mlme.tid_state_rx[tid] =
  1425. HT_AGG_STATE_REQ_STOP_BA_MSK |
  1426. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  1427. spin_unlock_bh(&sta->lock);
  1428. /* stop HW Rx aggregation. ampdu_action existence
  1429. * already verified in session init so we add the BUG_ON */
  1430. BUG_ON(!local->ops->ampdu_action);
  1431. #ifdef CONFIG_MAC80211_HT_DEBUG
  1432. printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
  1433. print_mac(mac, ra), tid);
  1434. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1435. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
  1436. ra, tid, NULL);
  1437. if (ret)
  1438. printk(KERN_DEBUG "HW problem - can not stop rx "
  1439. "aggregation for tid %d\n", tid);
  1440. /* shutdown timer has not expired */
  1441. if (initiator != WLAN_BACK_TIMER)
  1442. del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
  1443. /* check if this is a self generated aggregation halt */
  1444. if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
  1445. ieee80211_send_delba(sdata, ra, tid, 0, reason);
  1446. /* free the reordering buffer */
  1447. for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
  1448. if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
  1449. /* release the reordered frames */
  1450. dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
  1451. sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
  1452. sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
  1453. }
  1454. }
  1455. /* free resources */
  1456. kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
  1457. kfree(sta->ampdu_mlme.tid_rx[tid]);
  1458. sta->ampdu_mlme.tid_rx[tid] = NULL;
  1459. sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
  1460. rcu_read_unlock();
  1461. }
  1462. static void ieee80211_sta_process_delba(struct ieee80211_sub_if_data *sdata,
  1463. struct ieee80211_mgmt *mgmt, size_t len)
  1464. {
  1465. struct ieee80211_local *local = sdata->local;
  1466. struct sta_info *sta;
  1467. u16 tid, params;
  1468. u16 initiator;
  1469. DECLARE_MAC_BUF(mac);
  1470. rcu_read_lock();
  1471. sta = sta_info_get(local, mgmt->sa);
  1472. if (!sta) {
  1473. rcu_read_unlock();
  1474. return;
  1475. }
  1476. params = le16_to_cpu(mgmt->u.action.u.delba.params);
  1477. tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
  1478. initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
  1479. #ifdef CONFIG_MAC80211_HT_DEBUG
  1480. if (net_ratelimit())
  1481. printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
  1482. print_mac(mac, mgmt->sa),
  1483. initiator ? "initiator" : "recipient", tid,
  1484. mgmt->u.action.u.delba.reason_code);
  1485. #endif /* CONFIG_MAC80211_HT_DEBUG */
  1486. if (initiator == WLAN_BACK_INITIATOR)
  1487. ieee80211_sta_stop_rx_ba_session(sdata, sta->addr, tid,
  1488. WLAN_BACK_INITIATOR, 0);
  1489. else { /* WLAN_BACK_RECIPIENT */
  1490. spin_lock_bh(&sta->lock);
  1491. sta->ampdu_mlme.tid_state_tx[tid] =
  1492. HT_AGG_STATE_OPERATIONAL;
  1493. spin_unlock_bh(&sta->lock);
  1494. ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
  1495. WLAN_BACK_RECIPIENT);
  1496. }
  1497. rcu_read_unlock();
  1498. }
  1499. /*
  1500. * After sending add Block Ack request we activated a timer until
  1501. * add Block Ack response will arrive from the recipient.
  1502. * If this timer expires sta_addba_resp_timer_expired will be executed.
  1503. */
  1504. void sta_addba_resp_timer_expired(unsigned long data)
  1505. {
  1506. /* not an elegant detour, but there is no choice as the timer passes
  1507. * only one argument, and both sta_info and TID are needed, so init
  1508. * flow in sta_info_create gives the TID as data, while the timer_to_id
  1509. * array gives the sta through container_of */
  1510. u16 tid = *(u8 *)data;
  1511. struct sta_info *temp_sta = container_of((void *)data,
  1512. struct sta_info, timer_to_tid[tid]);
  1513. struct ieee80211_local *local = temp_sta->local;
  1514. struct ieee80211_hw *hw = &local->hw;
  1515. struct sta_info *sta;
  1516. u8 *state;
  1517. rcu_read_lock();
  1518. sta = sta_info_get(local, temp_sta->addr);
  1519. if (!sta) {
  1520. rcu_read_unlock();
  1521. return;
  1522. }
  1523. state = &sta->ampdu_mlme.tid_state_tx[tid];
  1524. /* check if the TID waits for addBA response */
  1525. spin_lock_bh(&sta->lock);
  1526. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  1527. spin_unlock_bh(&sta->lock);
  1528. *state = HT_AGG_STATE_IDLE;
  1529. #ifdef CONFIG_MAC80211_HT_DEBUG
  1530. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  1531. "expecting addBA response there", tid);
  1532. #endif
  1533. goto timer_expired_exit;
  1534. }
  1535. #ifdef CONFIG_MAC80211_HT_DEBUG
  1536. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  1537. #endif
  1538. /* go through the state check in stop_BA_session */
  1539. *state = HT_AGG_STATE_OPERATIONAL;
  1540. spin_unlock_bh(&sta->lock);
  1541. ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
  1542. WLAN_BACK_INITIATOR);
  1543. timer_expired_exit:
  1544. rcu_read_unlock();
  1545. }
  1546. void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr)
  1547. {
  1548. struct ieee80211_local *local = sdata->local;
  1549. int i;
  1550. for (i = 0; i < STA_TID_NUM; i++) {
  1551. ieee80211_stop_tx_ba_session(&local->hw, addr, i,
  1552. WLAN_BACK_INITIATOR);
  1553. ieee80211_sta_stop_rx_ba_session(sdata, addr, i,
  1554. WLAN_BACK_RECIPIENT,
  1555. WLAN_REASON_QSTA_LEAVE_QBSS);
  1556. }
  1557. }
  1558. static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_data *sdata,
  1559. struct ieee80211_msrment_ie *request_ie,
  1560. const u8 *da, const u8 *bssid,
  1561. u8 dialog_token)
  1562. {
  1563. struct ieee80211_local *local = sdata->local;
  1564. struct sk_buff *skb;
  1565. struct ieee80211_mgmt *msr_report;
  1566. skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom +
  1567. sizeof(struct ieee80211_msrment_ie));
  1568. if (!skb) {
  1569. printk(KERN_ERR "%s: failed to allocate buffer for "
  1570. "measurement report frame\n", sdata->dev->name);
  1571. return;
  1572. }
  1573. skb_reserve(skb, local->hw.extra_tx_headroom);
  1574. msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24);
  1575. memset(msr_report, 0, 24);
  1576. memcpy(msr_report->da, da, ETH_ALEN);
  1577. memcpy(msr_report->sa, sdata->dev->dev_addr, ETH_ALEN);
  1578. memcpy(msr_report->bssid, bssid, ETH_ALEN);
  1579. msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1580. IEEE80211_STYPE_ACTION);
  1581. skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement));
  1582. msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
  1583. msr_report->u.action.u.measurement.action_code =
  1584. WLAN_ACTION_SPCT_MSR_RPRT;
  1585. msr_report->u.action.u.measurement.dialog_token = dialog_token;
  1586. msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT;
  1587. msr_report->u.action.u.measurement.length =
  1588. sizeof(struct ieee80211_msrment_ie);
  1589. memset(&msr_report->u.action.u.measurement.msr_elem, 0,
  1590. sizeof(struct ieee80211_msrment_ie));
  1591. msr_report->u.action.u.measurement.msr_elem.token = request_ie->token;
  1592. msr_report->u.action.u.measurement.msr_elem.mode |=
  1593. IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED;
  1594. msr_report->u.action.u.measurement.msr_elem.type = request_ie->type;
  1595. ieee80211_sta_tx(sdata, skb, 0);
  1596. }
  1597. static void ieee80211_sta_process_measurement_req(struct ieee80211_sub_if_data *sdata,
  1598. struct ieee80211_mgmt *mgmt,
  1599. size_t len)
  1600. {
  1601. /*
  1602. * Ignoring measurement request is spec violation.
  1603. * Mandatory measurements must be reported optional
  1604. * measurements might be refused or reported incapable
  1605. * For now just refuse
  1606. * TODO: Answer basic measurement as unmeasured
  1607. */
  1608. ieee80211_send_refuse_measurement_request(sdata,
  1609. &mgmt->u.action.u.measurement.msr_elem,
  1610. mgmt->sa, mgmt->bssid,
  1611. mgmt->u.action.u.measurement.dialog_token);
  1612. }
  1613. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  1614. struct ieee80211_if_sta *ifsta,
  1615. struct ieee80211_mgmt *mgmt,
  1616. size_t len)
  1617. {
  1618. u16 auth_alg, auth_transaction, status_code;
  1619. DECLARE_MAC_BUF(mac);
  1620. if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  1621. sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
  1622. return;
  1623. if (len < 24 + 6)
  1624. return;
  1625. if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
  1626. memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  1627. return;
  1628. if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
  1629. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  1630. return;
  1631. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  1632. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  1633. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  1634. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  1635. /*
  1636. * IEEE 802.11 standard does not require authentication in IBSS
  1637. * networks and most implementations do not seem to use it.
  1638. * However, try to reply to authentication attempts if someone
  1639. * has actually implemented this.
  1640. */
  1641. if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
  1642. return;
  1643. ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0);
  1644. }
  1645. if (auth_alg != ifsta->auth_alg ||
  1646. auth_transaction != ifsta->auth_transaction)
  1647. return;
  1648. if (status_code != WLAN_STATUS_SUCCESS) {
  1649. if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
  1650. u8 algs[3];
  1651. const int num_algs = ARRAY_SIZE(algs);
  1652. int i, pos;
  1653. algs[0] = algs[1] = algs[2] = 0xff;
  1654. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  1655. algs[0] = WLAN_AUTH_OPEN;
  1656. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  1657. algs[1] = WLAN_AUTH_SHARED_KEY;
  1658. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  1659. algs[2] = WLAN_AUTH_LEAP;
  1660. if (ifsta->auth_alg == WLAN_AUTH_OPEN)
  1661. pos = 0;
  1662. else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
  1663. pos = 1;
  1664. else
  1665. pos = 2;
  1666. for (i = 0; i < num_algs; i++) {
  1667. pos++;
  1668. if (pos >= num_algs)
  1669. pos = 0;
  1670. if (algs[pos] == ifsta->auth_alg ||
  1671. algs[pos] == 0xff)
  1672. continue;
  1673. if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
  1674. !ieee80211_sta_wep_configured(sdata))
  1675. continue;
  1676. ifsta->auth_alg = algs[pos];
  1677. break;
  1678. }
  1679. }
  1680. return;
  1681. }
  1682. switch (ifsta->auth_alg) {
  1683. case WLAN_AUTH_OPEN:
  1684. case WLAN_AUTH_LEAP:
  1685. ieee80211_auth_completed(sdata, ifsta);
  1686. break;
  1687. case WLAN_AUTH_SHARED_KEY:
  1688. if (ifsta->auth_transaction == 4)
  1689. ieee80211_auth_completed(sdata, ifsta);
  1690. else
  1691. ieee80211_auth_challenge(sdata, ifsta, mgmt, len);
  1692. break;
  1693. }
  1694. }
  1695. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  1696. struct ieee80211_if_sta *ifsta,
  1697. struct ieee80211_mgmt *mgmt,
  1698. size_t len)
  1699. {
  1700. u16 reason_code;
  1701. DECLARE_MAC_BUF(mac);
  1702. if (len < 24 + 2)
  1703. return;
  1704. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1705. return;
  1706. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  1707. if (ifsta->flags & IEEE80211_STA_AUTHENTICATED)
  1708. printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name);
  1709. if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  1710. ifsta->state == IEEE80211_STA_MLME_ASSOCIATE ||
  1711. ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1712. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  1713. mod_timer(&ifsta->timer, jiffies +
  1714. IEEE80211_RETRY_AUTH_INTERVAL);
  1715. }
  1716. ieee80211_set_disassoc(sdata, ifsta, true, false, 0);
  1717. ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED;
  1718. }
  1719. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  1720. struct ieee80211_if_sta *ifsta,
  1721. struct ieee80211_mgmt *mgmt,
  1722. size_t len)
  1723. {
  1724. u16 reason_code;
  1725. DECLARE_MAC_BUF(mac);
  1726. if (len < 24 + 2)
  1727. return;
  1728. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN))
  1729. return;
  1730. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  1731. if (ifsta->flags & IEEE80211_STA_ASSOCIATED)
  1732. printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name);
  1733. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) {
  1734. ifsta->state = IEEE80211_STA_MLME_ASSOCIATE;
  1735. mod_timer(&ifsta->timer, jiffies +
  1736. IEEE80211_RETRY_AUTH_INTERVAL);
  1737. }
  1738. ieee80211_set_disassoc(sdata, ifsta, false, false, 0);
  1739. }
  1740. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  1741. struct ieee80211_if_sta *ifsta,
  1742. struct ieee80211_mgmt *mgmt,
  1743. size_t len,
  1744. int reassoc)
  1745. {
  1746. struct ieee80211_local *local = sdata->local;
  1747. struct ieee80211_supported_band *sband;
  1748. struct sta_info *sta;
  1749. u64 rates, basic_rates;
  1750. u16 capab_info, status_code, aid;
  1751. struct ieee802_11_elems elems;
  1752. struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
  1753. u8 *pos;
  1754. int i, j;
  1755. DECLARE_MAC_BUF(mac);
  1756. bool have_higher_than_11mbit = false;
  1757. /* AssocResp and ReassocResp have identical structure, so process both
  1758. * of them in this function. */
  1759. if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE)
  1760. return;
  1761. if (len < 24 + 6)
  1762. return;
  1763. if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
  1764. return;
  1765. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  1766. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  1767. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  1768. printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x "
  1769. "status=%d aid=%d)\n",
  1770. sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa),
  1771. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  1772. if (status_code != WLAN_STATUS_SUCCESS) {
  1773. printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
  1774. sdata->dev->name, status_code);
  1775. /* if this was a reassociation, ensure we try a "full"
  1776. * association next time. This works around some broken APs
  1777. * which do not correctly reject reassociation requests. */
  1778. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  1779. return;
  1780. }
  1781. if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
  1782. printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
  1783. "set\n", sdata->dev->name, aid);
  1784. aid &= ~(BIT(15) | BIT(14));
  1785. pos = mgmt->u.assoc_resp.variable;
  1786. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
  1787. if (!elems.supp_rates) {
  1788. printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
  1789. sdata->dev->name);
  1790. return;
  1791. }
  1792. printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
  1793. ifsta->aid = aid;
  1794. ifsta->ap_capab = capab_info;
  1795. kfree(ifsta->assocresp_ies);
  1796. ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
  1797. ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL);
  1798. if (ifsta->assocresp_ies)
  1799. memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
  1800. rcu_read_lock();
  1801. /* Add STA entry for the AP */
  1802. sta = sta_info_get(local, ifsta->bssid);
  1803. if (!sta) {
  1804. struct ieee80211_sta_bss *bss;
  1805. int err;
  1806. sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
  1807. if (!sta) {
  1808. printk(KERN_DEBUG "%s: failed to alloc STA entry for"
  1809. " the AP\n", sdata->dev->name);
  1810. rcu_read_unlock();
  1811. return;
  1812. }
  1813. bss = ieee80211_rx_bss_get(local, ifsta->bssid,
  1814. local->hw.conf.channel->center_freq,
  1815. ifsta->ssid, ifsta->ssid_len);
  1816. if (bss) {
  1817. sta->last_signal = bss->signal;
  1818. sta->last_qual = bss->qual;
  1819. sta->last_noise = bss->noise;
  1820. ieee80211_rx_bss_put(local, bss);
  1821. }
  1822. err = sta_info_insert(sta);
  1823. if (err) {
  1824. printk(KERN_DEBUG "%s: failed to insert STA entry for"
  1825. " the AP (error %d)\n", sdata->dev->name, err);
  1826. rcu_read_unlock();
  1827. return;
  1828. }
  1829. /* update new sta with its last rx activity */
  1830. sta->last_rx = jiffies;
  1831. }
  1832. /*
  1833. * FIXME: Do we really need to update the sta_info's information here?
  1834. * We already know about the AP (we found it in our list) so it
  1835. * should already be filled with the right info, no?
  1836. * As is stands, all this is racy because typically we assume
  1837. * the information that is filled in here (except flags) doesn't
  1838. * change while a STA structure is alive. As such, it should move
  1839. * to between the sta_info_alloc() and sta_info_insert() above.
  1840. */
  1841. set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
  1842. WLAN_STA_AUTHORIZED);
  1843. rates = 0;
  1844. basic_rates = 0;
  1845. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1846. for (i = 0; i < elems.supp_rates_len; i++) {
  1847. int rate = (elems.supp_rates[i] & 0x7f) * 5;
  1848. if (rate > 110)
  1849. have_higher_than_11mbit = true;
  1850. for (j = 0; j < sband->n_bitrates; j++) {
  1851. if (sband->bitrates[j].bitrate == rate)
  1852. rates |= BIT(j);
  1853. if (elems.supp_rates[i] & 0x80)
  1854. basic_rates |= BIT(j);
  1855. }
  1856. }
  1857. for (i = 0; i < elems.ext_supp_rates_len; i++) {
  1858. int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
  1859. if (rate > 110)
  1860. have_higher_than_11mbit = true;
  1861. for (j = 0; j < sband->n_bitrates; j++) {
  1862. if (sband->bitrates[j].bitrate == rate)
  1863. rates |= BIT(j);
  1864. if (elems.ext_supp_rates[i] & 0x80)
  1865. basic_rates |= BIT(j);
  1866. }
  1867. }
  1868. sta->supp_rates[local->hw.conf.channel->band] = rates;
  1869. sdata->basic_rates = basic_rates;
  1870. /* cf. IEEE 802.11 9.2.12 */
  1871. if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
  1872. have_higher_than_11mbit)
  1873. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  1874. else
  1875. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  1876. if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
  1877. (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
  1878. struct ieee80211_ht_bss_info bss_info;
  1879. ieee80211_ht_cap_ie_to_ht_info(
  1880. (struct ieee80211_ht_cap *)
  1881. elems.ht_cap_elem, &sta->ht_info);
  1882. ieee80211_ht_addt_info_ie_to_ht_bss_info(
  1883. (struct ieee80211_ht_addt_info *)
  1884. elems.ht_info_elem, &bss_info);
  1885. ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
  1886. }
  1887. rate_control_rate_init(sta, local);
  1888. if (elems.wmm_param) {
  1889. set_sta_flags(sta, WLAN_STA_WME);
  1890. rcu_read_unlock();
  1891. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  1892. elems.wmm_param_len);
  1893. } else
  1894. rcu_read_unlock();
  1895. /* set AID and assoc capability,
  1896. * ieee80211_set_associated() will tell the driver */
  1897. bss_conf->aid = aid;
  1898. bss_conf->assoc_capability = capab_info;
  1899. ieee80211_set_associated(sdata, ifsta);
  1900. ieee80211_associated(sdata, ifsta);
  1901. }
  1902. static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
  1903. struct ieee80211_if_sta *ifsta,
  1904. struct ieee80211_sta_bss *bss)
  1905. {
  1906. struct ieee80211_local *local = sdata->local;
  1907. int res, rates, i, j;
  1908. struct sk_buff *skb;
  1909. struct ieee80211_mgmt *mgmt;
  1910. u8 *pos;
  1911. struct ieee80211_supported_band *sband;
  1912. union iwreq_data wrqu;
  1913. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1914. /* Remove possible STA entries from other IBSS networks. */
  1915. sta_info_flush_delayed(sdata);
  1916. if (local->ops->reset_tsf) {
  1917. /* Reset own TSF to allow time synchronization work. */
  1918. local->ops->reset_tsf(local_to_hw(local));
  1919. }
  1920. memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
  1921. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  1922. if (res)
  1923. return res;
  1924. local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
  1925. sdata->drop_unencrypted = bss->capability &
  1926. WLAN_CAPABILITY_PRIVACY ? 1 : 0;
  1927. res = ieee80211_set_freq(sdata, bss->freq);
  1928. if (res)
  1929. return res;
  1930. /* Build IBSS probe response */
  1931. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
  1932. if (skb) {
  1933. skb_reserve(skb, local->hw.extra_tx_headroom);
  1934. mgmt = (struct ieee80211_mgmt *)
  1935. skb_put(skb, 24 + sizeof(mgmt->u.beacon));
  1936. memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
  1937. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1938. IEEE80211_STYPE_PROBE_RESP);
  1939. memset(mgmt->da, 0xff, ETH_ALEN);
  1940. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  1941. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  1942. mgmt->u.beacon.beacon_int =
  1943. cpu_to_le16(local->hw.conf.beacon_int);
  1944. mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp);
  1945. mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
  1946. pos = skb_put(skb, 2 + ifsta->ssid_len);
  1947. *pos++ = WLAN_EID_SSID;
  1948. *pos++ = ifsta->ssid_len;
  1949. memcpy(pos, ifsta->ssid, ifsta->ssid_len);
  1950. rates = bss->supp_rates_len;
  1951. if (rates > 8)
  1952. rates = 8;
  1953. pos = skb_put(skb, 2 + rates);
  1954. *pos++ = WLAN_EID_SUPP_RATES;
  1955. *pos++ = rates;
  1956. memcpy(pos, bss->supp_rates, rates);
  1957. if (bss->band == IEEE80211_BAND_2GHZ) {
  1958. pos = skb_put(skb, 2 + 1);
  1959. *pos++ = WLAN_EID_DS_PARAMS;
  1960. *pos++ = 1;
  1961. *pos++ = ieee80211_frequency_to_channel(bss->freq);
  1962. }
  1963. pos = skb_put(skb, 2 + 2);
  1964. *pos++ = WLAN_EID_IBSS_PARAMS;
  1965. *pos++ = 2;
  1966. /* FIX: set ATIM window based on scan results */
  1967. *pos++ = 0;
  1968. *pos++ = 0;
  1969. if (bss->supp_rates_len > 8) {
  1970. rates = bss->supp_rates_len - 8;
  1971. pos = skb_put(skb, 2 + rates);
  1972. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1973. *pos++ = rates;
  1974. memcpy(pos, &bss->supp_rates[8], rates);
  1975. }
  1976. ifsta->probe_resp = skb;
  1977. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  1978. }
  1979. rates = 0;
  1980. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  1981. for (i = 0; i < bss->supp_rates_len; i++) {
  1982. int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
  1983. for (j = 0; j < sband->n_bitrates; j++)
  1984. if (sband->bitrates[j].bitrate == bitrate)
  1985. rates |= BIT(j);
  1986. }
  1987. ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
  1988. ieee80211_sta_def_wmm_params(sdata, bss, 1);
  1989. ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED;
  1990. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  1991. memset(&wrqu, 0, sizeof(wrqu));
  1992. memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN);
  1993. wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
  1994. return res;
  1995. }
  1996. u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
  1997. struct ieee802_11_elems *elems,
  1998. enum ieee80211_band band)
  1999. {
  2000. struct ieee80211_supported_band *sband;
  2001. struct ieee80211_rate *bitrates;
  2002. size_t num_rates;
  2003. u64 supp_rates;
  2004. int i, j;
  2005. sband = local->hw.wiphy->bands[band];
  2006. if (!sband) {
  2007. WARN_ON(1);
  2008. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  2009. }
  2010. bitrates = sband->bitrates;
  2011. num_rates = sband->n_bitrates;
  2012. supp_rates = 0;
  2013. for (i = 0; i < elems->supp_rates_len +
  2014. elems->ext_supp_rates_len; i++) {
  2015. u8 rate = 0;
  2016. int own_rate;
  2017. if (i < elems->supp_rates_len)
  2018. rate = elems->supp_rates[i];
  2019. else if (elems->ext_supp_rates)
  2020. rate = elems->ext_supp_rates
  2021. [i - elems->supp_rates_len];
  2022. own_rate = 5 * (rate & 0x7f);
  2023. for (j = 0; j < num_rates; j++)
  2024. if (bitrates[j].bitrate == own_rate)
  2025. supp_rates |= BIT(j);
  2026. }
  2027. return supp_rates;
  2028. }
  2029. static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local,
  2030. enum ieee80211_band band)
  2031. {
  2032. struct ieee80211_supported_band *sband;
  2033. struct ieee80211_rate *bitrates;
  2034. u64 mandatory_rates;
  2035. enum ieee80211_rate_flags mandatory_flag;
  2036. int i;
  2037. sband = local->hw.wiphy->bands[band];
  2038. if (!sband) {
  2039. WARN_ON(1);
  2040. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  2041. }
  2042. if (band == IEEE80211_BAND_2GHZ)
  2043. mandatory_flag = IEEE80211_RATE_MANDATORY_B;
  2044. else
  2045. mandatory_flag = IEEE80211_RATE_MANDATORY_A;
  2046. bitrates = sband->bitrates;
  2047. mandatory_rates = 0;
  2048. for (i = 0; i < sband->n_bitrates; i++)
  2049. if (bitrates[i].flags & mandatory_flag)
  2050. mandatory_rates |= BIT(i);
  2051. return mandatory_rates;
  2052. }
  2053. struct ieee80211_sta_bss *
  2054. ieee80211_bss_info_update(struct ieee80211_local *local,
  2055. struct ieee80211_rx_status *rx_status,
  2056. struct ieee80211_mgmt *mgmt,
  2057. size_t len,
  2058. struct ieee802_11_elems *elems,
  2059. int freq, bool beacon)
  2060. {
  2061. struct ieee80211_sta_bss *bss;
  2062. int clen;
  2063. #ifdef CONFIG_MAC80211_MESH
  2064. if (elems->mesh_config)
  2065. bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id,
  2066. elems->mesh_id_len, elems->mesh_config, freq);
  2067. else
  2068. #endif
  2069. bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq,
  2070. elems->ssid, elems->ssid_len);
  2071. if (!bss) {
  2072. #ifdef CONFIG_MAC80211_MESH
  2073. if (elems->mesh_config)
  2074. bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id,
  2075. elems->mesh_id_len, elems->mesh_config,
  2076. elems->mesh_config_len, freq);
  2077. else
  2078. #endif
  2079. bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq,
  2080. elems->ssid, elems->ssid_len);
  2081. if (!bss)
  2082. return NULL;
  2083. } else {
  2084. #if 0
  2085. /* TODO: order by RSSI? */
  2086. spin_lock_bh(&local->sta_bss_lock);
  2087. list_move_tail(&bss->list, &local->sta_bss_list);
  2088. spin_unlock_bh(&local->sta_bss_lock);
  2089. #endif
  2090. }
  2091. /* save the ERP value so that it is available at association time */
  2092. if (elems->erp_info && elems->erp_info_len >= 1) {
  2093. bss->erp_value = elems->erp_info[0];
  2094. bss->has_erp_value = 1;
  2095. }
  2096. bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
  2097. bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
  2098. if (elems->tim) {
  2099. struct ieee80211_tim_ie *tim_ie =
  2100. (struct ieee80211_tim_ie *)elems->tim;
  2101. bss->dtim_period = tim_ie->dtim_period;
  2102. }
  2103. /* set default value for buggy APs */
  2104. if (!elems->tim || bss->dtim_period == 0)
  2105. bss->dtim_period = 1;
  2106. bss->supp_rates_len = 0;
  2107. if (elems->supp_rates) {
  2108. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  2109. if (clen > elems->supp_rates_len)
  2110. clen = elems->supp_rates_len;
  2111. memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates,
  2112. clen);
  2113. bss->supp_rates_len += clen;
  2114. }
  2115. if (elems->ext_supp_rates) {
  2116. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  2117. if (clen > elems->ext_supp_rates_len)
  2118. clen = elems->ext_supp_rates_len;
  2119. memcpy(&bss->supp_rates[bss->supp_rates_len],
  2120. elems->ext_supp_rates, clen);
  2121. bss->supp_rates_len += clen;
  2122. }
  2123. bss->band = rx_status->band;
  2124. bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
  2125. bss->last_update = jiffies;
  2126. bss->signal = rx_status->signal;
  2127. bss->noise = rx_status->noise;
  2128. bss->qual = rx_status->qual;
  2129. bss->wmm_used = elems->wmm_param || elems->wmm_info;
  2130. if (!beacon)
  2131. bss->last_probe_resp = jiffies;
  2132. /*
  2133. * For probe responses, or if we don't have any information yet,
  2134. * use the IEs from the beacon.
  2135. */
  2136. if (!bss->ies || !beacon) {
  2137. if (bss->ies == NULL || bss->ies_len < elems->total_len) {
  2138. kfree(bss->ies);
  2139. bss->ies = kmalloc(elems->total_len, GFP_ATOMIC);
  2140. }
  2141. if (bss->ies) {
  2142. memcpy(bss->ies, elems->ie_start, elems->total_len);
  2143. bss->ies_len = elems->total_len;
  2144. } else
  2145. bss->ies_len = 0;
  2146. }
  2147. return bss;
  2148. }
  2149. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  2150. struct ieee80211_mgmt *mgmt,
  2151. size_t len,
  2152. struct ieee80211_rx_status *rx_status,
  2153. struct ieee802_11_elems *elems,
  2154. bool beacon)
  2155. {
  2156. struct ieee80211_local *local = sdata->local;
  2157. int freq;
  2158. struct ieee80211_sta_bss *bss;
  2159. struct sta_info *sta;
  2160. struct ieee80211_channel *channel;
  2161. u64 beacon_timestamp, rx_timestamp;
  2162. u64 supp_rates = 0;
  2163. enum ieee80211_band band = rx_status->band;
  2164. DECLARE_MAC_BUF(mac);
  2165. DECLARE_MAC_BUF(mac2);
  2166. if (elems->ds_params && elems->ds_params_len == 1)
  2167. freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
  2168. else
  2169. freq = rx_status->freq;
  2170. channel = ieee80211_get_channel(local->hw.wiphy, freq);
  2171. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  2172. return;
  2173. if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id &&
  2174. elems->mesh_config && mesh_matches_local(elems, sdata)) {
  2175. supp_rates = ieee80211_sta_get_rates(local, elems, band);
  2176. mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
  2177. mesh_peer_accepts_plinks(elems));
  2178. }
  2179. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates &&
  2180. memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
  2181. supp_rates = ieee80211_sta_get_rates(local, elems, band);
  2182. rcu_read_lock();
  2183. sta = sta_info_get(local, mgmt->sa);
  2184. if (sta) {
  2185. u64 prev_rates;
  2186. prev_rates = sta->supp_rates[band];
  2187. /* make sure mandatory rates are always added */
  2188. sta->supp_rates[band] = supp_rates |
  2189. ieee80211_sta_get_mandatory_rates(local, band);
  2190. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2191. if (sta->supp_rates[band] != prev_rates)
  2192. printk(KERN_DEBUG "%s: updated supp_rates set "
  2193. "for %s based on beacon info (0x%llx | "
  2194. "0x%llx -> 0x%llx)\n",
  2195. sdata->dev->name, print_mac(mac, sta->addr),
  2196. (unsigned long long) prev_rates,
  2197. (unsigned long long) supp_rates,
  2198. (unsigned long long) sta->supp_rates[band]);
  2199. #endif
  2200. } else {
  2201. ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid,
  2202. mgmt->sa, supp_rates);
  2203. }
  2204. rcu_read_unlock();
  2205. }
  2206. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  2207. freq, beacon);
  2208. if (!bss)
  2209. return;
  2210. /* was just updated in ieee80211_bss_info_update */
  2211. beacon_timestamp = bss->timestamp;
  2212. /*
  2213. * In STA mode, the remaining parameters should not be overridden
  2214. * by beacons because they're not necessarily accurate there.
  2215. */
  2216. if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
  2217. bss->last_probe_resp && beacon) {
  2218. ieee80211_rx_bss_put(local, bss);
  2219. return;
  2220. }
  2221. /* check if we need to merge IBSS */
  2222. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
  2223. bss->capability & WLAN_CAPABILITY_IBSS &&
  2224. bss->freq == local->oper_channel->center_freq &&
  2225. elems->ssid_len == sdata->u.sta.ssid_len &&
  2226. memcmp(elems->ssid, sdata->u.sta.ssid,
  2227. sdata->u.sta.ssid_len) == 0) {
  2228. if (rx_status->flag & RX_FLAG_TSFT) {
  2229. /* in order for correct IBSS merging we need mactime
  2230. *
  2231. * since mactime is defined as the time the first data
  2232. * symbol of the frame hits the PHY, and the timestamp
  2233. * of the beacon is defined as "the time that the data
  2234. * symbol containing the first bit of the timestamp is
  2235. * transmitted to the PHY plus the transmitting STA’s
  2236. * delays through its local PHY from the MAC-PHY
  2237. * interface to its interface with the WM"
  2238. * (802.11 11.1.2) - equals the time this bit arrives at
  2239. * the receiver - we have to take into account the
  2240. * offset between the two.
  2241. * e.g: at 1 MBit that means mactime is 192 usec earlier
  2242. * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
  2243. */
  2244. int rate = local->hw.wiphy->bands[band]->
  2245. bitrates[rx_status->rate_idx].bitrate;
  2246. rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
  2247. } else if (local && local->ops && local->ops->get_tsf)
  2248. /* second best option: get current TSF */
  2249. rx_timestamp = local->ops->get_tsf(local_to_hw(local));
  2250. else
  2251. /* can't merge without knowing the TSF */
  2252. rx_timestamp = -1LLU;
  2253. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2254. printk(KERN_DEBUG "RX beacon SA=%s BSSID="
  2255. "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
  2256. print_mac(mac, mgmt->sa),
  2257. print_mac(mac2, mgmt->bssid),
  2258. (unsigned long long)rx_timestamp,
  2259. (unsigned long long)beacon_timestamp,
  2260. (unsigned long long)(rx_timestamp - beacon_timestamp),
  2261. jiffies);
  2262. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2263. if (beacon_timestamp > rx_timestamp) {
  2264. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2265. printk(KERN_DEBUG "%s: beacon TSF higher than "
  2266. "local TSF - IBSS merge with BSSID %s\n",
  2267. sdata->dev->name, print_mac(mac, mgmt->bssid));
  2268. #endif
  2269. ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss);
  2270. ieee80211_ibss_add_sta(sdata, NULL,
  2271. mgmt->bssid, mgmt->sa,
  2272. supp_rates);
  2273. }
  2274. }
  2275. ieee80211_rx_bss_put(local, bss);
  2276. }
  2277. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  2278. struct ieee80211_mgmt *mgmt,
  2279. size_t len,
  2280. struct ieee80211_rx_status *rx_status)
  2281. {
  2282. size_t baselen;
  2283. struct ieee802_11_elems elems;
  2284. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2285. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  2286. return; /* ignore ProbeResp to foreign address */
  2287. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  2288. if (baselen > len)
  2289. return;
  2290. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  2291. &elems);
  2292. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
  2293. /* direct probe may be part of the association flow */
  2294. if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
  2295. &ifsta->request)) {
  2296. printk(KERN_DEBUG "%s direct probe responded\n",
  2297. sdata->dev->name);
  2298. ieee80211_authenticate(sdata, ifsta);
  2299. }
  2300. }
  2301. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  2302. struct ieee80211_mgmt *mgmt,
  2303. size_t len,
  2304. struct ieee80211_rx_status *rx_status)
  2305. {
  2306. struct ieee80211_if_sta *ifsta;
  2307. size_t baselen;
  2308. struct ieee802_11_elems elems;
  2309. struct ieee80211_local *local = sdata->local;
  2310. struct ieee80211_conf *conf = &local->hw.conf;
  2311. u32 changed = 0;
  2312. /* Process beacon from the current BSS */
  2313. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  2314. if (baselen > len)
  2315. return;
  2316. ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
  2317. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
  2318. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  2319. return;
  2320. ifsta = &sdata->u.sta;
  2321. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) ||
  2322. memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
  2323. return;
  2324. ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param,
  2325. elems.wmm_param_len);
  2326. if (elems.erp_info && elems.erp_info_len >= 1)
  2327. changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
  2328. else {
  2329. u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info);
  2330. changed |= ieee80211_handle_protect_preamb(sdata, false,
  2331. (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0);
  2332. }
  2333. if (elems.ht_cap_elem && elems.ht_info_elem &&
  2334. elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
  2335. struct ieee80211_ht_bss_info bss_info;
  2336. ieee80211_ht_addt_info_ie_to_ht_bss_info(
  2337. (struct ieee80211_ht_addt_info *)
  2338. elems.ht_info_elem, &bss_info);
  2339. changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
  2340. &bss_info);
  2341. }
  2342. ieee80211_bss_info_change_notify(sdata, changed);
  2343. }
  2344. static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
  2345. struct ieee80211_if_sta *ifsta,
  2346. struct ieee80211_mgmt *mgmt,
  2347. size_t len,
  2348. struct ieee80211_rx_status *rx_status)
  2349. {
  2350. struct ieee80211_local *local = sdata->local;
  2351. int tx_last_beacon;
  2352. struct sk_buff *skb;
  2353. struct ieee80211_mgmt *resp;
  2354. u8 *pos, *end;
  2355. DECLARE_MAC_BUF(mac);
  2356. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2357. DECLARE_MAC_BUF(mac2);
  2358. DECLARE_MAC_BUF(mac3);
  2359. #endif
  2360. if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS ||
  2361. ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
  2362. len < 24 + 2 || !ifsta->probe_resp)
  2363. return;
  2364. if (local->ops->tx_last_beacon)
  2365. tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
  2366. else
  2367. tx_last_beacon = 1;
  2368. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2369. printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID="
  2370. "%s (tx_last_beacon=%d)\n",
  2371. sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da),
  2372. print_mac(mac3, mgmt->bssid), tx_last_beacon);
  2373. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2374. if (!tx_last_beacon)
  2375. return;
  2376. if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
  2377. memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
  2378. return;
  2379. end = ((u8 *) mgmt) + len;
  2380. pos = mgmt->u.probe_req.variable;
  2381. if (pos[0] != WLAN_EID_SSID ||
  2382. pos + 2 + pos[1] > end) {
  2383. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2384. printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
  2385. "from %s\n",
  2386. sdata->dev->name, print_mac(mac, mgmt->sa));
  2387. #endif
  2388. return;
  2389. }
  2390. if (pos[1] != 0 &&
  2391. (pos[1] != ifsta->ssid_len ||
  2392. memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
  2393. /* Ignore ProbeReq for foreign SSID */
  2394. return;
  2395. }
  2396. /* Reply with ProbeResp */
  2397. skb = skb_copy(ifsta->probe_resp, GFP_KERNEL);
  2398. if (!skb)
  2399. return;
  2400. resp = (struct ieee80211_mgmt *) skb->data;
  2401. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  2402. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2403. printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n",
  2404. sdata->dev->name, print_mac(mac, resp->da));
  2405. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2406. ieee80211_sta_tx(sdata, skb, 0);
  2407. }
  2408. static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
  2409. struct ieee80211_if_sta *ifsta,
  2410. struct ieee80211_mgmt *mgmt,
  2411. size_t len,
  2412. struct ieee80211_rx_status *rx_status)
  2413. {
  2414. struct ieee80211_local *local = sdata->local;
  2415. /* all categories we currently handle have action_code */
  2416. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2417. return;
  2418. switch (mgmt->u.action.category) {
  2419. case WLAN_CATEGORY_SPECTRUM_MGMT:
  2420. if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ)
  2421. break;
  2422. switch (mgmt->u.action.u.measurement.action_code) {
  2423. case WLAN_ACTION_SPCT_MSR_REQ:
  2424. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2425. sizeof(mgmt->u.action.u.measurement)))
  2426. break;
  2427. ieee80211_sta_process_measurement_req(sdata, mgmt, len);
  2428. break;
  2429. }
  2430. break;
  2431. case WLAN_CATEGORY_BACK:
  2432. switch (mgmt->u.action.u.addba_req.action_code) {
  2433. case WLAN_ACTION_ADDBA_REQ:
  2434. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2435. sizeof(mgmt->u.action.u.addba_req)))
  2436. break;
  2437. ieee80211_sta_process_addba_request(local, mgmt, len);
  2438. break;
  2439. case WLAN_ACTION_ADDBA_RESP:
  2440. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2441. sizeof(mgmt->u.action.u.addba_resp)))
  2442. break;
  2443. ieee80211_sta_process_addba_resp(local, mgmt, len);
  2444. break;
  2445. case WLAN_ACTION_DELBA:
  2446. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2447. sizeof(mgmt->u.action.u.delba)))
  2448. break;
  2449. ieee80211_sta_process_delba(sdata, mgmt, len);
  2450. break;
  2451. }
  2452. break;
  2453. case PLINK_CATEGORY:
  2454. if (ieee80211_vif_is_mesh(&sdata->vif))
  2455. mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
  2456. break;
  2457. case MESH_PATH_SEL_CATEGORY:
  2458. if (ieee80211_vif_is_mesh(&sdata->vif))
  2459. mesh_rx_path_sel_frame(sdata, mgmt, len);
  2460. break;
  2461. }
  2462. }
  2463. void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  2464. struct ieee80211_rx_status *rx_status)
  2465. {
  2466. struct ieee80211_local *local = sdata->local;
  2467. struct ieee80211_if_sta *ifsta;
  2468. struct ieee80211_mgmt *mgmt;
  2469. u16 fc;
  2470. if (skb->len < 24)
  2471. goto fail;
  2472. ifsta = &sdata->u.sta;
  2473. mgmt = (struct ieee80211_mgmt *) skb->data;
  2474. fc = le16_to_cpu(mgmt->frame_control);
  2475. switch (fc & IEEE80211_FCTL_STYPE) {
  2476. case IEEE80211_STYPE_PROBE_REQ:
  2477. case IEEE80211_STYPE_PROBE_RESP:
  2478. case IEEE80211_STYPE_BEACON:
  2479. case IEEE80211_STYPE_ACTION:
  2480. memcpy(skb->cb, rx_status, sizeof(*rx_status));
  2481. case IEEE80211_STYPE_AUTH:
  2482. case IEEE80211_STYPE_ASSOC_RESP:
  2483. case IEEE80211_STYPE_REASSOC_RESP:
  2484. case IEEE80211_STYPE_DEAUTH:
  2485. case IEEE80211_STYPE_DISASSOC:
  2486. skb_queue_tail(&ifsta->skb_queue, skb);
  2487. queue_work(local->hw.workqueue, &ifsta->work);
  2488. return;
  2489. }
  2490. fail:
  2491. kfree_skb(skb);
  2492. }
  2493. static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  2494. struct sk_buff *skb)
  2495. {
  2496. struct ieee80211_rx_status *rx_status;
  2497. struct ieee80211_if_sta *ifsta;
  2498. struct ieee80211_mgmt *mgmt;
  2499. u16 fc;
  2500. ifsta = &sdata->u.sta;
  2501. rx_status = (struct ieee80211_rx_status *) skb->cb;
  2502. mgmt = (struct ieee80211_mgmt *) skb->data;
  2503. fc = le16_to_cpu(mgmt->frame_control);
  2504. switch (fc & IEEE80211_FCTL_STYPE) {
  2505. case IEEE80211_STYPE_PROBE_REQ:
  2506. ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len,
  2507. rx_status);
  2508. break;
  2509. case IEEE80211_STYPE_PROBE_RESP:
  2510. ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status);
  2511. break;
  2512. case IEEE80211_STYPE_BEACON:
  2513. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  2514. break;
  2515. case IEEE80211_STYPE_AUTH:
  2516. ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len);
  2517. break;
  2518. case IEEE80211_STYPE_ASSOC_RESP:
  2519. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0);
  2520. break;
  2521. case IEEE80211_STYPE_REASSOC_RESP:
  2522. ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1);
  2523. break;
  2524. case IEEE80211_STYPE_DEAUTH:
  2525. ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len);
  2526. break;
  2527. case IEEE80211_STYPE_DISASSOC:
  2528. ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len);
  2529. break;
  2530. case IEEE80211_STYPE_ACTION:
  2531. ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status);
  2532. break;
  2533. }
  2534. kfree_skb(skb);
  2535. }
  2536. static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
  2537. {
  2538. struct ieee80211_local *local = sdata->local;
  2539. int active = 0;
  2540. struct sta_info *sta;
  2541. rcu_read_lock();
  2542. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  2543. if (sta->sdata == sdata &&
  2544. time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
  2545. jiffies)) {
  2546. active++;
  2547. break;
  2548. }
  2549. }
  2550. rcu_read_unlock();
  2551. return active;
  2552. }
  2553. static void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, unsigned long exp_time)
  2554. {
  2555. struct ieee80211_local *local = sdata->local;
  2556. struct sta_info *sta, *tmp;
  2557. LIST_HEAD(tmp_list);
  2558. DECLARE_MAC_BUF(mac);
  2559. unsigned long flags;
  2560. spin_lock_irqsave(&local->sta_lock, flags);
  2561. list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
  2562. if (time_after(jiffies, sta->last_rx + exp_time)) {
  2563. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2564. printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
  2565. sdata->dev->name, print_mac(mac, sta->addr));
  2566. #endif
  2567. __sta_info_unlink(&sta);
  2568. if (sta)
  2569. list_add(&sta->list, &tmp_list);
  2570. }
  2571. spin_unlock_irqrestore(&local->sta_lock, flags);
  2572. list_for_each_entry_safe(sta, tmp, &tmp_list, list)
  2573. sta_info_destroy(sta);
  2574. }
  2575. static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
  2576. struct ieee80211_if_sta *ifsta)
  2577. {
  2578. mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
  2579. ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
  2580. if (ieee80211_sta_active_ibss(sdata))
  2581. return;
  2582. printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
  2583. "IBSS networks with same SSID (merge)\n", sdata->dev->name);
  2584. ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len);
  2585. }
  2586. #ifdef CONFIG_MAC80211_MESH
  2587. static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
  2588. struct ieee80211_if_sta *ifsta)
  2589. {
  2590. bool free_plinks;
  2591. ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
  2592. mesh_path_expire(sdata);
  2593. free_plinks = mesh_plink_availables(sdata);
  2594. if (free_plinks != sdata->u.sta.accepting_plinks)
  2595. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  2596. mod_timer(&ifsta->timer, jiffies +
  2597. IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
  2598. }
  2599. void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
  2600. {
  2601. struct ieee80211_if_sta *ifsta;
  2602. ifsta = &sdata->u.sta;
  2603. ifsta->state = IEEE80211_STA_MLME_MESH_UP;
  2604. ieee80211_sta_timer((unsigned long)sdata);
  2605. ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
  2606. }
  2607. #endif
  2608. void ieee80211_sta_timer(unsigned long data)
  2609. {
  2610. struct ieee80211_sub_if_data *sdata =
  2611. (struct ieee80211_sub_if_data *) data;
  2612. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2613. struct ieee80211_local *local = sdata->local;
  2614. set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  2615. queue_work(local->hw.workqueue, &ifsta->work);
  2616. }
  2617. static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata,
  2618. struct ieee80211_if_sta *ifsta)
  2619. {
  2620. struct ieee80211_local *local = sdata->local;
  2621. if (local->ops->reset_tsf) {
  2622. /* Reset own TSF to allow time synchronization work. */
  2623. local->ops->reset_tsf(local_to_hw(local));
  2624. }
  2625. ifsta->wmm_last_param_set = -1; /* allow any WMM update */
  2626. if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
  2627. ifsta->auth_alg = WLAN_AUTH_OPEN;
  2628. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
  2629. ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
  2630. else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
  2631. ifsta->auth_alg = WLAN_AUTH_LEAP;
  2632. else
  2633. ifsta->auth_alg = WLAN_AUTH_OPEN;
  2634. ifsta->auth_transaction = -1;
  2635. ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
  2636. ifsta->assoc_scan_tries = 0;
  2637. ifsta->direct_probe_tries = 0;
  2638. ifsta->auth_tries = 0;
  2639. ifsta->assoc_tries = 0;
  2640. netif_tx_stop_all_queues(sdata->dev);
  2641. netif_carrier_off(sdata->dev);
  2642. }
  2643. void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
  2644. struct ieee80211_if_sta *ifsta)
  2645. {
  2646. struct ieee80211_local *local = sdata->local;
  2647. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  2648. return;
  2649. if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
  2650. IEEE80211_STA_AUTO_BSSID_SEL)) &&
  2651. (ifsta->flags & (IEEE80211_STA_SSID_SET |
  2652. IEEE80211_STA_AUTO_SSID_SEL))) {
  2653. if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED)
  2654. ieee80211_set_disassoc(sdata, ifsta, true, true,
  2655. WLAN_REASON_DEAUTH_LEAVING);
  2656. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  2657. queue_work(local->hw.workqueue, &ifsta->work);
  2658. }
  2659. }
  2660. static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
  2661. const char *ssid, int ssid_len)
  2662. {
  2663. int tmp, hidden_ssid;
  2664. if (ssid_len == ifsta->ssid_len &&
  2665. !memcmp(ifsta->ssid, ssid, ssid_len))
  2666. return 1;
  2667. if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL)
  2668. return 0;
  2669. hidden_ssid = 1;
  2670. tmp = ssid_len;
  2671. while (tmp--) {
  2672. if (ssid[tmp] != '\0') {
  2673. hidden_ssid = 0;
  2674. break;
  2675. }
  2676. }
  2677. if (hidden_ssid && ifsta->ssid_len == ssid_len)
  2678. return 1;
  2679. if (ssid_len == 1 && ssid[0] == ' ')
  2680. return 1;
  2681. return 0;
  2682. }
  2683. static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
  2684. struct ieee80211_if_sta *ifsta)
  2685. {
  2686. struct ieee80211_local *local = sdata->local;
  2687. struct ieee80211_sta_bss *bss;
  2688. struct ieee80211_supported_band *sband;
  2689. u8 bssid[ETH_ALEN], *pos;
  2690. int i;
  2691. int ret;
  2692. DECLARE_MAC_BUF(mac);
  2693. #if 0
  2694. /* Easier testing, use fixed BSSID. */
  2695. memset(bssid, 0xfe, ETH_ALEN);
  2696. #else
  2697. /* Generate random, not broadcast, locally administered BSSID. Mix in
  2698. * own MAC address to make sure that devices that do not have proper
  2699. * random number generator get different BSSID. */
  2700. get_random_bytes(bssid, ETH_ALEN);
  2701. for (i = 0; i < ETH_ALEN; i++)
  2702. bssid[i] ^= sdata->dev->dev_addr[i];
  2703. bssid[0] &= ~0x01;
  2704. bssid[0] |= 0x02;
  2705. #endif
  2706. printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
  2707. sdata->dev->name, print_mac(mac, bssid));
  2708. bss = ieee80211_rx_bss_add(local, bssid,
  2709. local->hw.conf.channel->center_freq,
  2710. sdata->u.sta.ssid, sdata->u.sta.ssid_len);
  2711. if (!bss)
  2712. return -ENOMEM;
  2713. bss->band = local->hw.conf.channel->band;
  2714. sband = local->hw.wiphy->bands[bss->band];
  2715. if (local->hw.conf.beacon_int == 0)
  2716. local->hw.conf.beacon_int = 100;
  2717. bss->beacon_int = local->hw.conf.beacon_int;
  2718. bss->last_update = jiffies;
  2719. bss->capability = WLAN_CAPABILITY_IBSS;
  2720. if (sdata->default_key)
  2721. bss->capability |= WLAN_CAPABILITY_PRIVACY;
  2722. else
  2723. sdata->drop_unencrypted = 0;
  2724. bss->supp_rates_len = sband->n_bitrates;
  2725. pos = bss->supp_rates;
  2726. for (i = 0; i < sband->n_bitrates; i++) {
  2727. int rate = sband->bitrates[i].bitrate;
  2728. *pos++ = (u8) (rate / 5);
  2729. }
  2730. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  2731. ieee80211_rx_bss_put(local, bss);
  2732. return ret;
  2733. }
  2734. static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
  2735. struct ieee80211_if_sta *ifsta)
  2736. {
  2737. struct ieee80211_local *local = sdata->local;
  2738. struct ieee80211_sta_bss *bss;
  2739. int found = 0;
  2740. u8 bssid[ETH_ALEN];
  2741. int active_ibss;
  2742. DECLARE_MAC_BUF(mac);
  2743. DECLARE_MAC_BUF(mac2);
  2744. if (ifsta->ssid_len == 0)
  2745. return -EINVAL;
  2746. active_ibss = ieee80211_sta_active_ibss(sdata);
  2747. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2748. printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
  2749. sdata->dev->name, active_ibss);
  2750. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2751. spin_lock_bh(&local->sta_bss_lock);
  2752. list_for_each_entry(bss, &local->sta_bss_list, list) {
  2753. if (ifsta->ssid_len != bss->ssid_len ||
  2754. memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
  2755. || !(bss->capability & WLAN_CAPABILITY_IBSS))
  2756. continue;
  2757. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2758. printk(KERN_DEBUG " bssid=%s found\n",
  2759. print_mac(mac, bss->bssid));
  2760. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2761. memcpy(bssid, bss->bssid, ETH_ALEN);
  2762. found = 1;
  2763. if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
  2764. break;
  2765. }
  2766. spin_unlock_bh(&local->sta_bss_lock);
  2767. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2768. if (found)
  2769. printk(KERN_DEBUG " sta_find_ibss: selected %s current "
  2770. "%s\n", print_mac(mac, bssid),
  2771. print_mac(mac2, ifsta->bssid));
  2772. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2773. if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  2774. int ret;
  2775. int search_freq;
  2776. if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
  2777. search_freq = bss->freq;
  2778. else
  2779. search_freq = local->hw.conf.channel->center_freq;
  2780. bss = ieee80211_rx_bss_get(local, bssid, search_freq,
  2781. ifsta->ssid, ifsta->ssid_len);
  2782. if (!bss)
  2783. goto dont_join;
  2784. printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
  2785. " based on configured SSID\n",
  2786. sdata->dev->name, print_mac(mac, bssid));
  2787. ret = ieee80211_sta_join_ibss(sdata, ifsta, bss);
  2788. ieee80211_rx_bss_put(local, bss);
  2789. return ret;
  2790. }
  2791. dont_join:
  2792. #ifdef CONFIG_MAC80211_IBSS_DEBUG
  2793. printk(KERN_DEBUG " did not try to join ibss\n");
  2794. #endif /* CONFIG_MAC80211_IBSS_DEBUG */
  2795. /* Selected IBSS not found in current scan results - try to scan */
  2796. if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED &&
  2797. !ieee80211_sta_active_ibss(sdata)) {
  2798. mod_timer(&ifsta->timer, jiffies +
  2799. IEEE80211_IBSS_MERGE_INTERVAL);
  2800. } else if (time_after(jiffies, local->last_scan_completed +
  2801. IEEE80211_SCAN_INTERVAL)) {
  2802. printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
  2803. "join\n", sdata->dev->name);
  2804. return ieee80211_sta_req_scan(sdata, ifsta->ssid,
  2805. ifsta->ssid_len);
  2806. } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) {
  2807. int interval = IEEE80211_SCAN_INTERVAL;
  2808. if (time_after(jiffies, ifsta->ibss_join_req +
  2809. IEEE80211_IBSS_JOIN_TIMEOUT)) {
  2810. if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
  2811. (!(local->oper_channel->flags &
  2812. IEEE80211_CHAN_NO_IBSS)))
  2813. return ieee80211_sta_create_ibss(sdata, ifsta);
  2814. if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
  2815. printk(KERN_DEBUG "%s: IBSS not allowed on"
  2816. " %d MHz\n", sdata->dev->name,
  2817. local->hw.conf.channel->center_freq);
  2818. }
  2819. /* No IBSS found - decrease scan interval and continue
  2820. * scanning. */
  2821. interval = IEEE80211_SCAN_INTERVAL_SLOW;
  2822. }
  2823. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  2824. mod_timer(&ifsta->timer, jiffies + interval);
  2825. return 0;
  2826. }
  2827. return 0;
  2828. }
  2829. int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
  2830. {
  2831. struct ieee80211_if_sta *ifsta;
  2832. int res;
  2833. if (len > IEEE80211_MAX_SSID_LEN)
  2834. return -EINVAL;
  2835. ifsta = &sdata->u.sta;
  2836. if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
  2837. memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
  2838. memcpy(ifsta->ssid, ssid, len);
  2839. ifsta->ssid_len = len;
  2840. ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
  2841. res = 0;
  2842. /*
  2843. * Hack! MLME code needs to be cleaned up to have different
  2844. * entry points for configuration and internal selection change
  2845. */
  2846. if (netif_running(sdata->dev))
  2847. res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
  2848. if (res) {
  2849. printk(KERN_DEBUG "%s: Failed to config new SSID to "
  2850. "the low-level driver\n", sdata->dev->name);
  2851. return res;
  2852. }
  2853. }
  2854. if (len)
  2855. ifsta->flags |= IEEE80211_STA_SSID_SET;
  2856. else
  2857. ifsta->flags &= ~IEEE80211_STA_SSID_SET;
  2858. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
  2859. !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
  2860. ifsta->ibss_join_req = jiffies;
  2861. ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
  2862. return ieee80211_sta_find_ibss(sdata, ifsta);
  2863. }
  2864. return 0;
  2865. }
  2866. int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
  2867. {
  2868. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2869. memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
  2870. *len = ifsta->ssid_len;
  2871. return 0;
  2872. }
  2873. int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
  2874. {
  2875. struct ieee80211_if_sta *ifsta;
  2876. int res;
  2877. ifsta = &sdata->u.sta;
  2878. if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
  2879. memcpy(ifsta->bssid, bssid, ETH_ALEN);
  2880. res = 0;
  2881. /*
  2882. * Hack! See also ieee80211_sta_set_ssid.
  2883. */
  2884. if (netif_running(sdata->dev))
  2885. res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
  2886. if (res) {
  2887. printk(KERN_DEBUG "%s: Failed to config new BSSID to "
  2888. "the low-level driver\n", sdata->dev->name);
  2889. return res;
  2890. }
  2891. }
  2892. if (is_valid_ether_addr(bssid))
  2893. ifsta->flags |= IEEE80211_STA_BSSID_SET;
  2894. else
  2895. ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
  2896. return 0;
  2897. }
  2898. int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
  2899. {
  2900. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  2901. kfree(ifsta->extra_ie);
  2902. if (len == 0) {
  2903. ifsta->extra_ie = NULL;
  2904. ifsta->extra_ie_len = 0;
  2905. return 0;
  2906. }
  2907. ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
  2908. if (!ifsta->extra_ie) {
  2909. ifsta->extra_ie_len = 0;
  2910. return -ENOMEM;
  2911. }
  2912. memcpy(ifsta->extra_ie, ie, len);
  2913. ifsta->extra_ie_len = len;
  2914. return 0;
  2915. }
  2916. struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
  2917. struct sk_buff *skb, u8 *bssid,
  2918. u8 *addr, u64 supp_rates)
  2919. {
  2920. struct ieee80211_local *local = sdata->local;
  2921. struct sta_info *sta;
  2922. DECLARE_MAC_BUF(mac);
  2923. int band = local->hw.conf.channel->band;
  2924. /* TODO: Could consider removing the least recently used entry and
  2925. * allow new one to be added. */
  2926. if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
  2927. if (net_ratelimit()) {
  2928. printk(KERN_DEBUG "%s: No room for a new IBSS STA "
  2929. "entry %s\n", sdata->dev->name, print_mac(mac, addr));
  2930. }
  2931. return NULL;
  2932. }
  2933. if (compare_ether_addr(bssid, sdata->u.sta.bssid))
  2934. return NULL;
  2935. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  2936. printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
  2937. wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name);
  2938. #endif
  2939. sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
  2940. if (!sta)
  2941. return NULL;
  2942. set_sta_flags(sta, WLAN_STA_AUTHORIZED);
  2943. /* make sure mandatory rates are always added */
  2944. sta->supp_rates[band] = supp_rates |
  2945. ieee80211_sta_get_mandatory_rates(local, band);
  2946. rate_control_rate_init(sta, local);
  2947. if (sta_info_insert(sta))
  2948. return NULL;
  2949. return sta;
  2950. }
  2951. static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
  2952. struct ieee80211_if_sta *ifsta)
  2953. {
  2954. struct ieee80211_local *local = sdata->local;
  2955. struct ieee80211_sta_bss *bss, *selected = NULL;
  2956. int top_rssi = 0, freq;
  2957. spin_lock_bh(&local->sta_bss_lock);
  2958. freq = local->oper_channel->center_freq;
  2959. list_for_each_entry(bss, &local->sta_bss_list, list) {
  2960. if (!(bss->capability & WLAN_CAPABILITY_ESS))
  2961. continue;
  2962. if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL |
  2963. IEEE80211_STA_AUTO_BSSID_SEL |
  2964. IEEE80211_STA_AUTO_CHANNEL_SEL)) &&
  2965. (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^
  2966. !!sdata->default_key))
  2967. continue;
  2968. if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) &&
  2969. bss->freq != freq)
  2970. continue;
  2971. if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) &&
  2972. memcmp(bss->bssid, ifsta->bssid, ETH_ALEN))
  2973. continue;
  2974. if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) &&
  2975. !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len))
  2976. continue;
  2977. if (!selected || top_rssi < bss->signal) {
  2978. selected = bss;
  2979. top_rssi = bss->signal;
  2980. }
  2981. }
  2982. if (selected)
  2983. atomic_inc(&selected->users);
  2984. spin_unlock_bh(&local->sta_bss_lock);
  2985. if (selected) {
  2986. ieee80211_set_freq(sdata, selected->freq);
  2987. if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
  2988. ieee80211_sta_set_ssid(sdata, selected->ssid,
  2989. selected->ssid_len);
  2990. ieee80211_sta_set_bssid(sdata, selected->bssid);
  2991. ieee80211_sta_def_wmm_params(sdata, selected, 0);
  2992. /* Send out direct probe if no probe resp was received or
  2993. * the one we have is outdated
  2994. */
  2995. if (!selected->last_probe_resp ||
  2996. time_after(jiffies, selected->last_probe_resp
  2997. + IEEE80211_SCAN_RESULT_EXPIRE))
  2998. ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE;
  2999. else
  3000. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  3001. ieee80211_rx_bss_put(local, selected);
  3002. ieee80211_sta_reset_auth(sdata, ifsta);
  3003. return 0;
  3004. } else {
  3005. if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
  3006. ifsta->assoc_scan_tries++;
  3007. if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
  3008. ieee80211_sta_start_scan(sdata, NULL, 0);
  3009. else
  3010. ieee80211_sta_start_scan(sdata, ifsta->ssid,
  3011. ifsta->ssid_len);
  3012. ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
  3013. set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
  3014. } else
  3015. ifsta->state = IEEE80211_STA_MLME_DISABLED;
  3016. }
  3017. return -1;
  3018. }
  3019. int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
  3020. {
  3021. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  3022. printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
  3023. sdata->dev->name, reason);
  3024. if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
  3025. sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
  3026. return -EINVAL;
  3027. ieee80211_set_disassoc(sdata, ifsta, true, true, reason);
  3028. return 0;
  3029. }
  3030. int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
  3031. {
  3032. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  3033. printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
  3034. sdata->dev->name, reason);
  3035. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  3036. return -EINVAL;
  3037. if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
  3038. return -1;
  3039. ieee80211_set_disassoc(sdata, ifsta, false, true, reason);
  3040. return 0;
  3041. }
  3042. void ieee80211_notify_mac(struct ieee80211_hw *hw,
  3043. enum ieee80211_notification_types notif_type)
  3044. {
  3045. struct ieee80211_local *local = hw_to_local(hw);
  3046. struct ieee80211_sub_if_data *sdata;
  3047. switch (notif_type) {
  3048. case IEEE80211_NOTIFY_RE_ASSOC:
  3049. rcu_read_lock();
  3050. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  3051. if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
  3052. continue;
  3053. ieee80211_sta_req_auth(sdata, &sdata->u.sta);
  3054. }
  3055. rcu_read_unlock();
  3056. break;
  3057. }
  3058. }
  3059. EXPORT_SYMBOL(ieee80211_notify_mac);
  3060. void ieee80211_sta_work(struct work_struct *work)
  3061. {
  3062. struct ieee80211_sub_if_data *sdata =
  3063. container_of(work, struct ieee80211_sub_if_data, u.sta.work);
  3064. struct ieee80211_local *local = sdata->local;
  3065. struct ieee80211_if_sta *ifsta;
  3066. struct sk_buff *skb;
  3067. if (!netif_running(sdata->dev))
  3068. return;
  3069. if (local->sta_sw_scanning || local->sta_hw_scanning)
  3070. return;
  3071. if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA &&
  3072. sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
  3073. sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT))
  3074. return;
  3075. ifsta = &sdata->u.sta;
  3076. while ((skb = skb_dequeue(&ifsta->skb_queue)))
  3077. ieee80211_sta_rx_queued_mgmt(sdata, skb);
  3078. #ifdef CONFIG_MAC80211_MESH
  3079. if (ifsta->preq_queue_len &&
  3080. time_after(jiffies,
  3081. ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
  3082. mesh_path_start_discovery(sdata);
  3083. #endif
  3084. if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
  3085. ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
  3086. ifsta->state != IEEE80211_STA_MLME_ASSOCIATE &&
  3087. test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
  3088. if (ifsta->scan_ssid_len)
  3089. ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len);
  3090. else
  3091. ieee80211_sta_start_scan(sdata, NULL, 0);
  3092. return;
  3093. }
  3094. if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) {
  3095. if (ieee80211_sta_config_auth(sdata, ifsta))
  3096. return;
  3097. clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request);
  3098. } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request))
  3099. return;
  3100. switch (ifsta->state) {
  3101. case IEEE80211_STA_MLME_DISABLED:
  3102. break;
  3103. case IEEE80211_STA_MLME_DIRECT_PROBE:
  3104. ieee80211_direct_probe(sdata, ifsta);
  3105. break;
  3106. case IEEE80211_STA_MLME_AUTHENTICATE:
  3107. ieee80211_authenticate(sdata, ifsta);
  3108. break;
  3109. case IEEE80211_STA_MLME_ASSOCIATE:
  3110. ieee80211_associate(sdata, ifsta);
  3111. break;
  3112. case IEEE80211_STA_MLME_ASSOCIATED:
  3113. ieee80211_associated(sdata, ifsta);
  3114. break;
  3115. case IEEE80211_STA_MLME_IBSS_SEARCH:
  3116. ieee80211_sta_find_ibss(sdata, ifsta);
  3117. break;
  3118. case IEEE80211_STA_MLME_IBSS_JOINED:
  3119. ieee80211_sta_merge_ibss(sdata, ifsta);
  3120. break;
  3121. #ifdef CONFIG_MAC80211_MESH
  3122. case IEEE80211_STA_MLME_MESH_UP:
  3123. ieee80211_mesh_housekeeping(sdata, ifsta);
  3124. break;
  3125. #endif
  3126. default:
  3127. WARN_ON(1);
  3128. break;
  3129. }
  3130. if (ieee80211_privacy_mismatch(sdata, ifsta)) {
  3131. printk(KERN_DEBUG "%s: privacy configuration mismatch and "
  3132. "mixed-cell disabled - disassociate\n", sdata->dev->name);
  3133. ieee80211_set_disassoc(sdata, ifsta, false, true,
  3134. WLAN_REASON_UNSPECIFIED);
  3135. }
  3136. }
  3137. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  3138. {
  3139. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  3140. struct ieee80211_if_sta *ifsta;
  3141. if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
  3142. ifsta = &sdata->u.sta;
  3143. if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
  3144. (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) &&
  3145. !ieee80211_sta_active_ibss(sdata)))
  3146. ieee80211_sta_find_ibss(sdata, ifsta);
  3147. }
  3148. }