wmgr.c 172 KB

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