wmgr.c 136 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602
  1. /*
  2. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. *
  20. * File: wmgr.c
  21. *
  22. * Purpose: Handles the 802.11 management functions
  23. *
  24. * Author: Lyndon Chen
  25. *
  26. * Date: May 8, 2002
  27. *
  28. * Functions:
  29. * nsMgrObjectInitial - Initialize Management Object data structure
  30. * vMgrObjectReset - Reset Management Object data structure
  31. * vMgrAssocBeginSta - Start associate function
  32. * vMgrReAssocBeginSta - Start reassociate function
  33. * vMgrDisassocBeginSta - Start disassociate function
  34. * s_vMgrRxAssocRequest - Handle Rcv associate_request
  35. * s_vMgrRxAssocResponse - Handle Rcv associate_response
  36. * vMrgAuthenBeginSta - Start authentication function
  37. * vMgrDeAuthenDeginSta - Start deauthentication function
  38. * s_vMgrRxAuthentication - Handle Rcv authentication
  39. * s_vMgrRxAuthenSequence_1 - Handle Rcv authentication sequence 1
  40. * s_vMgrRxAuthenSequence_2 - Handle Rcv authentication sequence 2
  41. * s_vMgrRxAuthenSequence_3 - Handle Rcv authentication sequence 3
  42. * s_vMgrRxAuthenSequence_4 - Handle Rcv authentication sequence 4
  43. * s_vMgrRxDisassociation - Handle Rcv disassociation
  44. * s_vMgrRxBeacon - Handle Rcv Beacon
  45. * vMgrCreateOwnIBSS - Create ad_hoc IBSS or AP BSS
  46. * vMgrJoinBSSBegin - Join BSS function
  47. * s_vMgrSynchBSS - Synch & adopt BSS parameters
  48. * s_MgrMakeBeacon - Create Baecon frame
  49. * s_MgrMakeProbeResponse - Create Probe Response frame
  50. * s_MgrMakeAssocRequest - Create Associate Request frame
  51. * s_MgrMakeReAssocRequest - Create ReAssociate Request frame
  52. * s_vMgrRxProbeResponse - Handle Rcv probe_response
  53. * s_vMrgRxProbeRequest - Handle Rcv probe_request
  54. * bMgrPrepareBeaconToSend - Prepare Beacon frame
  55. * s_vMgrLogStatus - Log 802.11 Status
  56. * vMgrRxManagePacket - Rcv management frame dispatch function
  57. * s_vMgrFormatTIM- Assembler TIM field of beacon
  58. * vMgrTimerInit- Initial 1-sec and command call back funtions
  59. *
  60. * Revision History:
  61. *
  62. */
  63. #include "tmacro.h"
  64. #include "desc.h"
  65. #include "device.h"
  66. #include "card.h"
  67. #include "channel.h"
  68. #include "80211hdr.h"
  69. #include "80211mgr.h"
  70. #include "wmgr.h"
  71. #include "wcmd.h"
  72. #include "mac.h"
  73. #include "bssdb.h"
  74. #include "power.h"
  75. #include "datarate.h"
  76. #include "baseband.h"
  77. #include "rxtx.h"
  78. #include "wpa.h"
  79. #include "rf.h"
  80. #include "iowpa.h"
  81. /*--------------------- Static Definitions -------------------------*/
  82. /*--------------------- Static Classes ----------------------------*/
  83. /*--------------------- Static Functions --------------------------*/
  84. //2008-8-4 <add> by chester
  85. static bool ChannelExceedZoneType(
  86. struct vnt_private *pDevice,
  87. unsigned char byCurrChannel
  88. );
  89. // Association/diassociation functions
  90. static
  91. PSTxMgmtPacket
  92. s_MgrMakeAssocRequest(
  93. struct vnt_private *pDevice,
  94. PSMgmtObject pMgmt,
  95. unsigned char *pDAddr,
  96. unsigned short wCurrCapInfo,
  97. unsigned short wListenInterval,
  98. PWLAN_IE_SSID pCurrSSID,
  99. PWLAN_IE_SUPP_RATES pCurrRates,
  100. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  101. );
  102. static
  103. void
  104. s_vMgrRxAssocRequest(
  105. struct vnt_private *pDevice,
  106. PSMgmtObject pMgmt,
  107. PSRxMgmtPacket pRxPacket,
  108. unsigned int uNodeIndex
  109. );
  110. static
  111. PSTxMgmtPacket
  112. s_MgrMakeReAssocRequest(
  113. struct vnt_private *pDevice,
  114. PSMgmtObject pMgmt,
  115. unsigned char *pDAddr,
  116. unsigned short wCurrCapInfo,
  117. unsigned short wListenInterval,
  118. PWLAN_IE_SSID pCurrSSID,
  119. PWLAN_IE_SUPP_RATES pCurrRates,
  120. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  121. );
  122. static
  123. void
  124. s_vMgrRxAssocResponse(
  125. struct vnt_private *pDevice,
  126. PSMgmtObject pMgmt,
  127. PSRxMgmtPacket pRxPacket,
  128. bool bReAssocType
  129. );
  130. static
  131. void
  132. s_vMgrRxDisassociation(
  133. struct vnt_private *pDevice,
  134. PSMgmtObject pMgmt,
  135. PSRxMgmtPacket pRxPacket
  136. );
  137. // Authentication/deauthen functions
  138. static
  139. void
  140. s_vMgrRxAuthenSequence_1(
  141. struct vnt_private *pDevice,
  142. PSMgmtObject pMgmt,
  143. PWLAN_FR_AUTHEN pFrame
  144. );
  145. static
  146. void
  147. s_vMgrRxAuthenSequence_2(
  148. struct vnt_private *pDevice,
  149. PSMgmtObject pMgmt,
  150. PWLAN_FR_AUTHEN pFrame
  151. );
  152. static
  153. void
  154. s_vMgrRxAuthenSequence_3(
  155. struct vnt_private *pDevice,
  156. PSMgmtObject pMgmt,
  157. PWLAN_FR_AUTHEN pFrame
  158. );
  159. static
  160. void
  161. s_vMgrRxAuthenSequence_4(
  162. struct vnt_private *pDevice,
  163. PSMgmtObject pMgmt,
  164. PWLAN_FR_AUTHEN pFrame
  165. );
  166. static
  167. void
  168. s_vMgrRxAuthentication(
  169. struct vnt_private *pDevice,
  170. PSMgmtObject pMgmt,
  171. PSRxMgmtPacket pRxPacket
  172. );
  173. static
  174. void
  175. s_vMgrRxDeauthentication(
  176. struct vnt_private *pDevice,
  177. PSMgmtObject pMgmt,
  178. PSRxMgmtPacket pRxPacket
  179. );
  180. // Scan functions
  181. // probe request/response functions
  182. static
  183. void
  184. s_vMgrRxProbeRequest(
  185. struct vnt_private *pDevice,
  186. PSMgmtObject pMgmt,
  187. PSRxMgmtPacket pRxPacket
  188. );
  189. static
  190. void
  191. s_vMgrRxProbeResponse(
  192. struct vnt_private *pDevice,
  193. PSMgmtObject pMgmt,
  194. PSRxMgmtPacket pRxPacket
  195. );
  196. // beacon functions
  197. static
  198. void
  199. s_vMgrRxBeacon(
  200. struct vnt_private *pDevice,
  201. PSMgmtObject pMgmt,
  202. PSRxMgmtPacket pRxPacket,
  203. bool bInScan
  204. );
  205. static
  206. void
  207. s_vMgrFormatTIM(
  208. PSMgmtObject pMgmt,
  209. PWLAN_IE_TIM pTIM
  210. );
  211. static
  212. PSTxMgmtPacket
  213. s_MgrMakeBeacon(
  214. struct vnt_private *pDevice,
  215. PSMgmtObject pMgmt,
  216. unsigned short wCurrCapInfo,
  217. unsigned short wCurrBeaconPeriod,
  218. unsigned int uCurrChannel,
  219. unsigned short wCurrATIMWinodw,
  220. PWLAN_IE_SSID pCurrSSID,
  221. unsigned char *pCurrBSSID,
  222. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  223. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  224. );
  225. // Association response
  226. static
  227. PSTxMgmtPacket
  228. s_MgrMakeAssocResponse(
  229. struct vnt_private *pDevice,
  230. PSMgmtObject pMgmt,
  231. unsigned short wCurrCapInfo,
  232. unsigned short wAssocStatus,
  233. unsigned short wAssocAID,
  234. unsigned char *pDstAddr,
  235. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  236. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  237. );
  238. // ReAssociation response
  239. static
  240. PSTxMgmtPacket
  241. s_MgrMakeReAssocResponse(
  242. struct vnt_private *pDevice,
  243. PSMgmtObject pMgmt,
  244. unsigned short wCurrCapInfo,
  245. unsigned short wAssocStatus,
  246. unsigned short wAssocAID,
  247. unsigned char *pDstAddr,
  248. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  249. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  250. );
  251. // Probe response
  252. static
  253. PSTxMgmtPacket
  254. s_MgrMakeProbeResponse(
  255. struct vnt_private *pDevice,
  256. PSMgmtObject pMgmt,
  257. unsigned short wCurrCapInfo,
  258. unsigned short wCurrBeaconPeriod,
  259. unsigned int uCurrChannel,
  260. unsigned short wCurrATIMWinodw,
  261. unsigned char *pDstAddr,
  262. PWLAN_IE_SSID pCurrSSID,
  263. unsigned char *pCurrBSSID,
  264. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  265. PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
  266. unsigned char byPHYType
  267. );
  268. // received status
  269. static
  270. void
  271. s_vMgrLogStatus(
  272. PSMgmtObject pMgmt,
  273. unsigned short wStatus
  274. );
  275. static
  276. void
  277. s_vMgrSynchBSS(
  278. struct vnt_private *pDevice,
  279. unsigned int uBSSMode,
  280. PKnownBSS pCurr,
  281. PCMD_STATUS pStatus
  282. );
  283. static bool
  284. s_bCipherMatch(
  285. PKnownBSS pBSSNode,
  286. NDIS_802_11_ENCRYPTION_STATUS EncStatus,
  287. unsigned char *pbyCCSPK,
  288. unsigned char *pbyCCSGK
  289. );
  290. static void Encyption_Rebuild(
  291. struct vnt_private *pDevice,
  292. PKnownBSS pCurr
  293. );
  294. /*--------------------- Export Variables --------------------------*/
  295. /*--------------------- Export Functions --------------------------*/
  296. /*+
  297. *
  298. * Routine Description:
  299. * Allocates and initializes the Management object.
  300. *
  301. * Return Value:
  302. * Ndis_staus.
  303. *
  304. -*/
  305. void
  306. vMgrObjectInit(
  307. void *hDeviceContext
  308. )
  309. {
  310. struct vnt_private *pDevice = hDeviceContext;
  311. PSMgmtObject pMgmt = pDevice->pMgmt;
  312. int ii;
  313. pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
  314. pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
  315. pMgmt->uCurrChannel = pDevice->uChannel;
  316. for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
  317. pMgmt->abyDesireBSSID[ii] = 0xFF;
  318. pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  319. pMgmt->byCSSPK = KEY_CTL_NONE;
  320. pMgmt->byCSSGK = KEY_CTL_NONE;
  321. pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
  322. BSSvClearBSSList((void *)pDevice, false);
  323. }
  324. /*+
  325. *
  326. * Routine Description:
  327. * Initializes timer object
  328. *
  329. * Return Value:
  330. * Ndis_staus.
  331. *
  332. -*/
  333. void
  334. vMgrTimerInit(
  335. void *hDeviceContext
  336. )
  337. {
  338. struct vnt_private *pDevice = hDeviceContext;
  339. PSMgmtObject pMgmt = pDevice->pMgmt;
  340. init_timer(&pMgmt->sTimerSecondCallback);
  341. pMgmt->sTimerSecondCallback.data = (unsigned long) pDevice;
  342. pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
  343. pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
  344. init_timer(&pDevice->sTimerCommand);
  345. pDevice->sTimerCommand.data = (unsigned long) pDevice;
  346. pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
  347. pDevice->sTimerCommand.expires = RUN_AT(HZ);
  348. init_timer(&pDevice->sTimerTxData);
  349. pDevice->sTimerTxData.data = (unsigned long) pDevice;
  350. pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
  351. pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
  352. pDevice->fTxDataInSleep = false;
  353. pDevice->IsTxDataTrigger = false;
  354. pDevice->nTxDataTimeCout = 0;
  355. pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
  356. pDevice->uCmdDequeueIdx = 0;
  357. pDevice->uCmdEnqueueIdx = 0;
  358. }
  359. /*+
  360. *
  361. * Routine Description:
  362. * Reset the management object structure.
  363. *
  364. * Return Value:
  365. * None.
  366. *
  367. -*/
  368. void
  369. vMgrObjectReset(
  370. void *hDeviceContext
  371. )
  372. {
  373. struct vnt_private *pDevice = hDeviceContext;
  374. PSMgmtObject pMgmt = pDevice->pMgmt;
  375. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  376. pMgmt->eCurrState = WMAC_STATE_IDLE;
  377. pDevice->bEnablePSMode = false;
  378. // TODO: timer
  379. }
  380. /*+
  381. *
  382. * Routine Description:
  383. * Start the station association procedure. Namely, send an
  384. * association request frame to the AP.
  385. *
  386. * Return Value:
  387. * None.
  388. *
  389. -*/
  390. void
  391. vMgrAssocBeginSta(
  392. void *hDeviceContext,
  393. PSMgmtObject pMgmt,
  394. PCMD_STATUS pStatus
  395. )
  396. {
  397. struct vnt_private *pDevice = hDeviceContext;
  398. PSTxMgmtPacket pTxPacket;
  399. pMgmt->wCurrCapInfo = 0;
  400. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
  401. if (pDevice->bEncryptionEnable)
  402. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
  403. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  404. if (pMgmt->wListenInterval == 0)
  405. pMgmt->wListenInterval = 1; // at least one.
  406. // ERP Phy (802.11g) should support short preamble.
  407. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
  408. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  409. if (CARDbIsShorSlotTime(pMgmt->pAdapter))
  410. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
  411. } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
  412. if (CARDbIsShortPreamble(pMgmt->pAdapter))
  413. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  414. }
  415. if (pMgmt->b11hEnable)
  416. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
  417. /* build an assocreq frame and send it */
  418. pTxPacket = s_MgrMakeAssocRequest
  419. (
  420. pDevice,
  421. pMgmt,
  422. pMgmt->abyCurrBSSID,
  423. pMgmt->wCurrCapInfo,
  424. pMgmt->wListenInterval,
  425. (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
  426. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  427. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
  428. );
  429. if (pTxPacket != NULL) {
  430. /* send the frame */
  431. *pStatus = csMgmt_xmit(pDevice, pTxPacket);
  432. if (*pStatus == CMD_STATUS_PENDING) {
  433. pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
  434. *pStatus = CMD_STATUS_SUCCESS;
  435. }
  436. } else {
  437. *pStatus = CMD_STATUS_RESOURCES;
  438. }
  439. }
  440. /*+
  441. *
  442. * Routine Description:
  443. * Start the station re-association procedure.
  444. *
  445. * Return Value:
  446. * None.
  447. *
  448. -*/
  449. void
  450. vMgrReAssocBeginSta(
  451. void *hDeviceContext,
  452. PSMgmtObject pMgmt,
  453. PCMD_STATUS pStatus
  454. )
  455. {
  456. struct vnt_private *pDevice = hDeviceContext;
  457. PSTxMgmtPacket pTxPacket;
  458. pMgmt->wCurrCapInfo = 0;
  459. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
  460. if (pDevice->bEncryptionEnable)
  461. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
  462. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  463. if (pMgmt->wListenInterval == 0)
  464. pMgmt->wListenInterval = 1; // at least one.
  465. // ERP Phy (802.11g) should support short preamble.
  466. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
  467. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  468. if (CARDbIsShorSlotTime(pMgmt->pAdapter))
  469. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
  470. } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
  471. if (CARDbIsShortPreamble(pMgmt->pAdapter))
  472. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  473. }
  474. if (pMgmt->b11hEnable)
  475. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
  476. pTxPacket = s_MgrMakeReAssocRequest
  477. (
  478. pDevice,
  479. pMgmt,
  480. pMgmt->abyCurrBSSID,
  481. pMgmt->wCurrCapInfo,
  482. pMgmt->wListenInterval,
  483. (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
  484. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  485. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
  486. );
  487. if (pTxPacket != NULL) {
  488. /* send the frame */
  489. *pStatus = csMgmt_xmit(pDevice, pTxPacket);
  490. if (*pStatus != CMD_STATUS_PENDING)
  491. pr_debug("Mgt:Reassociation tx failed\n");
  492. else
  493. pr_debug("Mgt:Reassociation tx sending\n");
  494. }
  495. }
  496. /*+
  497. *
  498. * Routine Description:
  499. * Send an dis-association request frame to the AP.
  500. *
  501. * Return Value:
  502. * None.
  503. *
  504. -*/
  505. void
  506. vMgrDisassocBeginSta(
  507. void *hDeviceContext,
  508. PSMgmtObject pMgmt,
  509. unsigned char *abyDestAddress,
  510. unsigned short wReason,
  511. PCMD_STATUS pStatus
  512. )
  513. {
  514. struct vnt_private *pDevice = hDeviceContext;
  515. PSTxMgmtPacket pTxPacket = NULL;
  516. WLAN_FR_DISASSOC sFrame;
  517. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  518. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
  519. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  520. // Setup the sFrame structure
  521. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  522. sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
  523. // format fixed field frame structure
  524. vMgrEncodeDisassociation(&sFrame);
  525. // Setup the header
  526. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  527. (
  528. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  529. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
  530. ));
  531. memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
  532. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  533. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  534. // Set reason code
  535. *(sFrame.pwReason) = cpu_to_le16(wReason);
  536. pTxPacket->cbMPDULen = sFrame.len;
  537. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  538. // send the frame
  539. *pStatus = csMgmt_xmit(pDevice, pTxPacket);
  540. if (*pStatus == CMD_STATUS_PENDING) {
  541. pMgmt->eCurrState = WMAC_STATE_IDLE;
  542. *pStatus = CMD_STATUS_SUCCESS;
  543. }
  544. }
  545. /*+
  546. *
  547. * Routine Description:(AP function)
  548. * Handle incoming station association request frames.
  549. *
  550. * Return Value:
  551. * None.
  552. *
  553. -*/
  554. static
  555. void
  556. s_vMgrRxAssocRequest(
  557. struct vnt_private *pDevice,
  558. PSMgmtObject pMgmt,
  559. PSRxMgmtPacket pRxPacket,
  560. unsigned int uNodeIndex
  561. )
  562. {
  563. WLAN_FR_ASSOCREQ sFrame;
  564. CMD_STATUS Status;
  565. PSTxMgmtPacket pTxPacket;
  566. unsigned short wAssocStatus = 0;
  567. unsigned short wAssocAID = 0;
  568. unsigned int uRateLen = WLAN_RATES_MAXLEN;
  569. unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
  570. unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
  571. if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
  572. return;
  573. // node index not found
  574. if (!uNodeIndex)
  575. return;
  576. //check if node is authenticated
  577. //decode the frame
  578. memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
  579. memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  580. memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  581. sFrame.len = pRxPacket->cbMPDULen;
  582. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  583. vMgrDecodeAssocRequest(&sFrame);
  584. if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
  585. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
  586. pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
  587. pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
  588. pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
  589. WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
  590. // Todo: check sta basic rate, if ap can't support, set status code
  591. if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
  592. uRateLen = WLAN_RATES_MAXLEN_11B;
  593. abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
  594. abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
  595. (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
  596. uRateLen);
  597. abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
  598. if (pDevice->eCurrentPHYType == PHY_TYPE_11G)
  599. abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
  600. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
  601. uRateLen);
  602. else
  603. abyCurrExtSuppRates[1] = 0;
  604. RATEvParseMaxRate((void *)pDevice,
  605. (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
  606. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
  607. false, // do not change our basic rate
  608. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
  609. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
  610. &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
  611. &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
  612. &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
  613. );
  614. // set max tx rate
  615. pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
  616. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
  617. pr_debug("RxAssocRequest:wTxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
  618. // Todo: check sta preamble, if ap can't support, set status code
  619. pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
  620. WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
  621. pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
  622. WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
  623. pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
  624. wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
  625. wAssocAID = (unsigned short)uNodeIndex;
  626. // check if ERP support
  627. if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
  628. pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
  629. if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
  630. // B only STA join
  631. pDevice->bProtectMode = true;
  632. pDevice->bNonERPPresent = true;
  633. }
  634. if (!pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
  635. pDevice->bBarkerPreambleMd = true;
  636. pr_info("Associate AID= %d\n", wAssocAID);
  637. pr_info("MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  638. sFrame.pHdr->sA3.abyAddr2[0],
  639. sFrame.pHdr->sA3.abyAddr2[1],
  640. sFrame.pHdr->sA3.abyAddr2[2],
  641. sFrame.pHdr->sA3.abyAddr2[3],
  642. sFrame.pHdr->sA3.abyAddr2[4],
  643. sFrame.pHdr->sA3.abyAddr2[5]
  644. );
  645. pr_info("Max Support rate = %d\n",
  646. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
  647. } else {
  648. /* TODO: received STA under state1 handle */
  649. return;
  650. }
  651. // assoc response reply..
  652. pTxPacket = s_MgrMakeAssocResponse
  653. (
  654. pDevice,
  655. pMgmt,
  656. pMgmt->wCurrCapInfo,
  657. wAssocStatus,
  658. wAssocAID,
  659. sFrame.pHdr->sA3.abyAddr2,
  660. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  661. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
  662. );
  663. if (pTxPacket != NULL) {
  664. if (pDevice->bEnableHostapd)
  665. return;
  666. /* send the frame */
  667. Status = csMgmt_xmit(pDevice, pTxPacket);
  668. if (Status != CMD_STATUS_PENDING)
  669. pr_debug("Mgt:Assoc response tx failed\n");
  670. else
  671. pr_debug("Mgt:Assoc response tx sending..\n");
  672. }
  673. }
  674. /*+
  675. *
  676. * Description:(AP function)
  677. * Handle incoming station re-association request frames.
  678. *
  679. * Parameters:
  680. * In:
  681. * pMgmt - Management Object structure
  682. * pRxPacket - Received Packet
  683. * Out:
  684. * none
  685. *
  686. * Return Value: None.
  687. *
  688. -*/
  689. static
  690. void
  691. s_vMgrRxReAssocRequest(
  692. struct vnt_private *pDevice,
  693. PSMgmtObject pMgmt,
  694. PSRxMgmtPacket pRxPacket,
  695. unsigned int uNodeIndex
  696. )
  697. {
  698. WLAN_FR_REASSOCREQ sFrame;
  699. CMD_STATUS Status;
  700. PSTxMgmtPacket pTxPacket;
  701. unsigned short wAssocStatus = 0;
  702. unsigned short wAssocAID = 0;
  703. unsigned int uRateLen = WLAN_RATES_MAXLEN;
  704. unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
  705. unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
  706. if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
  707. return;
  708. // node index not found
  709. if (!uNodeIndex)
  710. return;
  711. //check if node is authenticated
  712. //decode the frame
  713. memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
  714. sFrame.len = pRxPacket->cbMPDULen;
  715. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  716. vMgrDecodeReassocRequest(&sFrame);
  717. if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
  718. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
  719. pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
  720. pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
  721. pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
  722. WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
  723. // Todo: check sta basic rate, if ap can't support, set status code
  724. if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
  725. uRateLen = WLAN_RATES_MAXLEN_11B;
  726. abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
  727. abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
  728. (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
  729. uRateLen);
  730. abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
  731. if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
  732. abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
  733. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
  734. uRateLen);
  735. } else {
  736. abyCurrExtSuppRates[1] = 0;
  737. }
  738. RATEvParseMaxRate((void *)pDevice,
  739. (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
  740. (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
  741. false, // do not change our basic rate
  742. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
  743. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
  744. &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
  745. &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
  746. &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
  747. );
  748. // set max tx rate
  749. pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
  750. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
  751. pr_debug("RxReAssocRequest:TxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
  752. // Todo: check sta preamble, if ap can't support, set status code
  753. pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
  754. WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
  755. pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
  756. WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
  757. pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
  758. wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
  759. wAssocAID = (unsigned short)uNodeIndex;
  760. // if suppurt ERP
  761. if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
  762. pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
  763. if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
  764. // B only STA join
  765. pDevice->bProtectMode = true;
  766. pDevice->bNonERPPresent = true;
  767. }
  768. if (!pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
  769. pDevice->bBarkerPreambleMd = true;
  770. pr_info("Rx ReAssociate AID= %d\n", wAssocAID);
  771. pr_info("MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
  772. sFrame.pHdr->sA3.abyAddr2[0],
  773. sFrame.pHdr->sA3.abyAddr2[1],
  774. sFrame.pHdr->sA3.abyAddr2[2],
  775. sFrame.pHdr->sA3.abyAddr2[3],
  776. sFrame.pHdr->sA3.abyAddr2[4],
  777. sFrame.pHdr->sA3.abyAddr2[5]
  778. );
  779. pr_info("Max Support rate = %d\n",
  780. pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
  781. }
  782. // assoc response reply..
  783. pTxPacket = s_MgrMakeReAssocResponse
  784. (
  785. pDevice,
  786. pMgmt,
  787. pMgmt->wCurrCapInfo,
  788. wAssocStatus,
  789. wAssocAID,
  790. sFrame.pHdr->sA3.abyAddr2,
  791. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  792. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
  793. );
  794. if (pTxPacket != NULL) {
  795. /* send the frame */
  796. if (pDevice->bEnableHostapd)
  797. return;
  798. Status = csMgmt_xmit(pDevice, pTxPacket);
  799. if (Status != CMD_STATUS_PENDING)
  800. pr_debug("Mgt:ReAssoc response tx failed\n");
  801. else
  802. pr_debug("Mgt:ReAssoc response tx sending..\n");
  803. }
  804. }
  805. /*+
  806. *
  807. * Routine Description:
  808. * Handle incoming association response frames.
  809. *
  810. * Return Value:
  811. * None.
  812. *
  813. -*/
  814. static
  815. void
  816. s_vMgrRxAssocResponse(
  817. struct vnt_private *pDevice,
  818. PSMgmtObject pMgmt,
  819. PSRxMgmtPacket pRxPacket,
  820. bool bReAssocType
  821. )
  822. {
  823. WLAN_FR_ASSOCRESP sFrame;
  824. PWLAN_IE_SSID pItemSSID;
  825. unsigned char *pbyIEs;
  826. viawget_wpa_header *wpahdr;
  827. if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
  828. pMgmt->eCurrState == WMAC_STATE_ASSOC) {
  829. sFrame.len = pRxPacket->cbMPDULen;
  830. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  831. // decode the frame
  832. vMgrDecodeAssocResponse(&sFrame);
  833. if ((sFrame.pwCapInfo == NULL) ||
  834. (sFrame.pwStatus == NULL) ||
  835. (sFrame.pwAid == NULL) ||
  836. (sFrame.pSuppRates == NULL)) {
  837. DBG_PORT80(0xCC);
  838. return;
  839. }
  840. pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
  841. pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
  842. pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
  843. pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
  844. pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
  845. pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
  846. pbyIEs = pMgmt->sAssocInfo.abyIEs;
  847. pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
  848. memcpy(pbyIEs, (sFrame.pBuf + 24 + 6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
  849. // save values and set current BSS state
  850. if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
  851. // set AID
  852. pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
  853. if ((pMgmt->wCurrAID >> 14) != (BIT0 | BIT1))
  854. pr_debug("AID from AP, has two msb clear\n");
  855. pr_info("Association Successful, AID=%d\n",
  856. pMgmt->wCurrAID & ~(BIT14 | BIT15));
  857. pMgmt->eCurrState = WMAC_STATE_ASSOC;
  858. BSSvUpdateAPNode((void *)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
  859. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
  860. pr_info("Link with AP(SSID): %s\n", pItemSSID->abySSID);
  861. pDevice->bLinkPass = true;
  862. pDevice->uBBVGADiffCount = 0;
  863. if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
  864. if (skb_tailroom(pDevice->skb) < (sizeof(viawget_wpa_header) + pMgmt->sAssocInfo.AssocInfo.ResponseIELength +
  865. pMgmt->sAssocInfo.AssocInfo.RequestIELength)) { //data room not enough
  866. dev_kfree_skb(pDevice->skb);
  867. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  868. }
  869. wpahdr = (viawget_wpa_header *)pDevice->skb->data;
  870. wpahdr->type = VIAWGET_ASSOC_MSG;
  871. wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
  872. wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
  873. memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
  874. memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
  875. pbyIEs,
  876. wpahdr->resp_ie_len
  877. );
  878. skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
  879. pDevice->skb->dev = pDevice->wpadev;
  880. skb_reset_mac_header(pDevice->skb);
  881. pDevice->skb->pkt_type = PACKET_HOST;
  882. pDevice->skb->protocol = htons(ETH_P_802_2);
  883. memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
  884. netif_rx(pDevice->skb);
  885. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  886. }
  887. //2008-0409-07, <Add> by Einsn Liu
  888. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  889. {
  890. unsigned char buf[512];
  891. size_t len;
  892. union iwreq_data wrqu;
  893. int we_event;
  894. memset(buf, 0, 512);
  895. len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
  896. if (len) {
  897. memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
  898. memset(&wrqu, 0, sizeof(wrqu));
  899. wrqu.data.length = len;
  900. we_event = IWEVASSOCREQIE;
  901. wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
  902. }
  903. memset(buf, 0, 512);
  904. len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
  905. if (len) {
  906. memcpy(buf, pbyIEs, len);
  907. memset(&wrqu, 0, sizeof(wrqu));
  908. wrqu.data.length = len;
  909. we_event = IWEVASSOCRESPIE;
  910. wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
  911. }
  912. memset(&wrqu, 0, sizeof(wrqu));
  913. memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
  914. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  915. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  916. }
  917. #endif //#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  918. //End Add -- //2008-0409-07, <Add> by Einsn Liu
  919. } else {
  920. if (bReAssocType) {
  921. pMgmt->eCurrState = WMAC_STATE_IDLE;
  922. } else {
  923. // jump back to the auth state and indicate the error
  924. pMgmt->eCurrState = WMAC_STATE_AUTH;
  925. }
  926. s_vMgrLogStatus(pMgmt, cpu_to_le16((*(sFrame.pwStatus))));
  927. }
  928. }
  929. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  930. //need clear flags related to Networkmanager
  931. pDevice->bwextcount = 0;
  932. pDevice->bWPASuppWextEnabled = false;
  933. #endif
  934. if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
  935. timer_expire(pDevice->sTimerCommand, 0);
  936. }
  937. /*+
  938. *
  939. * Routine Description:
  940. * Start the station authentication procedure. Namely, send an
  941. * authentication frame to the AP.
  942. *
  943. * Return Value:
  944. * None.
  945. *
  946. -*/
  947. void
  948. vMgrAuthenBeginSta(
  949. void *hDeviceContext,
  950. PSMgmtObject pMgmt,
  951. PCMD_STATUS pStatus
  952. )
  953. {
  954. struct vnt_private *pDevice = hDeviceContext;
  955. WLAN_FR_AUTHEN sFrame;
  956. PSTxMgmtPacket pTxPacket = NULL;
  957. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  958. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
  959. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  960. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  961. sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
  962. vMgrEncodeAuthen(&sFrame);
  963. /* insert values */
  964. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  965. (
  966. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  967. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
  968. ));
  969. memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
  970. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  971. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  972. if (pMgmt->bShareKeyAlgorithm)
  973. *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
  974. else
  975. *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
  976. *(sFrame.pwAuthSequence) = cpu_to_le16(1);
  977. /* Adjust the length fields */
  978. pTxPacket->cbMPDULen = sFrame.len;
  979. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  980. *pStatus = csMgmt_xmit(pDevice, pTxPacket);
  981. if (*pStatus == CMD_STATUS_PENDING) {
  982. pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
  983. *pStatus = CMD_STATUS_SUCCESS;
  984. }
  985. }
  986. /*+
  987. *
  988. * Routine Description:
  989. * Start the station(AP) deauthentication procedure. Namely, send an
  990. * deauthentication frame to the AP or Sta.
  991. *
  992. * Return Value:
  993. * None.
  994. *
  995. -*/
  996. void
  997. vMgrDeAuthenBeginSta(
  998. void *hDeviceContext,
  999. PSMgmtObject pMgmt,
  1000. unsigned char *abyDestAddress,
  1001. unsigned short wReason,
  1002. PCMD_STATUS pStatus
  1003. )
  1004. {
  1005. struct vnt_private *pDevice = hDeviceContext;
  1006. WLAN_FR_DEAUTHEN sFrame;
  1007. PSTxMgmtPacket pTxPacket = NULL;
  1008. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  1009. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
  1010. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  1011. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  1012. sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
  1013. vMgrEncodeDeauthen(&sFrame);
  1014. /* insert values */
  1015. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  1016. (
  1017. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  1018. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
  1019. ));
  1020. memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
  1021. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  1022. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1023. *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
  1024. /* Adjust the length fields */
  1025. pTxPacket->cbMPDULen = sFrame.len;
  1026. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  1027. *pStatus = csMgmt_xmit(pDevice, pTxPacket);
  1028. if (*pStatus == CMD_STATUS_PENDING)
  1029. *pStatus = CMD_STATUS_SUCCESS;
  1030. }
  1031. /*+
  1032. *
  1033. * Routine Description:
  1034. * Handle incoming authentication frames.
  1035. *
  1036. * Return Value:
  1037. * None.
  1038. *
  1039. -*/
  1040. static
  1041. void
  1042. s_vMgrRxAuthentication(
  1043. struct vnt_private *pDevice,
  1044. PSMgmtObject pMgmt,
  1045. PSRxMgmtPacket pRxPacket
  1046. )
  1047. {
  1048. WLAN_FR_AUTHEN sFrame;
  1049. // we better be an AP or a STA in AUTHPENDING otherwise ignore
  1050. if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
  1051. pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
  1052. return;
  1053. }
  1054. // decode the frame
  1055. sFrame.len = pRxPacket->cbMPDULen;
  1056. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1057. vMgrDecodeAuthen(&sFrame);
  1058. switch (cpu_to_le16((*(sFrame.pwAuthSequence)))) {
  1059. case 1:
  1060. //AP function
  1061. s_vMgrRxAuthenSequence_1(pDevice, pMgmt, &sFrame);
  1062. break;
  1063. case 2:
  1064. s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
  1065. break;
  1066. case 3:
  1067. //AP function
  1068. s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
  1069. break;
  1070. case 4:
  1071. s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
  1072. break;
  1073. default:
  1074. pr_debug("Auth Sequence error, seq = %d\n",
  1075. cpu_to_le16((*(sFrame.pwAuthSequence))));
  1076. break;
  1077. }
  1078. }
  1079. /*+
  1080. *
  1081. * Routine Description:
  1082. * Handles incoming authen frames with sequence 1. Currently
  1083. * assumes we're an AP. So far, no one appears to use authentication
  1084. * in Ad-Hoc mode.
  1085. *
  1086. * Return Value:
  1087. * None.
  1088. *
  1089. -*/
  1090. static
  1091. void
  1092. s_vMgrRxAuthenSequence_1(
  1093. struct vnt_private *pDevice,
  1094. PSMgmtObject pMgmt,
  1095. PWLAN_FR_AUTHEN pFrame
  1096. )
  1097. {
  1098. PSTxMgmtPacket pTxPacket = NULL;
  1099. unsigned int uNodeIndex;
  1100. WLAN_FR_AUTHEN sFrame;
  1101. PSKeyItem pTransmitKey;
  1102. // Insert a Node entry
  1103. if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
  1104. BSSvCreateOneNode(pDevice, &uNodeIndex);
  1105. memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
  1106. WLAN_ADDR_LEN);
  1107. }
  1108. if (pMgmt->bShareKeyAlgorithm) {
  1109. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
  1110. pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
  1111. } else {
  1112. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
  1113. }
  1114. // send auth reply
  1115. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  1116. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
  1117. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  1118. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  1119. sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
  1120. // format buffer structure
  1121. vMgrEncodeAuthen(&sFrame);
  1122. // insert values
  1123. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  1124. (
  1125. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  1126. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
  1127. WLAN_SET_FC_ISWEP(0)
  1128. ));
  1129. memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
  1130. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  1131. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1132. *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
  1133. *(sFrame.pwAuthSequence) = cpu_to_le16(2);
  1134. if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
  1135. if (pMgmt->bShareKeyAlgorithm)
  1136. *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
  1137. else
  1138. *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
  1139. } else {
  1140. if (pMgmt->bShareKeyAlgorithm)
  1141. *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
  1142. else
  1143. *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
  1144. }
  1145. if (pMgmt->bShareKeyAlgorithm &&
  1146. (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
  1147. sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
  1148. sFrame.len += WLAN_CHALLENGE_IE_LEN;
  1149. sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
  1150. sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
  1151. memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
  1152. // get group key
  1153. if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
  1154. rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
  1155. rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
  1156. }
  1157. memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
  1158. }
  1159. /* Adjust the length fields */
  1160. pTxPacket->cbMPDULen = sFrame.len;
  1161. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  1162. // send the frame
  1163. if (pDevice->bEnableHostapd)
  1164. return;
  1165. pr_debug("Mgt:Authreq_reply sequence_1 tx..\n");
  1166. if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
  1167. pr_debug("Mgt:Authreq_reply sequence_1 tx failed\n");
  1168. }
  1169. /*+
  1170. *
  1171. * Routine Description:
  1172. * Handles incoming auth frames with sequence number 2. Currently
  1173. * assumes we're a station.
  1174. *
  1175. *
  1176. * Return Value:
  1177. * None.
  1178. *
  1179. -*/
  1180. static
  1181. void
  1182. s_vMgrRxAuthenSequence_2(
  1183. struct vnt_private *pDevice,
  1184. PSMgmtObject pMgmt,
  1185. PWLAN_FR_AUTHEN pFrame
  1186. )
  1187. {
  1188. WLAN_FR_AUTHEN sFrame;
  1189. PSTxMgmtPacket pTxPacket = NULL;
  1190. switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm)))) {
  1191. case WLAN_AUTH_ALG_OPENSYSTEM:
  1192. if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
  1193. pr_info("802.11 Authen (OPEN) Successful\n");
  1194. pMgmt->eCurrState = WMAC_STATE_AUTH;
  1195. timer_expire(pDevice->sTimerCommand, 0);
  1196. } else {
  1197. pr_info("802.11 Authen (OPEN) Failed\n");
  1198. s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
  1199. pMgmt->eCurrState = WMAC_STATE_IDLE;
  1200. }
  1201. break;
  1202. case WLAN_AUTH_ALG_SHAREDKEY:
  1203. if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
  1204. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  1205. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
  1206. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  1207. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  1208. sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
  1209. // format buffer structure
  1210. vMgrEncodeAuthen(&sFrame);
  1211. // insert values
  1212. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  1213. (
  1214. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  1215. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
  1216. WLAN_SET_FC_ISWEP(1)
  1217. ));
  1218. memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1219. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  1220. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1221. *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
  1222. *(sFrame.pwAuthSequence) = cpu_to_le16(3);
  1223. *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
  1224. sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
  1225. sFrame.len += WLAN_CHALLENGE_IE_LEN;
  1226. sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
  1227. sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
  1228. memcpy(sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
  1229. // Adjust the length fields
  1230. pTxPacket->cbMPDULen = sFrame.len;
  1231. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  1232. // send the frame
  1233. if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
  1234. pr_debug("Mgt:Auth_reply sequence_2 tx failed\n");
  1235. pr_debug("Mgt:Auth_reply sequence_2 tx ...\n");
  1236. } else {
  1237. pr_debug("Mgt:rx Auth_reply sequence_2 status error ...\n");
  1238. s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
  1239. }
  1240. break;
  1241. default:
  1242. pr_debug("Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n",
  1243. cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
  1244. break;
  1245. }
  1246. }
  1247. /*+
  1248. *
  1249. * Routine Description:
  1250. * Handles incoming authen frames with sequence 3. Currently
  1251. * assumes we're an AP. This function assumes the frame has
  1252. * already been successfully decrypted.
  1253. *
  1254. *
  1255. * Return Value:
  1256. * None.
  1257. *
  1258. -*/
  1259. static
  1260. void
  1261. s_vMgrRxAuthenSequence_3(
  1262. struct vnt_private *pDevice,
  1263. PSMgmtObject pMgmt,
  1264. PWLAN_FR_AUTHEN pFrame
  1265. )
  1266. {
  1267. PSTxMgmtPacket pTxPacket = NULL;
  1268. unsigned int uStatusCode = 0;
  1269. unsigned int uNodeIndex = 0;
  1270. WLAN_FR_AUTHEN sFrame;
  1271. if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
  1272. uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
  1273. goto reply;
  1274. }
  1275. if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
  1276. if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
  1277. uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
  1278. goto reply;
  1279. }
  1280. if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
  1281. uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
  1282. goto reply;
  1283. }
  1284. } else {
  1285. uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
  1286. goto reply;
  1287. }
  1288. if (uNodeIndex) {
  1289. pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
  1290. pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
  1291. }
  1292. uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
  1293. pr_debug("Challenge text check ok..\n");
  1294. reply:
  1295. // send auth reply
  1296. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  1297. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
  1298. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  1299. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  1300. sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
  1301. // format buffer structure
  1302. vMgrEncodeAuthen(&sFrame);
  1303. /* insert values */
  1304. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  1305. (
  1306. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  1307. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
  1308. WLAN_SET_FC_ISWEP(0)
  1309. ));
  1310. memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
  1311. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  1312. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1313. *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
  1314. *(sFrame.pwAuthSequence) = cpu_to_le16(4);
  1315. *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
  1316. /* Adjust the length fields */
  1317. pTxPacket->cbMPDULen = sFrame.len;
  1318. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  1319. // send the frame
  1320. if (pDevice->bEnableHostapd)
  1321. return;
  1322. if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
  1323. pr_debug("Mgt:Authreq_reply sequence_4 tx failed\n");
  1324. }
  1325. /*+
  1326. *
  1327. * Routine Description:
  1328. * Handles incoming authen frames with sequence 4
  1329. *
  1330. *
  1331. * Return Value:
  1332. * None.
  1333. *
  1334. -*/
  1335. static
  1336. void
  1337. s_vMgrRxAuthenSequence_4(
  1338. struct vnt_private *pDevice,
  1339. PSMgmtObject pMgmt,
  1340. PWLAN_FR_AUTHEN pFrame
  1341. )
  1342. {
  1343. if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
  1344. pr_info("802.11 Authen (SHAREDKEY) Successful\n");
  1345. pMgmt->eCurrState = WMAC_STATE_AUTH;
  1346. timer_expire(pDevice->sTimerCommand, 0);
  1347. } else{
  1348. pr_info("802.11 Authen (SHAREDKEY) Failed\n");
  1349. s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
  1350. pMgmt->eCurrState = WMAC_STATE_IDLE;
  1351. }
  1352. }
  1353. /*+
  1354. *
  1355. * Routine Description:
  1356. * Handles incoming disassociation frames
  1357. *
  1358. *
  1359. * Return Value:
  1360. * None.
  1361. *
  1362. -*/
  1363. static
  1364. void
  1365. s_vMgrRxDisassociation(
  1366. struct vnt_private *pDevice,
  1367. PSMgmtObject pMgmt,
  1368. PSRxMgmtPacket pRxPacket
  1369. )
  1370. {
  1371. WLAN_FR_DISASSOC sFrame;
  1372. unsigned int uNodeIndex = 0;
  1373. viawget_wpa_header *wpahdr;
  1374. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  1375. // if is acting an AP..
  1376. // a STA is leaving this BSS..
  1377. sFrame.len = pRxPacket->cbMPDULen;
  1378. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1379. if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
  1380. BSSvRemoveOneNode(pDevice, uNodeIndex);
  1381. else
  1382. pr_debug("Rx disassoc, sta not found\n");
  1383. } else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
  1384. sFrame.len = pRxPacket->cbMPDULen;
  1385. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1386. vMgrDecodeDisassociation(&sFrame);
  1387. pr_info("AP disassociated me, reason=%d\n",
  1388. cpu_to_le16(*(sFrame.pwReason)));
  1389. //TODO: do something let upper layer know or
  1390. //try to send associate packet again because of inactivity timeout
  1391. if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
  1392. wpahdr = (viawget_wpa_header *)pDevice->skb->data;
  1393. wpahdr->type = VIAWGET_DISASSOC_MSG;
  1394. wpahdr->resp_ie_len = 0;
  1395. wpahdr->req_ie_len = 0;
  1396. skb_put(pDevice->skb, sizeof(viawget_wpa_header));
  1397. pDevice->skb->dev = pDevice->wpadev;
  1398. skb_reset_mac_header(pDevice->skb);
  1399. pDevice->skb->pkt_type = PACKET_HOST;
  1400. pDevice->skb->protocol = htons(ETH_P_802_2);
  1401. memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
  1402. netif_rx(pDevice->skb);
  1403. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  1404. }
  1405. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  1406. {
  1407. union iwreq_data wrqu;
  1408. memset(&wrqu, 0, sizeof(wrqu));
  1409. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1410. pr_debug("wireless_send_event--->SIOCGIWAP(disassociated)\n");
  1411. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  1412. }
  1413. #endif
  1414. }
  1415. /* else, ignore it */
  1416. }
  1417. /*+
  1418. *
  1419. * Routine Description:
  1420. * Handles incoming deauthentication frames
  1421. *
  1422. *
  1423. * Return Value:
  1424. * None.
  1425. *
  1426. -*/
  1427. static
  1428. void
  1429. s_vMgrRxDeauthentication(
  1430. struct vnt_private *pDevice,
  1431. PSMgmtObject pMgmt,
  1432. PSRxMgmtPacket pRxPacket
  1433. )
  1434. {
  1435. WLAN_FR_DEAUTHEN sFrame;
  1436. unsigned int uNodeIndex = 0;
  1437. viawget_wpa_header *wpahdr;
  1438. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  1439. //Todo:
  1440. // if is acting an AP..
  1441. // a STA is leaving this BSS..
  1442. sFrame.len = pRxPacket->cbMPDULen;
  1443. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1444. if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
  1445. BSSvRemoveOneNode(pDevice, uNodeIndex);
  1446. else
  1447. pr_info("Rx deauth, sta not found\n");
  1448. } else {
  1449. if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
  1450. sFrame.len = pRxPacket->cbMPDULen;
  1451. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1452. vMgrDecodeDeauthen(&sFrame);
  1453. pr_info("AP deauthed me, reason=%d\n",
  1454. cpu_to_le16((*(sFrame.pwReason))));
  1455. // TODO: update BSS list for specific BSSID if pre-authentication case
  1456. if (ether_addr_equal(sFrame.pHdr->sA3.abyAddr3,
  1457. pMgmt->abyCurrBSSID)) {
  1458. if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
  1459. pMgmt->sNodeDBTable[0].bActive = false;
  1460. pMgmt->eCurrMode = WMAC_MODE_STANDBY;
  1461. pMgmt->eCurrState = WMAC_STATE_IDLE;
  1462. netif_stop_queue(pDevice->dev);
  1463. pDevice->bLinkPass = false;
  1464. }
  1465. }
  1466. if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
  1467. wpahdr = (viawget_wpa_header *)pDevice->skb->data;
  1468. wpahdr->type = VIAWGET_DISASSOC_MSG;
  1469. wpahdr->resp_ie_len = 0;
  1470. wpahdr->req_ie_len = 0;
  1471. skb_put(pDevice->skb, sizeof(viawget_wpa_header));
  1472. pDevice->skb->dev = pDevice->wpadev;
  1473. skb_reset_mac_header(pDevice->skb);
  1474. pDevice->skb->pkt_type = PACKET_HOST;
  1475. pDevice->skb->protocol = htons(ETH_P_802_2);
  1476. memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
  1477. netif_rx(pDevice->skb);
  1478. pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
  1479. }
  1480. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  1481. {
  1482. union iwreq_data wrqu;
  1483. memset(&wrqu, 0, sizeof(wrqu));
  1484. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1485. PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
  1486. wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
  1487. }
  1488. #endif
  1489. }
  1490. /* else, ignore it. TODO: IBSS authentication service
  1491. would be implemented here */
  1492. }
  1493. }
  1494. //2008-8-4 <add> by chester
  1495. /*+
  1496. *
  1497. * Routine Description:
  1498. * check if current channel is match ZoneType.
  1499. *for USA:1~11;
  1500. * Japan:1~13;
  1501. * Europe:1~13
  1502. * Return Value:
  1503. * True:exceed;
  1504. * False:normal case
  1505. -*/
  1506. static bool
  1507. ChannelExceedZoneType(
  1508. struct vnt_private *pDevice,
  1509. unsigned char byCurrChannel
  1510. )
  1511. {
  1512. bool exceed = false;
  1513. switch (pDevice->byZoneType) {
  1514. case 0x00: //USA:1~11
  1515. if ((byCurrChannel < 1) || (byCurrChannel > 11))
  1516. exceed = true;
  1517. break;
  1518. case 0x01: //Japan:1~13
  1519. case 0x02: //Europe:1~13
  1520. if ((byCurrChannel < 1) || (byCurrChannel > 13))
  1521. exceed = true;
  1522. break;
  1523. default: //reserve for other zonetype
  1524. break;
  1525. }
  1526. return exceed;
  1527. }
  1528. /*+
  1529. *
  1530. * Routine Description:
  1531. * Handles and analysis incoming beacon frames.
  1532. *
  1533. *
  1534. * Return Value:
  1535. * None.
  1536. *
  1537. -*/
  1538. static
  1539. void
  1540. s_vMgrRxBeacon(
  1541. struct vnt_private *pDevice,
  1542. PSMgmtObject pMgmt,
  1543. PSRxMgmtPacket pRxPacket,
  1544. bool bInScan
  1545. )
  1546. {
  1547. PKnownBSS pBSSList;
  1548. WLAN_FR_BEACON sFrame;
  1549. u64 qwTSFOffset;
  1550. bool bIsBSSIDEqual = false;
  1551. bool bIsSSIDEqual = false;
  1552. bool bTSFLargeDiff = false;
  1553. bool bTSFOffsetPostive = false;
  1554. bool bUpdateTSF = false;
  1555. bool bIsAPBeacon = false;
  1556. bool bIsChannelEqual = false;
  1557. unsigned int uLocateByteIndex;
  1558. unsigned char byTIMBitOn = 0;
  1559. unsigned short wAIDNumber = 0;
  1560. unsigned int uNodeIndex;
  1561. u64 qwTimestamp, qwLocalTSF;
  1562. u64 qwCurrTSF;
  1563. unsigned short wStartIndex = 0;
  1564. unsigned short wAIDIndex = 0;
  1565. unsigned char byCurrChannel = pRxPacket->byRxChannel;
  1566. ERPObject sERP;
  1567. unsigned int uRateLen = WLAN_RATES_MAXLEN;
  1568. bool bChannelHit = false;
  1569. bool bUpdatePhyParameter = false;
  1570. unsigned char byIEChannel = 0;
  1571. memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
  1572. sFrame.len = pRxPacket->cbMPDULen;
  1573. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  1574. // decode the beacon frame
  1575. vMgrDecodeBeacon(&sFrame);
  1576. if ((sFrame.pwBeaconInterval == NULL) ||
  1577. (sFrame.pwCapInfo == NULL) ||
  1578. (sFrame.pSSID == NULL) ||
  1579. (sFrame.pSuppRates == NULL)) {
  1580. pr_debug("Rx beacon frame error\n");
  1581. return;
  1582. }
  1583. if (sFrame.pDSParms != NULL) {
  1584. if (byCurrChannel > CB_MAX_CHANNEL_24G) {
  1585. // channel remapping to
  1586. byIEChannel = get_channel_mapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
  1587. } else {
  1588. byIEChannel = sFrame.pDSParms->byCurrChannel;
  1589. }
  1590. if (byCurrChannel != byIEChannel) {
  1591. // adjust channel info. bcs we rcv adjacent channel packets
  1592. bChannelHit = false;
  1593. byCurrChannel = byIEChannel;
  1594. }
  1595. } else {
  1596. // no DS channel info
  1597. bChannelHit = true;
  1598. }
  1599. //2008-0730-01<Add>by MikeLiu
  1600. if (ChannelExceedZoneType(pDevice, byCurrChannel))
  1601. return;
  1602. if (sFrame.pERP != NULL) {
  1603. sERP.byERP = sFrame.pERP->byContext;
  1604. sERP.bERPExist = true;
  1605. } else {
  1606. sERP.bERPExist = false;
  1607. sERP.byERP = 0;
  1608. }
  1609. pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
  1610. if (pBSSList == NULL) {
  1611. pr_debug("Beacon/insert: RxChannel = : %d\n", byCurrChannel);
  1612. BSSbInsertToBSSList((void *)pDevice,
  1613. sFrame.pHdr->sA3.abyAddr3,
  1614. *sFrame.pqwTimestamp,
  1615. *sFrame.pwBeaconInterval,
  1616. *sFrame.pwCapInfo,
  1617. byCurrChannel,
  1618. sFrame.pSSID,
  1619. sFrame.pSuppRates,
  1620. sFrame.pExtSuppRates,
  1621. &sERP,
  1622. sFrame.pRSN,
  1623. sFrame.pRSNWPA,
  1624. sFrame.pIE_Country,
  1625. sFrame.pIE_Quiet,
  1626. sFrame.len - WLAN_HDR_ADDR3_LEN,
  1627. sFrame.pHdr->sA4.abyAddr4, // payload of beacon
  1628. (void *)pRxPacket
  1629. );
  1630. } else {
  1631. BSSbUpdateToBSSList((void *)pDevice,
  1632. *sFrame.pqwTimestamp,
  1633. *sFrame.pwBeaconInterval,
  1634. *sFrame.pwCapInfo,
  1635. byCurrChannel,
  1636. bChannelHit,
  1637. sFrame.pSSID,
  1638. sFrame.pSuppRates,
  1639. sFrame.pExtSuppRates,
  1640. &sERP,
  1641. sFrame.pRSN,
  1642. sFrame.pRSNWPA,
  1643. sFrame.pIE_Country,
  1644. sFrame.pIE_Quiet,
  1645. pBSSList,
  1646. sFrame.len - WLAN_HDR_ADDR3_LEN,
  1647. sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
  1648. (void *)pRxPacket
  1649. );
  1650. }
  1651. if (bInScan)
  1652. return;
  1653. if (byCurrChannel == (unsigned char)pMgmt->uCurrChannel)
  1654. bIsChannelEqual = true;
  1655. if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
  1656. // if rx beacon without ERP field
  1657. if (sERP.bERPExist) {
  1658. if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)) {
  1659. pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
  1660. pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
  1661. }
  1662. } else {
  1663. pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
  1664. pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
  1665. }
  1666. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  1667. if (!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
  1668. pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
  1669. if (!sERP.bERPExist)
  1670. pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
  1671. }
  1672. // set to MAC&BBP
  1673. if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
  1674. if (!pDevice->bProtectMode) {
  1675. MACvEnableProtectMD(pDevice->PortOffset);
  1676. pDevice->bProtectMode = true;
  1677. }
  1678. }
  1679. }
  1680. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
  1681. return;
  1682. // check if BSSID the same
  1683. if (memcmp(sFrame.pHdr->sA3.abyAddr3,
  1684. pMgmt->abyCurrBSSID,
  1685. WLAN_BSSID_LEN) == 0) {
  1686. bIsBSSIDEqual = true;
  1687. // 2008-05-21 <add> by Richardtai
  1688. pDevice->uCurrRSSI = pRxPacket->uRSSI;
  1689. pDevice->byCurrSQ = pRxPacket->bySQ;
  1690. if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
  1691. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  1692. }
  1693. // check if SSID the same
  1694. if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
  1695. if (memcmp(sFrame.pSSID->abySSID,
  1696. ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
  1697. sFrame.pSSID->len
  1698. ) == 0) {
  1699. bIsSSIDEqual = true;
  1700. }
  1701. }
  1702. if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo) &&
  1703. bIsBSSIDEqual &&
  1704. bIsSSIDEqual &&
  1705. (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
  1706. (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
  1707. // add state check to prevent reconnect fail since we'll receive Beacon
  1708. bIsAPBeacon = true;
  1709. if (pBSSList != NULL) {
  1710. // Compare PHY parameter setting
  1711. if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
  1712. bUpdatePhyParameter = true;
  1713. pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
  1714. }
  1715. if (sFrame.pERP != NULL) {
  1716. if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
  1717. (pMgmt->byERPContext != sFrame.pERP->byContext)) {
  1718. bUpdatePhyParameter = true;
  1719. pMgmt->byERPContext = sFrame.pERP->byContext;
  1720. }
  1721. }
  1722. //
  1723. // Basic Rate Set may change dynamically
  1724. //
  1725. if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B)
  1726. uRateLen = WLAN_RATES_MAXLEN_11B;
  1727. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
  1728. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1729. uRateLen);
  1730. pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
  1731. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  1732. uRateLen);
  1733. RATEvParseMaxRate((void *)pDevice,
  1734. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1735. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  1736. true,
  1737. &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
  1738. &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
  1739. &(pMgmt->sNodeDBTable[0].wSuppRate),
  1740. &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
  1741. &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
  1742. );
  1743. if (bUpdatePhyParameter) {
  1744. CARDbSetPhyParameter(pMgmt->pAdapter,
  1745. pMgmt->eCurrentPHYMode,
  1746. pMgmt->wCurrCapInfo,
  1747. pMgmt->byERPContext,
  1748. pMgmt->abyCurrSuppRates,
  1749. pMgmt->abyCurrExtSuppRates
  1750. );
  1751. }
  1752. if (sFrame.pIE_PowerConstraint != NULL) {
  1753. CARDvSetPowerConstraint(pMgmt->pAdapter,
  1754. (unsigned char) pBSSList->uChannel,
  1755. sFrame.pIE_PowerConstraint->byPower
  1756. );
  1757. }
  1758. if (sFrame.pIE_CHSW != NULL) {
  1759. CARDbChannelSwitch(pMgmt->pAdapter,
  1760. sFrame.pIE_CHSW->byMode,
  1761. get_channel_mapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
  1762. sFrame.pIE_CHSW->byCount
  1763. );
  1764. } else if (!bIsChannelEqual) {
  1765. set_channel(pMgmt->pAdapter, pBSSList->uChannel);
  1766. }
  1767. }
  1768. }
  1769. // pr_debug("Beacon 2\n");
  1770. // check if CF field exists
  1771. if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
  1772. if (sFrame.pCFParms->wCFPDurRemaining > 0) {
  1773. // TODO: deal with CFP period to set NAV
  1774. }
  1775. }
  1776. qwTimestamp = le64_to_cpu(*sFrame.pqwTimestamp);
  1777. qwLocalTSF = pRxPacket->qwLocalTSF;
  1778. // check if beacon TSF larger or small than our local TSF
  1779. if (qwTimestamp >= qwLocalTSF)
  1780. bTSFOffsetPostive = true;
  1781. else
  1782. bTSFOffsetPostive = false;
  1783. if (bTSFOffsetPostive)
  1784. qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
  1785. else
  1786. qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
  1787. if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
  1788. bTSFLargeDiff = true;
  1789. // if infra mode
  1790. if (bIsAPBeacon) {
  1791. // Infra mode: Local TSF always follow AP's TSF if Difference huge.
  1792. if (bTSFLargeDiff)
  1793. bUpdateTSF = true;
  1794. if (pDevice->bEnablePSMode && (sFrame.pTIM != NULL)) {
  1795. // deal with DTIM, analysis TIM
  1796. pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false;
  1797. pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
  1798. pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
  1799. wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
  1800. // check if AID in TIM field bit on
  1801. // wStartIndex = N1
  1802. wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
  1803. // AIDIndex = N2
  1804. wAIDIndex = (wAIDNumber >> 3);
  1805. if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
  1806. uLocateByteIndex = wAIDIndex - wStartIndex;
  1807. // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
  1808. if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
  1809. byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
  1810. pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
  1811. } else {
  1812. pMgmt->bInTIM = false;
  1813. }
  1814. } else {
  1815. pMgmt->bInTIM = false;
  1816. }
  1817. if (pMgmt->bInTIM ||
  1818. (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
  1819. pMgmt->bInTIMWake = true;
  1820. // send out ps-poll packet
  1821. if (pMgmt->bInTIM)
  1822. PSvSendPSPOLL(pDevice);
  1823. } else {
  1824. pMgmt->bInTIMWake = false;
  1825. pr_debug("BCN: Not In TIM..\n");
  1826. if (!pDevice->bPWBitOn) {
  1827. pr_debug("BCN: Send Null Packet\n");
  1828. if (PSbSendNullPacket(pDevice))
  1829. pDevice->bPWBitOn = true;
  1830. }
  1831. if (PSbConsiderPowerDown(pDevice, false, false))
  1832. pr_debug("BCN: Power down now...\n");
  1833. }
  1834. }
  1835. }
  1836. // if adhoc mode
  1837. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
  1838. if (bIsBSSIDEqual) {
  1839. // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
  1840. if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
  1841. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  1842. // adhoc mode:TSF updated only when beacon larger than local TSF
  1843. if (bTSFLargeDiff && bTSFOffsetPostive &&
  1844. (pMgmt->eCurrState == WMAC_STATE_JOINTED))
  1845. bUpdateTSF = true;
  1846. // During dpc, already in spinlocked.
  1847. if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
  1848. // Update the STA, (Technically the Beacons of all the IBSS nodes
  1849. // should be identical, but that's not happening in practice.
  1850. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
  1851. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1852. WLAN_RATES_MAXLEN_11B);
  1853. RATEvParseMaxRate((void *)pDevice,
  1854. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1855. NULL,
  1856. true,
  1857. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
  1858. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
  1859. &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
  1860. &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
  1861. &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
  1862. );
  1863. pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
  1864. pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
  1865. pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
  1866. } else {
  1867. // Todo, initial Node content
  1868. BSSvCreateOneNode(pDevice, &uNodeIndex);
  1869. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
  1870. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1871. WLAN_RATES_MAXLEN_11B);
  1872. RATEvParseMaxRate((void *)pDevice,
  1873. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1874. NULL,
  1875. true,
  1876. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
  1877. &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
  1878. &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
  1879. &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
  1880. &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
  1881. );
  1882. memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
  1883. pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
  1884. pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
  1885. {
  1886. pr_debug("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate, uNodeIndex);
  1887. }
  1888. }
  1889. // if other stations joined, indicate connection to upper layer..
  1890. if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
  1891. pr_debug("Current IBSS State: [Started]........to: [Jointed]\n");
  1892. pMgmt->eCurrState = WMAC_STATE_JOINTED;
  1893. pDevice->bLinkPass = true;
  1894. if (netif_queue_stopped(pDevice->dev))
  1895. netif_wake_queue(pDevice->dev);
  1896. pMgmt->sNodeDBTable[0].bActive = true;
  1897. pMgmt->sNodeDBTable[0].uInActiveCount = 0;
  1898. }
  1899. } else if (bIsSSIDEqual) {
  1900. // See other adhoc sta with the same SSID but BSSID is different.
  1901. // adpot this vars only when TSF larger then us.
  1902. if (bTSFLargeDiff && bTSFOffsetPostive) {
  1903. // we don't support ATIM under adhoc mode
  1904. // if (sFrame.pIBSSParms->wATIMWindow == 0) {
  1905. // adpot this vars
  1906. // TODO: check sFrame cap if privacy on, and support rate syn
  1907. memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
  1908. memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  1909. pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
  1910. pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
  1911. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
  1912. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  1913. WLAN_RATES_MAXLEN_11B);
  1914. // set HW beacon interval and re-synchronizing....
  1915. pr_debug("Rejoining to Other Adhoc group with same SSID........\n");
  1916. VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
  1917. CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
  1918. CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
  1919. // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
  1920. MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
  1921. CARDbSetPhyParameter(pMgmt->pAdapter,
  1922. pMgmt->eCurrentPHYMode,
  1923. pMgmt->wCurrCapInfo,
  1924. pMgmt->byERPContext,
  1925. pMgmt->abyCurrSuppRates,
  1926. pMgmt->abyCurrExtSuppRates);
  1927. // Prepare beacon frame
  1928. bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
  1929. }
  1930. }
  1931. }
  1932. // endian issue ???
  1933. // Update TSF
  1934. if (bUpdateTSF) {
  1935. CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
  1936. CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
  1937. CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
  1938. CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
  1939. }
  1940. }
  1941. /*+
  1942. *
  1943. * Routine Description:
  1944. * Instructs the hw to create a bss using the supplied
  1945. * attributes. Note that this implementation only supports Ad-Hoc
  1946. * BSS creation.
  1947. *
  1948. *
  1949. * Return Value:
  1950. * CMD_STATUS
  1951. *
  1952. -*/
  1953. void
  1954. vMgrCreateOwnIBSS(
  1955. void *hDeviceContext,
  1956. PCMD_STATUS pStatus
  1957. )
  1958. {
  1959. struct vnt_private *pDevice = hDeviceContext;
  1960. PSMgmtObject pMgmt = pDevice->pMgmt;
  1961. unsigned short wMaxBasicRate;
  1962. unsigned short wMaxSuppRate;
  1963. unsigned char byTopCCKBasicRate;
  1964. unsigned char byTopOFDMBasicRate;
  1965. u64 qwCurrTSF;
  1966. unsigned int ii;
  1967. unsigned char abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
  1968. unsigned char abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
  1969. unsigned char abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
  1970. unsigned short wSuppRate;
  1971. pr_debug("Create Basic Service Set .......\n");
  1972. if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
  1973. if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
  1974. (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
  1975. (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
  1976. // encryption mode error
  1977. *pStatus = CMD_STATUS_FAILURE;
  1978. return;
  1979. }
  1980. }
  1981. pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
  1982. pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
  1983. if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
  1984. pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
  1985. } else {
  1986. if (pDevice->byBBType == BB_TYPE_11G)
  1987. pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
  1988. if (pDevice->byBBType == BB_TYPE_11B)
  1989. pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
  1990. if (pDevice->byBBType == BB_TYPE_11A)
  1991. pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
  1992. }
  1993. if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
  1994. pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
  1995. pMgmt->abyCurrExtSuppRates[1] = 0;
  1996. for (ii = 0; ii < 4; ii++)
  1997. pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
  1998. } else {
  1999. pMgmt->abyCurrSuppRates[1] = 8;
  2000. pMgmt->abyCurrExtSuppRates[1] = 0;
  2001. for (ii = 0; ii < 8; ii++)
  2002. pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
  2003. }
  2004. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
  2005. pMgmt->abyCurrSuppRates[1] = 8;
  2006. pMgmt->abyCurrExtSuppRates[1] = 4;
  2007. for (ii = 0; ii < 4; ii++)
  2008. pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
  2009. for (ii = 4; ii < 8; ii++)
  2010. pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
  2011. for (ii = 0; ii < 4; ii++)
  2012. pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
  2013. }
  2014. // Disable Protect Mode
  2015. pDevice->bProtectMode = false;
  2016. MACvDisableProtectMD(pDevice->PortOffset);
  2017. pDevice->bBarkerPreambleMd = false;
  2018. MACvDisableBarkerPreambleMd(pDevice->PortOffset);
  2019. // Kyle Test 2003.11.04
  2020. // set HW beacon interval
  2021. if (pMgmt->wIBSSBeaconPeriod == 0)
  2022. pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
  2023. CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
  2024. // clear TSF counter
  2025. VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
  2026. // enable TSF counter
  2027. VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
  2028. // set Next TBTT
  2029. CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
  2030. pMgmt->uIBSSChannel = pDevice->uChannel;
  2031. if (pMgmt->uIBSSChannel == 0)
  2032. pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
  2033. // set basic rate
  2034. RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  2035. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
  2036. &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
  2037. &byTopCCKBasicRate, &byTopOFDMBasicRate);
  2038. if (pMgmt->eConfigMode == WMAC_CONFIG_AP)
  2039. pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
  2040. if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
  2041. memcpy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
  2042. pMgmt->byIBSSDFSRecovery = 10;
  2043. pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
  2044. }
  2045. // Adopt pre-configured IBSS vars to current vars
  2046. pMgmt->eCurrState = WMAC_STATE_STARTED;
  2047. pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
  2048. pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
  2049. pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
  2050. MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
  2051. pDevice->uCurrRSSI = 0;
  2052. pDevice->byCurrSQ = 0;
  2053. memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  2054. memcpy(pMgmt->abyCurrSSID,
  2055. pMgmt->abyDesireSSID,
  2056. ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
  2057. );
  2058. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  2059. // AP mode BSSID = MAC addr
  2060. memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  2061. pr_info("AP beacon created BSSID:%pM\n",
  2062. pMgmt->abyCurrBSSID);
  2063. }
  2064. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  2065. // BSSID selected must be randomized as spec 11.1.3
  2066. pMgmt->abyCurrBSSID[5] = (u8) (qwCurrTSF & 0x000000ff);
  2067. pMgmt->abyCurrBSSID[4] = (u8) ((qwCurrTSF & 0x0000ff00) >> 8);
  2068. pMgmt->abyCurrBSSID[3] = (u8) ((qwCurrTSF & 0x00ff0000) >> 16);
  2069. pMgmt->abyCurrBSSID[2] = (u8) ((qwCurrTSF & 0x00000ff0) >> 4);
  2070. pMgmt->abyCurrBSSID[1] = (u8) ((qwCurrTSF & 0x000ff000) >> 12);
  2071. pMgmt->abyCurrBSSID[0] = (u8) ((qwCurrTSF & 0x0ff00000) >> 20);
  2072. pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
  2073. pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
  2074. pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
  2075. pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
  2076. pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
  2077. pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
  2078. pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
  2079. pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
  2080. pr_info("Adhoc beacon created bssid:%pM\n",
  2081. pMgmt->abyCurrBSSID);
  2082. }
  2083. // Set Capability Info
  2084. pMgmt->wCurrCapInfo = 0;
  2085. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  2086. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
  2087. pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
  2088. pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
  2089. }
  2090. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
  2091. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
  2092. if (pDevice->bEncryptionEnable) {
  2093. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
  2094. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  2095. if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  2096. pMgmt->byCSSPK = KEY_CTL_CCMP;
  2097. pMgmt->byCSSGK = KEY_CTL_CCMP;
  2098. } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  2099. pMgmt->byCSSPK = KEY_CTL_TKIP;
  2100. pMgmt->byCSSGK = KEY_CTL_TKIP;
  2101. } else {
  2102. pMgmt->byCSSPK = KEY_CTL_NONE;
  2103. pMgmt->byCSSGK = KEY_CTL_WEP;
  2104. }
  2105. } else {
  2106. pMgmt->byCSSPK = KEY_CTL_WEP;
  2107. pMgmt->byCSSGK = KEY_CTL_WEP;
  2108. }
  2109. }
  2110. pMgmt->byERPContext = 0;
  2111. if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
  2112. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_AP);
  2113. } else {
  2114. CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
  2115. }
  2116. CARDbSetPhyParameter(pMgmt->pAdapter,
  2117. pMgmt->eCurrentPHYMode,
  2118. pMgmt->wCurrCapInfo,
  2119. pMgmt->byERPContext,
  2120. pMgmt->abyCurrSuppRates,
  2121. pMgmt->abyCurrExtSuppRates
  2122. );
  2123. CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
  2124. // set channel and clear NAV
  2125. set_channel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
  2126. pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
  2127. if (CARDbIsShortPreamble(pMgmt->pAdapter))
  2128. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
  2129. else
  2130. pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
  2131. if (pMgmt->b11hEnable &&
  2132. (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
  2133. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
  2134. } else {
  2135. pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
  2136. }
  2137. pMgmt->eCurrState = WMAC_STATE_STARTED;
  2138. // Prepare beacon to send
  2139. if (bMgrPrepareBeaconToSend((void *)pDevice, pMgmt))
  2140. *pStatus = CMD_STATUS_SUCCESS;
  2141. }
  2142. /*+
  2143. *
  2144. * Routine Description:
  2145. * Instructs wmac to join a bss using the supplied attributes.
  2146. * The arguments may the BSSID or SSID and the rest of the
  2147. * attributes are obtained from the scan result of known bss list.
  2148. *
  2149. *
  2150. * Return Value:
  2151. * None.
  2152. *
  2153. -*/
  2154. void
  2155. vMgrJoinBSSBegin(
  2156. void *hDeviceContext,
  2157. PCMD_STATUS pStatus
  2158. )
  2159. {
  2160. struct vnt_private *pDevice = hDeviceContext;
  2161. PSMgmtObject pMgmt = pDevice->pMgmt;
  2162. PKnownBSS pCurr = NULL;
  2163. unsigned int ii, uu;
  2164. PWLAN_IE_SUPP_RATES pItemRates = NULL;
  2165. PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
  2166. PWLAN_IE_SSID pItemSSID;
  2167. unsigned int uRateLen = WLAN_RATES_MAXLEN;
  2168. unsigned short wMaxBasicRate = RATE_1M;
  2169. unsigned short wMaxSuppRate = RATE_1M;
  2170. unsigned short wSuppRate;
  2171. unsigned char byTopCCKBasicRate = RATE_1M;
  2172. unsigned char byTopOFDMBasicRate = RATE_1M;
  2173. for (ii = 0; ii < MAX_BSS_NUM; ii++) {
  2174. if (pMgmt->sBSSList[ii].bActive)
  2175. break;
  2176. }
  2177. if (ii == MAX_BSS_NUM) {
  2178. *pStatus = CMD_STATUS_RESOURCES;
  2179. pr_info("BSS finding:BSS list is empty\n");
  2180. return;
  2181. }
  2182. // Search known BSS list for prefer BSSID or SSID
  2183. pCurr = BSSpSearchBSSList(pDevice,
  2184. pMgmt->abyDesireBSSID,
  2185. pMgmt->abyDesireSSID,
  2186. pMgmt->eConfigPHYMode
  2187. );
  2188. if (pCurr == NULL) {
  2189. *pStatus = CMD_STATUS_RESOURCES;
  2190. pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
  2191. pr_info("Scanning [%s] not found, disconnected !\n",
  2192. pItemSSID->abySSID);
  2193. return;
  2194. }
  2195. pr_info("AP(BSS) finding:Found a AP(BSS)..\n");
  2196. if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))) {
  2197. if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) || (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
  2198. // patch for CISCO migration mode
  2199. }
  2200. #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
  2201. Encyption_Rebuild(pDevice, pCurr);
  2202. #endif
  2203. // Infrastructure BSS
  2204. s_vMgrSynchBSS(pDevice,
  2205. WMAC_MODE_ESS_STA,
  2206. pCurr,
  2207. pStatus
  2208. );
  2209. if (*pStatus == CMD_STATUS_SUCCESS) {
  2210. // Adopt this BSS state vars in Mgmt Object
  2211. pMgmt->uCurrChannel = pCurr->uChannel;
  2212. memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  2213. memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
  2214. if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B)
  2215. uRateLen = WLAN_RATES_MAXLEN_11B;
  2216. pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
  2217. pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
  2218. // Parse Support Rate IE
  2219. pItemRates->byElementID = WLAN_EID_SUPP_RATES;
  2220. pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
  2221. pItemRates,
  2222. uRateLen);
  2223. // Parse Extension Support Rate IE
  2224. pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
  2225. pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
  2226. pItemExtRates,
  2227. uRateLen);
  2228. // Stuffing Rate IE
  2229. if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
  2230. for (ii = 0; ii < (unsigned int)(8 - pItemRates->len);) {
  2231. pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
  2232. ii++;
  2233. if (pItemExtRates->len <= ii)
  2234. break;
  2235. }
  2236. pItemRates->len += (unsigned char)ii;
  2237. if (pItemExtRates->len - ii > 0) {
  2238. pItemExtRates->len -= (unsigned char)ii;
  2239. for (uu = 0; uu < pItemExtRates->len; uu++)
  2240. pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
  2241. } else {
  2242. pItemExtRates->len = 0;
  2243. }
  2244. }
  2245. RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
  2246. &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
  2247. &byTopCCKBasicRate, &byTopOFDMBasicRate);
  2248. // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
  2249. // TODO: deal with if wCapInfo the PS-Pollable is on.
  2250. pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
  2251. memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  2252. memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
  2253. memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
  2254. pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
  2255. pMgmt->eCurrState = WMAC_STATE_JOINTED;
  2256. // Add current BSS to Candidate list
  2257. // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
  2258. if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
  2259. bool bResult = bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
  2260. pr_debug("bAdd_PMKID_Candidate: 1(%d)\n",
  2261. bResult);
  2262. if (!bResult) {
  2263. vFlush_PMKID_Candidate((void *)pDevice);
  2264. pr_debug("vFlush_PMKID_Candidate: 4\n");
  2265. bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
  2266. }
  2267. }
  2268. // Preamble type auto-switch: if AP can receive short-preamble cap,
  2269. // we can turn on too.
  2270. pr_debug("Join ESS\n");
  2271. pr_debug("End of Join AP -- A/B/G Action\n");
  2272. } else {
  2273. pMgmt->eCurrState = WMAC_STATE_IDLE;
  2274. }
  2275. } else {
  2276. // ad-hoc mode BSS
  2277. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  2278. if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  2279. if (!WPA_SearchRSN(0, WPA_TKIP, pCurr)) {
  2280. // encryption mode error
  2281. pMgmt->eCurrState = WMAC_STATE_IDLE;
  2282. return;
  2283. }
  2284. } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  2285. if (!WPA_SearchRSN(0, WPA_AESCCMP, pCurr)) {
  2286. // encryption mode error
  2287. pMgmt->eCurrState = WMAC_STATE_IDLE;
  2288. return;
  2289. }
  2290. } else {
  2291. // encryption mode error
  2292. pMgmt->eCurrState = WMAC_STATE_IDLE;
  2293. return;
  2294. }
  2295. }
  2296. s_vMgrSynchBSS(pDevice,
  2297. WMAC_MODE_IBSS_STA,
  2298. pCurr,
  2299. pStatus
  2300. );
  2301. if (*pStatus == CMD_STATUS_SUCCESS) {
  2302. // Adopt this BSS state vars in Mgmt Object
  2303. // TODO: check if CapInfo privacy on, but we don't..
  2304. pMgmt->uCurrChannel = pCurr->uChannel;
  2305. // Parse Support Rate IE
  2306. pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
  2307. pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
  2308. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  2309. WLAN_RATES_MAXLEN_11B);
  2310. // set basic rate
  2311. RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  2312. NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
  2313. &byTopCCKBasicRate, &byTopOFDMBasicRate);
  2314. pMgmt->wCurrCapInfo = pCurr->wCapInfo;
  2315. pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
  2316. memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
  2317. memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
  2318. memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
  2319. MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
  2320. pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
  2321. pMgmt->eCurrState = WMAC_STATE_STARTED;
  2322. pr_debug("Join IBSS ok:%pM\n",
  2323. pMgmt->abyCurrBSSID);
  2324. // Preamble type auto-switch: if AP can receive short-preamble cap,
  2325. // and if registry setting is short preamble we can turn on too.
  2326. // Prepare beacon
  2327. bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
  2328. } else {
  2329. pMgmt->eCurrState = WMAC_STATE_IDLE;
  2330. }
  2331. }
  2332. }
  2333. /*+
  2334. *
  2335. * Routine Description:
  2336. * Set HW to synchronize a specific BSS from known BSS list.
  2337. *
  2338. *
  2339. * Return Value:
  2340. * PCM_STATUS
  2341. *
  2342. -*/
  2343. static
  2344. void
  2345. s_vMgrSynchBSS(
  2346. struct vnt_private *pDevice,
  2347. unsigned int uBSSMode,
  2348. PKnownBSS pCurr,
  2349. PCMD_STATUS pStatus
  2350. )
  2351. {
  2352. CARD_PHY_TYPE ePhyType = PHY_TYPE_11B;
  2353. PSMgmtObject pMgmt = pDevice->pMgmt;
  2354. //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
  2355. unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
  2356. unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
  2357. //6M, 9M, 12M, 48M
  2358. unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
  2359. unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
  2360. *pStatus = CMD_STATUS_FAILURE;
  2361. if (!s_bCipherMatch(pCurr,
  2362. pDevice->eEncryptionStatus,
  2363. &(pMgmt->byCSSPK),
  2364. &(pMgmt->byCSSGK))) {
  2365. pr_debug("s_bCipherMatch Fail .......\n");
  2366. return;
  2367. }
  2368. pMgmt->pCurrBSS = pCurr;
  2369. // if previous mode is IBSS.
  2370. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  2371. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
  2372. MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  2373. }
  2374. // Init the BSS informations
  2375. pDevice->bProtectMode = false;
  2376. MACvDisableProtectMD(pDevice->PortOffset);
  2377. pDevice->bBarkerPreambleMd = false;
  2378. MACvDisableBarkerPreambleMd(pDevice->PortOffset);
  2379. pDevice->bNonERPPresent = false;
  2380. pDevice->byPreambleType = 0;
  2381. pDevice->wBasicRate = 0;
  2382. // Set Basic Rate
  2383. CARDbAddBasicRate((void *)pDevice, RATE_1M);
  2384. // calculate TSF offset
  2385. // TSF Offset = Received Timestamp TSF - Marked Local's TSF
  2386. CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
  2387. CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
  2388. // set Next TBTT
  2389. // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
  2390. CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
  2391. // set BSSID
  2392. MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
  2393. MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
  2394. pr_debug("Sync:set CurrBSSID address = %pM\n", pMgmt->abyCurrBSSID);
  2395. if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
  2396. if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
  2397. (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
  2398. ePhyType = PHY_TYPE_11A;
  2399. } else {
  2400. return;
  2401. }
  2402. } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
  2403. if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
  2404. (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
  2405. (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
  2406. ePhyType = PHY_TYPE_11B;
  2407. } else {
  2408. return;
  2409. }
  2410. } else {
  2411. if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
  2412. (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
  2413. ePhyType = PHY_TYPE_11G;
  2414. } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
  2415. ePhyType = PHY_TYPE_11B;
  2416. } else {
  2417. return;
  2418. }
  2419. }
  2420. if (ePhyType == PHY_TYPE_11A) {
  2421. memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
  2422. pMgmt->abyCurrExtSuppRates[1] = 0;
  2423. } else if (ePhyType == PHY_TYPE_11B) {
  2424. memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
  2425. pMgmt->abyCurrExtSuppRates[1] = 0;
  2426. } else {
  2427. memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
  2428. memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
  2429. }
  2430. if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
  2431. CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, NL80211_IFTYPE_STATION);
  2432. // Add current BSS to Candidate list
  2433. // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
  2434. if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
  2435. CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
  2436. } else {
  2437. CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, NL80211_IFTYPE_ADHOC);
  2438. }
  2439. if (!CARDbSetPhyParameter(pMgmt->pAdapter,
  2440. ePhyType,
  2441. pCurr->wCapInfo,
  2442. pCurr->sERP.byERP,
  2443. pMgmt->abyCurrSuppRates,
  2444. pMgmt->abyCurrExtSuppRates)) {
  2445. pr_debug("<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
  2446. return;
  2447. }
  2448. // set channel and clear NAV
  2449. if (!set_channel(pMgmt->pAdapter, pCurr->uChannel)) {
  2450. pr_debug("<----s_bSynchBSS Set Channel [%d]\n",
  2451. pCurr->uChannel);
  2452. return;
  2453. }
  2454. pMgmt->uCurrChannel = pCurr->uChannel;
  2455. pMgmt->eCurrentPHYMode = ePhyType;
  2456. pMgmt->byERPContext = pCurr->sERP.byERP;
  2457. pr_debug("Sync:Set to channel = [%d]\n", (int)pCurr->uChannel);
  2458. *pStatus = CMD_STATUS_SUCCESS;
  2459. return;
  2460. };
  2461. //mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
  2462. // ,need reset eAuthenMode and eEncryptionStatus
  2463. static void Encyption_Rebuild(
  2464. struct vnt_private *pDevice,
  2465. PKnownBSS pCurr
  2466. )
  2467. {
  2468. PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
  2469. if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selection,
  2470. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-select it according to real pairwise-key info.
  2471. if (pCurr->bWPAValid) { //WPA-PSK
  2472. pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
  2473. if (pCurr->abyPKType[0] == WPA_TKIP) {
  2474. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
  2475. PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
  2476. } else if (pCurr->abyPKType[0] == WPA_AESCCMP) {
  2477. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
  2478. PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
  2479. }
  2480. } else if (pCurr->bWPA2Valid) { //WPA2-PSK
  2481. pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
  2482. if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
  2483. pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
  2484. PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
  2485. } else if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
  2486. pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
  2487. PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
  2488. }
  2489. }
  2490. }
  2491. }
  2492. /*+
  2493. *
  2494. * Routine Description:
  2495. * Format TIM field
  2496. *
  2497. *
  2498. * Return Value:
  2499. * void
  2500. *
  2501. -*/
  2502. static
  2503. void
  2504. s_vMgrFormatTIM(
  2505. PSMgmtObject pMgmt,
  2506. PWLAN_IE_TIM pTIM
  2507. )
  2508. {
  2509. unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
  2510. unsigned char byMap;
  2511. unsigned int ii, jj;
  2512. bool bStartFound = false;
  2513. bool bMulticast = false;
  2514. unsigned short wStartIndex = 0;
  2515. unsigned short wEndIndex = 0;
  2516. // Find size of partial virtual bitmap
  2517. for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
  2518. byMap = pMgmt->abyPSTxMap[ii];
  2519. if (!ii) {
  2520. // Mask out the broadcast bit which is indicated separately.
  2521. bMulticast = (byMap & byMask[0]) != 0;
  2522. if (bMulticast)
  2523. pMgmt->sNodeDBTable[0].bRxPSPoll = true;
  2524. byMap = 0;
  2525. }
  2526. if (byMap) {
  2527. if (!bStartFound) {
  2528. bStartFound = true;
  2529. wStartIndex = ii;
  2530. }
  2531. wEndIndex = ii;
  2532. }
  2533. }
  2534. // Round start index down to nearest even number
  2535. wStartIndex &= ~BIT0;
  2536. // Round end index up to nearest even number
  2537. wEndIndex = ((wEndIndex + 1) & ~BIT0);
  2538. // Size of element payload
  2539. pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
  2540. // Fill in the Fixed parts of the TIM
  2541. pTIM->byDTIMCount = pMgmt->byDTIMCount;
  2542. pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
  2543. pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
  2544. (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
  2545. // Append variable part of TIM
  2546. for (ii = wStartIndex, jj = 0; ii <= wEndIndex; ii++, jj++)
  2547. pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
  2548. // Aid = 0 don't used.
  2549. pTIM->byVirtBitMap[0] &= ~BIT0;
  2550. }
  2551. /*+
  2552. *
  2553. * Routine Description:
  2554. * Constructs an Beacon frame(Ad-hoc mode)
  2555. *
  2556. *
  2557. * Return Value:
  2558. * PTR to frame; or NULL on allocation failure
  2559. *
  2560. -*/
  2561. static
  2562. PSTxMgmtPacket
  2563. s_MgrMakeBeacon(
  2564. struct vnt_private *pDevice,
  2565. PSMgmtObject pMgmt,
  2566. unsigned short wCurrCapInfo,
  2567. unsigned short wCurrBeaconPeriod,
  2568. unsigned int uCurrChannel,
  2569. unsigned short wCurrATIMWinodw,
  2570. PWLAN_IE_SSID pCurrSSID,
  2571. unsigned char *pCurrBSSID,
  2572. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  2573. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  2574. )
  2575. {
  2576. PSTxMgmtPacket pTxPacket = NULL;
  2577. WLAN_FR_BEACON sFrame;
  2578. unsigned char abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  2579. unsigned char *pbyBuffer;
  2580. unsigned int uLength = 0;
  2581. PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
  2582. unsigned int ii;
  2583. // prepare beacon frame
  2584. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  2585. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
  2586. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  2587. // Setup the sFrame structure.
  2588. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  2589. sFrame.len = WLAN_BEACON_FR_MAXLEN;
  2590. vMgrEncodeBeacon(&sFrame);
  2591. // Setup the header
  2592. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  2593. (
  2594. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  2595. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
  2596. ));
  2597. if (pDevice->bEnablePSMode)
  2598. sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_PWRMGT(1));
  2599. memcpy(sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
  2600. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  2601. memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
  2602. *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
  2603. *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
  2604. // Copy SSID
  2605. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  2606. sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
  2607. memcpy(sFrame.pSSID,
  2608. pCurrSSID,
  2609. ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
  2610. );
  2611. // Copy the rate set
  2612. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2613. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
  2614. memcpy(sFrame.pSuppRates,
  2615. pCurrSuppRates,
  2616. ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
  2617. );
  2618. // DS parameter
  2619. if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
  2620. sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
  2621. sFrame.len += (1) + WLAN_IEHDR_LEN;
  2622. sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
  2623. sFrame.pDSParms->len = 1;
  2624. sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
  2625. }
  2626. // TIM field
  2627. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  2628. sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
  2629. sFrame.pTIM->byElementID = WLAN_EID_TIM;
  2630. s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
  2631. sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
  2632. }
  2633. if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
  2634. // IBSS parameter
  2635. sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
  2636. sFrame.len += (2) + WLAN_IEHDR_LEN;
  2637. sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
  2638. sFrame.pIBSSParms->len = 2;
  2639. sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
  2640. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  2641. /* RSN parameter */
  2642. sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
  2643. sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
  2644. sFrame.pRSNWPA->len = 12;
  2645. sFrame.pRSNWPA->abyOUI[0] = 0x00;
  2646. sFrame.pRSNWPA->abyOUI[1] = 0x50;
  2647. sFrame.pRSNWPA->abyOUI[2] = 0xf2;
  2648. sFrame.pRSNWPA->abyOUI[3] = 0x01;
  2649. sFrame.pRSNWPA->wVersion = 1;
  2650. sFrame.pRSNWPA->abyMulticast[0] = 0x00;
  2651. sFrame.pRSNWPA->abyMulticast[1] = 0x50;
  2652. sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
  2653. if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
  2654. sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
  2655. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
  2656. sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
  2657. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
  2658. sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
  2659. else
  2660. sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
  2661. // Pairwise Key Cipher Suite
  2662. sFrame.pRSNWPA->wPKCount = 0;
  2663. // Auth Key Management Suite
  2664. *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
  2665. sFrame.pRSNWPA->len += 2;
  2666. // RSN Capabilities
  2667. *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
  2668. sFrame.pRSNWPA->len += 2;
  2669. sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  2670. }
  2671. }
  2672. if (pMgmt->b11hEnable && (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
  2673. // Country IE
  2674. pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
  2675. set_country_IE(pMgmt->pAdapter, pbyBuffer);
  2676. set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
  2677. uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
  2678. pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
  2679. // Power Constrain IE
  2680. ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
  2681. ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
  2682. ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
  2683. pbyBuffer += (1) + WLAN_IEHDR_LEN;
  2684. uLength += (1) + WLAN_IEHDR_LEN;
  2685. if (pMgmt->bSwitchChannel) {
  2686. // Channel Switch IE
  2687. ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
  2688. ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
  2689. ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
  2690. ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
  2691. ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
  2692. pbyBuffer += (3) + WLAN_IEHDR_LEN;
  2693. uLength += (3) + WLAN_IEHDR_LEN;
  2694. }
  2695. // TPC report
  2696. ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
  2697. ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
  2698. ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
  2699. ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
  2700. pbyBuffer += (2) + WLAN_IEHDR_LEN;
  2701. uLength += (2) + WLAN_IEHDR_LEN;
  2702. // IBSS DFS
  2703. if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
  2704. pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
  2705. pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
  2706. pIBSSDFS->len = 7;
  2707. memcpy(pIBSSDFS->abyDFSOwner,
  2708. pMgmt->abyIBSSDFSOwner,
  2709. 6);
  2710. pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
  2711. pbyBuffer += (7) + WLAN_IEHDR_LEN;
  2712. uLength += (7) + WLAN_IEHDR_LEN;
  2713. for (ii = CB_MAX_CHANNEL_24G+1; ii <= CB_MAX_CHANNEL; ii++) {
  2714. if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1)) {
  2715. pbyBuffer += 2;
  2716. uLength += 2;
  2717. pIBSSDFS->len += 2;
  2718. }
  2719. }
  2720. }
  2721. sFrame.len += uLength;
  2722. }
  2723. if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
  2724. sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
  2725. sFrame.len += 1 + WLAN_IEHDR_LEN;
  2726. sFrame.pERP->byElementID = WLAN_EID_ERP;
  2727. sFrame.pERP->len = 1;
  2728. sFrame.pERP->byContext = 0;
  2729. if (pDevice->bProtectMode)
  2730. sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
  2731. if (pDevice->bNonERPPresent)
  2732. sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
  2733. if (pDevice->bBarkerPreambleMd)
  2734. sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
  2735. }
  2736. if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
  2737. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2738. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
  2739. memcpy(sFrame.pExtSuppRates,
  2740. pCurrExtSuppRates,
  2741. ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
  2742. );
  2743. }
  2744. // hostapd wpa/wpa2 IE
  2745. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnableHostapd) {
  2746. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  2747. if (pMgmt->wWPAIELen != 0) {
  2748. sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
  2749. memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
  2750. sFrame.len += pMgmt->wWPAIELen;
  2751. }
  2752. }
  2753. }
  2754. /* Adjust the length fields */
  2755. pTxPacket->cbMPDULen = sFrame.len;
  2756. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  2757. return pTxPacket;
  2758. }
  2759. /*+
  2760. *
  2761. * Routine Description:
  2762. * Constructs an Prob-response frame
  2763. *
  2764. *
  2765. * Return Value:
  2766. * PTR to frame; or NULL on allocation failure
  2767. *
  2768. -*/
  2769. static PSTxMgmtPacket
  2770. s_MgrMakeProbeResponse(
  2771. struct vnt_private *pDevice,
  2772. PSMgmtObject pMgmt,
  2773. unsigned short wCurrCapInfo,
  2774. unsigned short wCurrBeaconPeriod,
  2775. unsigned int uCurrChannel,
  2776. unsigned short wCurrATIMWinodw,
  2777. unsigned char *pDstAddr,
  2778. PWLAN_IE_SSID pCurrSSID,
  2779. unsigned char *pCurrBSSID,
  2780. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  2781. PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
  2782. unsigned char byPHYType
  2783. )
  2784. {
  2785. PSTxMgmtPacket pTxPacket = NULL;
  2786. WLAN_FR_PROBERESP sFrame;
  2787. unsigned char *pbyBuffer;
  2788. unsigned int uLength = 0;
  2789. PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
  2790. unsigned int ii;
  2791. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  2792. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
  2793. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  2794. // Setup the sFrame structure.
  2795. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  2796. sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
  2797. vMgrEncodeProbeResponse(&sFrame);
  2798. // Setup the header
  2799. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  2800. (
  2801. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  2802. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
  2803. ));
  2804. memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
  2805. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  2806. memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
  2807. *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
  2808. *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
  2809. if (byPHYType == BB_TYPE_11B)
  2810. *sFrame.pwCapInfo &= cpu_to_le16((unsigned short)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
  2811. // Copy SSID
  2812. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  2813. sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
  2814. memcpy(sFrame.pSSID,
  2815. pCurrSSID,
  2816. ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
  2817. );
  2818. // Copy the rate set
  2819. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2820. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
  2821. memcpy(sFrame.pSuppRates,
  2822. pCurrSuppRates,
  2823. ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
  2824. );
  2825. // DS parameter
  2826. if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
  2827. sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
  2828. sFrame.len += (1) + WLAN_IEHDR_LEN;
  2829. sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
  2830. sFrame.pDSParms->len = 1;
  2831. sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
  2832. }
  2833. if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
  2834. // IBSS parameter
  2835. sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
  2836. sFrame.len += (2) + WLAN_IEHDR_LEN;
  2837. sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
  2838. sFrame.pIBSSParms->len = 2;
  2839. sFrame.pIBSSParms->wATIMWindow = 0;
  2840. }
  2841. if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
  2842. sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
  2843. sFrame.len += 1 + WLAN_IEHDR_LEN;
  2844. sFrame.pERP->byElementID = WLAN_EID_ERP;
  2845. sFrame.pERP->len = 1;
  2846. sFrame.pERP->byContext = 0;
  2847. if (pDevice->bProtectMode)
  2848. sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
  2849. if (pDevice->bNonERPPresent)
  2850. sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
  2851. if (pDevice->bBarkerPreambleMd)
  2852. sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
  2853. }
  2854. if (pMgmt->b11hEnable && (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
  2855. // Country IE
  2856. pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
  2857. set_country_IE(pMgmt->pAdapter, pbyBuffer);
  2858. set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
  2859. uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
  2860. pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
  2861. // Power Constrain IE
  2862. ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
  2863. ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
  2864. ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
  2865. pbyBuffer += (1) + WLAN_IEHDR_LEN;
  2866. uLength += (1) + WLAN_IEHDR_LEN;
  2867. if (pMgmt->bSwitchChannel) {
  2868. // Channel Switch IE
  2869. ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
  2870. ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
  2871. ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
  2872. ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
  2873. ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
  2874. pbyBuffer += (3) + WLAN_IEHDR_LEN;
  2875. uLength += (3) + WLAN_IEHDR_LEN;
  2876. }
  2877. // TPC report
  2878. ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
  2879. ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
  2880. ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
  2881. ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
  2882. pbyBuffer += (2) + WLAN_IEHDR_LEN;
  2883. uLength += (2) + WLAN_IEHDR_LEN;
  2884. // IBSS DFS
  2885. if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
  2886. pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
  2887. pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
  2888. pIBSSDFS->len = 7;
  2889. memcpy(pIBSSDFS->abyDFSOwner,
  2890. pMgmt->abyIBSSDFSOwner,
  2891. 6);
  2892. pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
  2893. pbyBuffer += (7) + WLAN_IEHDR_LEN;
  2894. uLength += (7) + WLAN_IEHDR_LEN;
  2895. for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CB_MAX_CHANNEL; ii++) {
  2896. if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1)) {
  2897. pbyBuffer += 2;
  2898. uLength += 2;
  2899. pIBSSDFS->len += 2;
  2900. }
  2901. }
  2902. }
  2903. sFrame.len += uLength;
  2904. }
  2905. if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
  2906. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2907. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
  2908. memcpy(sFrame.pExtSuppRates,
  2909. pCurrExtSuppRates,
  2910. ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
  2911. );
  2912. }
  2913. // hostapd wpa/wpa2 IE
  2914. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnableHostapd) {
  2915. if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  2916. if (pMgmt->wWPAIELen != 0) {
  2917. sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
  2918. memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
  2919. sFrame.len += pMgmt->wWPAIELen;
  2920. }
  2921. }
  2922. }
  2923. // Adjust the length fields
  2924. pTxPacket->cbMPDULen = sFrame.len;
  2925. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  2926. return pTxPacket;
  2927. }
  2928. /*+
  2929. *
  2930. * Routine Description:
  2931. * Constructs an association request frame
  2932. *
  2933. *
  2934. * Return Value:
  2935. * A ptr to frame or NULL on allocation failure
  2936. *
  2937. -*/
  2938. static PSTxMgmtPacket
  2939. s_MgrMakeAssocRequest(
  2940. struct vnt_private *pDevice,
  2941. PSMgmtObject pMgmt,
  2942. unsigned char *pDAddr,
  2943. unsigned short wCurrCapInfo,
  2944. unsigned short wListenInterval,
  2945. PWLAN_IE_SSID pCurrSSID,
  2946. PWLAN_IE_SUPP_RATES pCurrRates,
  2947. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  2948. )
  2949. {
  2950. PSTxMgmtPacket pTxPacket = NULL;
  2951. WLAN_FR_ASSOCREQ sFrame;
  2952. unsigned char *pbyIEs;
  2953. unsigned char *pbyRSN;
  2954. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  2955. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
  2956. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  2957. // Setup the sFrame structure.
  2958. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  2959. sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
  2960. // format fixed field frame structure
  2961. vMgrEncodeAssocRequest(&sFrame);
  2962. // Setup the header
  2963. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  2964. (
  2965. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  2966. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
  2967. ));
  2968. memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
  2969. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  2970. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  2971. // Set the capability and listen interval
  2972. *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
  2973. *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
  2974. // sFrame.len point to end of fixed field
  2975. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  2976. sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
  2977. memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
  2978. pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
  2979. pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  2980. pbyIEs = pMgmt->sAssocInfo.abyIEs;
  2981. memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
  2982. pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
  2983. // Copy the rate set
  2984. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2985. if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
  2986. sFrame.len += 4 + WLAN_IEHDR_LEN;
  2987. else
  2988. sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
  2989. memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  2990. // Copy the extension rate set
  2991. if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
  2992. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  2993. sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
  2994. memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
  2995. }
  2996. pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
  2997. memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  2998. pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
  2999. // for 802.11h
  3000. if (pMgmt->b11hEnable) {
  3001. if (sFrame.pCurrPowerCap == NULL) {
  3002. sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
  3003. sFrame.len += (2 + WLAN_IEHDR_LEN);
  3004. sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
  3005. sFrame.pCurrPowerCap->len = 2;
  3006. CARDvGetPowerCapability(pMgmt->pAdapter,
  3007. &(sFrame.pCurrPowerCap->byMinPower),
  3008. &(sFrame.pCurrPowerCap->byMaxPower)
  3009. );
  3010. }
  3011. if (sFrame.pCurrSuppCh == NULL) {
  3012. sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
  3013. sFrame.len += set_support_channels(pMgmt->pAdapter, (unsigned char *)sFrame.pCurrSuppCh);
  3014. }
  3015. }
  3016. if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
  3017. (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
  3018. (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
  3019. (pMgmt->pCurrBSS != NULL)) {
  3020. /* WPA IE */
  3021. sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
  3022. sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
  3023. sFrame.pRSNWPA->len = 16;
  3024. sFrame.pRSNWPA->abyOUI[0] = 0x00;
  3025. sFrame.pRSNWPA->abyOUI[1] = 0x50;
  3026. sFrame.pRSNWPA->abyOUI[2] = 0xf2;
  3027. sFrame.pRSNWPA->abyOUI[3] = 0x01;
  3028. sFrame.pRSNWPA->wVersion = 1;
  3029. //Group Key Cipher Suite
  3030. sFrame.pRSNWPA->abyMulticast[0] = 0x00;
  3031. sFrame.pRSNWPA->abyMulticast[1] = 0x50;
  3032. sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
  3033. if (pMgmt->byCSSGK == KEY_CTL_WEP)
  3034. sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
  3035. else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  3036. sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
  3037. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  3038. sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
  3039. else
  3040. sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
  3041. // Pairwise Key Cipher Suite
  3042. sFrame.pRSNWPA->wPKCount = 1;
  3043. sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
  3044. sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
  3045. sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
  3046. if (pMgmt->byCSSPK == KEY_CTL_TKIP)
  3047. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
  3048. else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
  3049. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
  3050. else
  3051. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
  3052. // Auth Key Management Suite
  3053. pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
  3054. *pbyRSN++ = 0x01;
  3055. *pbyRSN++ = 0x00;
  3056. *pbyRSN++ = 0x00;
  3057. *pbyRSN++ = 0x50;
  3058. *pbyRSN++ = 0xf2;
  3059. if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)
  3060. *pbyRSN++ = WPA_AUTH_PSK;
  3061. else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA)
  3062. *pbyRSN++ = WPA_AUTH_IEEE802_1X;
  3063. else
  3064. *pbyRSN++ = WPA_NONE;
  3065. sFrame.pRSNWPA->len += 6;
  3066. // RSN Capabilities
  3067. *pbyRSN++ = 0x00;
  3068. *pbyRSN++ = 0x00;
  3069. sFrame.pRSNWPA->len += 2;
  3070. sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3071. // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
  3072. pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3073. memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
  3074. pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3075. } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
  3076. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
  3077. (pMgmt->pCurrBSS != NULL)) {
  3078. unsigned int ii;
  3079. unsigned short *pwPMKID;
  3080. // WPA IE
  3081. sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
  3082. sFrame.pRSN->byElementID = WLAN_EID_RSN;
  3083. sFrame.pRSN->len = 6; //Version(2)+GK(4)
  3084. sFrame.pRSN->wVersion = 1;
  3085. //Group Key Cipher Suite
  3086. sFrame.pRSN->abyRSN[0] = 0x00;
  3087. sFrame.pRSN->abyRSN[1] = 0x0F;
  3088. sFrame.pRSN->abyRSN[2] = 0xAC;
  3089. if (pMgmt->byCSSGK == KEY_CTL_WEP)
  3090. sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
  3091. else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  3092. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
  3093. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  3094. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
  3095. else
  3096. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
  3097. // Pairwise Key Cipher Suite
  3098. sFrame.pRSN->abyRSN[4] = 1;
  3099. sFrame.pRSN->abyRSN[5] = 0;
  3100. sFrame.pRSN->abyRSN[6] = 0x00;
  3101. sFrame.pRSN->abyRSN[7] = 0x0F;
  3102. sFrame.pRSN->abyRSN[8] = 0xAC;
  3103. if (pMgmt->byCSSPK == KEY_CTL_TKIP)
  3104. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
  3105. else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
  3106. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
  3107. else if (pMgmt->byCSSPK == KEY_CTL_NONE)
  3108. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
  3109. else
  3110. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
  3111. sFrame.pRSN->len += 6;
  3112. // Auth Key Management Suite
  3113. sFrame.pRSN->abyRSN[10] = 1;
  3114. sFrame.pRSN->abyRSN[11] = 0;
  3115. sFrame.pRSN->abyRSN[12] = 0x00;
  3116. sFrame.pRSN->abyRSN[13] = 0x0F;
  3117. sFrame.pRSN->abyRSN[14] = 0xAC;
  3118. if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)
  3119. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
  3120. else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
  3121. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
  3122. else
  3123. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
  3124. sFrame.pRSN->len += 6;
  3125. // RSN Capabilities
  3126. if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist) {
  3127. memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
  3128. } else {
  3129. sFrame.pRSN->abyRSN[16] = 0;
  3130. sFrame.pRSN->abyRSN[17] = 0;
  3131. }
  3132. sFrame.pRSN->len += 2;
  3133. if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && pDevice->bRoaming && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
  3134. // RSN PMKID
  3135. pbyRSN = &sFrame.pRSN->abyRSN[18];
  3136. pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
  3137. *pwPMKID = 0; // Initialize PMKID count
  3138. pbyRSN += 2; // Point to PMKID list
  3139. for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
  3140. if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
  3141. (*pwPMKID)++;
  3142. memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
  3143. pbyRSN += 16;
  3144. }
  3145. }
  3146. if (*pwPMKID != 0)
  3147. sFrame.pRSN->len += (2 + (*pwPMKID)*16);
  3148. }
  3149. sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3150. // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
  3151. pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3152. memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
  3153. pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3154. }
  3155. // Adjust the length fields
  3156. pTxPacket->cbMPDULen = sFrame.len;
  3157. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  3158. return pTxPacket;
  3159. }
  3160. /*+
  3161. *
  3162. * Routine Description:
  3163. * Constructs an re-association request frame
  3164. *
  3165. *
  3166. * Return Value:
  3167. * A ptr to frame or NULL on allocation failure
  3168. *
  3169. -*/
  3170. static PSTxMgmtPacket
  3171. s_MgrMakeReAssocRequest(
  3172. struct vnt_private *pDevice,
  3173. PSMgmtObject pMgmt,
  3174. unsigned char *pDAddr,
  3175. unsigned short wCurrCapInfo,
  3176. unsigned short wListenInterval,
  3177. PWLAN_IE_SSID pCurrSSID,
  3178. PWLAN_IE_SUPP_RATES pCurrRates,
  3179. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  3180. )
  3181. {
  3182. PSTxMgmtPacket pTxPacket = NULL;
  3183. WLAN_FR_REASSOCREQ sFrame;
  3184. unsigned char *pbyIEs;
  3185. unsigned char *pbyRSN;
  3186. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  3187. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
  3188. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  3189. /* Setup the sFrame structure. */
  3190. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  3191. sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
  3192. // format fixed field frame structure
  3193. vMgrEncodeReassocRequest(&sFrame);
  3194. /* Setup the header */
  3195. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  3196. (
  3197. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  3198. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
  3199. ));
  3200. memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
  3201. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  3202. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  3203. /* Set the capability and listen interval */
  3204. *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
  3205. *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
  3206. memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  3207. /* Copy the SSID */
  3208. /* sFrame.len point to end of fixed field */
  3209. sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
  3210. sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
  3211. memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
  3212. pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
  3213. pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
  3214. pbyIEs = pMgmt->sAssocInfo.abyIEs;
  3215. memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
  3216. pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
  3217. /* Copy the rate set */
  3218. /* sFrame.len point to end of SSID */
  3219. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3220. sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
  3221. memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  3222. // Copy the extension rate set
  3223. if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
  3224. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3225. sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
  3226. memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
  3227. }
  3228. pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
  3229. memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
  3230. pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
  3231. if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
  3232. (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
  3233. (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
  3234. (pMgmt->pCurrBSS != NULL)) {
  3235. /* WPA IE */
  3236. sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
  3237. sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
  3238. sFrame.pRSNWPA->len = 16;
  3239. sFrame.pRSNWPA->abyOUI[0] = 0x00;
  3240. sFrame.pRSNWPA->abyOUI[1] = 0x50;
  3241. sFrame.pRSNWPA->abyOUI[2] = 0xf2;
  3242. sFrame.pRSNWPA->abyOUI[3] = 0x01;
  3243. sFrame.pRSNWPA->wVersion = 1;
  3244. //Group Key Cipher Suite
  3245. sFrame.pRSNWPA->abyMulticast[0] = 0x00;
  3246. sFrame.pRSNWPA->abyMulticast[1] = 0x50;
  3247. sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
  3248. if (pMgmt->byCSSGK == KEY_CTL_WEP)
  3249. sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
  3250. else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  3251. sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
  3252. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  3253. sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
  3254. else
  3255. sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
  3256. // Pairwise Key Cipher Suite
  3257. sFrame.pRSNWPA->wPKCount = 1;
  3258. sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
  3259. sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
  3260. sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
  3261. if (pMgmt->byCSSPK == KEY_CTL_TKIP)
  3262. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
  3263. else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
  3264. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
  3265. else
  3266. sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
  3267. // Auth Key Management Suite
  3268. pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
  3269. *pbyRSN++ = 0x01;
  3270. *pbyRSN++ = 0x00;
  3271. *pbyRSN++ = 0x00;
  3272. *pbyRSN++ = 0x50;
  3273. *pbyRSN++ = 0xf2;
  3274. if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)
  3275. *pbyRSN++ = WPA_AUTH_PSK;
  3276. else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA)
  3277. *pbyRSN++ = WPA_AUTH_IEEE802_1X;
  3278. else
  3279. *pbyRSN++ = WPA_NONE;
  3280. sFrame.pRSNWPA->len += 6;
  3281. // RSN Capabilities
  3282. *pbyRSN++ = 0x00;
  3283. *pbyRSN++ = 0x00;
  3284. sFrame.pRSNWPA->len += 2;
  3285. sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3286. // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
  3287. pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3288. memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
  3289. pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
  3290. } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
  3291. (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
  3292. (pMgmt->pCurrBSS != NULL)) {
  3293. unsigned int ii;
  3294. unsigned short *pwPMKID;
  3295. /* WPA IE */
  3296. sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
  3297. sFrame.pRSN->byElementID = WLAN_EID_RSN;
  3298. sFrame.pRSN->len = 6; //Version(2)+GK(4)
  3299. sFrame.pRSN->wVersion = 1;
  3300. //Group Key Cipher Suite
  3301. sFrame.pRSN->abyRSN[0] = 0x00;
  3302. sFrame.pRSN->abyRSN[1] = 0x0F;
  3303. sFrame.pRSN->abyRSN[2] = 0xAC;
  3304. if (pMgmt->byCSSGK == KEY_CTL_WEP)
  3305. sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
  3306. else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
  3307. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
  3308. else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
  3309. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
  3310. else
  3311. sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
  3312. // Pairwise Key Cipher Suite
  3313. sFrame.pRSN->abyRSN[4] = 1;
  3314. sFrame.pRSN->abyRSN[5] = 0;
  3315. sFrame.pRSN->abyRSN[6] = 0x00;
  3316. sFrame.pRSN->abyRSN[7] = 0x0F;
  3317. sFrame.pRSN->abyRSN[8] = 0xAC;
  3318. if (pMgmt->byCSSPK == KEY_CTL_TKIP)
  3319. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
  3320. else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
  3321. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
  3322. else if (pMgmt->byCSSPK == KEY_CTL_NONE)
  3323. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
  3324. else
  3325. sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
  3326. sFrame.pRSN->len += 6;
  3327. // Auth Key Management Suite
  3328. sFrame.pRSN->abyRSN[10] = 1;
  3329. sFrame.pRSN->abyRSN[11] = 0;
  3330. sFrame.pRSN->abyRSN[12] = 0x00;
  3331. sFrame.pRSN->abyRSN[13] = 0x0F;
  3332. sFrame.pRSN->abyRSN[14] = 0xAC;
  3333. if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)
  3334. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
  3335. else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
  3336. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
  3337. else
  3338. sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
  3339. sFrame.pRSN->len += 6;
  3340. // RSN Capabilities
  3341. if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist) {
  3342. memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
  3343. } else {
  3344. sFrame.pRSN->abyRSN[16] = 0;
  3345. sFrame.pRSN->abyRSN[17] = 0;
  3346. }
  3347. sFrame.pRSN->len += 2;
  3348. if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && pDevice->bRoaming && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
  3349. // RSN PMKID
  3350. pbyRSN = &sFrame.pRSN->abyRSN[18];
  3351. pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
  3352. *pwPMKID = 0; // Initialize PMKID count
  3353. pbyRSN += 2; // Point to PMKID list
  3354. for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
  3355. if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
  3356. (*pwPMKID)++;
  3357. memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
  3358. pbyRSN += 16;
  3359. }
  3360. }
  3361. if (*pwPMKID != 0)
  3362. sFrame.pRSN->len += (2 + (*pwPMKID) * 16);
  3363. }
  3364. sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3365. // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
  3366. pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3367. memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
  3368. pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
  3369. }
  3370. /* Adjust the length fields */
  3371. pTxPacket->cbMPDULen = sFrame.len;
  3372. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  3373. return pTxPacket;
  3374. }
  3375. /*+
  3376. *
  3377. * Routine Description:
  3378. * Constructs an assoc-response frame
  3379. *
  3380. *
  3381. * Return Value:
  3382. * PTR to frame; or NULL on allocation failure
  3383. *
  3384. -*/
  3385. static PSTxMgmtPacket
  3386. s_MgrMakeAssocResponse(
  3387. struct vnt_private *pDevice,
  3388. PSMgmtObject pMgmt,
  3389. unsigned short wCurrCapInfo,
  3390. unsigned short wAssocStatus,
  3391. unsigned short wAssocAID,
  3392. unsigned char *pDstAddr,
  3393. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  3394. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  3395. )
  3396. {
  3397. PSTxMgmtPacket pTxPacket = NULL;
  3398. WLAN_FR_ASSOCRESP sFrame;
  3399. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  3400. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
  3401. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  3402. // Setup the sFrame structure
  3403. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  3404. sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
  3405. vMgrEncodeAssocResponse(&sFrame);
  3406. // Setup the header
  3407. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  3408. (
  3409. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  3410. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
  3411. ));
  3412. memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
  3413. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  3414. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  3415. *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
  3416. *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
  3417. *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
  3418. // Copy the rate set
  3419. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3420. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
  3421. memcpy(sFrame.pSuppRates,
  3422. pCurrSuppRates,
  3423. ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
  3424. );
  3425. if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
  3426. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3427. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
  3428. memcpy(sFrame.pExtSuppRates,
  3429. pCurrExtSuppRates,
  3430. ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
  3431. );
  3432. }
  3433. // Adjust the length fields
  3434. pTxPacket->cbMPDULen = sFrame.len;
  3435. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  3436. return pTxPacket;
  3437. }
  3438. /*+
  3439. *
  3440. * Routine Description:
  3441. * Constructs an reassoc-response frame
  3442. *
  3443. *
  3444. * Return Value:
  3445. * PTR to frame; or NULL on allocation failure
  3446. *
  3447. -*/
  3448. static PSTxMgmtPacket
  3449. s_MgrMakeReAssocResponse(
  3450. struct vnt_private *pDevice,
  3451. PSMgmtObject pMgmt,
  3452. unsigned short wCurrCapInfo,
  3453. unsigned short wAssocStatus,
  3454. unsigned short wAssocAID,
  3455. unsigned char *pDstAddr,
  3456. PWLAN_IE_SUPP_RATES pCurrSuppRates,
  3457. PWLAN_IE_SUPP_RATES pCurrExtSuppRates
  3458. )
  3459. {
  3460. PSTxMgmtPacket pTxPacket = NULL;
  3461. WLAN_FR_REASSOCRESP sFrame;
  3462. pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
  3463. memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
  3464. pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
  3465. // Setup the sFrame structure
  3466. sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
  3467. sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
  3468. vMgrEncodeReassocResponse(&sFrame);
  3469. // Setup the header
  3470. sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
  3471. (
  3472. WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
  3473. WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
  3474. ));
  3475. memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
  3476. memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
  3477. memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
  3478. *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
  3479. *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
  3480. *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
  3481. // Copy the rate set
  3482. sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3483. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
  3484. memcpy(sFrame.pSuppRates,
  3485. pCurrSuppRates,
  3486. ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
  3487. );
  3488. if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
  3489. sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
  3490. sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
  3491. memcpy(sFrame.pExtSuppRates,
  3492. pCurrExtSuppRates,
  3493. ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
  3494. );
  3495. }
  3496. // Adjust the length fields
  3497. pTxPacket->cbMPDULen = sFrame.len;
  3498. pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
  3499. return pTxPacket;
  3500. }
  3501. /*+
  3502. *
  3503. * Routine Description:
  3504. * Handles probe response management frames.
  3505. *
  3506. *
  3507. * Return Value:
  3508. * none.
  3509. *
  3510. -*/
  3511. static
  3512. void
  3513. s_vMgrRxProbeResponse(
  3514. struct vnt_private *pDevice,
  3515. PSMgmtObject pMgmt,
  3516. PSRxMgmtPacket pRxPacket
  3517. )
  3518. {
  3519. PKnownBSS pBSSList = NULL;
  3520. WLAN_FR_PROBERESP sFrame;
  3521. unsigned char byCurrChannel = pRxPacket->byRxChannel;
  3522. ERPObject sERP;
  3523. unsigned char byIEChannel = 0;
  3524. bool bChannelHit = true;
  3525. memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
  3526. // decode the frame
  3527. sFrame.len = pRxPacket->cbMPDULen;
  3528. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  3529. vMgrDecodeProbeResponse(&sFrame);
  3530. if ((sFrame.pqwTimestamp == NULL) ||
  3531. (sFrame.pwBeaconInterval == NULL) ||
  3532. (sFrame.pwCapInfo == NULL) ||
  3533. (sFrame.pSSID == NULL) ||
  3534. (sFrame.pSuppRates == NULL)) {
  3535. pr_debug("Probe resp:Fail addr:[%p]\n",
  3536. pRxPacket->p80211Header);
  3537. DBG_PORT80(0xCC);
  3538. return;
  3539. }
  3540. if (sFrame.pSSID->len == 0)
  3541. pr_debug("Rx Probe resp: SSID len = 0\n");
  3542. if (sFrame.pDSParms != NULL) {
  3543. if (byCurrChannel > CB_MAX_CHANNEL_24G) {
  3544. // channel remapping to
  3545. byIEChannel = get_channel_mapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
  3546. } else {
  3547. byIEChannel = sFrame.pDSParms->byCurrChannel;
  3548. }
  3549. if (byCurrChannel != byIEChannel) {
  3550. // adjust channel info. bcs we rcv adjacent channel packets
  3551. bChannelHit = false;
  3552. byCurrChannel = byIEChannel;
  3553. }
  3554. } else {
  3555. // no DS channel info
  3556. bChannelHit = true;
  3557. }
  3558. //2008-0730-01<Add>by MikeLiu
  3559. if (ChannelExceedZoneType(pDevice, byCurrChannel))
  3560. return;
  3561. if (sFrame.pERP != NULL) {
  3562. sERP.byERP = sFrame.pERP->byContext;
  3563. sERP.bERPExist = true;
  3564. } else {
  3565. sERP.bERPExist = false;
  3566. sERP.byERP = 0;
  3567. }
  3568. // update or insert the bss
  3569. pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
  3570. if (pBSSList) {
  3571. BSSbUpdateToBSSList((void *)pDevice,
  3572. *sFrame.pqwTimestamp,
  3573. *sFrame.pwBeaconInterval,
  3574. *sFrame.pwCapInfo,
  3575. byCurrChannel,
  3576. bChannelHit,
  3577. sFrame.pSSID,
  3578. sFrame.pSuppRates,
  3579. sFrame.pExtSuppRates,
  3580. &sERP,
  3581. sFrame.pRSN,
  3582. sFrame.pRSNWPA,
  3583. sFrame.pIE_Country,
  3584. sFrame.pIE_Quiet,
  3585. pBSSList,
  3586. sFrame.len - WLAN_HDR_ADDR3_LEN,
  3587. sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
  3588. (void *)pRxPacket
  3589. );
  3590. } else {
  3591. pr_debug("Probe resp/insert: RxChannel = : %d\n",
  3592. byCurrChannel);
  3593. BSSbInsertToBSSList((void *)pDevice,
  3594. sFrame.pHdr->sA3.abyAddr3,
  3595. *sFrame.pqwTimestamp,
  3596. *sFrame.pwBeaconInterval,
  3597. *sFrame.pwCapInfo,
  3598. byCurrChannel,
  3599. sFrame.pSSID,
  3600. sFrame.pSuppRates,
  3601. sFrame.pExtSuppRates,
  3602. &sERP,
  3603. sFrame.pRSN,
  3604. sFrame.pRSNWPA,
  3605. sFrame.pIE_Country,
  3606. sFrame.pIE_Quiet,
  3607. sFrame.len - WLAN_HDR_ADDR3_LEN,
  3608. sFrame.pHdr->sA4.abyAddr4, // payload of beacon
  3609. (void *)pRxPacket
  3610. );
  3611. }
  3612. }
  3613. /*+
  3614. *
  3615. * Routine Description:(AP)or(Ad-hoc STA)
  3616. * Handles probe request management frames.
  3617. *
  3618. *
  3619. * Return Value:
  3620. * none.
  3621. *
  3622. -*/
  3623. static
  3624. void
  3625. s_vMgrRxProbeRequest(
  3626. struct vnt_private *pDevice,
  3627. PSMgmtObject pMgmt,
  3628. PSRxMgmtPacket pRxPacket
  3629. )
  3630. {
  3631. WLAN_FR_PROBEREQ sFrame;
  3632. CMD_STATUS Status;
  3633. PSTxMgmtPacket pTxPacket;
  3634. unsigned char byPHYType = BB_TYPE_11B;
  3635. // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
  3636. // STA have to response this request.
  3637. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
  3638. ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
  3639. memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
  3640. // decode the frame
  3641. sFrame.len = pRxPacket->cbMPDULen;
  3642. sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
  3643. vMgrDecodeProbeRequest(&sFrame);
  3644. if (sFrame.pSSID->len != 0) {
  3645. if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
  3646. return;
  3647. if (memcmp(sFrame.pSSID->abySSID,
  3648. ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
  3649. ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
  3650. return;
  3651. }
  3652. }
  3653. if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL))
  3654. byPHYType = BB_TYPE_11G;
  3655. // Probe response reply..
  3656. pTxPacket = s_MgrMakeProbeResponse
  3657. (
  3658. pDevice,
  3659. pMgmt,
  3660. pMgmt->wCurrCapInfo,
  3661. pMgmt->wCurrBeaconPeriod,
  3662. pMgmt->uCurrChannel,
  3663. 0,
  3664. sFrame.pHdr->sA3.abyAddr2,
  3665. (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
  3666. (unsigned char *)pMgmt->abyCurrBSSID,
  3667. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  3668. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
  3669. byPHYType
  3670. );
  3671. if (pTxPacket != NULL) {
  3672. /* send the frame */
  3673. Status = csMgmt_xmit(pDevice, pTxPacket);
  3674. if (Status != CMD_STATUS_PENDING)
  3675. pr_debug("Mgt:Probe response tx failed\n");
  3676. }
  3677. }
  3678. }
  3679. /*+
  3680. *
  3681. * Routine Description:
  3682. *
  3683. * Entry point for the reception and handling of 802.11 management
  3684. * frames. Makes a determination of the frame type and then calls
  3685. * the appropriate function.
  3686. *
  3687. *
  3688. * Return Value:
  3689. * none.
  3690. *
  3691. -*/
  3692. void
  3693. vMgrRxManagePacket(
  3694. void *hDeviceContext,
  3695. PSMgmtObject pMgmt,
  3696. PSRxMgmtPacket pRxPacket
  3697. )
  3698. {
  3699. struct vnt_private *pDevice = hDeviceContext;
  3700. bool bInScan = false;
  3701. unsigned int uNodeIndex = 0;
  3702. NODE_STATE eNodeState = 0;
  3703. CMD_STATUS Status;
  3704. if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
  3705. if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
  3706. eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
  3707. }
  3708. switch (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl))) {
  3709. case WLAN_FSTYPE_ASSOCREQ:
  3710. // Frame Clase = 2
  3711. pr_debug("rx assocreq\n");
  3712. if (eNodeState < NODE_AUTH) {
  3713. // send deauth notification
  3714. // reason = (6) class 2 received from nonauth sta
  3715. vMgrDeAuthenBeginSta(pDevice,
  3716. pMgmt,
  3717. pRxPacket->p80211Header->sA3.abyAddr2,
  3718. (6),
  3719. &Status
  3720. );
  3721. pr_debug("wmgr: send vMgrDeAuthenBeginSta 1\n");
  3722. } else {
  3723. s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
  3724. }
  3725. break;
  3726. case WLAN_FSTYPE_ASSOCRESP:
  3727. // Frame Clase = 2
  3728. pr_debug("rx assocresp1\n");
  3729. s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
  3730. pr_debug("rx assocresp2\n");
  3731. break;
  3732. case WLAN_FSTYPE_REASSOCREQ:
  3733. // Frame Clase = 2
  3734. pr_debug("rx reassocreq\n");
  3735. // Todo: reassoc
  3736. if (eNodeState < NODE_AUTH) {
  3737. // send deauth notification
  3738. // reason = (6) class 2 received from nonauth sta
  3739. vMgrDeAuthenBeginSta(pDevice,
  3740. pMgmt,
  3741. pRxPacket->p80211Header->sA3.abyAddr2,
  3742. (6),
  3743. &Status
  3744. );
  3745. pr_debug("wmgr: send vMgrDeAuthenBeginSta 2\n");
  3746. }
  3747. s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
  3748. break;
  3749. case WLAN_FSTYPE_REASSOCRESP:
  3750. // Frame Clase = 2
  3751. pr_debug("rx reassocresp\n");
  3752. s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
  3753. break;
  3754. case WLAN_FSTYPE_PROBEREQ:
  3755. // Frame Clase = 0
  3756. s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
  3757. break;
  3758. case WLAN_FSTYPE_PROBERESP:
  3759. // Frame Clase = 0
  3760. pr_debug("rx proberesp\n");
  3761. s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
  3762. break;
  3763. case WLAN_FSTYPE_BEACON:
  3764. // Frame Clase = 0
  3765. if (pMgmt->eScanState != WMAC_NO_SCANNING)
  3766. bInScan = true;
  3767. s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
  3768. break;
  3769. case WLAN_FSTYPE_ATIM:
  3770. // Frame Clase = 1
  3771. pr_debug("rx atim\n");
  3772. break;
  3773. case WLAN_FSTYPE_DISASSOC:
  3774. // Frame Clase = 2
  3775. pr_debug("rx disassoc\n");
  3776. if (eNodeState < NODE_AUTH) {
  3777. // send deauth notification
  3778. // reason = (6) class 2 received from nonauth sta
  3779. vMgrDeAuthenBeginSta(pDevice,
  3780. pMgmt,
  3781. pRxPacket->p80211Header->sA3.abyAddr2,
  3782. (6),
  3783. &Status
  3784. );
  3785. pr_debug("wmgr: send vMgrDeAuthenBeginSta 3\n");
  3786. }
  3787. s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
  3788. break;
  3789. case WLAN_FSTYPE_AUTHEN:
  3790. // Frame Clase = 1
  3791. pr_debug("rx authen\n");
  3792. s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
  3793. break;
  3794. case WLAN_FSTYPE_DEAUTHEN:
  3795. // Frame Clase = 1
  3796. pr_debug("rx deauthen\n");
  3797. s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
  3798. break;
  3799. default:
  3800. pr_debug("rx unknown mgmt\n");
  3801. }
  3802. }
  3803. /*+
  3804. *
  3805. * Routine Description:
  3806. *
  3807. *
  3808. * Prepare beacon to send
  3809. *
  3810. * Return Value:
  3811. * true if success; false if failed.
  3812. *
  3813. -*/
  3814. bool
  3815. bMgrPrepareBeaconToSend(
  3816. void *hDeviceContext,
  3817. PSMgmtObject pMgmt
  3818. )
  3819. {
  3820. struct vnt_private *pDevice = hDeviceContext;
  3821. PSTxMgmtPacket pTxPacket;
  3822. if (pDevice->bEncryptionEnable || pDevice->bEnable8021x)
  3823. pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
  3824. else
  3825. pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
  3826. pTxPacket = s_MgrMakeBeacon
  3827. (
  3828. pDevice,
  3829. pMgmt,
  3830. pMgmt->wCurrCapInfo,
  3831. pMgmt->wCurrBeaconPeriod,
  3832. pMgmt->uCurrChannel,
  3833. pMgmt->wCurrATIMWindow,
  3834. (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
  3835. (unsigned char *)pMgmt->abyCurrBSSID,
  3836. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
  3837. (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
  3838. );
  3839. if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
  3840. (pMgmt->abyCurrBSSID[0] == 0))
  3841. return false;
  3842. csBeacon_xmit(pDevice, pTxPacket);
  3843. return true;
  3844. }
  3845. /*+
  3846. *
  3847. * Routine Description:
  3848. *
  3849. * Log a warning message based on the contents of the Status
  3850. * Code field of an 802.11 management frame. Defines are
  3851. * derived from 802.11-1997 SPEC.
  3852. *
  3853. * Return Value:
  3854. * none.
  3855. *
  3856. -*/
  3857. static
  3858. void
  3859. s_vMgrLogStatus(
  3860. PSMgmtObject pMgmt,
  3861. unsigned short wStatus
  3862. )
  3863. {
  3864. switch (wStatus) {
  3865. case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
  3866. pr_info("Status code == Unspecified error\n");
  3867. break;
  3868. case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
  3869. pr_info("Status code == Can't support all requested capabilities\n");
  3870. break;
  3871. case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
  3872. pr_info("Status code == Reassoc denied, can't confirm original Association\n");
  3873. break;
  3874. case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
  3875. pr_info("Status code == Assoc denied, undefine in spec\n");
  3876. break;
  3877. case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
  3878. pr_info("Status code == Peer doesn't support authen algorithm\n");
  3879. break;
  3880. case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
  3881. pr_info("Status code == Authen frame received out of sequence\n");
  3882. break;
  3883. case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
  3884. pr_info("Status code == Authen rejected, challenge failure\n");
  3885. break;
  3886. case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
  3887. pr_info("Status code == Authen rejected, timeout waiting for next frame\n");
  3888. break;
  3889. case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
  3890. pr_info("Status code == Assoc denied, AP too busy\n");
  3891. break;
  3892. case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
  3893. pr_info("Status code == Assoc denied, we haven't enough basic rates\n");
  3894. break;
  3895. case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
  3896. pr_info("Status code == Assoc denied, we do not support short preamble\n");
  3897. break;
  3898. case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
  3899. pr_info("Status code == Assoc denied, we do not support PBCC\n");
  3900. break;
  3901. case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
  3902. pr_info("Status code == Assoc denied, we do not support channel agility\n");
  3903. break;
  3904. default:
  3905. pr_info("Unknown status code %d\n", wStatus);
  3906. break;
  3907. }
  3908. }
  3909. /*
  3910. *
  3911. * Description:
  3912. * Add BSSID in PMKID Candidate list.
  3913. *
  3914. * Parameters:
  3915. * In:
  3916. * hDeviceContext - device structure point
  3917. * pbyBSSID - BSSID address for adding
  3918. * wRSNCap - BSS's RSN capability
  3919. * Out:
  3920. * none
  3921. *
  3922. * Return Value: none.
  3923. *
  3924. -*/
  3925. bool
  3926. bAdd_PMKID_Candidate(
  3927. void *hDeviceContext,
  3928. unsigned char *pbyBSSID,
  3929. PSRSNCapObject psRSNCapObj
  3930. )
  3931. {
  3932. struct vnt_private *pDevice = hDeviceContext;
  3933. struct pmkid_candidate *pCandidateList;
  3934. unsigned int ii = 0;
  3935. pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
  3936. (int)pDevice->gsPMKIDCandidate.NumCandidates);
  3937. if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
  3938. return false;
  3939. if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
  3940. return false;
  3941. // Update Old Candidate
  3942. for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
  3943. pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
  3944. if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
  3945. if (psRSNCapObj->bRSNCapExist && (psRSNCapObj->wRSNCap & BIT0))
  3946. pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
  3947. else
  3948. pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
  3949. return true;
  3950. }
  3951. }
  3952. // New Candidate
  3953. pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
  3954. if (psRSNCapObj->bRSNCapExist && (psRSNCapObj->wRSNCap & BIT0))
  3955. pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
  3956. else
  3957. pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
  3958. memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
  3959. pDevice->gsPMKIDCandidate.NumCandidates++;
  3960. pr_debug("NumCandidates:%d\n",
  3961. (int)pDevice->gsPMKIDCandidate.NumCandidates);
  3962. return true;
  3963. }
  3964. /*
  3965. *
  3966. * Description:
  3967. * Flush PMKID Candidate list.
  3968. *
  3969. * Parameters:
  3970. * In:
  3971. * hDeviceContext - device structure point
  3972. * Out:
  3973. * none
  3974. *
  3975. * Return Value: none.
  3976. *
  3977. -*/
  3978. void
  3979. vFlush_PMKID_Candidate(
  3980. void *hDeviceContext
  3981. )
  3982. {
  3983. struct vnt_private *pDevice = hDeviceContext;
  3984. if (pDevice == NULL)
  3985. return;
  3986. memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
  3987. }
  3988. static bool
  3989. s_bCipherMatch(
  3990. PKnownBSS pBSSNode,
  3991. NDIS_802_11_ENCRYPTION_STATUS EncStatus,
  3992. unsigned char *pbyCCSPK,
  3993. unsigned char *pbyCCSGK
  3994. )
  3995. {
  3996. unsigned char byMulticastCipher = KEY_CTL_INVALID;
  3997. unsigned char byCipherMask = 0x00;
  3998. int i;
  3999. if (pBSSNode == NULL)
  4000. return false;
  4001. // check cap. of BSS
  4002. if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
  4003. (EncStatus == Ndis802_11Encryption1Enabled)) {
  4004. // default is WEP only
  4005. byMulticastCipher = KEY_CTL_WEP;
  4006. }
  4007. if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
  4008. pBSSNode->bWPA2Valid &&
  4009. //20080123-01,<Add> by Einsn Liu
  4010. ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
  4011. //WPA2
  4012. // check Group Key Cipher
  4013. if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
  4014. (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
  4015. byMulticastCipher = KEY_CTL_WEP;
  4016. } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
  4017. byMulticastCipher = KEY_CTL_TKIP;
  4018. } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
  4019. byMulticastCipher = KEY_CTL_CCMP;
  4020. } else {
  4021. byMulticastCipher = KEY_CTL_INVALID;
  4022. }
  4023. // check Pairwise Key Cipher
  4024. for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
  4025. if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
  4026. (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
  4027. // this should not happen as defined 802.11i
  4028. byCipherMask |= 0x01;
  4029. } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
  4030. byCipherMask |= 0x02;
  4031. } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
  4032. byCipherMask |= 0x04;
  4033. } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
  4034. // use group key only ignore all others
  4035. byCipherMask = 0;
  4036. i = pBSSNode->wCSSPKCount;
  4037. }
  4038. }
  4039. } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
  4040. pBSSNode->bWPAValid &&
  4041. ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
  4042. //WPA
  4043. // check Group Key Cipher
  4044. if ((pBSSNode->byGKType == WPA_WEP40) ||
  4045. (pBSSNode->byGKType == WPA_WEP104)) {
  4046. byMulticastCipher = KEY_CTL_WEP;
  4047. } else if (pBSSNode->byGKType == WPA_TKIP) {
  4048. byMulticastCipher = KEY_CTL_TKIP;
  4049. } else if (pBSSNode->byGKType == WPA_AESCCMP) {
  4050. byMulticastCipher = KEY_CTL_CCMP;
  4051. } else {
  4052. byMulticastCipher = KEY_CTL_INVALID;
  4053. }
  4054. // check Pairwise Key Cipher
  4055. for (i = 0; i < pBSSNode->wPKCount; i++) {
  4056. if (pBSSNode->abyPKType[i] == WPA_TKIP) {
  4057. byCipherMask |= 0x02;
  4058. } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
  4059. byCipherMask |= 0x04;
  4060. } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
  4061. // use group key only ignore all others
  4062. byCipherMask = 0;
  4063. i = pBSSNode->wPKCount;
  4064. }
  4065. }
  4066. }
  4067. pr_debug("%d, %d, %d, %d, EncStatus:%d\n",
  4068. byMulticastCipher, byCipherMask,
  4069. pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
  4070. // mask our cap. with BSS
  4071. if (EncStatus == Ndis802_11Encryption1Enabled) {
  4072. // For supporting Cisco migration mode, don't care pairwise key cipher
  4073. if ((byMulticastCipher == KEY_CTL_WEP) &&
  4074. (byCipherMask == 0)) {
  4075. *pbyCCSGK = KEY_CTL_WEP;
  4076. *pbyCCSPK = KEY_CTL_NONE;
  4077. return true;
  4078. } else {
  4079. return false;
  4080. }
  4081. } else if (EncStatus == Ndis802_11Encryption2Enabled) {
  4082. if ((byMulticastCipher == KEY_CTL_TKIP) &&
  4083. (byCipherMask == 0)) {
  4084. *pbyCCSGK = KEY_CTL_TKIP;
  4085. *pbyCCSPK = KEY_CTL_NONE;
  4086. return true;
  4087. } else if ((byMulticastCipher == KEY_CTL_WEP) &&
  4088. ((byCipherMask & 0x02) != 0)) {
  4089. *pbyCCSGK = KEY_CTL_WEP;
  4090. *pbyCCSPK = KEY_CTL_TKIP;
  4091. return true;
  4092. } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
  4093. ((byCipherMask & 0x02) != 0)) {
  4094. *pbyCCSGK = KEY_CTL_TKIP;
  4095. *pbyCCSPK = KEY_CTL_TKIP;
  4096. return true;
  4097. } else {
  4098. return false;
  4099. }
  4100. } else if (EncStatus == Ndis802_11Encryption3Enabled) {
  4101. if ((byMulticastCipher == KEY_CTL_CCMP) &&
  4102. (byCipherMask == 0)) {
  4103. // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
  4104. return false;
  4105. } else if ((byMulticastCipher == KEY_CTL_WEP) &&
  4106. ((byCipherMask & 0x04) != 0)) {
  4107. *pbyCCSGK = KEY_CTL_WEP;
  4108. *pbyCCSPK = KEY_CTL_CCMP;
  4109. return true;
  4110. } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
  4111. ((byCipherMask & 0x04) != 0)) {
  4112. *pbyCCSGK = KEY_CTL_TKIP;
  4113. *pbyCCSPK = KEY_CTL_CCMP;
  4114. return true;
  4115. } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
  4116. ((byCipherMask & 0x04) != 0)) {
  4117. *pbyCCSGK = KEY_CTL_CCMP;
  4118. *pbyCCSPK = KEY_CTL_CCMP;
  4119. return true;
  4120. } else {
  4121. return false;
  4122. }
  4123. }
  4124. return true;
  4125. }