wlan_lib.c 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License version 2 as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  10. */
  11. /*******************************************************************************
  12. * C O M P I L E R F L A G S
  13. ********************************************************************************
  14. */
  15. /*******************************************************************************
  16. * E X T E R N A L R E F E R E N C E S
  17. ********************************************************************************
  18. */
  19. #include "precomp.h"
  20. #include "mgmt/ais_fsm.h"
  21. /*******************************************************************************
  22. * C O N S T A N T S
  23. ********************************************************************************
  24. */
  25. /* 6.1.1.2 Interpretation of priority parameter in MAC service primitives */
  26. /* Static convert the Priority Parameter/TID(User Priority/TS Identifier) to Traffic Class */
  27. const UINT_8 aucPriorityParam2TC[] = {
  28. TC1_INDEX,
  29. TC0_INDEX,
  30. TC0_INDEX,
  31. TC1_INDEX,
  32. TC2_INDEX,
  33. TC2_INDEX,
  34. TC3_INDEX,
  35. TC3_INDEX
  36. };
  37. /*******************************************************************************
  38. * D A T A T Y P E S
  39. ********************************************************************************
  40. */
  41. typedef struct _CODE_MAPPING_T {
  42. UINT_32 u4RegisterValue;
  43. INT_32 i4TxpowerOffset;
  44. } CODE_MAPPING_T, *P_CODE_MAPPING_T;
  45. /*******************************************************************************
  46. * P U B L I C D A T A
  47. ********************************************************************************
  48. */
  49. BOOLEAN fgIsBusAccessFailed = FALSE;
  50. /*******************************************************************************
  51. * P R I V A T E D A T A
  52. ********************************************************************************
  53. */
  54. /*******************************************************************************
  55. * M A C R O S
  56. ********************************************************************************
  57. */
  58. #define SIGNED_EXTEND(n, _sValue) \
  59. (((_sValue) & BIT((n)-1)) ? ((_sValue) | BITS(n, 31)) : \
  60. ((_sValue) & ~BITS(n, 31)))
  61. /* TODO: Check */
  62. /* OID set handlers without the need to access HW register */
  63. PFN_OID_HANDLER_FUNC apfnOidSetHandlerWOHwAccess[] = {
  64. wlanoidSetChannel,
  65. wlanoidSetBeaconInterval,
  66. wlanoidSetAtimWindow,
  67. wlanoidSetFrequency,
  68. };
  69. /* TODO: Check */
  70. /* OID query handlers without the need to access HW register */
  71. PFN_OID_HANDLER_FUNC apfnOidQueryHandlerWOHwAccess[] = {
  72. wlanoidQueryBssid,
  73. wlanoidQuerySsid,
  74. wlanoidQueryInfrastructureMode,
  75. wlanoidQueryAuthMode,
  76. wlanoidQueryEncryptionStatus,
  77. wlanoidQueryPmkid,
  78. wlanoidQueryNetworkTypeInUse,
  79. wlanoidQueryBssidList,
  80. wlanoidQueryAcpiDevicePowerState,
  81. wlanoidQuerySupportedRates,
  82. wlanoidQueryDesiredRates,
  83. wlanoidQuery802dot11PowerSaveProfile,
  84. wlanoidQueryBeaconInterval,
  85. wlanoidQueryAtimWindow,
  86. wlanoidQueryFrequency,
  87. };
  88. /* OID set handlers allowed in RF test mode */
  89. PFN_OID_HANDLER_FUNC apfnOidSetHandlerAllowedInRFTest[] = {
  90. wlanoidRftestSetTestMode,
  91. wlanoidRftestSetAbortTestMode,
  92. wlanoidRftestSetAutoTest,
  93. wlanoidSetMcrWrite,
  94. wlanoidSetEepromWrite
  95. };
  96. /* OID query handlers allowed in RF test mode */
  97. PFN_OID_HANDLER_FUNC apfnOidQueryHandlerAllowedInRFTest[] = {
  98. wlanoidRftestQueryAutoTest,
  99. wlanoidQueryMcrRead,
  100. wlanoidQueryEepromRead
  101. }
  102. ;
  103. PFN_OID_HANDLER_FUNC apfnOidWOTimeoutCheck[] = {
  104. wlanoidRftestSetTestMode,
  105. wlanoidRftestSetAbortTestMode,
  106. wlanoidSetAcpiDevicePowerState,
  107. };
  108. /*******************************************************************************
  109. * M A C R O S
  110. ********************************************************************************
  111. */
  112. /*******************************************************************************
  113. * F U N C T I O N D E C L A R A T I O N S
  114. ********************************************************************************
  115. */
  116. /*******************************************************************************
  117. * F U N C T I O N S
  118. ********************************************************************************
  119. */
  120. #if 0 /* no use */
  121. /*----------------------------------------------------------------------------*/
  122. /*!
  123. * \brief This is a private routine, which is used to check if HW access is needed
  124. * for the OID query/ set handlers.
  125. *
  126. * \param[IN] pfnOidHandler Pointer to the OID handler.
  127. * \param[IN] fgSetInfo It is a Set information handler.
  128. *
  129. * \retval TRUE This function needs HW access
  130. * \retval FALSE This function does not need HW access
  131. */
  132. /*----------------------------------------------------------------------------*/
  133. BOOLEAN wlanIsHandlerNeedHwAccess(IN PFN_OID_HANDLER_FUNC pfnOidHandler, IN BOOLEAN fgSetInfo)
  134. {
  135. PFN_OID_HANDLER_FUNC *apfnOidHandlerWOHwAccess;
  136. UINT_32 i;
  137. UINT_32 u4NumOfElem;
  138. if (fgSetInfo) {
  139. apfnOidHandlerWOHwAccess = apfnOidSetHandlerWOHwAccess;
  140. u4NumOfElem = sizeof(apfnOidSetHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
  141. } else {
  142. apfnOidHandlerWOHwAccess = apfnOidQueryHandlerWOHwAccess;
  143. u4NumOfElem = sizeof(apfnOidQueryHandlerWOHwAccess) / sizeof(PFN_OID_HANDLER_FUNC);
  144. }
  145. for (i = 0; i < u4NumOfElem; i++) {
  146. if (apfnOidHandlerWOHwAccess[i] == pfnOidHandler)
  147. return FALSE;
  148. }
  149. return TRUE;
  150. } /* wlanIsHandlerNeedHwAccess */
  151. /*----------------------------------------------------------------------------*/
  152. /*!
  153. * \brief This routine is called to set flag for later handling card
  154. * ejected event.
  155. *
  156. * \param[in] prAdapter Pointer to the Adapter structure.
  157. *
  158. * \return (none)
  159. *
  160. * \note When surprised removal happens, Glue layer should invoke this
  161. * function to notify WPDD not to do any hw access.
  162. */
  163. /*----------------------------------------------------------------------------*/
  164. VOID wlanCardEjected(IN P_ADAPTER_T prAdapter)
  165. {
  166. DEBUGFUNC("wlanCardEjected");
  167. /* INITLOG(("\n")); */
  168. ASSERT(prAdapter);
  169. /* mark that the card is being ejected, NDIS will shut us down soon */
  170. nicTxRelease(prAdapter);
  171. } /* wlanCardEjected */
  172. #endif
  173. /*----------------------------------------------------------------------------*/
  174. /*!
  175. * \brief Create adapter object
  176. *
  177. * \param prAdapter This routine is call to allocate the driver software objects.
  178. * If fails, return NULL.
  179. * \retval NULL If it fails, NULL is returned.
  180. * \retval NOT NULL If the adapter was initialized successfully.
  181. */
  182. /*----------------------------------------------------------------------------*/
  183. P_ADAPTER_T wlanAdapterCreate(IN P_GLUE_INFO_T prGlueInfo)
  184. {
  185. P_ADAPTER_T prAdpater = (P_ADAPTER_T) NULL;
  186. DEBUGFUNC("wlanAdapterCreate");
  187. do {
  188. prAdpater = (P_ADAPTER_T) kalMemAlloc(sizeof(ADAPTER_T), VIR_MEM_TYPE);
  189. if (!prAdpater) {
  190. DBGLOG(INIT, ERROR, "Allocate ADAPTER memory ==> FAILED\n");
  191. break;
  192. }
  193. kalMemZero(prAdpater, sizeof(ADAPTER_T));
  194. prAdpater->prGlueInfo = prGlueInfo;
  195. } while (FALSE);
  196. return prAdpater;
  197. } /* wlanAdapterCreate */
  198. /*----------------------------------------------------------------------------*/
  199. /*!
  200. * \brief Destroy adapter object
  201. *
  202. * \param prAdapter This routine is call to destroy the driver software objects.
  203. * If fails, return NULL.
  204. * \return (none)
  205. */
  206. /*----------------------------------------------------------------------------*/
  207. VOID wlanAdapterDestroy(IN P_ADAPTER_T prAdapter)
  208. {
  209. if (!prAdapter)
  210. return;
  211. kalMemFree(prAdapter, VIR_MEM_TYPE, sizeof(ADAPTER_T));
  212. }
  213. /*----------------------------------------------------------------------------*/
  214. /*!
  215. * \brief Initialize the adapter. The sequence is
  216. * 1. Disable interrupt
  217. * 2. Read adapter configuration from EEPROM and registry, verify chip ID.
  218. * 3. Create NIC Tx/Rx resource.
  219. * 4. Initialize the chip
  220. * 5. Initialize the protocol
  221. * 6. Enable Interrupt
  222. *
  223. * \param prAdapter Pointer of Adapter Data Structure
  224. *
  225. * \retval WLAN_STATUS_SUCCESS: Success
  226. * \retval WLAN_STATUS_FAILURE: Failed
  227. */
  228. /*----------------------------------------------------------------------------*/
  229. WLAN_STATUS
  230. wlanAdapterStart(IN P_ADAPTER_T prAdapter,
  231. IN P_REG_INFO_T prRegInfo, IN PVOID pvFwImageMapFile, IN UINT_32 u4FwImageFileLength)
  232. {
  233. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  234. UINT_32 i, u4Value = 0;
  235. UINT_32 u4WHISR = 0;
  236. UINT_8 aucTxCount[8];
  237. #if CFG_ENABLE_FW_DOWNLOAD
  238. UINT_32 u4FwLoadAddr, u4ImgSecSize;
  239. #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
  240. UINT_32 j;
  241. P_FIRMWARE_DIVIDED_DOWNLOAD_T prFwHead;
  242. BOOLEAN fgValidHead;
  243. const UINT_32 u4CRCOffset = offsetof(FIRMWARE_DIVIDED_DOWNLOAD_T, u4NumOfEntries);
  244. #endif
  245. #endif
  246. enum Adapter_Start_Fail_Reason {
  247. ALLOC_ADAPTER_MEM_FAIL,
  248. DRIVER_OWN_FAIL,
  249. INIT_ADAPTER_FAIL,
  250. RAM_CODE_DOWNLOAD_FAIL,
  251. WAIT_FIRMWARE_READY_FAIL,
  252. FAIL_REASON_MAX
  253. } eFailReason;
  254. ASSERT(prAdapter);
  255. DEBUGFUNC("wlanAdapterStart");
  256. eFailReason = FAIL_REASON_MAX;
  257. /* 4 <0> Reset variables in ADAPTER_T */
  258. prAdapter->fgIsFwOwn = TRUE;
  259. prAdapter->fgIsEnterD3ReqIssued = FALSE;
  260. QUEUE_INITIALIZE(&(prAdapter->rPendingCmdQueue));
  261. /* Initialize rWlanInfo */
  262. kalMemSet(&(prAdapter->rWlanInfo), 0, sizeof(WLAN_INFO_T));
  263. /* 4 <0.1> reset fgIsBusAccessFailed */
  264. fgIsBusAccessFailed = FALSE;
  265. prAdapter->ulSuspendFlag = 0;
  266. do {
  267. u4Status = nicAllocateAdapterMemory(prAdapter);
  268. if (u4Status != WLAN_STATUS_SUCCESS) {
  269. DBGLOG(INIT, ERROR, "nicAllocateAdapterMemory Error!\n");
  270. u4Status = WLAN_STATUS_FAILURE;
  271. eFailReason = ALLOC_ADAPTER_MEM_FAIL;
  272. break;
  273. }
  274. prAdapter->u4OsPacketFilter = PARAM_PACKET_FILTER_SUPPORTED;
  275. DBGLOG(INIT, TRACE, "wlanAdapterStart(): Acquiring LP-OWN %d\n", fgIsResetting);
  276. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  277. #if !CFG_ENABLE_FULL_PM
  278. nicpmSetDriverOwn(prAdapter);
  279. #endif
  280. if (prAdapter->fgIsFwOwn == TRUE) {
  281. DBGLOG(INIT, ERROR, "nicpmSetDriverOwn() failed!\n");
  282. u4Status = WLAN_STATUS_FAILURE;
  283. eFailReason = DRIVER_OWN_FAIL;
  284. break;
  285. }
  286. /* 4 <1> Initialize the Adapter */
  287. u4Status = nicInitializeAdapter(prAdapter);
  288. if (u4Status != WLAN_STATUS_SUCCESS) {
  289. DBGLOG(INIT, ERROR, "nicInitializeAdapter failed!\n");
  290. u4Status = WLAN_STATUS_FAILURE;
  291. eFailReason = INIT_ADAPTER_FAIL;
  292. break;
  293. }
  294. /* init wake lock before interrupt enable and tx thread */
  295. KAL_WAKE_LOCK_INIT(prAdapter, &prAdapter->rTxThreadWakeLock, "WLAN TX THREAD");
  296. /* 4 <2> Initialize System Service (MGMT Memory pool and STA_REC) */
  297. nicInitSystemService(prAdapter);
  298. /* 4 <3> Initialize Tx */
  299. nicTxInitialize(prAdapter);
  300. wlanDefTxPowerCfg(prAdapter);
  301. /* 4 <4> Initialize Rx */
  302. nicRxInitialize(prAdapter);
  303. #if CFG_ENABLE_FW_DOWNLOAD
  304. if (pvFwImageMapFile == NULL) {
  305. DBGLOG(INIT, ERROR, "No Firmware found!\n");
  306. u4Status = WLAN_STATUS_FAILURE;
  307. eFailReason = RAM_CODE_DOWNLOAD_FAIL;
  308. break;
  309. }
  310. /* 1. disable interrupt, download is done by polling mode only */
  311. nicDisableInterrupt(prAdapter);
  312. /* 2. Initialize Tx Resource to fw download state */
  313. nicTxInitResetResource(prAdapter);
  314. /* 3. FW download here */
  315. u4FwLoadAddr = prRegInfo->u4LoadAddress;
  316. #if CFG_ENABLE_FW_DIVIDED_DOWNLOAD
  317. /* 3a. parse file header for decision of divided firmware download or not */
  318. prFwHead = (P_FIRMWARE_DIVIDED_DOWNLOAD_T) pvFwImageMapFile;
  319. if (prFwHead->u4Signature == MTK_WIFI_SIGNATURE &&
  320. prFwHead->u4CRC == wlanCRC32((PUINT_8) pvFwImageMapFile + u4CRCOffset,
  321. u4FwImageFileLength - u4CRCOffset)) {
  322. fgValidHead = TRUE;
  323. } else {
  324. fgValidHead = FALSE;
  325. }
  326. /* 3b. engage divided firmware downloading */
  327. if (fgValidHead == TRUE) {
  328. DBGLOG(INIT, TRACE, "wlanAdapterStart(): fgValidHead == TRUE\n");
  329. for (i = 0; i < prFwHead->u4NumOfEntries; i++) {
  330. #if CFG_START_ADDRESS_IS_1ST_SECTION_ADDR
  331. if (i == 0) {
  332. prRegInfo->u4StartAddress = prFwHead->arSection[i].u4DestAddr;
  333. DBGLOG(INIT, TRACE,
  334. "wlanAdapterStart(): FW start address 0x%08x\n",
  335. prRegInfo->u4StartAddress);
  336. }
  337. #endif
  338. #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
  339. if (wlanImageSectionDownloadAggregated(prAdapter,
  340. prFwHead->arSection[i].u4DestAddr,
  341. prFwHead->arSection[i].u4Length,
  342. (PUINT_8) pvFwImageMapFile +
  343. prFwHead->arSection[i].u4Offset) !=
  344. WLAN_STATUS_SUCCESS) {
  345. DBGLOG(INIT, ERROR, "Firmware scatter download failed!\n");
  346. u4Status = WLAN_STATUS_FAILURE;
  347. }
  348. #else
  349. for (j = 0; j < prFwHead->arSection[i].u4Length; j += CMD_PKT_SIZE_FOR_IMAGE) {
  350. if (j + CMD_PKT_SIZE_FOR_IMAGE < prFwHead->arSection[i].u4Length)
  351. u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
  352. else
  353. u4ImgSecSize = prFwHead->arSection[i].u4Length - j;
  354. if (wlanImageSectionDownload(prAdapter,
  355. prFwHead->arSection[i].u4DestAddr + j,
  356. u4ImgSecSize,
  357. (PUINT_8) pvFwImageMapFile +
  358. prFwHead->arSection[i].u4Offset + j) !=
  359. WLAN_STATUS_SUCCESS) {
  360. DBGLOG(INIT, ERROR,
  361. "Firmware scatter download failed %d!\n", (int)i);
  362. u4Status = WLAN_STATUS_FAILURE;
  363. break;
  364. }
  365. }
  366. #endif
  367. /* escape from loop if any pending error occurs */
  368. if (u4Status == WLAN_STATUS_FAILURE)
  369. break;
  370. }
  371. } else
  372. #endif
  373. #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
  374. if (wlanImageSectionDownloadAggregated(prAdapter,
  375. u4FwLoadAddr,
  376. u4FwImageFileLength,
  377. (PUINT_8) pvFwImageMapFile) !=
  378. WLAN_STATUS_SUCCESS) {
  379. DBGLOG(INIT, ERROR, "Firmware scatter download failed!\n");
  380. u4Status = WLAN_STATUS_FAILURE;
  381. }
  382. #else
  383. for (i = 0; i < u4FwImageFileLength; i += CMD_PKT_SIZE_FOR_IMAGE) {
  384. if (i + CMD_PKT_SIZE_FOR_IMAGE < u4FwImageFileLength)
  385. u4ImgSecSize = CMD_PKT_SIZE_FOR_IMAGE;
  386. else
  387. u4ImgSecSize = u4FwImageFileLength - i;
  388. if (wlanImageSectionDownload(prAdapter,
  389. u4FwLoadAddr + i,
  390. u4ImgSecSize,
  391. (PUINT_8) pvFwImageMapFile + i) !=
  392. WLAN_STATUS_SUCCESS) {
  393. DBGLOG(INIT, ERROR, "Firmware scatter download failed!\n");
  394. u4Status = WLAN_STATUS_FAILURE;
  395. break;
  396. }
  397. }
  398. #endif
  399. if (u4Status != WLAN_STATUS_SUCCESS) {
  400. eFailReason = RAM_CODE_DOWNLOAD_FAIL;
  401. break;
  402. }
  403. #if !CFG_ENABLE_FW_DOWNLOAD_ACK
  404. /* Send INIT_CMD_ID_QUERY_PENDING_ERROR command and wait for response */
  405. if (wlanImageQueryStatus(prAdapter) != WLAN_STATUS_SUCCESS) {
  406. DBGLOG(INIT, ERROR, "Firmware download failed!\n");
  407. u4Status = WLAN_STATUS_FAILURE;
  408. break;
  409. }
  410. #endif
  411. /* 4. send Wi-Fi Start command */
  412. DBGLOG(INIT, INFO, "<wifi> send Wi-Fi Start command\n");
  413. #if CFG_OVERRIDE_FW_START_ADDRESS
  414. wlanConfigWifiFunc(prAdapter, TRUE, prRegInfo->u4StartAddress);
  415. #else
  416. wlanConfigWifiFunc(prAdapter, FALSE, 0);
  417. #endif
  418. #endif
  419. DBGLOG(INIT, TRACE, "wlanAdapterStart(): Waiting for Ready bit..\n");
  420. /* 4 <5> check Wi-Fi FW asserts ready bit */
  421. i = 0;
  422. while (1) {
  423. HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
  424. if (u4Value & WCIR_WLAN_READY) {
  425. DBGLOG(INIT, TRACE, "Ready bit asserted\n");
  426. break;
  427. } else if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE || fgIsBusAccessFailed == TRUE) {
  428. u4Status = WLAN_STATUS_FAILURE;
  429. eFailReason = WAIT_FIRMWARE_READY_FAIL;
  430. break;
  431. } else if (i >= CFG_RESPONSE_POLLING_TIMEOUT) {
  432. UINT_32 u4MailBox0;
  433. nicGetMailbox(prAdapter, 0, &u4MailBox0);
  434. DBGLOG(INIT, ERROR, "Waiting for Ready bit: Timeout, ID=%u\n",
  435. (u4MailBox0 & 0x0000FFFF));
  436. u4Status = WLAN_STATUS_FAILURE;
  437. eFailReason = WAIT_FIRMWARE_READY_FAIL;
  438. break;
  439. }
  440. i++;
  441. kalMsleep(10);
  442. }
  443. if (u4Status == WLAN_STATUS_SUCCESS) {
  444. /* 1. reset interrupt status */
  445. HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
  446. if (HAL_IS_TX_DONE_INTR(u4WHISR))
  447. HAL_READ_TX_RELEASED_COUNT(prAdapter, aucTxCount);
  448. /* 2. reset TX Resource for normal operation */
  449. nicTxResetResource(prAdapter);
  450. /* 3. query for permanent address by polling */
  451. wlanQueryPermanentAddress(prAdapter);
  452. #if (CFG_SUPPORT_NIC_CAPABILITY == 1)
  453. /* 4. query for NIC capability */
  454. wlanQueryNicCapability(prAdapter);
  455. #endif
  456. /* 4.1 query for compiler flags */
  457. wlanQueryCompileFlags(prAdapter);
  458. /* 5. Override network address */
  459. wlanUpdateNetworkAddress(prAdapter);
  460. /* 6. indicate disconnection as default status */
  461. kalIndicateStatusAndComplete(prAdapter->prGlueInfo, WLAN_STATUS_MEDIA_DISCONNECT, NULL, 0);
  462. }
  463. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  464. if (u4Status != WLAN_STATUS_SUCCESS) {
  465. eFailReason = WAIT_FIRMWARE_READY_FAIL;
  466. break;
  467. }
  468. /* OID timeout timer initialize */
  469. cnmTimerInitTimer(prAdapter,
  470. &prAdapter->rOidTimeoutTimer,
  471. (PFN_MGMT_TIMEOUT_FUNC) wlanReleasePendingOid, (ULONG) NULL);
  472. /* Return Indicated Rfb list timer */
  473. cnmTimerInitTimer(prAdapter,
  474. &prAdapter->rReturnIndicatedRfbListTimer,
  475. (PFN_MGMT_TIMEOUT_FUNC) wlanReturnIndicatedPacketsTimeOut, (ULONG) NULL);
  476. /* Power state initialization */
  477. prAdapter->fgWiFiInSleepyState = FALSE;
  478. prAdapter->rAcpiState = ACPI_STATE_D0;
  479. /* Online scan option */
  480. if (prRegInfo->fgDisOnlineScan == 0)
  481. prAdapter->fgEnOnlineScan = TRUE;
  482. else
  483. prAdapter->fgEnOnlineScan = FALSE;
  484. /* Beacon lost detection option */
  485. if (prRegInfo->fgDisBcnLostDetection != 0)
  486. prAdapter->fgDisBcnLostDetection = TRUE;
  487. /* Load compile time constant */
  488. prAdapter->rWlanInfo.u2BeaconPeriod = CFG_INIT_ADHOC_BEACON_INTERVAL;
  489. prAdapter->rWlanInfo.u2AtimWindow = CFG_INIT_ADHOC_ATIM_WINDOW;
  490. #if 1 /* set PM parameters */
  491. prAdapter->fgEnArpFilter = prRegInfo->fgEnArpFilter;
  492. prAdapter->u4PsCurrentMeasureEn = prRegInfo->u4PsCurrentMeasureEn;
  493. prAdapter->u4UapsdAcBmp = prRegInfo->u4UapsdAcBmp;
  494. prAdapter->u4MaxSpLen = prRegInfo->u4MaxSpLen;
  495. DBGLOG(INIT, TRACE, "[1] fgEnArpFilter:0x%x, u4UapsdAcBmp:0x%x, u4MaxSpLen:0x%x",
  496. prAdapter->fgEnArpFilter, prAdapter->u4UapsdAcBmp, prAdapter->u4MaxSpLen);
  497. prAdapter->fgEnCtiaPowerMode = FALSE;
  498. #if CFG_SUPPORT_DBG_POWERMODE
  499. prAdapter->fgEnDbgPowerMode = FALSE;
  500. #endif
  501. #endif
  502. /* MGMT Initialization */
  503. nicInitMGMT(prAdapter, prRegInfo);
  504. /* Enable WZC Disassociation */
  505. prAdapter->rWifiVar.fgSupportWZCDisassociation = TRUE;
  506. /* Apply Rate Setting */
  507. if ((ENUM_REGISTRY_FIXED_RATE_T) (prRegInfo->u4FixedRate) < FIXED_RATE_NUM)
  508. prAdapter->rWifiVar.eRateSetting = (ENUM_REGISTRY_FIXED_RATE_T) (prRegInfo->u4FixedRate);
  509. else
  510. prAdapter->rWifiVar.eRateSetting = FIXED_RATE_NONE;
  511. if (prAdapter->rWifiVar.eRateSetting == FIXED_RATE_NONE) {
  512. /* Enable Auto (Long/Short) Preamble */
  513. prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_AUTO;
  514. } else if ((prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_20M_400NS &&
  515. prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS7_20M_400NS)
  516. || (prAdapter->rWifiVar.eRateSetting >= FIXED_RATE_MCS0_40M_400NS &&
  517. prAdapter->rWifiVar.eRateSetting <= FIXED_RATE_MCS32_400NS)) {
  518. /* Force Short Preamble */
  519. prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_SHORT;
  520. } else {
  521. /* Force Long Preamble */
  522. prAdapter->rWifiVar.ePreambleType = PREAMBLE_TYPE_LONG;
  523. }
  524. /* Disable Hidden SSID Join */
  525. prAdapter->rWifiVar.fgEnableJoinToHiddenSSID = FALSE;
  526. /* Enable Short Slot Time */
  527. prAdapter->rWifiVar.fgIsShortSlotTimeOptionEnable = TRUE;
  528. /* configure available PHY type set */
  529. nicSetAvailablePhyTypeSet(prAdapter);
  530. #if 1 /* set PM parameters */
  531. {
  532. #if CFG_SUPPORT_PWR_MGT
  533. prAdapter->u4PowerMode = prRegInfo->u4PowerMode;
  534. prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucNetTypeIndex =
  535. NETWORK_TYPE_P2P_INDEX;
  536. prAdapter->rWlanInfo.arPowerSaveMode[NETWORK_TYPE_P2P_INDEX].ucPsProfile = ENUM_PSP_FAST_SWITCH;
  537. #else
  538. prAdapter->u4PowerMode = ENUM_PSP_CONTINUOUS_ACTIVE;
  539. #endif
  540. nicConfigPowerSaveProfile(prAdapter, NETWORK_TYPE_AIS_INDEX, /* FIXIT */
  541. prAdapter->u4PowerMode, FALSE);
  542. }
  543. #endif
  544. #if CFG_SUPPORT_NVRAM
  545. /* load manufacture data */
  546. wlanLoadManufactureData(prAdapter, prRegInfo);
  547. #endif
  548. #ifdef CONFIG_MTK_TC1_FEATURE /* 1 //keep alive packet time change from default 30secs to 20secs. //TC01// */
  549. {
  550. CMD_SW_DBG_CTRL_T rCmdSwCtrl;
  551. rCmdSwCtrl.u4Id = 0x90100000;
  552. rCmdSwCtrl.u4Data = 30;
  553. DBGLOG(INIT, TRACE, "wlanAdapterStart Keepaliveapcket 0x%x, %d\n",
  554. rCmdSwCtrl.u4Id, rCmdSwCtrl.u4Data);
  555. wlanSendSetQueryCmd(prAdapter,
  556. CMD_ID_SW_DBG_CTRL,
  557. TRUE,
  558. FALSE,
  559. FALSE,
  560. NULL, NULL, sizeof(CMD_SW_DBG_CTRL_T), (PUINT_8) (&rCmdSwCtrl), NULL, 0);
  561. }
  562. #endif
  563. #if 0
  564. /* Update Auto rate parameters in FW */
  565. nicRlmArUpdateParms(prAdapter,
  566. prRegInfo->u4ArSysParam0,
  567. prRegInfo->u4ArSysParam1, prRegInfo->u4ArSysParam2, prRegInfo->u4ArSysParam3);
  568. #endif
  569. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  570. /* clock gating workaround */
  571. prAdapter->fgIsClockGatingEnabled = FALSE;
  572. #endif
  573. } while (FALSE);
  574. if (u4Status == WLAN_STATUS_SUCCESS) {
  575. /* restore to hardware default */
  576. HAL_SET_INTR_STATUS_READ_CLEAR(prAdapter);
  577. HAL_SET_MAILBOX_READ_CLEAR(prAdapter, FALSE);
  578. /* Enable interrupt */
  579. nicEnableInterrupt(prAdapter);
  580. } else {
  581. /* release allocated memory */
  582. switch (eFailReason) {
  583. case WAIT_FIRMWARE_READY_FAIL:
  584. DBGLOG(INIT, ERROR, "Wait firmware ready fail, FailReason: %d\n",
  585. eFailReason);
  586. g_IsNeedDoChipReset = 1;
  587. kalSendAeeWarning("[Wait firmware ready fail!]", __func__);
  588. KAL_WAKE_LOCK_DESTROY(prAdapter, &prAdapter->rTxThreadWakeLock);
  589. nicRxUninitialize(prAdapter);
  590. nicTxRelease(prAdapter);
  591. /* System Service Uninitialization */
  592. nicUninitSystemService(prAdapter);
  593. nicReleaseAdapterMemory(prAdapter);
  594. break;
  595. case RAM_CODE_DOWNLOAD_FAIL:
  596. DBGLOG(INIT, ERROR, "Ram code download fail, FailReason: %d\n",
  597. eFailReason);
  598. g_IsNeedDoChipReset = 1;
  599. kalSendAeeWarning("[Ram code download fail!]", __func__);
  600. KAL_WAKE_LOCK_DESTROY(prAdapter, &prAdapter->rTxThreadWakeLock);
  601. nicRxUninitialize(prAdapter);
  602. nicTxRelease(prAdapter);
  603. /* System Service Uninitialization */
  604. nicUninitSystemService(prAdapter);
  605. nicReleaseAdapterMemory(prAdapter);
  606. break;
  607. case INIT_ADAPTER_FAIL:
  608. nicReleaseAdapterMemory(prAdapter);
  609. break;
  610. case DRIVER_OWN_FAIL:
  611. nicReleaseAdapterMemory(prAdapter);
  612. break;
  613. case ALLOC_ADAPTER_MEM_FAIL:
  614. break;
  615. default:
  616. break;
  617. }
  618. }
  619. return u4Status;
  620. } /* wlanAdapterStart */
  621. /*----------------------------------------------------------------------------*/
  622. /*!
  623. * \brief Uninitialize the adapter
  624. *
  625. * \param prAdapter Pointer of Adapter Data Structure
  626. *
  627. * \retval WLAN_STATUS_SUCCESS: Success
  628. * \retval WLAN_STATUS_FAILURE: Failed
  629. */
  630. /*----------------------------------------------------------------------------*/
  631. WLAN_STATUS wlanAdapterStop(IN P_ADAPTER_T prAdapter)
  632. {
  633. UINT_32 i, u4Value = 0;
  634. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  635. ASSERT(prAdapter);
  636. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  637. if (prAdapter->fgIsClockGatingEnabled == TRUE)
  638. nicDisableClockGating(prAdapter);
  639. #endif
  640. /* MGMT - unitialization */
  641. nicUninitMGMT(prAdapter);
  642. if (prAdapter->rAcpiState == ACPI_STATE_D0 &&
  643. #if (CFG_CHIP_RESET_SUPPORT == 1)
  644. kalIsResetting() == FALSE &&
  645. #endif
  646. kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
  647. /* 0. Disable interrupt, this can be done without Driver own */
  648. nicDisableInterrupt(prAdapter);
  649. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  650. /* 1. Set CMD to FW to tell WIFI to stop (enter power off state) */
  651. /* the command must be issue to firmware even in wlanRemove() */
  652. if (prAdapter->fgIsFwOwn == FALSE && wlanSendNicPowerCtrlCmd(prAdapter, 1) == WLAN_STATUS_SUCCESS) {
  653. /* 2. Clear pending interrupt */
  654. i = 0;
  655. while (i < CFG_IST_LOOP_COUNT && nicProcessIST(prAdapter) != WLAN_STATUS_NOT_INDICATING) {
  656. i++;
  657. };
  658. /* 3. Wait til RDY bit has been cleaerd */
  659. i = 0;
  660. while (1) {
  661. HAL_MCR_RD(prAdapter, MCR_WCIR, &u4Value);
  662. if ((u4Value & WCIR_WLAN_READY) == 0)
  663. break;
  664. else if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE
  665. || fgIsBusAccessFailed == TRUE || i >= CFG_RESPONSE_POLLING_TIMEOUT) {
  666. g_IsNeedDoChipReset = 1;
  667. kalSendAeeWarning("[Read WCIR_WLAN_READY fail!]", __func__);
  668. break;
  669. }
  670. i++;
  671. kalMsleep(10);
  672. }
  673. }
  674. /* 4. Set Onwership to F/W */
  675. nicpmSetFWOwn(prAdapter, FALSE);
  676. #if CFG_FORCE_RESET_UNDER_BUS_ERROR
  677. if (HAL_TEST_FLAG(prAdapter, ADAPTER_FLAG_HW_ERR) == TRUE) {
  678. /* force acquire firmware own */
  679. kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_CLR);
  680. /* delay for 10ms */
  681. kalMdelay(10);
  682. /* force firmware reset via software interrupt */
  683. kalDevRegWrite(prAdapter->prGlueInfo, MCR_WSICR, WSICR_H2D_SW_INT_SET);
  684. /* force release firmware own */
  685. kalDevRegWrite(prAdapter->prGlueInfo, MCR_WHLPCR, WHLPCR_FW_OWN_REQ_SET);
  686. }
  687. #endif
  688. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  689. }
  690. nicRxUninitialize(prAdapter);
  691. nicTxRelease(prAdapter);
  692. /* System Service Uninitialization */
  693. nicUninitSystemService(prAdapter);
  694. nicReleaseAdapterMemory(prAdapter);
  695. #if defined(_HIF_SPI)
  696. /* Note: restore the SPI Mode Select from 32 bit to default */
  697. nicRestoreSpiDefMode(prAdapter);
  698. #endif
  699. return u4Status;
  700. } /* wlanAdapterStop */
  701. #if 0
  702. /*----------------------------------------------------------------------------*/
  703. /*!
  704. * \brief This function is called by ISR (interrupt).
  705. *
  706. * \param prAdapter Pointer of Adapter Data Structure
  707. *
  708. * \retval TRUE: NIC's interrupt
  709. * \retval FALSE: Not NIC's interrupt
  710. */
  711. /*----------------------------------------------------------------------------*/
  712. BOOLEAN wlanISR(IN P_ADAPTER_T prAdapter, IN BOOLEAN fgGlobalIntrCtrl)
  713. {
  714. ASSERT(prAdapter);
  715. if (fgGlobalIntrCtrl) {
  716. nicDisableInterrupt(prAdapter);
  717. /* wlanIST(prAdapter); */
  718. }
  719. return TRUE;
  720. }
  721. #endif
  722. /*----------------------------------------------------------------------------*/
  723. /*!
  724. * \brief This function is called by IST (task_let).
  725. *
  726. * \param prAdapter Pointer of Adapter Data Structure
  727. *
  728. * \return (none)
  729. */
  730. /*----------------------------------------------------------------------------*/
  731. VOID wlanIST(IN P_ADAPTER_T prAdapter)
  732. {
  733. ASSERT(prAdapter);
  734. /* wake up CONNSYS */
  735. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  736. /* handle interrupts */
  737. nicProcessIST(prAdapter);
  738. /* re-enable HIF interrupts */
  739. nicEnableInterrupt(prAdapter);
  740. /* CONNSYS can decide to sleep */
  741. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  742. }
  743. /*----------------------------------------------------------------------------*/
  744. /*!
  745. * \brief This function will check command queue to find out if any could be dequeued
  746. * and/or send to HIF to MT6620
  747. *
  748. * \param prAdapter Pointer of Adapter Data Structure
  749. * \param prCmdQue Pointer of Command Queue (in Glue Layer)
  750. *
  751. * \retval WLAN_STATUS_SUCCESS
  752. */
  753. /*----------------------------------------------------------------------------*/
  754. WLAN_STATUS wlanProcessCommandQueue(IN P_ADAPTER_T prAdapter, IN P_QUE_T prCmdQue)
  755. {
  756. WLAN_STATUS rStatus;
  757. QUE_T rTempCmdQue, rMergeCmdQue, rStandInCmdQue;
  758. P_QUE_T prTempCmdQue, prMergeCmdQue, prStandInCmdQue;
  759. P_QUE_ENTRY_T prQueueEntry;
  760. P_CMD_INFO_T prCmdInfo;
  761. P_MSDU_INFO_T prMsduInfo;
  762. ENUM_FRAME_ACTION_T eFrameAction = FRAME_ACTION_DROP_PKT;
  763. KAL_SPIN_LOCK_DECLARATION();
  764. /* sanity check */
  765. ASSERT(prAdapter);
  766. ASSERT(prCmdQue);
  767. /* init */
  768. prTempCmdQue = &rTempCmdQue;
  769. prMergeCmdQue = &rMergeCmdQue;
  770. prStandInCmdQue = &rStandInCmdQue;
  771. QUEUE_INITIALIZE(prTempCmdQue);
  772. QUEUE_INITIALIZE(prMergeCmdQue);
  773. QUEUE_INITIALIZE(prStandInCmdQue);
  774. /* 4 <1> Move whole list of CMD_INFO to the temp queue */
  775. /* copy all commands to prTempCmdQue and empty prCmdQue */
  776. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
  777. QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
  778. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
  779. /* 4 <2> Dequeue from head and check it is able to be sent */
  780. /* remove the first one */
  781. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  782. while (prQueueEntry) {
  783. prCmdInfo = (P_CMD_INFO_T) prQueueEntry;
  784. /* check how to handle the command: drop, queue, or tx */
  785. switch (prCmdInfo->eCmdType) {
  786. case COMMAND_TYPE_GENERAL_IOCTL:
  787. case COMMAND_TYPE_NETWORK_IOCTL:
  788. /* command packet will be always sent */
  789. eFrameAction = FRAME_ACTION_TX_PKT;
  790. break;
  791. case COMMAND_TYPE_SECURITY_FRAME:
  792. /* inquire with QM */
  793. eFrameAction = qmGetFrameAction(prAdapter,
  794. prCmdInfo->eNetworkType,
  795. prCmdInfo->ucStaRecIndex, NULL, FRAME_TYPE_802_1X);
  796. break;
  797. case COMMAND_TYPE_MANAGEMENT_FRAME:
  798. /* inquire with QM */
  799. prMsduInfo = (P_MSDU_INFO_T) (prCmdInfo->prPacket);
  800. eFrameAction = qmGetFrameAction(prAdapter,
  801. prMsduInfo->ucNetworkType,
  802. prMsduInfo->ucStaRecIndex, prMsduInfo, FRAME_TYPE_MMPDU);
  803. break;
  804. default:
  805. ASSERT(0);
  806. break;
  807. }
  808. /* 4 <3> handling upon dequeue result */
  809. if (eFrameAction == FRAME_ACTION_DROP_PKT) {
  810. if (prCmdInfo->eCmdType == COMMAND_TYPE_SECURITY_FRAME)
  811. DBGLOG(TX, WARN, "Drop Security frame seqNo=%d\n",
  812. prCmdInfo->ucCmdSeqNum);
  813. wlanReleaseCommand(prAdapter, prCmdInfo);
  814. } else if (eFrameAction == FRAME_ACTION_QUEUE_PKT) {
  815. if (prCmdInfo->eCmdType == COMMAND_TYPE_SECURITY_FRAME)
  816. DBGLOG(TX, INFO, "Queue Security frame seqNo=%d\n",
  817. prCmdInfo->ucCmdSeqNum);
  818. QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
  819. } else if (eFrameAction == FRAME_ACTION_TX_PKT) {
  820. /* 4 <4> Send the command */
  821. rStatus = wlanSendCommand(prAdapter, prCmdInfo);
  822. if (rStatus == WLAN_STATUS_RESOURCES) {
  823. /* no more TC4 resource for further transmission */
  824. QUEUE_INSERT_TAIL(prMergeCmdQue, prQueueEntry);
  825. DBGLOG(TX, WARN, "No TC4 resource to send cmd, CID=0x%x, SEQ=%d, CMD type=%d, OID=%d\n",
  826. prCmdInfo->ucCID, prCmdInfo->ucCmdSeqNum,
  827. prCmdInfo->eCmdType, prCmdInfo->fgIsOid);
  828. break;
  829. } else if (rStatus == WLAN_STATUS_PENDING) {
  830. /* command packet which needs further handling upon response */
  831. /* i.e. we need to wait for FW's response */
  832. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  833. QUEUE_INSERT_TAIL(&(prAdapter->rPendingCmdQueue), prQueueEntry);
  834. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  835. } else {
  836. /* send success or fail */
  837. P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T) prQueueEntry;
  838. if (rStatus == WLAN_STATUS_SUCCESS) {
  839. /* send success */
  840. if (prCmdInfo->pfCmdDoneHandler) {
  841. prCmdInfo->pfCmdDoneHandler(prAdapter, prCmdInfo,
  842. prCmdInfo->pucInfoBuffer);
  843. }
  844. } else {
  845. /* send fail */
  846. if (prCmdInfo->fgIsOid) {
  847. kalOidComplete(prAdapter->prGlueInfo, prCmdInfo->fgSetQuery,
  848. prCmdInfo->u4SetInfoLen, rStatus);
  849. }
  850. DBGLOG(TX, WARN, "Send CMD, status=%u, CID=%d, SEQ=%d, CMD type=%d, OID=%d\n",
  851. rStatus, prCmdInfo->ucCID, prCmdInfo->ucCmdSeqNum,
  852. prCmdInfo->eCmdType, prCmdInfo->fgIsOid);
  853. }
  854. /* free the command memory */
  855. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  856. }
  857. } else {
  858. /* impossible, wrong eFrameAction */
  859. ASSERT(0);
  860. }
  861. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  862. }
  863. /* 4 <3> Merge back to original queue */
  864. /* 4 <3.1> Merge prMergeCmdQue & prTempCmdQue */
  865. QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prTempCmdQue);
  866. /* 4 <3.2> Move prCmdQue to prStandInQue, due to prCmdQue might differ due to incoming 802.1X frames */
  867. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
  868. /* ??? here, prCmdQue shall be empty, why QUEUE_MOVE_ALL ??? */
  869. QUEUE_MOVE_ALL(prStandInCmdQue, prCmdQue);
  870. /* 4 <3.3> concatenate prStandInQue to prMergeCmdQue */
  871. QUEUE_CONCATENATE_QUEUES(prMergeCmdQue, prStandInCmdQue);
  872. /* 4 <3.4> then move prMergeCmdQue to prCmdQue */
  873. QUEUE_MOVE_ALL(prCmdQue, prMergeCmdQue);
  874. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_QUE);
  875. return WLAN_STATUS_SUCCESS;
  876. } /* end of wlanProcessCommandQueue() */
  877. /*----------------------------------------------------------------------------*/
  878. /*!
  879. * \brief This function will take CMD_INFO_T which carry some information of
  880. * incoming OID and notify the NIC_TX to send CMD.
  881. *
  882. * \param prAdapter Pointer of Adapter Data Structure
  883. * \param prCmdInfo Pointer of P_CMD_INFO_T
  884. *
  885. * \retval WLAN_STATUS_SUCCESS : CMD was written to HIF and be freed(CMD Done) immediately.
  886. * \retval WLAN_STATUS_RESOURCE : No resource for current command, need to wait for previous
  887. * frame finishing their transmission.
  888. * \retval WLAN_STATUS_FAILURE : Get failure while access HIF or been rejected.
  889. */
  890. /*----------------------------------------------------------------------------*/
  891. WLAN_STATUS wlanSendCommand(IN P_ADAPTER_T prAdapter, IN P_CMD_INFO_T prCmdInfo)
  892. {
  893. P_TX_CTRL_T prTxCtrl;
  894. UINT_8 ucTC; /* "Traffic Class" SW(Driver) resource classification */
  895. WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
  896. BOOLEAN pfgIsSecOrMgmt = FALSE;
  897. /* sanity check */
  898. ASSERT(prAdapter);
  899. ASSERT(prCmdInfo);
  900. /* init */
  901. prTxCtrl = &prAdapter->rTxCtrl;
  902. /* DbgPrint("wlanSendCommand()\n"); */
  903. /* */
  904. /* */
  905. #if DBG && 0
  906. LOG_FUNC("wlanSendCommand()\n");
  907. LOG_FUNC("CmdType %u NetworkType %u StaRecIndex %u Oid %u CID 0x%x SetQuery %u NeedResp %u CmdSeqNum %u\n",
  908. prCmdInfo->eCmdType,
  909. prCmdInfo->eNetworkType,
  910. prCmdInfo->ucStaRecIndex,
  911. prCmdInfo->fgIsOid,
  912. prCmdInfo->ucCID, prCmdInfo->fgSetQuery, prCmdInfo->fgNeedResp, prCmdInfo->ucCmdSeqNum);
  913. #endif
  914. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  915. if (prAdapter->fgIsClockGatingEnabled == TRUE)
  916. nicDisableClockGating(prAdapter);
  917. #endif
  918. do {
  919. /* <0> card removal check */
  920. if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE || fgIsBusAccessFailed == TRUE) {
  921. rStatus = WLAN_STATUS_FAILURE;
  922. break;
  923. }
  924. /* <1> Normal case of sending CMD Packet */
  925. if (!prCmdInfo->fgDriverDomainMCR) {
  926. /* <1.1> Assign Traffic Class(TC) = TC4. */
  927. ucTC = TC4_INDEX;
  928. if ((prCmdInfo->eCmdType == COMMAND_TYPE_SECURITY_FRAME) ||
  929. (prCmdInfo->eCmdType == COMMAND_TYPE_MANAGEMENT_FRAME))
  930. pfgIsSecOrMgmt = TRUE;
  931. wlanReadFwStatus(prAdapter);
  932. /* <1.2> Check if pending packet or resource was exhausted */
  933. rStatus = nicTxAcquireResource(prAdapter, ucTC, pfgIsSecOrMgmt);
  934. if (rStatus == WLAN_STATUS_RESOURCES) {
  935. DbgPrint("NO Resource:%d\n", ucTC);
  936. break;
  937. }
  938. /* <1.3> Forward CMD_INFO_T to NIC Layer */
  939. rStatus = nicTxCmd(prAdapter, prCmdInfo, ucTC);
  940. /* <1.4> Set Pending in response to Query Command/Need Response */
  941. if (rStatus == WLAN_STATUS_SUCCESS) {
  942. if ((!prCmdInfo->fgSetQuery) || (prCmdInfo->fgNeedResp))
  943. rStatus = WLAN_STATUS_PENDING;
  944. }
  945. }
  946. /* <2> "Special case" for access Driver Domain MCR */
  947. else {
  948. P_CMD_ACCESS_REG prCmdAccessReg;
  949. prCmdAccessReg = (P_CMD_ACCESS_REG) (prCmdInfo->pucInfoBuffer + CMD_HDR_SIZE);
  950. if (prCmdInfo->fgSetQuery) {
  951. /* address is in DWORD unit */
  952. HAL_MCR_WR(prAdapter, (prCmdAccessReg->u4Address & BITS(2, 31)),
  953. prCmdAccessReg->u4Data);
  954. } else {
  955. P_CMD_ACCESS_REG prEventAccessReg;
  956. UINT_32 u4Address;
  957. u4Address = prCmdAccessReg->u4Address;
  958. prEventAccessReg = (P_CMD_ACCESS_REG) prCmdInfo->pucInfoBuffer;
  959. prEventAccessReg->u4Address = u4Address;
  960. /* address is in DWORD unit */
  961. HAL_MCR_RD(prAdapter, prEventAccessReg->u4Address & BITS(2, 31),
  962. &prEventAccessReg->u4Data);
  963. }
  964. }
  965. } while (FALSE);
  966. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  967. if (prAdapter->fgIsClockGatingEnabled == FALSE)
  968. nicEnableClockGating(prAdapter);
  969. #endif
  970. return rStatus;
  971. } /* end of wlanSendCommand() */
  972. /*----------------------------------------------------------------------------*/
  973. /*!
  974. * \brief This function will release thd CMD_INFO upon its attribution
  975. *
  976. * \param prAdapter Pointer of Adapter Data Structure
  977. * \param prCmdInfo Pointer of CMD_INFO_T
  978. *
  979. * \return (none)
  980. */
  981. /*----------------------------------------------------------------------------*/
  982. VOID wlanReleaseCommand(IN P_ADAPTER_T prAdapter, IN P_CMD_INFO_T prCmdInfo)
  983. {
  984. P_TX_CTRL_T prTxCtrl;
  985. P_MSDU_INFO_T prMsduInfo;
  986. ASSERT(prAdapter);
  987. ASSERT(prCmdInfo);
  988. prTxCtrl = &prAdapter->rTxCtrl;
  989. switch (prCmdInfo->eCmdType) {
  990. case COMMAND_TYPE_GENERAL_IOCTL:
  991. case COMMAND_TYPE_NETWORK_IOCTL:
  992. if (prCmdInfo->fgIsOid) {
  993. /* for OID command, we need to do complete() to wake up kalIoctl() */
  994. kalOidComplete(prAdapter->prGlueInfo,
  995. prCmdInfo->fgSetQuery, prCmdInfo->u4SetInfoLen, WLAN_STATUS_FAILURE);
  996. }
  997. break;
  998. case COMMAND_TYPE_SECURITY_FRAME:
  999. /* free packets in kalSecurityFrameSendComplete() */
  1000. kalSecurityFrameSendComplete(prAdapter->prGlueInfo, prCmdInfo->prPacket, WLAN_STATUS_FAILURE);
  1001. break;
  1002. case COMMAND_TYPE_MANAGEMENT_FRAME:
  1003. prMsduInfo = (P_MSDU_INFO_T) prCmdInfo->prPacket;
  1004. /* invoke callbacks */
  1005. if (prMsduInfo->pfTxDoneHandler != NULL)
  1006. prMsduInfo->pfTxDoneHandler(prAdapter, prMsduInfo, TX_RESULT_DROPPED_IN_DRIVER);
  1007. GLUE_DEC_REF_CNT(prTxCtrl->i4TxMgmtPendingNum);
  1008. cnmMgtPktFree(prAdapter, prMsduInfo);
  1009. break;
  1010. default:
  1011. /* impossible, shall not be here */
  1012. ASSERT(0);
  1013. break;
  1014. }
  1015. /* free command buffer and return the command header to command pool */
  1016. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1017. } /* end of wlanReleaseCommand() */
  1018. /*----------------------------------------------------------------------------*/
  1019. /*!
  1020. * \brief This function will search the CMD Queue to look for the pending OID and
  1021. * compelete it immediately when system request a reset.
  1022. *
  1023. * \param prAdapter ointer of Adapter Data Structure
  1024. *
  1025. * \return (none)
  1026. */
  1027. /*----------------------------------------------------------------------------*/
  1028. VOID wlanReleasePendingOid(IN P_ADAPTER_T prAdapter, IN ULONG ulData)
  1029. {
  1030. P_QUE_T prCmdQue;
  1031. QUE_T rTempCmdQue;
  1032. P_QUE_T prTempCmdQue = &rTempCmdQue;
  1033. P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T) NULL;
  1034. P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T) NULL;
  1035. KAL_SPIN_LOCK_DECLARATION();
  1036. DEBUGFUNC("wlanReleasePendingOid");
  1037. ASSERT(prAdapter);
  1038. DBGLOG(OID, ERROR, "OID Timeout! Releasing pending OIDs ..\n");
  1039. do {
  1040. /* 1: Handle OID commands in pending queue */
  1041. /* Clear Pending OID in prAdapter->rPendingCmdQueue */
  1042. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  1043. /* move all pending commands to prTempCmdQue and empty prCmdQue */
  1044. prCmdQue = &prAdapter->rPendingCmdQueue;
  1045. QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
  1046. /* get first pending command */
  1047. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  1048. while (prQueueEntry) {
  1049. prCmdInfo = (P_CMD_INFO_T) prQueueEntry;
  1050. if (prCmdInfo->fgIsOid) {
  1051. if (prCmdInfo->pfCmdTimeoutHandler) {
  1052. prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
  1053. } else {
  1054. /* send complete() to wake up kalIoctl() */
  1055. kalOidComplete(prAdapter->prGlueInfo,
  1056. prCmdInfo->fgSetQuery, 0, WLAN_STATUS_FAILURE);
  1057. }
  1058. /* free command memory */
  1059. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1060. } else {
  1061. /* nothing to do so re-queue it to prCmdQue */
  1062. QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
  1063. }
  1064. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  1065. }
  1066. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  1067. /* 2: Clear pending OID staying in command queue */
  1068. kalOidCmdClearance(prAdapter->prGlueInfo);
  1069. /* 3: Do complete(), do we need this? because we have completed in kalOidComplete */
  1070. kalOidClearance(prAdapter->prGlueInfo);
  1071. } while (FALSE);
  1072. }
  1073. /*----------------------------------------------------------------------------*/
  1074. /*!
  1075. * \brief This function will search the CMD Queue to look for the pending CMD/OID for specific
  1076. * NETWORK TYPE and compelete it immediately when system request a reset.
  1077. *
  1078. * \param prAdapter ointer of Adapter Data Structure
  1079. *
  1080. * \return (none)
  1081. */
  1082. /*----------------------------------------------------------------------------*/
  1083. VOID wlanReleasePendingCMDbyNetwork(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_INDEX_T eNetworkType)
  1084. {
  1085. P_QUE_T prCmdQue;
  1086. QUE_T rTempCmdQue;
  1087. P_QUE_T prTempCmdQue = &rTempCmdQue;
  1088. P_QUE_ENTRY_T prQueueEntry = (P_QUE_ENTRY_T) NULL;
  1089. P_CMD_INFO_T prCmdInfo = (P_CMD_INFO_T) NULL;
  1090. KAL_SPIN_LOCK_DECLARATION();
  1091. ASSERT(prAdapter);
  1092. /* only free commands from the network interface, AIS, P2P, or BOW */
  1093. do {
  1094. /* 1: Clear Pending OID in prAdapter->rPendingCmdQueue */
  1095. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  1096. prCmdQue = &prAdapter->rPendingCmdQueue;
  1097. QUEUE_MOVE_ALL(prTempCmdQue, prCmdQue);
  1098. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  1099. while (prQueueEntry) {
  1100. prCmdInfo = (P_CMD_INFO_T) prQueueEntry;
  1101. DBGLOG(P2P, TRACE, "Pending CMD for Network Type:%d\n", prCmdInfo->eNetworkType);
  1102. if (prCmdInfo->eNetworkType == eNetworkType) {
  1103. if (prCmdInfo->pfCmdTimeoutHandler) {
  1104. prCmdInfo->pfCmdTimeoutHandler(prAdapter, prCmdInfo);
  1105. } else
  1106. kalOidComplete(prAdapter->prGlueInfo,
  1107. prCmdInfo->fgSetQuery, 0, WLAN_STATUS_FAILURE);
  1108. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1109. } else {
  1110. QUEUE_INSERT_TAIL(prCmdQue, prQueueEntry);
  1111. }
  1112. QUEUE_REMOVE_HEAD(prTempCmdQue, prQueueEntry, P_QUE_ENTRY_T);
  1113. }
  1114. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_PENDING);
  1115. } while (FALSE);
  1116. } /* wlanReleasePendingCMDbyNetwork */
  1117. /*----------------------------------------------------------------------------*/
  1118. /*!
  1119. * \brief Return the packet buffer and reallocate one to the RFB
  1120. *
  1121. * \param prAdapter Pointer of Adapter Data Structure
  1122. * \param pvPacket Pointer of returned packet
  1123. *
  1124. * \retval WLAN_STATUS_SUCCESS: Success
  1125. * \retval WLAN_STATUS_FAILURE: Failed
  1126. */
  1127. /*----------------------------------------------------------------------------*/
  1128. VOID wlanReturnPacket(IN P_ADAPTER_T prAdapter, IN PVOID pvPacket)
  1129. {
  1130. P_RX_CTRL_T prRxCtrl;
  1131. P_SW_RFB_T prSwRfb = NULL;
  1132. BOOLEAN fgIsUninitRfb = FALSE;
  1133. KAL_SPIN_LOCK_DECLARATION();
  1134. DEBUGFUNC("wlanReturnPacket");
  1135. ASSERT(prAdapter);
  1136. prRxCtrl = &prAdapter->rRxCtrl;
  1137. ASSERT(prRxCtrl);
  1138. /* free the packet */
  1139. if (pvPacket) {
  1140. kalPacketFree(prAdapter->prGlueInfo, pvPacket);
  1141. RX_ADD_CNT(prRxCtrl, RX_DATA_RETURNED_COUNT, 1);
  1142. #if CFG_NATIVE_802_11
  1143. if (GLUE_TEST_FLAG(prAdapter->prGlueInfo, GLUE_FLAG_HALT)) {
  1144. /*Todo:: nothing*/
  1145. /*Todo:: nothing*/
  1146. }
  1147. #endif
  1148. }
  1149. /* free the packet control block */
  1150. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
  1151. QUEUE_REMOVE_HEAD(&prRxCtrl->rIndicatedRfbList, prSwRfb, P_SW_RFB_T);
  1152. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
  1153. if (!prSwRfb) {
  1154. ASSERT(0);
  1155. return;
  1156. }
  1157. if (nicRxSetupRFB(prAdapter, prSwRfb)) {
  1158. ASSERT(0);
  1159. /* return; // Don't return here or it would lost SwRfb --kc */
  1160. if (!timerPendingTimer(&prAdapter->rReturnIndicatedRfbListTimer)) {
  1161. DBGLOG(RX, WARN,
  1162. "wlanReturnPacket, Start ReturnIndicatedRfbList Timer (%ds)\n",
  1163. RX_RETURN_INDICATED_RFB_TIMEOUT_SEC);
  1164. cnmTimerStartTimer(prAdapter, &prAdapter->rReturnIndicatedRfbListTimer,
  1165. SEC_TO_MSEC(RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
  1166. }
  1167. fgIsUninitRfb = TRUE;
  1168. }
  1169. nicRxReturnRFBwithUninit(prAdapter, prSwRfb, fgIsUninitRfb);
  1170. }
  1171. /*----------------------------------------------------------------------------*/
  1172. /*!
  1173. * \brief Return the indicated packet buffer and reallocate one to the RFB
  1174. *
  1175. * \param prAdapter Pointer of Adapter Data Structure
  1176. * \param pvPacket Pointer of returned packet
  1177. *
  1178. * \retval WLAN_STATUS_SUCCESS: Success
  1179. * \retval WLAN_STATUS_FAILURE: Failed
  1180. */
  1181. /*----------------------------------------------------------------------------*/
  1182. VOID wlanReturnIndicatedPacketsTimeOut(IN P_ADAPTER_T prAdapter, IN ULONG ulData)
  1183. {
  1184. P_RX_CTRL_T prRxCtrl;
  1185. P_SW_RFB_T prSwRfb = NULL;
  1186. BOOLEAN fgIsUninitRfb = FALSE;
  1187. KAL_SPIN_LOCK_DECLARATION();
  1188. WLAN_STATUS status = WLAN_STATUS_SUCCESS;
  1189. P_QUE_T prQueList;
  1190. DEBUGFUNC("wlanReturnIndicatedPacketsTimeOut");
  1191. DBGLOG(RX, WARN, "wlanReturnIndicatedPacketsTimeOut");
  1192. ASSERT(prAdapter);
  1193. prRxCtrl = &prAdapter->rRxCtrl;
  1194. ASSERT(prRxCtrl);
  1195. prQueList = &prRxCtrl->rIndicatedRfbList;
  1196. DBGLOG(RX, WARN, "IndicatedRfbList num = %u\n", (unsigned int)prQueList->u4NumElem);
  1197. while (QUEUE_IS_NOT_EMPTY(&prRxCtrl->rIndicatedRfbList)) {
  1198. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
  1199. QUEUE_REMOVE_HEAD(&prRxCtrl->rIndicatedRfbList, prSwRfb, P_SW_RFB_T);
  1200. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_RX_QUE);
  1201. if (nicRxSetupRFB(prAdapter, prSwRfb)) {
  1202. status = WLAN_STATUS_RESOURCES;
  1203. ASSERT(0);
  1204. fgIsUninitRfb = TRUE;
  1205. }
  1206. nicRxReturnRFBwithUninit(prAdapter, prSwRfb, fgIsUninitRfb);
  1207. if (status == WLAN_STATUS_RESOURCES)
  1208. break;
  1209. }
  1210. if (status == WLAN_STATUS_RESOURCES) {
  1211. DBGLOG(RX, WARN, "Start ReturnIndicatedRfbList Timer (%ds)\n", RX_RETURN_INDICATED_RFB_TIMEOUT_SEC);
  1212. /* restart timer */
  1213. cnmTimerStartTimer(prAdapter,
  1214. &prAdapter->rReturnIndicatedRfbListTimer,
  1215. SEC_TO_MSEC(RX_RETURN_INDICATED_RFB_TIMEOUT_SEC));
  1216. }
  1217. }
  1218. /*----------------------------------------------------------------------------*/
  1219. /*!
  1220. * \brief This function is a required function that returns information about
  1221. * the capabilities and status of the driver and/or its network adapter.
  1222. *
  1223. * \param[IN] prAdapter Pointer to the Adapter structure.
  1224. * \param[IN] pfnOidQryHandler Function pointer for the OID query handler.
  1225. * \param[IN] pvInfoBuf Points to a buffer for return the query information.
  1226. * \param[IN] u4QueryBufferLen Specifies the number of bytes at pvInfoBuf.
  1227. * \param[OUT] pu4QueryInfoLen Points to the number of bytes it written or is needed.
  1228. *
  1229. * \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
  1230. *
  1231. */
  1232. /*----------------------------------------------------------------------------*/
  1233. WLAN_STATUS
  1234. wlanQueryInformation(IN P_ADAPTER_T prAdapter,
  1235. IN PFN_OID_HANDLER_FUNC pfnOidQryHandler,
  1236. IN PVOID pvInfoBuf, IN UINT_32 u4InfoBufLen, OUT PUINT_32 pu4QryInfoLen)
  1237. {
  1238. WLAN_STATUS status = WLAN_STATUS_FAILURE;
  1239. ASSERT(prAdapter);
  1240. ASSERT(pu4QryInfoLen);
  1241. /* ignore any OID request after connected, under PS current measurement mode */
  1242. /* note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for
  1243. * blocking OIDs during current measurement
  1244. */
  1245. if (prAdapter->u4PsCurrentMeasureEn &&
  1246. (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED))
  1247. return WLAN_STATUS_SUCCESS;
  1248. #if 1
  1249. /* most OID handler will just queue a command packet */
  1250. status = pfnOidQryHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4QryInfoLen);
  1251. #else
  1252. if (wlanIsHandlerNeedHwAccess(pfnOidQryHandler, FALSE)) {
  1253. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  1254. /* Reset sleepy state */
  1255. if (prAdapter->fgWiFiInSleepyState == TRUE)
  1256. prAdapter->fgWiFiInSleepyState = FALSE;
  1257. status = pfnOidQryHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4QryInfoLen);
  1258. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  1259. } else
  1260. status = pfnOidQryHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4QryInfoLen);
  1261. #endif
  1262. return status;
  1263. }
  1264. /*----------------------------------------------------------------------------*/
  1265. /*!
  1266. * \brief This function is a required function that allows bound protocol drivers,
  1267. * or NDIS, to request changes in the state information that the miniport
  1268. * maintains for particular object identifiers, such as changes in multicast
  1269. * addresses.
  1270. *
  1271. * \param[IN] prAdapter Pointer to the Glue info structure.
  1272. * \param[IN] pfnOidSetHandler Points to the OID set handlers.
  1273. * \param[IN] pvInfoBuf Points to a buffer containing the OID-specific data for the set.
  1274. * \param[IN] u4InfoBufLen Specifies the number of bytes at prSetBuffer.
  1275. * \param[OUT] pu4SetInfoLen Points to the number of bytes it read or is needed.
  1276. *
  1277. * \retval WLAN_STATUS_xxx Different WLAN_STATUS code returned by different handlers.
  1278. *
  1279. */
  1280. /*----------------------------------------------------------------------------*/
  1281. WLAN_STATUS
  1282. wlanSetInformation(IN P_ADAPTER_T prAdapter,
  1283. IN PFN_OID_HANDLER_FUNC pfnOidSetHandler,
  1284. IN PVOID pvInfoBuf, IN UINT_32 u4InfoBufLen, OUT PUINT_32 pu4SetInfoLen)
  1285. {
  1286. WLAN_STATUS status = WLAN_STATUS_FAILURE;
  1287. ASSERT(prAdapter);
  1288. ASSERT(pu4SetInfoLen);
  1289. /* ignore any OID request after connected, under PS current measurement mode */
  1290. /* note: return WLAN_STATUS_FAILURE or WLAN_STATUS_SUCCESS for blocking
  1291. * OIDs during current measurement
  1292. */
  1293. if (prAdapter->u4PsCurrentMeasureEn &&
  1294. (prAdapter->prGlueInfo->eParamMediaStateIndicated == PARAM_MEDIA_STATE_CONNECTED))
  1295. return WLAN_STATUS_SUCCESS;
  1296. #if 1
  1297. /* most OID handler will just queue a command packet
  1298. * for power state transition OIDs, handler will acquire power control by itself
  1299. */
  1300. status = pfnOidSetHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4SetInfoLen);
  1301. #else
  1302. if (wlanIsHandlerNeedHwAccess(pfnOidSetHandler, TRUE)) {
  1303. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  1304. /* Reset sleepy state */
  1305. if (prAdapter->fgWiFiInSleepyState == TRUE)
  1306. prAdapter->fgWiFiInSleepyState = FALSE;
  1307. status = pfnOidSetHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4SetInfoLen);
  1308. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  1309. } else {
  1310. status = pfnOidSetHandler(prAdapter, pvInfoBuf, u4InfoBufLen, pu4SetInfoLen);
  1311. }
  1312. #endif
  1313. return status;
  1314. }
  1315. #if CFG_SUPPORT_WAPI
  1316. /*----------------------------------------------------------------------------*/
  1317. /*!
  1318. * \brief This function is a used to query driver's config wapi mode or not
  1319. *
  1320. * \param[IN] prAdapter Pointer to the Glue info structure.
  1321. *
  1322. * \retval TRUE for use wapi mode
  1323. *
  1324. */
  1325. /*----------------------------------------------------------------------------*/
  1326. BOOLEAN wlanQueryWapiMode(IN P_ADAPTER_T prAdapter)
  1327. {
  1328. ASSERT(prAdapter);
  1329. return prAdapter->rWifiVar.rConnSettings.fgWapiMode;
  1330. }
  1331. #endif
  1332. /*----------------------------------------------------------------------------*/
  1333. /*!
  1334. * \brief This function is called to set RX filter to Promiscuous Mode.
  1335. *
  1336. * \param[IN] prAdapter Pointer to the Adapter structure.
  1337. * \param[IN] fgEnablePromiscuousMode Enable/ disable RX Promiscuous Mode.
  1338. *
  1339. * \return (none)
  1340. */
  1341. /*----------------------------------------------------------------------------*/
  1342. VOID wlanSetPromiscuousMode(IN P_ADAPTER_T prAdapter, IN BOOLEAN fgEnablePromiscuousMode)
  1343. {
  1344. ASSERT(prAdapter);
  1345. }
  1346. /*----------------------------------------------------------------------------*/
  1347. /*!
  1348. * \brief This function is called to set RX filter to allow to receive
  1349. * broadcast address packets.
  1350. *
  1351. * \param[IN] prAdapter Pointer to the Adapter structure.
  1352. * \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
  1353. *
  1354. * \return (none)
  1355. */
  1356. /*----------------------------------------------------------------------------*/
  1357. VOID wlanRxSetBroadcast(IN P_ADAPTER_T prAdapter, IN BOOLEAN fgEnableBroadcast)
  1358. {
  1359. ASSERT(prAdapter);
  1360. }
  1361. /*----------------------------------------------------------------------------*/
  1362. /*!
  1363. * \brief This function is called to send out CMD_NIC_POWER_CTRL command packet
  1364. *
  1365. * \param[IN] prAdapter Pointer to the Adapter structure.
  1366. * \param[IN] ucPowerMode refer to CMD/EVENT document
  1367. *
  1368. * \return WLAN_STATUS_SUCCESS
  1369. * \return WLAN_STATUS_FAILURE
  1370. */
  1371. /*----------------------------------------------------------------------------*/
  1372. WLAN_STATUS wlanSendNicPowerCtrlCmd(IN P_ADAPTER_T prAdapter, IN UINT_8 ucPowerMode)
  1373. {
  1374. WLAN_STATUS status = WLAN_STATUS_SUCCESS;
  1375. P_GLUE_INFO_T prGlueInfo;
  1376. P_CMD_INFO_T prCmdInfo;
  1377. P_WIFI_CMD_T prWifiCmd;
  1378. UINT_8 ucTC, ucCmdSeqNum;
  1379. ASSERT(prAdapter);
  1380. prGlueInfo = prAdapter->prGlueInfo;
  1381. /* 1. Prepare CMD */
  1382. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, (CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL)));
  1383. if (!prCmdInfo) {
  1384. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  1385. return WLAN_STATUS_FAILURE;
  1386. }
  1387. /* 2.1 increase command sequence number */
  1388. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  1389. DBGLOG(REQ, TRACE, "ucCmdSeqNum =%d\n", ucCmdSeqNum);
  1390. /* 2.2 Setup common CMD Info Packet */
  1391. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  1392. prCmdInfo->u2InfoBufLen = (UINT_16) (CMD_HDR_SIZE + sizeof(CMD_NIC_POWER_CTRL));
  1393. prCmdInfo->pfCmdDoneHandler = NULL;
  1394. prCmdInfo->pfCmdTimeoutHandler = NULL;
  1395. prCmdInfo->fgIsOid = TRUE;
  1396. prCmdInfo->ucCID = CMD_ID_NIC_POWER_CTRL;
  1397. prCmdInfo->fgSetQuery = TRUE;
  1398. prCmdInfo->fgNeedResp = FALSE;
  1399. prCmdInfo->fgDriverDomainMCR = FALSE;
  1400. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  1401. prCmdInfo->u4SetInfoLen = sizeof(CMD_NIC_POWER_CTRL);
  1402. /* 2.3 Setup WIFI_CMD_T */
  1403. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  1404. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  1405. prWifiCmd->ucCID = prCmdInfo->ucCID;
  1406. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  1407. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  1408. kalMemZero(prWifiCmd->aucBuffer, sizeof(CMD_NIC_POWER_CTRL));
  1409. ((P_CMD_NIC_POWER_CTRL) (prWifiCmd->aucBuffer))->ucPowerMode = ucPowerMode;
  1410. /* 3. Issue CMD for entering specific power mode */
  1411. ucTC = TC4_INDEX;
  1412. while (1) {
  1413. /* 3.0 Removal check */
  1414. if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE || fgIsBusAccessFailed == TRUE) {
  1415. status = WLAN_STATUS_FAILURE;
  1416. break;
  1417. }
  1418. /* 3.1 Acquire TX Resource */
  1419. if (nicTxAcquireResource(prAdapter, ucTC, FALSE) == WLAN_STATUS_RESOURCES) {
  1420. /* wait and poll tx resource */
  1421. if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
  1422. DBGLOG(INIT, ERROR, "Fail to get TX resource return within timeout\n");
  1423. status = WLAN_STATUS_FAILURE;
  1424. break;
  1425. }
  1426. continue;
  1427. }
  1428. /* 3.2 Send CMD Info Packet */
  1429. if (nicTxCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
  1430. DBGLOG(INIT, ERROR, "Fail to transmit CMD_NIC_POWER_CTRL command\n");
  1431. status = WLAN_STATUS_FAILURE;
  1432. }
  1433. break;
  1434. };
  1435. /* 4. Free CMD Info Packet. */
  1436. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1437. /* 5. Add flag */
  1438. if (ucPowerMode == 1)
  1439. prAdapter->fgIsEnterD3ReqIssued = TRUE;
  1440. return status;
  1441. }
  1442. /*----------------------------------------------------------------------------*/
  1443. /*!
  1444. * \brief This function is called to check if it is RF test mode and
  1445. * the OID is allowed to be called or not
  1446. *
  1447. * \param[IN] prAdapter Pointer to the Adapter structure.
  1448. * \param[IN] fgEnableBroadcast Enable/ disable broadcast packet to be received.
  1449. *
  1450. * \return (none)
  1451. */
  1452. /*----------------------------------------------------------------------------*/
  1453. BOOLEAN wlanIsHandlerAllowedInRFTest(IN PFN_OID_HANDLER_FUNC pfnOidHandler, IN BOOLEAN fgSetInfo)
  1454. {
  1455. PFN_OID_HANDLER_FUNC *apfnOidHandlerAllowedInRFTest;
  1456. UINT_32 i;
  1457. UINT_32 u4NumOfElem;
  1458. if (fgSetInfo) {
  1459. apfnOidHandlerAllowedInRFTest = apfnOidSetHandlerAllowedInRFTest;
  1460. u4NumOfElem = sizeof(apfnOidSetHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
  1461. } else {
  1462. apfnOidHandlerAllowedInRFTest = apfnOidQueryHandlerAllowedInRFTest;
  1463. u4NumOfElem = sizeof(apfnOidQueryHandlerAllowedInRFTest) / sizeof(PFN_OID_HANDLER_FUNC);
  1464. }
  1465. for (i = 0; i < u4NumOfElem; i++) {
  1466. if (apfnOidHandlerAllowedInRFTest[i] == pfnOidHandler)
  1467. return TRUE;
  1468. }
  1469. return FALSE;
  1470. }
  1471. #if CFG_ENABLE_FW_DOWNLOAD
  1472. #if CFG_ENABLE_FW_DOWNLOAD_AGGREGATION
  1473. /*----------------------------------------------------------------------------*/
  1474. /*!
  1475. * @brief This function is called to download FW image in an aggregated way
  1476. *
  1477. * @param prAdapter Pointer to the Adapter structure.
  1478. *
  1479. * @return (none)
  1480. */
  1481. /*----------------------------------------------------------------------------*/
  1482. WLAN_STATUS
  1483. wlanImageSectionDownloadAggregated(IN P_ADAPTER_T prAdapter,
  1484. IN UINT_32 u4DestAddr, IN UINT_32 u4ImgSecSize, IN PUINT_8 pucImgSecBuf)
  1485. {
  1486. #if defined(MT6620) || defined(MT6628)
  1487. P_CMD_INFO_T prCmdInfo;
  1488. P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
  1489. P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
  1490. UINT_8 ucTC, ucCmdSeqNum;
  1491. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  1492. PUINT_8 pucOutputBuf = (PUINT_8) NULL; /* Pointer to Transmit Data Structure Frame */
  1493. UINT_32 u4PktCnt, u4Offset, u4Length;
  1494. UINT_32 u4TotalLength;
  1495. ASSERT(prAdapter);
  1496. ASSERT(pucImgSecBuf);
  1497. pucOutputBuf = prAdapter->rTxCtrl.pucTxCoalescingBufPtr;
  1498. DEBUGFUNC("wlanImageSectionDownloadAggregated");
  1499. if (u4ImgSecSize == 0)
  1500. return WLAN_STATUS_SUCCESS;
  1501. /* 1. Allocate CMD Info Packet and Pre-fill Headers */
  1502. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
  1503. sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) +
  1504. CMD_PKT_SIZE_FOR_IMAGE);
  1505. if (!prCmdInfo) {
  1506. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  1507. return WLAN_STATUS_FAILURE;
  1508. }
  1509. prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + CMD_PKT_SIZE_FOR_IMAGE;
  1510. /* 2. Use TC0's resource to download image. (only TC0 is allowed) */
  1511. ucTC = TC0_INDEX;
  1512. /* 3. Setup common CMD Info Packet */
  1513. prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T) (prCmdInfo->pucInfoBuffer);
  1514. prInitHifTxHeader->ucEtherTypeOffset = 0;
  1515. prInitHifTxHeader->ucCSflags = 0;
  1516. prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
  1517. /* 4. Setup CMD_DOWNLOAD_BUF */
  1518. prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF) (prInitHifTxHeader->rInitWifiCmd.aucBuffer);
  1519. prInitCmdDownloadBuf->u4DataMode = 0
  1520. #if CFG_ENABLE_FW_ENCRYPTION
  1521. | DOWNLOAD_BUF_ENCRYPTION_MODE
  1522. #endif
  1523. ;
  1524. /* 5.0 reset loop control variable */
  1525. u4TotalLength = 0;
  1526. u4Offset = u4PktCnt = 0;
  1527. /* 5.1 main loop for maximize transmission count per access */
  1528. while (u4Offset < u4ImgSecSize) {
  1529. if (nicTxAcquireResource(prAdapter, ucTC, FALSE) == WLAN_STATUS_SUCCESS) {
  1530. /* 5.1.1 calculate u4Length */
  1531. if (u4Offset + CMD_PKT_SIZE_FOR_IMAGE < u4ImgSecSize)
  1532. u4Length = CMD_PKT_SIZE_FOR_IMAGE;
  1533. else
  1534. u4Length = u4ImgSecSize - u4Offset;
  1535. /* 5.1.1 increase command sequence number */
  1536. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  1537. prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
  1538. /* 5.1.2 update HIF TX hardware header */
  1539. prInitHifTxHeader->u2TxByteCount =
  1540. ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16) u4Length);
  1541. /* 5.1.3 fill command header */
  1542. prInitCmdDownloadBuf->u4Address = u4DestAddr + u4Offset;
  1543. prInitCmdDownloadBuf->u4Length = u4Length;
  1544. prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf + u4Offset, u4Length);
  1545. /* 5.1.4.1 copy header to coalescing buffer */
  1546. kalMemCopy(pucOutputBuf + u4TotalLength,
  1547. (PVOID) prCmdInfo->pucInfoBuffer,
  1548. sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF));
  1549. /* 5.1.4.2 copy payload to coalescing buffer */
  1550. kalMemCopy(pucOutputBuf + u4TotalLength + sizeof(INIT_HIF_TX_HEADER_T) +
  1551. sizeof(INIT_CMD_DOWNLOAD_BUF), pucImgSecBuf + u4Offset, u4Length);
  1552. /* 5.1.4.3 update length and other variables */
  1553. u4TotalLength +=
  1554. ALIGN_4(sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4Length);
  1555. u4Offset += u4Length;
  1556. u4PktCnt++;
  1557. if (u4Offset < u4ImgSecSize)
  1558. continue;
  1559. } else if (u4PktCnt == 0) {
  1560. /* no resource, so get some back */
  1561. if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
  1562. u4Status = WLAN_STATUS_FAILURE;
  1563. DBGLOG(INIT, ERROR, "Fail to get TX resource return within timeout\n");
  1564. break;
  1565. }
  1566. }
  1567. if (u4PktCnt != 0) {
  1568. /* start transmission */
  1569. HAL_WRITE_TX_PORT(prAdapter,
  1570. 0,
  1571. u4TotalLength, (PUINT_8) pucOutputBuf, prAdapter->u4CoalescingBufCachedSize);
  1572. /* reset varaibles */
  1573. u4PktCnt = 0;
  1574. u4TotalLength = 0;
  1575. }
  1576. }
  1577. /* 8. Free CMD Info Packet. */
  1578. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1579. return u4Status;
  1580. #else
  1581. #error "Only MT6620/MT6628/MT6582 supports firmware download in an aggregated way"
  1582. return WLAN_STATUS_FAILURE;
  1583. #endif
  1584. }
  1585. #endif
  1586. /*----------------------------------------------------------------------------*/
  1587. /*!
  1588. * @brief This function is called to download FW image.
  1589. *
  1590. * @param prAdapter Pointer to the Adapter structure.
  1591. *
  1592. * @return (none)
  1593. */
  1594. /*----------------------------------------------------------------------------*/
  1595. WLAN_STATUS
  1596. wlanImageSectionDownload(IN P_ADAPTER_T prAdapter,
  1597. IN UINT_32 u4DestAddr, IN UINT_32 u4ImgSecSize, IN PUINT_8 pucImgSecBuf)
  1598. {
  1599. P_CMD_INFO_T prCmdInfo;
  1600. P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
  1601. P_INIT_CMD_DOWNLOAD_BUF prInitCmdDownloadBuf;
  1602. UINT_8 ucTC, ucCmdSeqNum;
  1603. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  1604. ASSERT(prAdapter);
  1605. ASSERT(pucImgSecBuf);
  1606. ASSERT(u4ImgSecSize <= CMD_PKT_SIZE_FOR_IMAGE);
  1607. DEBUGFUNC("wlanImageSectionDownload");
  1608. if (u4ImgSecSize == 0)
  1609. return WLAN_STATUS_SUCCESS;
  1610. /* 1. Allocate CMD Info Packet and its Buffer. */
  1611. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter,
  1612. sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + u4ImgSecSize);
  1613. if (!prCmdInfo) {
  1614. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  1615. return WLAN_STATUS_FAILURE;
  1616. }
  1617. prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_DOWNLOAD_BUF) + (UINT_16) u4ImgSecSize;
  1618. /* 2. Use TC0's resource to download image. (only TC0 is allowed) */
  1619. ucTC = TC0_INDEX;
  1620. /* 3. increase command sequence number */
  1621. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  1622. /* 4. Setup common CMD Info Packet */
  1623. prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T) (prCmdInfo->pucInfoBuffer);
  1624. prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_DOWNLOAD_BUF;
  1625. prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
  1626. /* 5. Setup CMD_DOWNLOAD_BUF */
  1627. prInitCmdDownloadBuf = (P_INIT_CMD_DOWNLOAD_BUF) (prInitHifTxHeader->rInitWifiCmd.aucBuffer);
  1628. prInitCmdDownloadBuf->u4Address = u4DestAddr;
  1629. prInitCmdDownloadBuf->u4Length = u4ImgSecSize;
  1630. prInitCmdDownloadBuf->u4CRC32 = wlanCRC32(pucImgSecBuf, u4ImgSecSize);
  1631. prInitCmdDownloadBuf->u4DataMode = 0
  1632. #if CFG_ENABLE_FW_DOWNLOAD_ACK
  1633. | DOWNLOAD_BUF_ACK_OPTION /* ACK needed */
  1634. #endif
  1635. #if CFG_ENABLE_FW_ENCRYPTION
  1636. | DOWNLOAD_BUF_ENCRYPTION_MODE
  1637. #endif
  1638. ;
  1639. kalMemCopy(prInitCmdDownloadBuf->aucBuffer, pucImgSecBuf, u4ImgSecSize);
  1640. /* 6. Send FW_Download command */
  1641. while (1) {
  1642. /* 6.1 Acquire TX Resource */
  1643. if (nicTxAcquireResource(prAdapter, ucTC, FALSE) == WLAN_STATUS_RESOURCES) {
  1644. if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
  1645. u4Status = WLAN_STATUS_FAILURE;
  1646. DBGLOG(INIT, ERROR, "Fail to get TX resource return within timeout\n");
  1647. break;
  1648. }
  1649. continue;
  1650. }
  1651. /* 6.2 Send CMD Info Packet */
  1652. if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
  1653. u4Status = WLAN_STATUS_FAILURE;
  1654. DBGLOG(INIT, ERROR, "Fail to transmit image download command\n");
  1655. }
  1656. break;
  1657. };
  1658. #if CFG_ENABLE_FW_DOWNLOAD_ACK
  1659. /* 7. Wait for INIT_EVENT_ID_CMD_RESULT */
  1660. u4Status = wlanImageSectionDownloadStatus(prAdapter, ucCmdSeqNum);
  1661. #endif
  1662. /* 8. Free CMD Info Packet. */
  1663. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1664. return u4Status;
  1665. }
  1666. #if !CFG_ENABLE_FW_DOWNLOAD_ACK
  1667. /*----------------------------------------------------------------------------*/
  1668. /*!
  1669. * @brief This function is called to confirm previously firmware download is done without error
  1670. *
  1671. * @param prAdapter Pointer to the Adapter structure.
  1672. *
  1673. * @return (none)
  1674. */
  1675. /*----------------------------------------------------------------------------*/
  1676. WLAN_STATUS wlanImageQueryStatus(IN P_ADAPTER_T prAdapter)
  1677. {
  1678. P_CMD_INFO_T prCmdInfo;
  1679. P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
  1680. UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR)];
  1681. UINT_32 u4RxPktLength;
  1682. P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
  1683. P_INIT_EVENT_PENDING_ERROR prEventPendingError;
  1684. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  1685. UINT_8 ucTC, ucCmdSeqNum;
  1686. ASSERT(prAdapter);
  1687. DEBUGFUNC("wlanImageQueryStatus");
  1688. /* 1. Allocate CMD Info Packet and it Buffer. */
  1689. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, sizeof(INIT_HIF_TX_HEADER_T));
  1690. if (!prCmdInfo) {
  1691. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  1692. return WLAN_STATUS_FAILURE;
  1693. }
  1694. kalMemZero(prCmdInfo, sizeof(INIT_HIF_TX_HEADER_T));
  1695. prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T);
  1696. /* 2. Use TC0's resource to download image. (only TC0 is allowed) */
  1697. ucTC = TC0_INDEX;
  1698. /* 3. increase command sequence number */
  1699. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  1700. /* 4. Setup common CMD Info Packet */
  1701. prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T) (prCmdInfo->pucInfoBuffer);
  1702. prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_QUERY_PENDING_ERROR;
  1703. prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
  1704. /* 5. Send command */
  1705. while (1) {
  1706. /* 5.1 Acquire TX Resource */
  1707. if (nicTxAcquireResource(prAdapter, ucTC, FALSE) == WLAN_STATUS_RESOURCES) {
  1708. if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
  1709. u4Status = WLAN_STATUS_FAILURE;
  1710. DBGLOG(INIT, ERROR, "Fail to get TX resource return within timeout\n");
  1711. break;
  1712. }
  1713. continue;
  1714. }
  1715. /* 5.2 Send CMD Info Packet */
  1716. if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
  1717. u4Status = WLAN_STATUS_FAILURE;
  1718. DBGLOG(INIT, ERROR, "Fail to transmit image download command\n");
  1719. }
  1720. break;
  1721. };
  1722. /* 6. Wait for INIT_EVENT_ID_PENDING_ERROR */
  1723. do {
  1724. if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE || fgIsBusAccessFailed == TRUE) {
  1725. u4Status = WLAN_STATUS_FAILURE;
  1726. } else if (nicRxWaitResponse(prAdapter,
  1727. 0,
  1728. aucBuffer,
  1729. sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_PENDING_ERROR),
  1730. &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
  1731. u4Status = WLAN_STATUS_FAILURE;
  1732. } else {
  1733. prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
  1734. /* EID / SeqNum check */
  1735. if (prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_PENDING_ERROR) {
  1736. u4Status = WLAN_STATUS_FAILURE;
  1737. } else if (prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
  1738. u4Status = WLAN_STATUS_FAILURE;
  1739. } else {
  1740. prEventPendingError =
  1741. (P_INIT_EVENT_PENDING_ERROR) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
  1742. if (prEventPendingError->ucStatus != 0) { /* 0 for download success */
  1743. u4Status = WLAN_STATUS_FAILURE;
  1744. } else {
  1745. u4Status = WLAN_STATUS_SUCCESS;
  1746. }
  1747. }
  1748. }
  1749. } while (FALSE);
  1750. /* 7. Free CMD Info Packet. */
  1751. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1752. return u4Status;
  1753. }
  1754. #else
  1755. /*----------------------------------------------------------------------------*/
  1756. /*!
  1757. * @brief This function is called to confirm the status of
  1758. * previously downloaded firmware scatter
  1759. *
  1760. * @param prAdapter Pointer to the Adapter structure.
  1761. * ucCmdSeqNum Sequence number of previous firmware scatter
  1762. *
  1763. * @return WLAN_STATUS_SUCCESS
  1764. * WLAN_STATUS_FAILURE
  1765. */
  1766. /*----------------------------------------------------------------------------*/
  1767. WLAN_STATUS wlanImageSectionDownloadStatus(IN P_ADAPTER_T prAdapter, IN UINT_8 ucCmdSeqNum)
  1768. {
  1769. UINT_8 aucBuffer[sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT)];
  1770. P_INIT_HIF_RX_HEADER_T prInitHifRxHeader;
  1771. P_INIT_EVENT_CMD_RESULT prEventCmdResult;
  1772. UINT_32 u4RxPktLength;
  1773. WLAN_STATUS u4Status;
  1774. ASSERT(prAdapter);
  1775. do {
  1776. if (kalIsCardRemoved(prAdapter->prGlueInfo) == TRUE || fgIsBusAccessFailed == TRUE) {
  1777. DBGLOG(INIT, ERROR, "kalIsCardRemoved or fgIsBusAccessFailed\n");
  1778. u4Status = WLAN_STATUS_FAILURE;
  1779. } else if (nicRxWaitResponse(prAdapter,
  1780. 0,
  1781. aucBuffer,
  1782. sizeof(INIT_HIF_RX_HEADER_T) + sizeof(INIT_EVENT_CMD_RESULT),/* 4B + 4B */
  1783. &u4RxPktLength) != WLAN_STATUS_SUCCESS) {
  1784. DBGLOG(INIT, ERROR, "nicRxWaitResponse fail\n");
  1785. u4Status = WLAN_STATUS_FAILURE;
  1786. } else {
  1787. prInitHifRxHeader = (P_INIT_HIF_RX_HEADER_T) aucBuffer;
  1788. /* EID / SeqNum check */
  1789. if (prInitHifRxHeader->rInitWifiEvent.ucEID != INIT_EVENT_ID_CMD_RESULT) {
  1790. DBGLOG(INIT, ERROR, "rInitWifiEvent.ucEID != INIT_EVENT_ID_CMD_RESULT\n");
  1791. u4Status = WLAN_STATUS_FAILURE;
  1792. g_IsNeedDoChipReset = 1;
  1793. kalSendAeeWarning("[Check EID error!]", __func__);
  1794. } else if (prInitHifRxHeader->rInitWifiEvent.ucSeqNum != ucCmdSeqNum) {
  1795. DBGLOG(INIT, ERROR, "rInitWifiEvent.ucSeqNum != ucCmdSeqNum\n");
  1796. u4Status = WLAN_STATUS_FAILURE;
  1797. g_IsNeedDoChipReset = 1;
  1798. kalSendAeeWarning("[Check SeqNum error!]", __func__);
  1799. } else {
  1800. prEventCmdResult =
  1801. (P_INIT_EVENT_CMD_RESULT) (prInitHifRxHeader->rInitWifiEvent.aucBuffer);
  1802. if (prEventCmdResult->ucStatus != 0) { /* 0 for download success */
  1803. /*
  1804. 0: success
  1805. 1: rejected by invalid param
  1806. 2: rejected by incorrect CRC
  1807. 3: rejected by decryption failure
  1808. 4: unknown CMD
  1809. */
  1810. DBGLOG(INIT, ERROR, "Read Response status error = %d\n",
  1811. prEventCmdResult->ucStatus);
  1812. u4Status = WLAN_STATUS_FAILURE;
  1813. } else {
  1814. u4Status = WLAN_STATUS_SUCCESS;
  1815. }
  1816. }
  1817. }
  1818. } while (FALSE);
  1819. return u4Status;
  1820. }
  1821. #endif
  1822. /*----------------------------------------------------------------------------*/
  1823. /*!
  1824. * @brief This function is called to start FW normal operation.
  1825. *
  1826. * @param prAdapter Pointer to the Adapter structure.
  1827. *
  1828. * @return (none)
  1829. */
  1830. /*----------------------------------------------------------------------------*/
  1831. WLAN_STATUS wlanConfigWifiFunc(IN P_ADAPTER_T prAdapter, IN BOOLEAN fgEnable, IN UINT_32 u4StartAddress)
  1832. {
  1833. P_CMD_INFO_T prCmdInfo;
  1834. P_INIT_HIF_TX_HEADER_T prInitHifTxHeader;
  1835. P_INIT_CMD_WIFI_START prInitCmdWifiStart;
  1836. UINT_8 ucTC, ucCmdSeqNum;
  1837. WLAN_STATUS u4Status = WLAN_STATUS_SUCCESS;
  1838. ASSERT(prAdapter);
  1839. DEBUGFUNC("wlanConfigWifiFunc");
  1840. /* 1. Allocate CMD Info Packet and its Buffer. */
  1841. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
  1842. if (!prCmdInfo) {
  1843. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  1844. return WLAN_STATUS_FAILURE;
  1845. }
  1846. kalMemZero(prCmdInfo->pucInfoBuffer, sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START));
  1847. prCmdInfo->u2InfoBufLen = sizeof(INIT_HIF_TX_HEADER_T) + sizeof(INIT_CMD_WIFI_START);
  1848. /* 2. Always use TC0 */
  1849. ucTC = TC0_INDEX;
  1850. /* 3. increase command sequence number */
  1851. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  1852. /* 4. Setup common CMD Info Packet */
  1853. prInitHifTxHeader = (P_INIT_HIF_TX_HEADER_T) (prCmdInfo->pucInfoBuffer);
  1854. prInitHifTxHeader->rInitWifiCmd.ucCID = INIT_CMD_ID_WIFI_START;
  1855. prInitHifTxHeader->rInitWifiCmd.ucSeqNum = ucCmdSeqNum;
  1856. prInitCmdWifiStart = (P_INIT_CMD_WIFI_START) (prInitHifTxHeader->rInitWifiCmd.aucBuffer);
  1857. prInitCmdWifiStart->u4Override = (fgEnable == TRUE ? 1 : 0);
  1858. prInitCmdWifiStart->u4Address = u4StartAddress;
  1859. /* 5. Seend WIFI start command */
  1860. while (1) {
  1861. /* 5.1 Acquire TX Resource */
  1862. if (nicTxAcquireResource(prAdapter, ucTC, FALSE) == WLAN_STATUS_RESOURCES) {
  1863. /* wait and poll tx resource */
  1864. if (nicTxPollingResource(prAdapter, ucTC) != WLAN_STATUS_SUCCESS) {
  1865. u4Status = WLAN_STATUS_FAILURE;
  1866. DBGLOG(INIT, ERROR, "Fail to get TX resource return within timeout\n");
  1867. break;
  1868. }
  1869. continue;
  1870. }
  1871. /* 5.2 Send CMD Info Packet */
  1872. if (nicTxInitCmd(prAdapter, prCmdInfo, ucTC) != WLAN_STATUS_SUCCESS) {
  1873. u4Status = WLAN_STATUS_FAILURE;
  1874. DBGLOG(INIT, ERROR, "Fail to transmit WIFI start command\n");
  1875. }
  1876. break;
  1877. };
  1878. /* 6. Free CMD Info Packet. */
  1879. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  1880. return u4Status;
  1881. }
  1882. /*----------------------------------------------------------------------------*/
  1883. /*!
  1884. * @brief This function is used to generate CRC32 checksum
  1885. *
  1886. * @param buf Pointer to the data.
  1887. * @param len data length
  1888. *
  1889. * @return crc32 value
  1890. */
  1891. /*----------------------------------------------------------------------------*/
  1892. static const UINT_32 crc32_ccitt_table[256] = {
  1893. 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
  1894. 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
  1895. 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
  1896. 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
  1897. 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
  1898. 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
  1899. 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
  1900. 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
  1901. 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
  1902. 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
  1903. 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
  1904. 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
  1905. 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
  1906. 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
  1907. 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
  1908. 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
  1909. 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
  1910. 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
  1911. 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
  1912. 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
  1913. 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
  1914. 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
  1915. 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
  1916. 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
  1917. 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
  1918. 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
  1919. 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
  1920. 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
  1921. 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
  1922. 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
  1923. 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
  1924. 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
  1925. 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
  1926. 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
  1927. 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
  1928. 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
  1929. 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
  1930. 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
  1931. 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
  1932. 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
  1933. 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
  1934. 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
  1935. 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
  1936. 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
  1937. 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
  1938. 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
  1939. 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
  1940. 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
  1941. 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
  1942. 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
  1943. 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
  1944. 0x2d02ef8d
  1945. };
  1946. UINT_32 wlanCRC32(PUINT_8 buf, UINT_32 len)
  1947. {
  1948. UINT_32 i, crc32 = 0xFFFFFFFF;
  1949. for (i = 0; i < len; i++)
  1950. crc32 = crc32_ccitt_table[(crc32 ^ buf[i]) & 0xff] ^ (crc32 >> 8);
  1951. return ~crc32;
  1952. }
  1953. #endif
  1954. /*----------------------------------------------------------------------------*/
  1955. /*!
  1956. * @brief This function is called to process queued RX packets
  1957. *
  1958. * @param prAdapter Pointer to the Adapter structure.
  1959. * prSwRfbListHead Pointer to head of RX packets link list
  1960. *
  1961. * @return (none)
  1962. */
  1963. /*----------------------------------------------------------------------------*/
  1964. WLAN_STATUS wlanProcessQueuedSwRfb(IN P_ADAPTER_T prAdapter, IN P_SW_RFB_T prSwRfbListHead)
  1965. {
  1966. P_SW_RFB_T prSwRfb, prNextSwRfb;
  1967. P_TX_CTRL_T prTxCtrl;
  1968. P_RX_CTRL_T prRxCtrl;
  1969. ASSERT(prAdapter);
  1970. ASSERT(prSwRfbListHead);
  1971. prTxCtrl = &prAdapter->rTxCtrl;
  1972. prRxCtrl = &prAdapter->rRxCtrl;
  1973. prSwRfb = prSwRfbListHead;
  1974. do {
  1975. /* save next first */
  1976. prNextSwRfb = (P_SW_RFB_T) QUEUE_GET_NEXT_ENTRY((P_QUE_ENTRY_T) prSwRfb);
  1977. switch (prSwRfb->eDst) {
  1978. case RX_PKT_DESTINATION_HOST:
  1979. /* to host */
  1980. nicRxProcessPktWithoutReorder(prAdapter, prSwRfb);
  1981. break;
  1982. case RX_PKT_DESTINATION_FORWARD:
  1983. /* need ot forward */
  1984. nicRxProcessForwardPkt(prAdapter, prSwRfb);
  1985. break;
  1986. case RX_PKT_DESTINATION_HOST_WITH_FORWARD:
  1987. /* to host and forward */
  1988. nicRxProcessGOBroadcastPkt(prAdapter, prSwRfb);
  1989. break;
  1990. case RX_PKT_DESTINATION_NULL:
  1991. /* free it */
  1992. nicRxReturnRFB(prAdapter, prSwRfb);
  1993. break;
  1994. default:
  1995. break;
  1996. }
  1997. #if CFG_HIF_RX_STARVATION_WARNING
  1998. prRxCtrl->u4DequeuedCnt++;
  1999. #endif
  2000. /* check next queued packet */
  2001. prSwRfb = prNextSwRfb;
  2002. } while (prSwRfb);
  2003. return WLAN_STATUS_SUCCESS;
  2004. }
  2005. /*----------------------------------------------------------------------------*/
  2006. /*!
  2007. * @brief This function is called to purge queued TX packets
  2008. * by indicating failure to OS and returned to free list
  2009. *
  2010. * @param prAdapter Pointer to the Adapter structure.
  2011. * prMsduInfoListHead Pointer to head of TX packets link list
  2012. *
  2013. * @return (none)
  2014. */
  2015. /*----------------------------------------------------------------------------*/
  2016. WLAN_STATUS wlanProcessQueuedMsduInfo(IN P_ADAPTER_T prAdapter, IN P_MSDU_INFO_T prMsduInfoListHead)
  2017. {
  2018. ASSERT(prAdapter);
  2019. ASSERT(prMsduInfoListHead);
  2020. nicTxFreeMsduInfoPacket(prAdapter, prMsduInfoListHead);
  2021. nicTxReturnMsduInfo(prAdapter, prMsduInfoListHead);
  2022. return WLAN_STATUS_SUCCESS;
  2023. }
  2024. /*----------------------------------------------------------------------------*/
  2025. /*!
  2026. * @brief This function is called to check if the OID handler needs timeout
  2027. *
  2028. * @param prAdapter Pointer to the Adapter structure.
  2029. * pfnOidHandler Pointer to the OID handler
  2030. *
  2031. * @return TRUE
  2032. * FALSE
  2033. */
  2034. /*----------------------------------------------------------------------------*/
  2035. BOOLEAN wlanoidTimeoutCheck(IN P_ADAPTER_T prAdapter, IN PFN_OID_HANDLER_FUNC pfnOidHandler)
  2036. {
  2037. PFN_OID_HANDLER_FUNC *apfnOidHandlerWOTimeoutCheck;
  2038. UINT_32 i;
  2039. UINT_32 u4NumOfElem;
  2040. apfnOidHandlerWOTimeoutCheck = apfnOidWOTimeoutCheck;
  2041. u4NumOfElem = sizeof(apfnOidWOTimeoutCheck) / sizeof(PFN_OID_HANDLER_FUNC);
  2042. /* skip some OID timeout checks ? */
  2043. for (i = 0; i < u4NumOfElem; i++) {
  2044. if (apfnOidHandlerWOTimeoutCheck[i] == pfnOidHandler)
  2045. return FALSE;
  2046. }
  2047. /* set timer if need timeout check */
  2048. /* cnmTimerStartTimer(prAdapter, */
  2049. /* &(prAdapter->rOidTimeoutTimer), */
  2050. /* 1000); */
  2051. cnmTimerStartTimer(prAdapter, &(prAdapter->rOidTimeoutTimer), 2000);
  2052. return TRUE;
  2053. }
  2054. /*----------------------------------------------------------------------------*/
  2055. /*!
  2056. * @brief This function is called to clear any pending OID timeout check
  2057. *
  2058. * @param prAdapter Pointer to the Adapter structure.
  2059. *
  2060. * @return none
  2061. */
  2062. /*----------------------------------------------------------------------------*/
  2063. VOID wlanoidClearTimeoutCheck(IN P_ADAPTER_T prAdapter)
  2064. {
  2065. ASSERT(prAdapter);
  2066. cnmTimerStopTimer(prAdapter, &(prAdapter->rOidTimeoutTimer));
  2067. }
  2068. /*----------------------------------------------------------------------------*/
  2069. /*!
  2070. * @brief This function is called to update network address in firmware domain
  2071. *
  2072. * @param prAdapter Pointer to the Adapter structure.
  2073. *
  2074. * @return WLAN_STATUS_FAILURE The request could not be processed
  2075. * WLAN_STATUS_PENDING The request has been queued for later processing
  2076. * WLAN_STATUS_SUCCESS The request has been processed
  2077. */
  2078. /*----------------------------------------------------------------------------*/
  2079. WLAN_STATUS wlanUpdateNetworkAddress(IN P_ADAPTER_T prAdapter)
  2080. {
  2081. const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
  2082. PARAM_MAC_ADDRESS rMacAddr = {0};
  2083. UINT_8 ucCmdSeqNum;
  2084. P_CMD_INFO_T prCmdInfo;
  2085. P_WIFI_CMD_T prWifiCmd;
  2086. P_CMD_BASIC_CONFIG prCmdBasicConfig;
  2087. UINT_32 u4SysTime;
  2088. DEBUGFUNC("wlanUpdateNetworkAddress");
  2089. ASSERT(prAdapter);
  2090. if (kalRetrieveNetworkAddress(prAdapter->prGlueInfo, &rMacAddr) == FALSE || IS_BMCAST_MAC_ADDR(rMacAddr)
  2091. || EQUAL_MAC_ADDR(aucZeroMacAddr, rMacAddr)) {
  2092. /* eFUSE has a valid address, don't do anything */
  2093. if (prAdapter->fgIsEmbbededMacAddrValid == TRUE) {
  2094. #if CFG_SHOW_MACADDR_SOURCE
  2095. DBGLOG(INIT, INFO, "Using embedded MAC address");
  2096. #endif
  2097. return WLAN_STATUS_SUCCESS;
  2098. }
  2099. #if CFG_SHOW_MACADDR_SOURCE
  2100. DBGLOG(INIT, INFO, "Using dynamically generated MAC address");
  2101. #endif
  2102. /* dynamic generate */
  2103. u4SysTime = kalGetTimeTick();
  2104. rMacAddr[0] = 0x00;
  2105. rMacAddr[1] = 0x08;
  2106. rMacAddr[2] = 0x22;
  2107. kalMemCopy(&rMacAddr[3], &u4SysTime, 3);
  2108. } else {
  2109. #if CFG_SHOW_MACADDR_SOURCE
  2110. DBGLOG(INIT, INFO, "Using host-supplied MAC address");
  2111. #endif
  2112. }
  2113. /* allocate command memory */
  2114. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
  2115. if (!prCmdInfo) {
  2116. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2117. return WLAN_STATUS_FAILURE;
  2118. }
  2119. /* increase command sequence number */
  2120. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2121. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2122. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2123. prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
  2124. prCmdInfo->pfCmdDoneHandler = NULL;
  2125. prCmdInfo->pfCmdTimeoutHandler = NULL;
  2126. prCmdInfo->fgIsOid = FALSE;
  2127. prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
  2128. prCmdInfo->fgSetQuery = TRUE;
  2129. prCmdInfo->fgNeedResp = FALSE;
  2130. prCmdInfo->fgDriverDomainMCR = FALSE;
  2131. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2132. prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
  2133. /* Setup WIFI_CMD_T */
  2134. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2135. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2136. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2137. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2138. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2139. /* configure CMD_BASIC_CONFIG */
  2140. prCmdBasicConfig = (P_CMD_BASIC_CONFIG) (prWifiCmd->aucBuffer);
  2141. kalMemCopy(&(prCmdBasicConfig->rMyMacAddr), &rMacAddr, PARAM_MAC_ADDR_LEN);
  2142. prCmdBasicConfig->ucNative80211 = 0;
  2143. prCmdBasicConfig->rCsumOffload.u2RxChecksum = 0;
  2144. prCmdBasicConfig->rCsumOffload.u2TxChecksum = 0;
  2145. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  2146. if (prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_TCP)
  2147. prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(2);
  2148. if (prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_UDP)
  2149. prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(1);
  2150. if (prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_TX_IP)
  2151. prCmdBasicConfig->rCsumOffload.u2TxChecksum |= BIT(0);
  2152. if (prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_TCP)
  2153. prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(2);
  2154. if (prAdapter->u4CSUMFlags & CSUM_OFFLOAD_EN_RX_UDP)
  2155. prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(1);
  2156. if (prAdapter->u4CSUMFlags & (CSUM_OFFLOAD_EN_RX_IPv4 | CSUM_OFFLOAD_EN_RX_IPv6))
  2157. prCmdBasicConfig->rCsumOffload.u2RxChecksum |= BIT(0);
  2158. #endif
  2159. /* send the command to FW */
  2160. if (wlanSendCommand(prAdapter, prCmdInfo) == WLAN_STATUS_RESOURCES) {
  2161. /* backup the command to wait response */
  2162. prCmdInfo->pfCmdDoneHandler = nicCmdEventQueryAddress;
  2163. kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T) prCmdInfo);
  2164. return WLAN_STATUS_PENDING;
  2165. }
  2166. /* send ok without response */
  2167. nicCmdEventQueryAddress(prAdapter, prCmdInfo, (PUINT_8) prCmdBasicConfig);
  2168. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2169. return WLAN_STATUS_SUCCESS;
  2170. }
  2171. /*----------------------------------------------------------------------------*/
  2172. /*!
  2173. * @brief This function is called to check if the device is in RF test mode
  2174. *
  2175. * @param pfnOidHandler Pointer to the OID handler
  2176. *
  2177. * @return TRUE
  2178. * FALSE
  2179. */
  2180. /*----------------------------------------------------------------------------*/
  2181. BOOLEAN wlanQueryTestMode(IN P_ADAPTER_T prAdapter)
  2182. {
  2183. ASSERT(prAdapter);
  2184. return prAdapter->fgTestMode;
  2185. }
  2186. /*----------------------------------------------------------------------------*/
  2187. /*!
  2188. * @brief This function is called to identify 802.1x and Bluetooth-over-Wi-Fi
  2189. * security frames, and queued into command queue for strict ordering
  2190. * due to 802.1x frames before add-key OIDs are not to be encrypted
  2191. *
  2192. * @param prAdapter Pointer of Adapter Data Structure
  2193. * @param prPacket Pointer of native packet
  2194. *
  2195. * @return TRUE
  2196. * FALSE
  2197. */
  2198. /*----------------------------------------------------------------------------*/
  2199. BOOLEAN wlanProcessSecurityFrame(IN P_ADAPTER_T prAdapter, IN P_NATIVE_PACKET prPacket)
  2200. {
  2201. UINT_8 ucPriorityParam;
  2202. UINT_8 aucEthDestAddr[PARAM_MAC_ADDR_LEN];
  2203. BOOLEAN fgIs1x = FALSE;
  2204. BOOLEAN fgIsPAL = FALSE;
  2205. UINT_32 u4PacketLen;
  2206. ULONG u4SysTime;
  2207. UINT_8 ucNetworkType;
  2208. P_CMD_INFO_T prCmdInfo;
  2209. UINT_8 ucCmdSeqNo = 0;
  2210. /* 1x data packets */
  2211. KAL_SPIN_LOCK_DECLARATION();
  2212. ASSERT(prAdapter);
  2213. ASSERT(prPacket);
  2214. /* retrieve some information for packet classification */
  2215. if (kalQoSFrameClassifierAndPacketInfo(prAdapter->prGlueInfo,
  2216. prPacket,
  2217. &ucPriorityParam,
  2218. &u4PacketLen,
  2219. aucEthDestAddr,
  2220. &fgIs1x,
  2221. &fgIsPAL,
  2222. &ucNetworkType,
  2223. &ucCmdSeqNo) == TRUE) {
  2224. /* almost TRUE except frame length < 14B */
  2225. if (fgIs1x == FALSE)
  2226. return FALSE;
  2227. /* get a free command entry */
  2228. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  2229. QUEUE_REMOVE_HEAD(&prAdapter->rFreeCmdList, prCmdInfo, P_CMD_INFO_T);
  2230. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_CMD_RESOURCE);
  2231. if (prCmdInfo) {
  2232. P_STA_RECORD_T prStaRec;
  2233. /* fill arrival time */
  2234. u4SysTime = (OS_SYSTIME) kalGetTimeTick();
  2235. GLUE_SET_PKT_ARRIVAL_TIME(prPacket, u4SysTime);
  2236. kalMemZero(prCmdInfo, sizeof(CMD_INFO_T));
  2237. prCmdInfo->eCmdType = COMMAND_TYPE_SECURITY_FRAME;
  2238. prCmdInfo->u2InfoBufLen = (UINT_16) u4PacketLen;
  2239. prCmdInfo->pucInfoBuffer = NULL;
  2240. prCmdInfo->prPacket = prPacket;
  2241. prCmdInfo->ucCmdSeqNum = ucCmdSeqNo;
  2242. #if 0
  2243. prCmdInfo->ucStaRecIndex = qmGetStaRecIdx(prAdapter,
  2244. aucEthDestAddr,
  2245. (ENUM_NETWORK_TYPE_INDEX_T) ucNetworkType);
  2246. #endif
  2247. prStaRec = cnmGetStaRecByAddress(prAdapter,
  2248. (ENUM_NETWORK_TYPE_INDEX_T) ucNetworkType,
  2249. aucEthDestAddr);
  2250. if (prStaRec)
  2251. prCmdInfo->ucStaRecIndex = prStaRec->ucIndex;
  2252. else
  2253. prCmdInfo->ucStaRecIndex = STA_REC_INDEX_NOT_FOUND;
  2254. prCmdInfo->eNetworkType = (ENUM_NETWORK_TYPE_INDEX_T) ucNetworkType;
  2255. prCmdInfo->pfCmdDoneHandler = wlanSecurityFrameTxDone;
  2256. prCmdInfo->pfCmdTimeoutHandler = wlanSecurityFrameTxTimeout;
  2257. prCmdInfo->fgIsOid = FALSE;
  2258. prCmdInfo->fgSetQuery = TRUE;
  2259. prCmdInfo->fgNeedResp = FALSE;
  2260. /*
  2261. queue the 1x packet and we will send the packet to CONNSYS by
  2262. using command queue
  2263. */
  2264. kalEnqueueCommand(prAdapter->prGlueInfo, (P_QUE_ENTRY_T) prCmdInfo);
  2265. /* TRUE: means we have already handled it in the function */
  2266. return TRUE;
  2267. }
  2268. /* no memory, why assert ? can skip the packet ? */
  2269. ASSERT(0);
  2270. return FALSE;
  2271. }
  2272. return FALSE;
  2273. }
  2274. /*----------------------------------------------------------------------------*/
  2275. /*!
  2276. * @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
  2277. * security frames has been sent to firmware
  2278. *
  2279. * @param prAdapter Pointer of Adapter Data Structure
  2280. * @param prCmdInfo Pointer of CMD_INFO_T
  2281. * @param pucEventBuf meaningless, only for API compatibility
  2282. *
  2283. * @return none
  2284. */
  2285. /*----------------------------------------------------------------------------*/
  2286. VOID wlanSecurityFrameTxDone(IN P_ADAPTER_T prAdapter, IN P_CMD_INFO_T prCmdInfo, IN PUINT_8 pucEventBuf)
  2287. {
  2288. ASSERT(prAdapter);
  2289. ASSERT(prCmdInfo);
  2290. if (prCmdInfo->eNetworkType == NETWORK_TYPE_AIS_INDEX &&
  2291. prAdapter->rWifiVar.rAisSpecificBssInfo.fgCounterMeasure) {
  2292. /* AIS counter measure so change RSN FSM to SEND_DEAUTH state */
  2293. P_STA_RECORD_T prSta = cnmGetStaRecByIndex(prAdapter, prCmdInfo->ucStaRecIndex);
  2294. if (prSta) {
  2295. kalMsleep(10);
  2296. secFsmEventEapolTxDone(prAdapter, prSta, TX_RESULT_SUCCESS);
  2297. }
  2298. }
  2299. /* free the packet */
  2300. kalSecurityFrameSendComplete(prAdapter->prGlueInfo, prCmdInfo->prPacket, WLAN_STATUS_SUCCESS);
  2301. DBGLOG(TX, TRACE, "Security frame tx done, SeqNum: %d\n", prCmdInfo->ucCmdSeqNum);
  2302. }
  2303. /*----------------------------------------------------------------------------*/
  2304. /*!
  2305. * @brief This function is called when 802.1x or Bluetooth-over-Wi-Fi
  2306. * security frames has failed sending to firmware
  2307. *
  2308. * @param prAdapter Pointer of Adapter Data Structure
  2309. * @param prCmdInfo Pointer of CMD_INFO_T
  2310. *
  2311. * @return none
  2312. */
  2313. /*----------------------------------------------------------------------------*/
  2314. VOID wlanSecurityFrameTxTimeout(IN P_ADAPTER_T prAdapter, IN P_CMD_INFO_T prCmdInfo)
  2315. {
  2316. ASSERT(prAdapter);
  2317. ASSERT(prCmdInfo);
  2318. /* free the packet */
  2319. kalSecurityFrameSendComplete(prAdapter->prGlueInfo, prCmdInfo->prPacket, WLAN_STATUS_FAILURE);
  2320. }
  2321. /*----------------------------------------------------------------------------*/
  2322. /*!
  2323. * @brief This function is called before AIS is starting a new scan
  2324. *
  2325. * @param prAdapter Pointer of Adapter Data Structure
  2326. *
  2327. * @return none
  2328. */
  2329. /*----------------------------------------------------------------------------*/
  2330. VOID wlanClearScanningResult(IN P_ADAPTER_T prAdapter)
  2331. {
  2332. BOOLEAN fgKeepCurrOne = FALSE;
  2333. UINT_32 i;
  2334. ASSERT(prAdapter);
  2335. /* clear scanning result except current one */
  2336. /* copy current one to prAdapter->rWlanInfo.arScanResult[0] */
  2337. if (kalGetMediaStateIndicated(prAdapter->prGlueInfo) == PARAM_MEDIA_STATE_CONNECTED) {
  2338. for (i = 0; i < prAdapter->rWlanInfo.u4ScanResultNum; i++) {
  2339. if (EQUAL_MAC_ADDR(prAdapter->rWlanInfo.rCurrBssId.arMacAddress,
  2340. prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
  2341. fgKeepCurrOne = TRUE;
  2342. if (i != 0) {
  2343. /* copy structure */
  2344. kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[0]),
  2345. &(prAdapter->rWlanInfo.arScanResult[i]),
  2346. OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
  2347. }
  2348. if (prAdapter->rWlanInfo.arScanResult[i].u4IELength > 0) {
  2349. if (prAdapter->rWlanInfo.apucScanResultIEs[i] !=
  2350. &(prAdapter->rWlanInfo.aucScanIEBuf[0])) {
  2351. /* move IEs to head */
  2352. kalMemCopy(prAdapter->rWlanInfo.aucScanIEBuf,
  2353. prAdapter->rWlanInfo.apucScanResultIEs[i],
  2354. prAdapter->rWlanInfo.arScanResult[i].u4IELength);
  2355. }
  2356. /* modify IE pointer */
  2357. prAdapter->rWlanInfo.apucScanResultIEs[0] =
  2358. &(prAdapter->rWlanInfo.aucScanIEBuf[0]);
  2359. } else {
  2360. prAdapter->rWlanInfo.apucScanResultIEs[0] = NULL;
  2361. }
  2362. break;
  2363. }
  2364. }
  2365. }
  2366. if (fgKeepCurrOne == TRUE) {
  2367. prAdapter->rWlanInfo.u4ScanResultNum = 1;
  2368. prAdapter->rWlanInfo.u4ScanIEBufferUsage = ALIGN_4(prAdapter->rWlanInfo.arScanResult[0].u4IELength);
  2369. } else {
  2370. prAdapter->rWlanInfo.u4ScanResultNum = 0;
  2371. prAdapter->rWlanInfo.u4ScanIEBufferUsage = 0;
  2372. }
  2373. }
  2374. /*----------------------------------------------------------------------------*/
  2375. /*!
  2376. * @brief This function is called when AIS received a beacon timeout event
  2377. *
  2378. * @param prAdapter Pointer of Adapter Data Structure
  2379. * @param arBSSID MAC address of the specified BSS
  2380. *
  2381. * @return none
  2382. */
  2383. /*----------------------------------------------------------------------------*/
  2384. VOID wlanClearBssInScanningResult(IN P_ADAPTER_T prAdapter, IN PUINT_8 arBSSID)
  2385. {
  2386. UINT_32 i, j, u4IELength = 0, u4IEMoveLength;
  2387. PUINT_8 pucIEPtr;
  2388. ASSERT(prAdapter);
  2389. /* clear the scanning result for arBSSID */
  2390. i = 0;
  2391. while (1) {
  2392. if (i >= prAdapter->rWlanInfo.u4ScanResultNum)
  2393. break;
  2394. if (EQUAL_MAC_ADDR(arBSSID, prAdapter->rWlanInfo.arScanResult[i].arMacAddress)) {
  2395. /* backup current IE length */
  2396. u4IELength = ALIGN_4(prAdapter->rWlanInfo.arScanResult[i].u4IELength);
  2397. pucIEPtr = prAdapter->rWlanInfo.apucScanResultIEs[i];
  2398. /* removed from middle */
  2399. for (j = i + 1; j < prAdapter->rWlanInfo.u4ScanResultNum; j++) {
  2400. kalMemCopy(&(prAdapter->rWlanInfo.arScanResult[j - 1]),
  2401. &(prAdapter->rWlanInfo.arScanResult[j]),
  2402. OFFSET_OF(PARAM_BSSID_EX_T, aucIEs));
  2403. prAdapter->rWlanInfo.apucScanResultIEs[j - 1] =
  2404. prAdapter->rWlanInfo.apucScanResultIEs[j];
  2405. }
  2406. prAdapter->rWlanInfo.u4ScanResultNum--;
  2407. /* remove IE buffer if needed := move rest of IE buffer */
  2408. if (u4IELength > 0) {
  2409. u4IEMoveLength = prAdapter->rWlanInfo.u4ScanIEBufferUsage -
  2410. (((ULONG) pucIEPtr) + (ULONG) u4IELength -
  2411. ((ULONG) (&(prAdapter->rWlanInfo.aucScanIEBuf[0]))));
  2412. kalMemCopy(pucIEPtr, pucIEPtr + u4IELength, u4IEMoveLength);
  2413. prAdapter->rWlanInfo.u4ScanIEBufferUsage -= u4IELength;
  2414. /* correction of pointers to IE buffer */
  2415. for (j = 0; j < prAdapter->rWlanInfo.u4ScanResultNum; j++) {
  2416. if (prAdapter->rWlanInfo.apucScanResultIEs[j] > pucIEPtr) {
  2417. prAdapter->rWlanInfo.apucScanResultIEs[j] =
  2418. (PUINT_8) ((ULONG) (prAdapter->rWlanInfo.apucScanResultIEs[j]) -
  2419. u4IELength);
  2420. }
  2421. }
  2422. }
  2423. }
  2424. i++;
  2425. }
  2426. }
  2427. #if CFG_TEST_WIFI_DIRECT_GO
  2428. VOID wlanEnableP2pFunction(IN P_ADAPTER_T prAdapter)
  2429. {
  2430. #if 0
  2431. P_MSG_P2P_FUNCTION_SWITCH_T prMsgFuncSwitch = (P_MSG_P2P_FUNCTION_SWITCH_T) NULL;
  2432. prMsgFuncSwitch =
  2433. (P_MSG_P2P_FUNCTION_SWITCH_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_FUNCTION_SWITCH_T));
  2434. if (!prMsgFuncSwitch) {
  2435. ASSERT(FALSE);
  2436. return;
  2437. }
  2438. prMsgFuncSwitch->rMsgHdr.eMsgId = MID_MNY_P2P_FUN_SWITCH;
  2439. prMsgFuncSwitch->fgIsFuncOn = TRUE;
  2440. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgFuncSwitch, MSG_SEND_METHOD_BUF);
  2441. #endif
  2442. }
  2443. VOID wlanEnableATGO(IN P_ADAPTER_T prAdapter)
  2444. {
  2445. P_MSG_P2P_CONNECTION_REQUEST_T prMsgConnReq = (P_MSG_P2P_CONNECTION_REQUEST_T) NULL;
  2446. UINT_8 aucTargetDeviceID[MAC_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  2447. prMsgConnReq =
  2448. (P_MSG_P2P_CONNECTION_REQUEST_T) cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_P2P_CONNECTION_REQUEST_T));
  2449. if (!prMsgConnReq) {
  2450. ASSERT(FALSE);
  2451. return;
  2452. }
  2453. prMsgConnReq->rMsgHdr.eMsgId = MID_MNY_P2P_CONNECTION_REQ;
  2454. /*=====Param Modified for test=====*/
  2455. COPY_MAC_ADDR(prMsgConnReq->aucDeviceID, aucTargetDeviceID);
  2456. prMsgConnReq->fgIsTobeGO = TRUE;
  2457. prMsgConnReq->fgIsPersistentGroup = FALSE;
  2458. /*=====Param Modified for test=====*/
  2459. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prMsgConnReq, MSG_SEND_METHOD_BUF);
  2460. }
  2461. #endif
  2462. /*----------------------------------------------------------------------------*/
  2463. /*!
  2464. * @brief This function is called to retrieve permanent address from firmware
  2465. *
  2466. * @param prAdapter Pointer of Adapter Data Structure
  2467. *
  2468. * @return WLAN_STATUS_SUCCESS
  2469. * WLAN_STATUS_FAILURE
  2470. */
  2471. /*----------------------------------------------------------------------------*/
  2472. WLAN_STATUS wlanQueryPermanentAddress(IN P_ADAPTER_T prAdapter)
  2473. {
  2474. UINT_8 ucCmdSeqNum;
  2475. P_CMD_INFO_T prCmdInfo;
  2476. P_WIFI_CMD_T prWifiCmd;
  2477. UINT_32 u4RxPktLength;
  2478. UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG)];
  2479. P_HIF_RX_HEADER_T prHifRxHdr;
  2480. P_WIFI_EVENT_T prEvent;
  2481. P_EVENT_BASIC_CONFIG prEventBasicConfig;
  2482. ASSERT(prAdapter);
  2483. DEBUGFUNC("wlanQueryPermanentAddress");
  2484. /* 1. Allocate CMD Info Packet and its Buffer */
  2485. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG));
  2486. if (!prCmdInfo) {
  2487. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2488. return WLAN_STATUS_FAILURE;
  2489. }
  2490. /* increase command sequence number */
  2491. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2492. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2493. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2494. prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_BASIC_CONFIG);
  2495. prCmdInfo->pfCmdDoneHandler = NULL;
  2496. prCmdInfo->fgIsOid = FALSE;
  2497. prCmdInfo->ucCID = CMD_ID_BASIC_CONFIG;
  2498. prCmdInfo->fgSetQuery = FALSE;
  2499. prCmdInfo->fgNeedResp = TRUE;
  2500. prCmdInfo->fgDriverDomainMCR = FALSE;
  2501. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2502. prCmdInfo->u4SetInfoLen = sizeof(CMD_BASIC_CONFIG);
  2503. /* Setup WIFI_CMD_T */
  2504. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2505. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2506. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2507. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2508. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2509. /* send the command */
  2510. wlanSendCommand(prAdapter, prCmdInfo);
  2511. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2512. /* wait for response */
  2513. if (nicRxWaitResponse(prAdapter,
  2514. 1,
  2515. aucBuffer,
  2516. sizeof(WIFI_EVENT_T) + sizeof(EVENT_BASIC_CONFIG), /* 8B + 12B */
  2517. &u4RxPktLength) != WLAN_STATUS_SUCCESS)
  2518. return WLAN_STATUS_FAILURE;
  2519. /* header checking .. */
  2520. prHifRxHdr = (P_HIF_RX_HEADER_T) aucBuffer;
  2521. if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT)
  2522. return WLAN_STATUS_FAILURE;
  2523. prEvent = (P_WIFI_EVENT_T) aucBuffer;
  2524. if (prEvent->ucEID != EVENT_ID_BASIC_CONFIG)
  2525. return WLAN_STATUS_FAILURE;
  2526. prEventBasicConfig = (P_EVENT_BASIC_CONFIG) (prEvent->aucBuffer);
  2527. COPY_MAC_ADDR(prAdapter->rWifiVar.aucPermanentAddress, &(prEventBasicConfig->rMyMacAddr));
  2528. COPY_MAC_ADDR(prAdapter->rWifiVar.aucMacAddress, &(prEventBasicConfig->rMyMacAddr));
  2529. return WLAN_STATUS_SUCCESS;
  2530. }
  2531. /*----------------------------------------------------------------------------*/
  2532. /*!
  2533. * @brief This function is called to retrieve NIC capability from firmware
  2534. *
  2535. * @param prAdapter Pointer of Adapter Data Structure
  2536. *
  2537. * @return WLAN_STATUS_SUCCESS
  2538. * WLAN_STATUS_FAILURE
  2539. */
  2540. /*----------------------------------------------------------------------------*/
  2541. UINT_32 g_u2FwIDVersion = 0;
  2542. WLAN_STATUS wlanQueryNicCapability(IN P_ADAPTER_T prAdapter)
  2543. {
  2544. UINT_8 ucCmdSeqNum;
  2545. P_CMD_INFO_T prCmdInfo;
  2546. P_WIFI_CMD_T prWifiCmd;
  2547. UINT_32 u4RxPktLength;
  2548. UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY)];
  2549. P_HIF_RX_HEADER_T prHifRxHdr;
  2550. P_WIFI_EVENT_T prEvent;
  2551. P_EVENT_NIC_CAPABILITY prEventNicCapability;
  2552. ASSERT(prAdapter);
  2553. DEBUGFUNC("wlanQueryNicCapability");
  2554. /* 1. Allocate CMD Info Packet and its Buffer */
  2555. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY));
  2556. if (!prCmdInfo) {
  2557. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2558. return WLAN_STATUS_FAILURE;
  2559. }
  2560. /* increase command sequence number */
  2561. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2562. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2563. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2564. prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(EVENT_NIC_CAPABILITY);
  2565. prCmdInfo->pfCmdDoneHandler = NULL;
  2566. prCmdInfo->fgIsOid = FALSE;
  2567. prCmdInfo->ucCID = CMD_ID_GET_NIC_CAPABILITY;
  2568. prCmdInfo->fgSetQuery = FALSE;
  2569. prCmdInfo->fgNeedResp = TRUE;
  2570. prCmdInfo->fgDriverDomainMCR = FALSE;
  2571. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2572. prCmdInfo->u4SetInfoLen = 0;
  2573. /* Setup WIFI_CMD_T */
  2574. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2575. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2576. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2577. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2578. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2579. /* send the command */
  2580. wlanSendCommand(prAdapter, prCmdInfo);
  2581. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2582. /* wait for FW response */
  2583. if (nicRxWaitResponse(prAdapter,
  2584. 1,
  2585. aucBuffer,
  2586. sizeof(WIFI_EVENT_T) + sizeof(EVENT_NIC_CAPABILITY),
  2587. &u4RxPktLength) != WLAN_STATUS_SUCCESS)
  2588. return WLAN_STATUS_FAILURE;
  2589. /* header checking .. */
  2590. prHifRxHdr = (P_HIF_RX_HEADER_T) aucBuffer;
  2591. if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT)
  2592. return WLAN_STATUS_FAILURE;
  2593. prEvent = (P_WIFI_EVENT_T) aucBuffer;
  2594. if (prEvent->ucEID != EVENT_ID_NIC_CAPABILITY)
  2595. return WLAN_STATUS_FAILURE;
  2596. prEventNicCapability = (P_EVENT_NIC_CAPABILITY) (prEvent->aucBuffer);
  2597. prAdapter->rVerInfo.u2FwProductID = prEventNicCapability->u2ProductID;
  2598. prAdapter->rVerInfo.u2FwOwnVersion = prEventNicCapability->u2FwVersion;
  2599. prAdapter->rVerInfo.u2FwPeerVersion = prEventNicCapability->u2DriverVersion;
  2600. prAdapter->rVerInfo.u2FwOwnVersionExtend = prEventNicCapability->aucReserved[0];
  2601. prAdapter->fgIsHw5GBandDisabled = (BOOLEAN) prEventNicCapability->ucHw5GBandDisabled;
  2602. prAdapter->fgIsEepromUsed = (BOOLEAN) prEventNicCapability->ucEepromUsed;
  2603. prAdapter->fgIsEfuseValid = (BOOLEAN) prEventNicCapability->ucEfuseValid;
  2604. prAdapter->fgIsEmbbededMacAddrValid = (BOOLEAN) prEventNicCapability->ucMacAddrValid;
  2605. g_u2FwIDVersion = (prAdapter->rVerInfo.u2FwProductID << 16) | (prAdapter->rVerInfo.u2FwOwnVersion);
  2606. #if (CFG_SUPPORT_TDLS == 1)
  2607. if (prEventNicCapability->ucFeatureSet & (1 << FEATURE_SET_OFFSET_TDLS))
  2608. prAdapter->fgTdlsIsSup = TRUE;
  2609. DBGLOG(TDLS, TRACE, "<wifi> support flag: 0x%x\n", prEventNicCapability->ucFeatureSet);
  2610. #else
  2611. prAdapter->fgTdlsIsSup = 0;
  2612. #endif /* CFG_SUPPORT_TDLS */
  2613. if (!(prEventNicCapability->ucFeatureSet & (1 << FEATURE_SET_OFFSET_5G_SUPPORT)))
  2614. prAdapter->fgEnable5GBand = FALSE; /* firmware does not support */
  2615. #if CFG_ENABLE_CAL_LOG
  2616. DBGLOG(INIT, LOUD, " RF CAL FAIL = (%d),BB CAL FAIL = (%d)\n",
  2617. prEventNicCapability->ucRfCalFail, prEventNicCapability->ucBbCalFail);
  2618. #endif
  2619. return WLAN_STATUS_SUCCESS;
  2620. }
  2621. /*----------------------------------------------------------------------------*/
  2622. /*!
  2623. * @brief This function is called to retrieve NIC capability from firmware
  2624. *
  2625. * @param prAdapter Pointer of Adapter Data Structure
  2626. *
  2627. * @return WLAN_STATUS_SUCCESS
  2628. * WLAN_STATUS_FAILURE
  2629. */
  2630. /*----------------------------------------------------------------------------*/
  2631. WLAN_STATUS wlanQueryDebugCode(IN P_ADAPTER_T prAdapter)
  2632. {
  2633. UINT_8 ucCmdSeqNum;
  2634. P_CMD_INFO_T prCmdInfo;
  2635. P_WIFI_CMD_T prWifiCmd;
  2636. ASSERT(prAdapter);
  2637. DEBUGFUNC("wlanQueryDebugCode");
  2638. /* 1. Allocate CMD Info Packet and its Buffer */
  2639. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE);
  2640. if (!prCmdInfo) {
  2641. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2642. return WLAN_STATUS_FAILURE;
  2643. }
  2644. /* increase command sequence number */
  2645. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2646. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2647. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2648. prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE;
  2649. prCmdInfo->pfCmdDoneHandler = NULL;
  2650. prCmdInfo->fgIsOid = FALSE;
  2651. prCmdInfo->ucCID = CMD_ID_GET_DEBUG_CODE;
  2652. prCmdInfo->fgSetQuery = FALSE;
  2653. prCmdInfo->fgNeedResp = FALSE;
  2654. prCmdInfo->fgDriverDomainMCR = FALSE;
  2655. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2656. prCmdInfo->u4SetInfoLen = 0;
  2657. /* Setup WIFI_CMD_T */
  2658. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2659. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2660. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2661. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2662. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2663. /* send the command */
  2664. wlanSendCommand(prAdapter, prCmdInfo);
  2665. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2666. return WLAN_STATUS_SUCCESS;
  2667. }
  2668. /*----------------------------------------------------------------------------*/
  2669. /*!
  2670. * @brief This function is called to retrieve compiler flag from firmware
  2671. *
  2672. * @param prAdapter Pointer of Adapter Data Structure
  2673. *
  2674. * @return WLAN_STATUS_SUCCESS
  2675. * WLAN_STATUS_FAILURE
  2676. */
  2677. /*----------------------------------------------------------------------------*/
  2678. WLAN_STATUS wlanQueryCompileFlag(IN P_ADAPTER_T prAdapter, IN UINT_32 u4QueryID, OUT PUINT_32 pu4CompilerFlag)
  2679. {
  2680. UINT_8 ucCmdSeqNum;
  2681. P_CMD_INFO_T prCmdInfo;
  2682. P_WIFI_CMD_T prWifiCmd;
  2683. UINT_32 u4RxPktLength;
  2684. UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(CMD_SW_DBG_CTRL_T)];
  2685. P_HIF_RX_HEADER_T prHifRxHdr;
  2686. P_WIFI_EVENT_T prEvent;
  2687. P_CMD_SW_DBG_CTRL_T prCmdNicCompileFlag, prEventNicCompileFlag;
  2688. ASSERT(prAdapter);
  2689. DEBUGFUNC(__func__);
  2690. /* 1. Allocate CMD Info Packet and its Buffer */
  2691. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_SW_DBG_CTRL_T));
  2692. if (!prCmdInfo) {
  2693. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2694. return WLAN_STATUS_FAILURE;
  2695. }
  2696. /* increase command sequence number */
  2697. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2698. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2699. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2700. prCmdInfo->u2InfoBufLen = CMD_HDR_SIZE + sizeof(CMD_SW_DBG_CTRL_T);
  2701. prCmdInfo->pfCmdDoneHandler = NULL;
  2702. prCmdInfo->fgIsOid = FALSE;
  2703. prCmdInfo->ucCID = CMD_ID_SW_DBG_CTRL;
  2704. prCmdInfo->fgSetQuery = FALSE;
  2705. prCmdInfo->fgNeedResp = TRUE;
  2706. prCmdInfo->fgDriverDomainMCR = FALSE;
  2707. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2708. prCmdInfo->u4SetInfoLen = 0;
  2709. /* Setup WIFI_CMD_T */
  2710. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2711. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2712. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2713. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2714. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2715. /* Fill up SW CR */
  2716. prCmdNicCompileFlag = (P_CMD_SW_DBG_CTRL_T) (prWifiCmd->aucBuffer);
  2717. prCmdNicCompileFlag->u4Id = u4QueryID;
  2718. wlanSendCommand(prAdapter, prCmdInfo);
  2719. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2720. if (nicRxWaitResponse(prAdapter,
  2721. 1,
  2722. aucBuffer,
  2723. sizeof(WIFI_EVENT_T) + sizeof(CMD_SW_DBG_CTRL_T),
  2724. &u4RxPktLength) != WLAN_STATUS_SUCCESS)
  2725. return WLAN_STATUS_FAILURE;
  2726. /* header checking .. */
  2727. prHifRxHdr = (P_HIF_RX_HEADER_T) aucBuffer;
  2728. if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT)
  2729. return WLAN_STATUS_FAILURE;
  2730. prEvent = (P_WIFI_EVENT_T) aucBuffer;
  2731. if (prEvent->ucEID != EVENT_ID_SW_DBG_CTRL)
  2732. return WLAN_STATUS_FAILURE;
  2733. prEventNicCompileFlag = (P_CMD_SW_DBG_CTRL_T) (prEvent->aucBuffer);
  2734. *pu4CompilerFlag = prEventNicCompileFlag->u4Data;
  2735. return WLAN_STATUS_SUCCESS;
  2736. }
  2737. WLAN_STATUS wlanQueryCompileFlags(IN P_ADAPTER_T prAdapter)
  2738. {
  2739. wlanQueryCompileFlag(prAdapter, 0xA0240000, &prAdapter->u4FwCompileFlag0);
  2740. wlanQueryCompileFlag(prAdapter, 0xA0240001, &prAdapter->u4FwCompileFlag1);
  2741. DBGLOG(INIT, TRACE,
  2742. "Compile Flags: 0x%08x 0x%08x\n", prAdapter->u4FwCompileFlag0, prAdapter->u4FwCompileFlag1);
  2743. return WLAN_STATUS_SUCCESS;
  2744. }
  2745. #if defined(MT6628)
  2746. static INT_32 wlanChangeCodeWord(INT_32 au4Input)
  2747. {
  2748. UINT_16 i;
  2749. #if TXPWR_USE_PDSLOPE
  2750. CODE_MAPPING_T arCodeTable[] = {
  2751. {0X100, -40},
  2752. {0X104, -35},
  2753. {0X128, -30},
  2754. {0X14C, -25},
  2755. {0X170, -20},
  2756. {0X194, -15},
  2757. {0X1B8, -10},
  2758. {0X1DC, -5},
  2759. {0, 0},
  2760. {0X24, 5},
  2761. {0X48, 10},
  2762. {0X6C, 15},
  2763. {0X90, 20},
  2764. {0XB4, 25},
  2765. {0XD8, 30},
  2766. {0XFC, 35},
  2767. {0XFF, 40},
  2768. };
  2769. #else
  2770. CODE_MAPPING_T arCodeTable[] = {
  2771. {0X100, 0x80},
  2772. {0X104, 0x80},
  2773. {0X128, 0x80},
  2774. {0X14C, 0x80},
  2775. {0X170, 0x80},
  2776. {0X194, 0x94},
  2777. {0X1B8, 0XB8},
  2778. {0X1DC, 0xDC},
  2779. {0, 0},
  2780. {0X24, 0x24},
  2781. {0X48, 0x48},
  2782. {0X6C, 0x6c},
  2783. {0X90, 0x7F},
  2784. {0XB4, 0x7F},
  2785. {0XD8, 0x7F},
  2786. {0XFC, 0x7F},
  2787. {0XFF, 0x7F},
  2788. };
  2789. #endif
  2790. for (i = 0; i < sizeof(arCodeTable) / sizeof(CODE_MAPPING_T); i++) {
  2791. if (arCodeTable[i].u4RegisterValue == au4Input)
  2792. return arCodeTable[i].i4TxpowerOffset;
  2793. }
  2794. return 0;
  2795. }
  2796. #endif
  2797. #if TXPWR_USE_PDSLOPE
  2798. /*----------------------------------------------------------------------------*/
  2799. /*!
  2800. * @brief
  2801. *
  2802. * @param prAdapter Pointer of Adapter Data Structure
  2803. *
  2804. * @return WLAN_STATUS_SUCCESS
  2805. * WLAN_STATUS_FAILURE
  2806. */
  2807. /*----------------------------------------------------------------------------*/
  2808. WLAN_STATUS wlanQueryPdMcr(IN P_ADAPTER_T prAdapter, P_PARAM_MCR_RW_STRUCT_T prMcrRdInfo)
  2809. {
  2810. UINT_8 ucCmdSeqNum;
  2811. P_CMD_INFO_T prCmdInfo;
  2812. P_WIFI_CMD_T prWifiCmd;
  2813. UINT_32 u4RxPktLength;
  2814. UINT_8 aucBuffer[sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG)];
  2815. P_HIF_RX_HEADER_T prHifRxHdr;
  2816. P_WIFI_EVENT_T prEvent;
  2817. P_CMD_ACCESS_REG prCmdMcrQuery;
  2818. ASSERT(prAdapter);
  2819. /* 1. Allocate CMD Info Packet and its Buffer */
  2820. prCmdInfo = cmdBufAllocateCmdInfo(prAdapter, CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
  2821. if (!prCmdInfo) {
  2822. DBGLOG(INIT, ERROR, "Allocate CMD_INFO_T ==> FAILED.\n");
  2823. return WLAN_STATUS_FAILURE;
  2824. }
  2825. /* increase command sequence number */
  2826. ucCmdSeqNum = nicIncreaseCmdSeqNum(prAdapter);
  2827. /* compose CMD_BUILD_CONNECTION cmd pkt */
  2828. prCmdInfo->eCmdType = COMMAND_TYPE_GENERAL_IOCTL;
  2829. prCmdInfo->u2InfoBufLen = (UINT_16) (CMD_HDR_SIZE + sizeof(CMD_ACCESS_REG));
  2830. prCmdInfo->pfCmdDoneHandler = NULL;
  2831. prCmdInfo->pfCmdTimeoutHandler = nicOidCmdTimeoutCommon;
  2832. prCmdInfo->fgIsOid = FALSE;
  2833. prCmdInfo->ucCID = CMD_ID_ACCESS_REG;
  2834. prCmdInfo->fgSetQuery = FALSE;
  2835. prCmdInfo->fgNeedResp = TRUE;
  2836. prCmdInfo->fgDriverDomainMCR = FALSE;
  2837. prCmdInfo->ucCmdSeqNum = ucCmdSeqNum;
  2838. prCmdInfo->u4SetInfoLen = sizeof(CMD_ACCESS_REG);
  2839. /* Setup WIFI_CMD_T */
  2840. prWifiCmd = (P_WIFI_CMD_T) (prCmdInfo->pucInfoBuffer);
  2841. prWifiCmd->u2TxByteCount_UserPriority = prCmdInfo->u2InfoBufLen;
  2842. prWifiCmd->ucCID = prCmdInfo->ucCID;
  2843. prWifiCmd->ucSetQuery = prCmdInfo->fgSetQuery;
  2844. prWifiCmd->ucSeqNum = prCmdInfo->ucCmdSeqNum;
  2845. kalMemCopy(prWifiCmd->aucBuffer, prMcrRdInfo, sizeof(CMD_ACCESS_REG));
  2846. wlanSendCommand(prAdapter, prCmdInfo);
  2847. cmdBufFreeCmdInfo(prAdapter, prCmdInfo);
  2848. if (nicRxWaitResponse(prAdapter,
  2849. 1,
  2850. aucBuffer,
  2851. sizeof(WIFI_EVENT_T) + sizeof(CMD_ACCESS_REG), &u4RxPktLength) != WLAN_STATUS_SUCCESS)
  2852. return WLAN_STATUS_FAILURE;
  2853. /* header checking .. */
  2854. prHifRxHdr = (P_HIF_RX_HEADER_T) aucBuffer;
  2855. if ((prHifRxHdr->u2PacketType & HIF_RX_HDR_PACKET_TYPE_MASK) != HIF_RX_PKT_TYPE_EVENT)
  2856. return WLAN_STATUS_FAILURE;
  2857. prEvent = (P_WIFI_EVENT_T) aucBuffer;
  2858. if (prEvent->ucEID != EVENT_ID_ACCESS_REG)
  2859. return WLAN_STATUS_FAILURE;
  2860. prCmdMcrQuery = (P_CMD_ACCESS_REG) (prEvent->aucBuffer);
  2861. prMcrRdInfo->u4McrOffset = prCmdMcrQuery->u4Address;
  2862. prMcrRdInfo->u4McrData = prCmdMcrQuery->u4Data;
  2863. return WLAN_STATUS_SUCCESS;
  2864. }
  2865. static INT_32 wlanIntRound(INT_32 au4Input)
  2866. {
  2867. if (au4Input >= 0) {
  2868. if ((au4Input % 10) == 5) {
  2869. au4Input = au4Input + 5;
  2870. return au4Input;
  2871. }
  2872. }
  2873. if (au4Input < 0) {
  2874. if ((au4Input % 10) == -5) {
  2875. au4Input = au4Input - 5;
  2876. return au4Input;
  2877. }
  2878. }
  2879. return au4Input;
  2880. }
  2881. static INT_32 wlanCal6628EfuseForm(IN P_ADAPTER_T prAdapter, INT_32 au4Input)
  2882. {
  2883. PARAM_MCR_RW_STRUCT_T rMcrRdInfo;
  2884. INT_32 au4PdSlope, au4TxPwrOffset, au4TxPwrOffset_Round;
  2885. INT_8 auTxPwrOffset_Round;
  2886. rMcrRdInfo.u4McrOffset = 0x60205c68;
  2887. rMcrRdInfo.u4McrData = 0;
  2888. au4TxPwrOffset = au4Input;
  2889. wlanQueryPdMcr(prAdapter, &rMcrRdInfo);
  2890. au4PdSlope = (rMcrRdInfo.u4McrData) & BITS(0, 6);
  2891. au4TxPwrOffset_Round = wlanIntRound((au4TxPwrOffset * au4PdSlope)) / 10;
  2892. au4TxPwrOffset_Round = -au4TxPwrOffset_Round;
  2893. if (au4TxPwrOffset_Round < -128)
  2894. au4TxPwrOffset_Round = 128;
  2895. else if (au4TxPwrOffset_Round < 0)
  2896. au4TxPwrOffset_Round += 256;
  2897. else if (au4TxPwrOffset_Round > 127)
  2898. au4TxPwrOffset_Round = 127;
  2899. auTxPwrOffset_Round = (UINT8) au4TxPwrOffset_Round;
  2900. return au4TxPwrOffset_Round;
  2901. }
  2902. #endif
  2903. #if defined(MT6628)
  2904. static VOID wlanChangeNvram6620to6628(PUINT_8 pucEFUSE)
  2905. {
  2906. #define EFUSE_CH_OFFSET1_L_MASK_6620 BITS(0, 8)
  2907. #define EFUSE_CH_OFFSET1_L_SHIFT_6620 0
  2908. #define EFUSE_CH_OFFSET1_M_MASK_6620 BITS(9, 17)
  2909. #define EFUSE_CH_OFFSET1_M_SHIFT_6620 9
  2910. #define EFUSE_CH_OFFSET1_H_MASK_6620 BITS(18, 26)
  2911. #define EFUSE_CH_OFFSET1_H_SHIFT_6620 18
  2912. #define EFUSE_CH_OFFSET1_VLD_MASK_6620 BIT(27)
  2913. #define EFUSE_CH_OFFSET1_VLD_SHIFT_6620 27
  2914. #define EFUSE_CH_OFFSET1_L_MASK_5931 BITS(0, 7)
  2915. #define EFUSE_CH_OFFSET1_L_SHIFT_5931 0
  2916. #define EFUSE_CH_OFFSET1_M_MASK_5931 BITS(8, 15)
  2917. #define EFUSE_CH_OFFSET1_M_SHIFT_5931 8
  2918. #define EFUSE_CH_OFFSET1_H_MASK_5931 BITS(16, 23)
  2919. #define EFUSE_CH_OFFSET1_H_SHIFT_5931 16
  2920. #define EFUSE_CH_OFFSET1_VLD_MASK_5931 BIT(24)
  2921. #define EFUSE_CH_OFFSET1_VLD_SHIFT_5931 24
  2922. #define EFUSE_ALL_CH_OFFSET1_MASK_5931 BITS(25, 27)
  2923. #define EFUSE_ALL_CH_OFFSET1_SHIFT_5931 25
  2924. INT_32 au4ChOffset;
  2925. INT_16 au2ChOffsetL, au2ChOffsetM, au2ChOffsetH;
  2926. au4ChOffset = *(UINT_32 *) (pucEFUSE + 72);
  2927. if ((au4ChOffset & EFUSE_CH_OFFSET1_VLD_MASK_6620) && ((*(UINT_32 *) (pucEFUSE + 28)) == 0)) {
  2928. au2ChOffsetL = ((au4ChOffset & EFUSE_CH_OFFSET1_L_MASK_6620) >> EFUSE_CH_OFFSET1_L_SHIFT_6620);
  2929. au2ChOffsetM = ((au4ChOffset & EFUSE_CH_OFFSET1_M_MASK_6620) >> EFUSE_CH_OFFSET1_M_SHIFT_6620);
  2930. au2ChOffsetH = ((au4ChOffset & EFUSE_CH_OFFSET1_H_MASK_6620) >> EFUSE_CH_OFFSET1_H_SHIFT_6620);
  2931. au2ChOffsetL = wlanChangeCodeWord(au2ChOffsetL);
  2932. au2ChOffsetM = wlanChangeCodeWord(au2ChOffsetM);
  2933. au2ChOffsetH = wlanChangeCodeWord(au2ChOffsetH);
  2934. au4ChOffset = 0;
  2935. au4ChOffset |= *(UINT_32 *) (pucEFUSE + 72)
  2936. >> (EFUSE_CH_OFFSET1_VLD_SHIFT_6620 -
  2937. EFUSE_CH_OFFSET1_VLD_SHIFT_5931) & EFUSE_CH_OFFSET1_VLD_MASK_5931;
  2938. au4ChOffset |=
  2939. ((((UINT_32) au2ChOffsetL) << EFUSE_CH_OFFSET1_L_SHIFT_5931) & EFUSE_CH_OFFSET1_L_MASK_5931);
  2940. au4ChOffset |=
  2941. ((((UINT_32) au2ChOffsetM) << EFUSE_CH_OFFSET1_M_SHIFT_5931) & EFUSE_CH_OFFSET1_M_MASK_5931);
  2942. au4ChOffset |=
  2943. ((((UINT_32) au2ChOffsetH) << EFUSE_CH_OFFSET1_H_SHIFT_5931) & EFUSE_CH_OFFSET1_H_MASK_5931);
  2944. *((INT_32 *) ((pucEFUSE + 28))) = au4ChOffset;
  2945. }
  2946. }
  2947. #endif
  2948. ENUM_BAND_EDGE_CERT_T getBandEdgeCert(P_ADAPTER_T prAdapter)
  2949. {
  2950. P_DOMAIN_INFO_ENTRY prDomainInfo;
  2951. P_DOMAIN_SUBBAND_INFO prSubband;
  2952. UINT32 i;
  2953. prDomainInfo = rlmDomainGetDomainInfo(prAdapter);
  2954. ASSERT(prDomainInfo);
  2955. for (i = 0; i < MAX_SUBBAND_NUM; i++) {
  2956. prSubband = &prDomainInfo->rSubBand[i];
  2957. if (prSubband->ucBand == BAND_2G4) {
  2958. if (prSubband->ucFirstChannelNum == 1) {
  2959. if (prSubband->ucNumChannels == 13)
  2960. return BAND_EDGE_CERT_KCC;
  2961. else
  2962. return BAND_EDGE_CERT_FCC;
  2963. }
  2964. }
  2965. }
  2966. return BAND_EDGE_CERT_FCC;
  2967. }
  2968. /*----------------------------------------------------------------------------*/
  2969. /*!
  2970. * @brief This function is called to load manufacture data from NVRAM
  2971. * if available and valid
  2972. *
  2973. * @param prAdapter Pointer of Adapter Data Structure
  2974. * @param prRegInfo Pointer of REG_INFO_T
  2975. *
  2976. * @return WLAN_STATUS_SUCCESS
  2977. * WLAN_STATUS_FAILURE
  2978. */
  2979. /*----------------------------------------------------------------------------*/
  2980. WLAN_STATUS wlanLoadManufactureData(IN P_ADAPTER_T prAdapter, IN P_REG_INFO_T prRegInfo)
  2981. {
  2982. #if CFG_SUPPORT_RDD_TEST_MODE
  2983. CMD_RDD_CH_T rRddParam;
  2984. #endif
  2985. #if CFG_SUPPORT_FCC_DYNAMIC_TX_PWR_ADJUST
  2986. CMD_FCC_TX_PWR_ADJUST FccTxPwrAdjust = {0x00};
  2987. #endif
  2988. UINT8 uc_NVRAM[EXTEND_NVRAM_SIZE] = {0x0};
  2989. UINT16 NVRAMSize = 0;
  2990. ASSERT(prAdapter);
  2991. /* 1. Version Check */
  2992. kalGetConfigurationVersion(prAdapter->prGlueInfo,
  2993. &(prAdapter->rVerInfo.u2Part1CfgOwnVersion),
  2994. &(prAdapter->rVerInfo.u2Part1CfgPeerVersion),
  2995. &(prAdapter->rVerInfo.u2Part2CfgOwnVersion),
  2996. &(prAdapter->rVerInfo.u2Part2CfgPeerVersion));
  2997. #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
  2998. if (CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
  2999. || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
  3000. || prAdapter->rVerInfo.u2Part1CfgOwnVersion <= CFG_DRV_PEER_VERSION
  3001. || prAdapter->rVerInfo.u2Part2CfgOwnVersion <= CFG_DRV_PEER_VERSION) {
  3002. return WLAN_STATUS_FAILURE;
  3003. }
  3004. #endif
  3005. /* Only when NVRAM size is EXTEND_NVRAM_SIZE bytes, send the whole NVRAM data to FW */
  3006. kalCfgDataRead16(prAdapter->prGlueInfo,
  3007. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, u2SizeOfNvram),
  3008. (PUINT_16)&NVRAMSize);
  3009. if (NVRAMSize >= EXTEND_NVRAM_SIZE) {
  3010. kalCfgDataRead(prAdapter->prGlueInfo,
  3011. 0,
  3012. sizeof(UINT_8)*EXTEND_NVRAM_SIZE,
  3013. (PUINT_16)&uc_NVRAM[0]);
  3014. wlanSendSetQueryCmd(prAdapter,
  3015. CMD_ID_SET_NVRAM_SETTINGS,
  3016. TRUE,
  3017. FALSE,
  3018. FALSE, NULL, NULL, sizeof(UINT_8) * EXTEND_NVRAM_SIZE,
  3019. (PUINT_8)(&uc_NVRAM[0]), NULL, 0);
  3020. /* MT6620 E1/E2 would be ignored directly */
  3021. }
  3022. if (prAdapter->rVerInfo.u2Part1CfgOwnVersion == 0x0001) {
  3023. prRegInfo->ucTxPwrValid = 1;
  3024. } else {
  3025. /* 2. Load TX power gain parameters if valid */
  3026. if (prRegInfo->ucTxPwrValid != 0) {
  3027. /* send to F/W */
  3028. nicUpdateTxPower(prAdapter, (P_CMD_TX_PWR_T) (&(prRegInfo->rTxPwr)));
  3029. }
  3030. }
  3031. #if CFG_SUPPORT_FCC_DYNAMIC_TX_PWR_ADJUST
  3032. /* Tx Power Adjust for FCC/CE Certification */
  3033. FccTxPwrAdjust.fgFccTxPwrAdjust = 1; /* 1:enable; 0:disable */
  3034. FccTxPwrAdjust.Offset_CCK = 14; /* drop 7dB */
  3035. FccTxPwrAdjust.Offset_HT20 = 16; /* drop 8dB */
  3036. FccTxPwrAdjust.Offset_HT40 = 14; /* drop 7dB*/
  3037. FccTxPwrAdjust.Channel_CCK[0] = 11; /* [0] for start channel */
  3038. FccTxPwrAdjust.Channel_CCK[1] = 13; /* [1] for ending channel */
  3039. FccTxPwrAdjust.Channel_HT20[0] = 11; /* [0] for start channel */
  3040. FccTxPwrAdjust.Channel_HT20[1] = 13; /* [1] for ending channel */
  3041. FccTxPwrAdjust.Channel_HT40[0] = 7; /* [0] for start channel,engineer mode ch9(2452) */
  3042. FccTxPwrAdjust.Channel_HT40[1] = 9; /* [1] for ending channel,engineer mode ch11(2462) */
  3043. wlanSendSetQueryCmd(prAdapter,
  3044. CMD_ID_SET_FCC_TX_PWR_CERT,
  3045. TRUE,
  3046. FALSE,
  3047. FALSE, NULL, NULL, sizeof(CMD_FCC_TX_PWR_ADJUST), (PUINT_8) (&FccTxPwrAdjust), NULL, 0);
  3048. #endif
  3049. /* 3. Check if needs to support 5GHz */
  3050. /* if(prRegInfo->ucEnable5GBand) { // Frank workaround */
  3051. if (1) {
  3052. /* check if it is disabled by hardware */
  3053. if (prAdapter->fgIsHw5GBandDisabled || prRegInfo->ucSupport5GBand == 0)
  3054. prAdapter->fgEnable5GBand = FALSE;
  3055. else
  3056. prAdapter->fgEnable5GBand = TRUE;
  3057. } else
  3058. prAdapter->fgEnable5GBand = FALSE;
  3059. DBGLOG(INIT, INFO, "NVRAM 5G Enable(%d) SW_En(%d) HW_Dis(%d)\n",
  3060. prRegInfo->ucEnable5GBand, prRegInfo->ucSupport5GBand, prAdapter->fgIsHw5GBandDisabled);
  3061. /* 4. Send EFUSE data */
  3062. #if defined(MT6628)
  3063. wlanChangeNvram6620to6628(prRegInfo->aucEFUSE);
  3064. #endif
  3065. wlanSendSetQueryCmd(prAdapter,
  3066. CMD_ID_SET_PHY_PARAM,
  3067. TRUE,
  3068. FALSE,
  3069. FALSE, NULL, NULL, sizeof(CMD_PHY_PARAM_T), (PUINT_8) (prRegInfo->aucEFUSE), NULL, 0);
  3070. #if CFG_SUPPORT_RDD_TEST_MODE
  3071. rRddParam.ucRddTestMode = (UINT_8) prRegInfo->u4RddTestMode;
  3072. rRddParam.ucRddShutCh = (UINT_8) prRegInfo->u4RddShutFreq;
  3073. rRddParam.ucRddStartCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStartFreq);
  3074. rRddParam.ucRddStopCh = (UINT_8) nicFreq2ChannelNum(prRegInfo->u4RddStopFreq);
  3075. rRddParam.ucRddDfs = (UINT_8) prRegInfo->u4RddDfs;
  3076. prAdapter->ucRddStatus = 0;
  3077. nicUpdateRddTestMode(prAdapter, (P_CMD_RDD_CH_T) (&rRddParam));
  3078. #endif
  3079. /* 5. Get 16-bits Country Code and Bandwidth */
  3080. prAdapter->rWifiVar.rConnSettings.u2CountryCode =
  3081. (((UINT_16) prRegInfo->au2CountryCode[0]) << 8) | (((UINT_16) prRegInfo->au2CountryCode[1]) & BITS(0, 7));
  3082. DBGLOG(INIT, INFO, "NVRAM CountryCode(0x%x 0x%x)\n",
  3083. prRegInfo->au2CountryCode[0], prRegInfo->au2CountryCode[1]);
  3084. #if 0 /* Bandwidth control will be controlled by GUI. 20110930
  3085. * So ignore the setting from registry/NVRAM
  3086. */
  3087. prAdapter->rWifiVar.rConnSettings.uc2G4BandwidthMode =
  3088. prRegInfo->uc2G4BwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
  3089. prAdapter->rWifiVar.rConnSettings.uc5GBandwidthMode =
  3090. prRegInfo->uc5GBwFixed20M ? CONFIG_BW_20M : CONFIG_BW_20_40M;
  3091. #endif
  3092. /* 6. Set domain and channel information to chip */
  3093. rlmDomainSendCmd(prAdapter, FALSE);
  3094. /* 7. set band edge tx power if available */
  3095. if (prRegInfo->fg2G4BandEdgePwrUsed) {
  3096. CMD_EDGE_TXPWR_LIMIT_T rCmdEdgeTxPwrLimit;
  3097. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrCCK = prRegInfo->cBandEdgeMaxPwrCCK;
  3098. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20 = prRegInfo->cBandEdgeMaxPwrOFDM20;
  3099. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40 = prRegInfo->cBandEdgeMaxPwrOFDM40;
  3100. rCmdEdgeTxPwrLimit.cBandEdgeCert = getBandEdgeCert(prAdapter);
  3101. DBGLOG(INIT, TRACE, "NVRAM 2G Bandedge CCK(%d) HT20(%d)HT40(%d)\n",
  3102. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrCCK,
  3103. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20, rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40);
  3104. wlanSendSetQueryCmd(prAdapter,
  3105. CMD_ID_SET_EDGE_TXPWR_LIMIT,
  3106. TRUE,
  3107. FALSE,
  3108. FALSE,
  3109. NULL,
  3110. NULL, sizeof(CMD_EDGE_TXPWR_LIMIT_T), (PUINT_8)&rCmdEdgeTxPwrLimit, NULL, 0);
  3111. }
  3112. /* 8. set 5G band edge tx power if available (add for 6625) */
  3113. if (prAdapter->fgEnable5GBand) {
  3114. #define NVRAM_5G_TX_BANDEDGE_VALID_OFFSET 10
  3115. #define NVRAM_5G_TX_BANDEDGE_OFDM20_OFFSET 11
  3116. #define NVRAM_5G_TX_BANDEDGE_OFDM40_OFFSET 12
  3117. if (prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_VALID_OFFSET]) {
  3118. CMD_EDGE_TXPWR_LIMIT_T rCmdEdgeTxPwrLimit;
  3119. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20
  3120. = prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_OFDM20_OFFSET];
  3121. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40
  3122. = prRegInfo->aucEFUSE[NVRAM_5G_TX_BANDEDGE_OFDM40_OFFSET];
  3123. DBGLOG(INIT, TRACE, "NVRAM 5G Bandedge HT20(%d)HT40(%d)\n",
  3124. rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM20, rCmdEdgeTxPwrLimit.cBandEdgeMaxPwrOFDM40);
  3125. wlanSendSetQueryCmd(prAdapter,
  3126. CMD_ID_SET_5G_EDGE_TXPWR_LIMIT,
  3127. TRUE,
  3128. FALSE,
  3129. FALSE,
  3130. NULL,
  3131. NULL,
  3132. sizeof(CMD_EDGE_TXPWR_LIMIT_T), (PUINT_8)&rCmdEdgeTxPwrLimit, NULL, 0);
  3133. }
  3134. }
  3135. /* 9. set RSSI compensation */
  3136. /* DBGLOG(INIT, INFO, ("[frank] RSSI valid(%d) 2G(%d) 5G(%d)",
  3137. prRegInfo->fgRssiCompensationValidbit,
  3138. prRegInfo->uc2GRssiCompensation,
  3139. prRegInfo->uc5GRssiCompensation)); */
  3140. if (prRegInfo->fgRssiCompensationValidbit) {
  3141. CMD_RSSI_COMPENSATE_T rCmdRssiCompensate;
  3142. rCmdRssiCompensate.uc2GRssiCompensation = prRegInfo->uc2GRssiCompensation;
  3143. rCmdRssiCompensate.uc5GRssiCompensation = prRegInfo->uc5GRssiCompensation;
  3144. DBGLOG(INIT, LOUD, "NVRAM RSSI Comp. 2G(%d)5G(%d)\n",
  3145. rCmdRssiCompensate.uc2GRssiCompensation, rCmdRssiCompensate.uc5GRssiCompensation);
  3146. wlanSendSetQueryCmd(prAdapter,
  3147. CMD_ID_SET_RSSI_COMPENSATE,
  3148. TRUE,
  3149. FALSE,
  3150. FALSE,
  3151. NULL, NULL, sizeof(CMD_RSSI_COMPENSATE_T), (PUINT_8)&rCmdRssiCompensate, NULL, 0);
  3152. }
  3153. /* 10. notify FW Band Support 5G */
  3154. if (prAdapter->fgEnable5GBand) {
  3155. CMD_BAND_SUPPORT_T rCmdBandSupport;
  3156. rCmdBandSupport.uc5GBandSupport = TRUE;
  3157. DBGLOG(INIT, TRACE, "NVRAM 5G BandSupport\n");
  3158. wlanSendSetQueryCmd(prAdapter,
  3159. CMD_ID_SET_BAND_SUPPORT,
  3160. TRUE,
  3161. FALSE,
  3162. FALSE,
  3163. NULL, NULL, sizeof(CMD_BAND_SUPPORT_T), (PUINT_8)&rCmdBandSupport, NULL, 0);
  3164. }
  3165. return WLAN_STATUS_SUCCESS;
  3166. }
  3167. /*----------------------------------------------------------------------------*/
  3168. /*!
  3169. * @brief This function is called to check
  3170. * Media Stream Mode is set to non-default value or not,
  3171. * and clear to default value if above criteria is met
  3172. *
  3173. * @param prAdapter Pointer of Adapter Data Structure
  3174. *
  3175. * @return TRUE
  3176. * The media stream mode was non-default value and has been reset
  3177. * FALSE
  3178. * The media stream mode is default value
  3179. */
  3180. /*----------------------------------------------------------------------------*/
  3181. BOOLEAN wlanResetMediaStreamMode(IN P_ADAPTER_T prAdapter)
  3182. {
  3183. ASSERT(prAdapter);
  3184. if (prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode != 0) {
  3185. prAdapter->rWlanInfo.eLinkAttr.ucMediaStreamMode = 0;
  3186. return TRUE;
  3187. } else {
  3188. return FALSE;
  3189. }
  3190. }
  3191. /*----------------------------------------------------------------------------*/
  3192. /*!
  3193. * @brief This function is called to check if any pending timer has expired
  3194. *
  3195. * @param prAdapter Pointer of Adapter Data Structure
  3196. *
  3197. * @return WLAN_STATUS_SUCCESS
  3198. */
  3199. /*----------------------------------------------------------------------------*/
  3200. WLAN_STATUS wlanTimerTimeoutCheck(IN P_ADAPTER_T prAdapter)
  3201. {
  3202. ASSERT(prAdapter);
  3203. /* check timer status */
  3204. cnmTimerDoTimeOutCheck(prAdapter);
  3205. return WLAN_STATUS_SUCCESS;
  3206. }
  3207. /*----------------------------------------------------------------------------*/
  3208. /*!
  3209. * @brief This function is called to check if any pending mailbox message
  3210. * to be handled
  3211. *
  3212. * @param prAdapter Pointer of Adapter Data Structure
  3213. *
  3214. * @return WLAN_STATUS_SUCCESS
  3215. */
  3216. /*----------------------------------------------------------------------------*/
  3217. WLAN_STATUS wlanProcessMboxMessage(IN P_ADAPTER_T prAdapter)
  3218. {
  3219. UINT_32 i;
  3220. ASSERT(prAdapter);
  3221. for (i = 0; i < MBOX_ID_TOTAL_NUM; i++) { /* MBOX_ID_TOTAL_NUM = 1 */
  3222. mboxRcvAllMsg(prAdapter, (ENUM_MBOX_ID_T) i);
  3223. }
  3224. return WLAN_STATUS_SUCCESS;
  3225. }
  3226. /*----------------------------------------------------------------------------*/
  3227. /*!
  3228. * @brief This function is called to enqueue a single TX packet into CORE
  3229. *
  3230. * @param prAdapter Pointer of Adapter Data Structure
  3231. * prNativePacket Pointer of Native Packet
  3232. *
  3233. * @return WLAN_STATUS_SUCCESS
  3234. * WLAN_STATUS_RESOURCES
  3235. * WLAN_STATUS_INVALID_PACKET
  3236. */
  3237. /*----------------------------------------------------------------------------*/
  3238. WLAN_STATUS wlanEnqueueTxPacket(IN P_ADAPTER_T prAdapter, IN P_NATIVE_PACKET prNativePacket)
  3239. {
  3240. P_TX_CTRL_T prTxCtrl;
  3241. P_MSDU_INFO_T prMsduInfo;
  3242. KAL_SPIN_LOCK_DECLARATION();
  3243. ASSERT(prAdapter);
  3244. prTxCtrl = &prAdapter->rTxCtrl;
  3245. /* get a free packet header */
  3246. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  3247. QUEUE_REMOVE_HEAD(&prTxCtrl->rFreeMsduInfoList, prMsduInfo, P_MSDU_INFO_T);
  3248. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_TX_MSDU_INFO_LIST);
  3249. if (prMsduInfo == NULL)
  3250. return WLAN_STATUS_RESOURCES;
  3251. prMsduInfo->eSrc = TX_PACKET_OS;
  3252. if (nicTxFillMsduInfo(prAdapter, prMsduInfo, prNativePacket) == FALSE) {
  3253. /* packet is not extractable */
  3254. /* fill fails */
  3255. kalSendComplete(prAdapter->prGlueInfo, prNativePacket, WLAN_STATUS_INVALID_PACKET);
  3256. nicTxReturnMsduInfo(prAdapter, prMsduInfo);
  3257. return WLAN_STATUS_INVALID_PACKET;
  3258. }
  3259. /* enqueue to QM */
  3260. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  3261. return WLAN_STATUS_SUCCESS;
  3262. }
  3263. /*----------------------------------------------------------------------------*/
  3264. /*!
  3265. * @brief This function is called to flush pending TX packets in CORE
  3266. *
  3267. * @param prAdapter Pointer of Adapter Data Structure
  3268. *
  3269. * @return WLAN_STATUS_SUCCESS
  3270. */
  3271. /*----------------------------------------------------------------------------*/
  3272. WLAN_STATUS wlanFlushTxPendingPackets(IN P_ADAPTER_T prAdapter)
  3273. {
  3274. ASSERT(prAdapter);
  3275. return nicTxFlush(prAdapter);
  3276. }
  3277. /*----------------------------------------------------------------------------*/
  3278. /*!
  3279. * \brief this function sends pending MSDU_INFO_T to MT6620
  3280. *
  3281. * @param prAdapter Pointer to the Adapter structure.
  3282. * @param pfgHwAccess Pointer for tracking LP-OWN status
  3283. *
  3284. * @retval WLAN_STATUS_SUCCESS Reset is done successfully.
  3285. */
  3286. /*----------------------------------------------------------------------------*/
  3287. WLAN_STATUS wlanTxPendingPackets(IN P_ADAPTER_T prAdapter, IN OUT PBOOLEAN pfgHwAccess)
  3288. {
  3289. P_TX_CTRL_T prTxCtrl;
  3290. P_MSDU_INFO_T prMsduInfo;
  3291. KAL_SPIN_LOCK_DECLARATION();
  3292. ASSERT(prAdapter);
  3293. prTxCtrl = &prAdapter->rTxCtrl;
  3294. ASSERT(pfgHwAccess);
  3295. /* <1> dequeue packets by txDequeuTxPackets() */
  3296. /* Note: prMsduInfo is a packet list queue */
  3297. KAL_ACQUIRE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
  3298. prMsduInfo = qmDequeueTxPackets(prAdapter, &prTxCtrl->rTc);
  3299. KAL_RELEASE_SPIN_LOCK(prAdapter, SPIN_LOCK_QM_TX_QUEUE);
  3300. if (prMsduInfo != NULL) {
  3301. if (kalIsCardRemoved(prAdapter->prGlueInfo) == FALSE) {
  3302. /* <2> Acquire LP-OWN if necessary */
  3303. if (*pfgHwAccess == FALSE) {
  3304. *pfgHwAccess = TRUE;
  3305. wlanAcquirePowerControl(prAdapter);
  3306. }
  3307. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  3308. if (prAdapter->fgIsClockGatingEnabled == TRUE)
  3309. nicDisableClockGating(prAdapter);
  3310. #endif
  3311. /* <3> send packet"s" to HIF */
  3312. nicTxMsduInfoList(prAdapter, prMsduInfo);
  3313. /* <4> update TC by txAdjustTcQuotas() */
  3314. nicTxAdjustTcq(prAdapter);
  3315. } else
  3316. wlanProcessQueuedMsduInfo(prAdapter, prMsduInfo); /* free the packet */
  3317. }
  3318. #if (MT6620_E1_ASIC_HIFSYS_WORKAROUND == 1)
  3319. if (prAdapter->fgIsClockGatingEnabled == FALSE)
  3320. nicEnableClockGating(prAdapter);
  3321. #endif
  3322. return WLAN_STATUS_SUCCESS;
  3323. }
  3324. /*----------------------------------------------------------------------------*/
  3325. /*!
  3326. * @brief This function is called to acquire power control from firmware
  3327. *
  3328. * @param prAdapter Pointer of Adapter Data Structure
  3329. *
  3330. * @return WLAN_STATUS_SUCCESS
  3331. */
  3332. /*----------------------------------------------------------------------------*/
  3333. WLAN_STATUS wlanAcquirePowerControl(IN P_ADAPTER_T prAdapter)
  3334. {
  3335. ASSERT(prAdapter);
  3336. /* do driver own */
  3337. ACQUIRE_POWER_CONTROL_FROM_PM(prAdapter);
  3338. /* Reset sleepy state *//* no use */
  3339. if (prAdapter->fgWiFiInSleepyState == TRUE)
  3340. prAdapter->fgWiFiInSleepyState = FALSE;
  3341. return WLAN_STATUS_SUCCESS;
  3342. }
  3343. /*----------------------------------------------------------------------------*/
  3344. /*!
  3345. * @brief This function is called to release power control to firmware
  3346. *
  3347. * @param prAdapter Pointer of Adapter Data Structure
  3348. *
  3349. * @return WLAN_STATUS_SUCCESS
  3350. */
  3351. /*----------------------------------------------------------------------------*/
  3352. WLAN_STATUS wlanReleasePowerControl(IN P_ADAPTER_T prAdapter)
  3353. {
  3354. ASSERT(prAdapter);
  3355. /* do FW own */
  3356. RECLAIM_POWER_CONTROL_TO_PM(prAdapter, FALSE);
  3357. return WLAN_STATUS_SUCCESS;
  3358. }
  3359. /*----------------------------------------------------------------------------*/
  3360. /*!
  3361. * @brief This function is called to report currently pending TX frames count
  3362. * (command packets are not included)
  3363. *
  3364. * @param prAdapter Pointer of Adapter Data Structure
  3365. *
  3366. * @return number of pending TX frames
  3367. */
  3368. /*----------------------------------------------------------------------------*/
  3369. UINT_32 wlanGetTxPendingFrameCount(IN P_ADAPTER_T prAdapter)
  3370. {
  3371. P_TX_CTRL_T prTxCtrl;
  3372. UINT_32 u4Num;
  3373. ASSERT(prAdapter);
  3374. prTxCtrl = &prAdapter->rTxCtrl;
  3375. /* number in prTxQueue + number in RX forward */
  3376. u4Num = kalGetTxPendingFrameCount(prAdapter->prGlueInfo) + (UINT_32) (prTxCtrl->i4PendingFwdFrameCount);
  3377. return u4Num;
  3378. }
  3379. /*----------------------------------------------------------------------------*/
  3380. /*!
  3381. * @brief This function is to report current ACPI state
  3382. *
  3383. * @param prAdapter Pointer of Adapter Data Structure
  3384. *
  3385. * @return ACPI_STATE_D0 Normal Operation Mode
  3386. * ACPI_STATE_D3 Suspend Mode
  3387. */
  3388. /*----------------------------------------------------------------------------*/
  3389. ENUM_ACPI_STATE_T wlanGetAcpiState(IN P_ADAPTER_T prAdapter)
  3390. {
  3391. ASSERT(prAdapter);
  3392. return prAdapter->rAcpiState;
  3393. }
  3394. /*----------------------------------------------------------------------------*/
  3395. /*!
  3396. * @brief This function is to update current ACPI state only
  3397. *
  3398. * @param prAdapter Pointer of Adapter Data Structure
  3399. * @param ePowerState ACPI_STATE_D0 Normal Operation Mode
  3400. * ACPI_STATE_D3 Suspend Mode
  3401. *
  3402. * @return none
  3403. */
  3404. /*----------------------------------------------------------------------------*/
  3405. VOID wlanSetAcpiState(IN P_ADAPTER_T prAdapter, IN ENUM_ACPI_STATE_T ePowerState)
  3406. {
  3407. ASSERT(prAdapter);
  3408. ASSERT(ePowerState <= ACPI_STATE_D3);
  3409. prAdapter->rAcpiState = ePowerState;
  3410. }
  3411. /*----------------------------------------------------------------------------*/
  3412. /*!
  3413. * @brief This function is to query ECO version from HIFSYS CR
  3414. *
  3415. * @param prAdapter Pointer of Adapter Data Structure
  3416. *
  3417. * @return zero Unable to retrieve ECO version information
  3418. * non-zero ECO version (1-based)
  3419. */
  3420. /*----------------------------------------------------------------------------*/
  3421. UINT_8 wlanGetEcoVersion(IN P_ADAPTER_T prAdapter)
  3422. {
  3423. ASSERT(prAdapter);
  3424. if (nicVerifyChipID(prAdapter) == TRUE)
  3425. return prAdapter->ucRevID + 1;
  3426. else
  3427. return 0;
  3428. }
  3429. /*----------------------------------------------------------------------------*/
  3430. /*!
  3431. * @brief This function is to setting the default Tx Power configuration
  3432. *
  3433. * @param prAdapter Pointer of Adapter Data Structure
  3434. *
  3435. * @return zero Unable to retrieve ECO version information
  3436. * non-zero ECO version (1-based)
  3437. */
  3438. /*----------------------------------------------------------------------------*/
  3439. VOID wlanDefTxPowerCfg(IN P_ADAPTER_T prAdapter)
  3440. {
  3441. UINT_8 i;
  3442. P_GLUE_INFO_T prGlueInfo = prAdapter->prGlueInfo;
  3443. P_SET_TXPWR_CTRL_T prTxpwr;
  3444. ASSERT(prGlueInfo);
  3445. prTxpwr = &prGlueInfo->rTxPwr;
  3446. prTxpwr->c2GLegacyStaPwrOffset = 0;
  3447. prTxpwr->c2GHotspotPwrOffset = 0;
  3448. prTxpwr->c2GP2pPwrOffset = 0;
  3449. prTxpwr->c2GBowPwrOffset = 0;
  3450. prTxpwr->c5GLegacyStaPwrOffset = 0;
  3451. prTxpwr->c5GHotspotPwrOffset = 0;
  3452. prTxpwr->c5GP2pPwrOffset = 0;
  3453. prTxpwr->c5GBowPwrOffset = 0;
  3454. prTxpwr->ucConcurrencePolicy = 0;
  3455. for (i = 0; i < 3; i++)
  3456. prTxpwr->acReserved1[i] = 0;
  3457. for (i = 0; i < 14; i++)
  3458. prTxpwr->acTxPwrLimit2G[i] = 63;
  3459. for (i = 0; i < 4; i++)
  3460. prTxpwr->acTxPwrLimit5G[i] = 63;
  3461. for (i = 0; i < 2; i++)
  3462. prTxpwr->acReserved2[i] = 0;
  3463. }
  3464. /*----------------------------------------------------------------------------*/
  3465. /*!
  3466. * @brief This function is to
  3467. * set preferred band configuration corresponding to network type
  3468. *
  3469. * @param prAdapter Pointer of Adapter Data Structure
  3470. * @param eBand Given band
  3471. * @param eNetTypeIndex Given Network Type
  3472. *
  3473. * @return none
  3474. */
  3475. /*----------------------------------------------------------------------------*/
  3476. VOID
  3477. wlanSetPreferBandByNetwork(IN P_ADAPTER_T prAdapter, IN ENUM_BAND_T eBand, IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex)
  3478. {
  3479. ASSERT(prAdapter);
  3480. ASSERT(eBand <= BAND_NUM);
  3481. ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
  3482. /* 1. set prefer band according to network type */
  3483. prAdapter->aePreferBand[eNetTypeIndex] = eBand;
  3484. /* 2. remove buffered BSS descriptors correspondingly */
  3485. if (eBand == BAND_2G4)
  3486. scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_5G, eNetTypeIndex);
  3487. else if (eBand == BAND_5G)
  3488. scanRemoveBssDescByBandAndNetwork(prAdapter, BAND_2G4, eNetTypeIndex);
  3489. }
  3490. /*----------------------------------------------------------------------------*/
  3491. /*!
  3492. * @brief This function is to
  3493. * get channel information corresponding to specified network type
  3494. *
  3495. * @param prAdapter Pointer of Adapter Data Structure
  3496. * @param eNetTypeIndex Given Network Type
  3497. *
  3498. * @return channel number
  3499. */
  3500. /*----------------------------------------------------------------------------*/
  3501. UINT_8 wlanGetChannelNumberByNetwork(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex)
  3502. {
  3503. P_BSS_INFO_T prBssInfo;
  3504. ASSERT(prAdapter);
  3505. ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
  3506. prBssInfo = &(prAdapter->rWifiVar.arBssInfo[eNetTypeIndex]);
  3507. return prBssInfo->ucPrimaryChannel;
  3508. }
  3509. /*----------------------------------------------------------------------------*/
  3510. /*!
  3511. * @brief This function is to
  3512. * get BSS descriptor information corresponding to specified network type
  3513. *
  3514. * @param prAdapter Pointer of Adapter Data Structure
  3515. * @param eNetTypeIndex Given Network Type
  3516. *
  3517. * @return pointer to BSS_DESC_T
  3518. */
  3519. /*----------------------------------------------------------------------------*/
  3520. P_BSS_DESC_T wlanGetTargetBssDescByNetwork(IN P_ADAPTER_T prAdapter, IN ENUM_NETWORK_TYPE_INDEX_T eNetTypeIndex)
  3521. {
  3522. ASSERT(prAdapter);
  3523. ASSERT(eNetTypeIndex <= NETWORK_TYPE_INDEX_NUM);
  3524. switch (eNetTypeIndex) {
  3525. case NETWORK_TYPE_AIS_INDEX:
  3526. return prAdapter->rWifiVar.rAisFsmInfo.prTargetBssDesc;
  3527. case NETWORK_TYPE_P2P_INDEX:
  3528. return NULL;
  3529. case NETWORK_TYPE_BOW_INDEX:
  3530. return prAdapter->rWifiVar.rBowFsmInfo.prTargetBssDesc;
  3531. default:
  3532. return NULL;
  3533. }
  3534. }
  3535. /*----------------------------------------------------------------------------*/
  3536. /*!
  3537. * @brief This function is to
  3538. * check unconfigured system properties and generate related message on
  3539. * scan list to notify users
  3540. *
  3541. * @param prAdapter Pointer of Adapter Data Structure
  3542. *
  3543. * @return WLAN_STATUS_SUCCESS
  3544. */
  3545. /*----------------------------------------------------------------------------*/
  3546. WLAN_STATUS wlanCheckSystemConfiguration(IN P_ADAPTER_T prAdapter)
  3547. {
  3548. #if (CFG_NVRAM_EXISTENCE_CHECK == 1) || (CFG_SW_NVRAM_VERSION_CHECK == 1)
  3549. const UINT_8 aucZeroMacAddr[] = NULL_MAC_ADDR;
  3550. const UINT_8 aucBCAddr[] = BC_MAC_ADDR;
  3551. BOOLEAN fgIsConfExist = TRUE;
  3552. BOOLEAN fgGenErrMsg = FALSE;
  3553. P_REG_INFO_T prRegInfo = NULL;
  3554. P_WLAN_BEACON_FRAME_T prBeacon = NULL;
  3555. P_IE_SSID_T prSsid = NULL;
  3556. UINT_32 u4ErrCode = 0;
  3557. UINT_8 aucErrMsg[32];
  3558. PARAM_SSID_T rSsid;
  3559. PARAM_802_11_CONFIG_T rConfiguration;
  3560. PARAM_RATES_EX rSupportedRates;
  3561. #endif
  3562. DEBUGFUNC("wlanCheckSystemConfiguration");
  3563. ASSERT(prAdapter);
  3564. #if (CFG_NVRAM_EXISTENCE_CHECK == 1)
  3565. if (kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) {
  3566. fgIsConfExist = FALSE;
  3567. fgGenErrMsg = TRUE;
  3568. }
  3569. #endif
  3570. #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
  3571. prRegInfo = kalGetConfiguration(prAdapter->prGlueInfo);
  3572. if (fgIsConfExist == TRUE && (CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
  3573. || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
  3574. || prAdapter->rVerInfo.u2Part1CfgOwnVersion <= CFG_DRV_PEER_VERSION
  3575. || prAdapter->rVerInfo.u2Part2CfgOwnVersion <= CFG_DRV_PEER_VERSION /* NVRAM */
  3576. || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
  3577. || prAdapter->rVerInfo.u2FwOwnVersion <= CFG_DRV_PEER_VERSION
  3578. #if CFG_SUPPORT_PWR_LIMIT_COUNTRY
  3579. || prAdapter->fgIsPowerLimitTableValid == FALSE
  3580. #endif
  3581. || (prAdapter->fgIsEmbbededMacAddrValid == FALSE &&
  3582. (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr)
  3583. || EQUAL_MAC_ADDR(aucZeroMacAddr, prRegInfo->aucMacAddr)))
  3584. || prRegInfo->ucTxPwrValid == 0))
  3585. fgGenErrMsg = TRUE;
  3586. #endif
  3587. if (fgGenErrMsg == TRUE) {
  3588. prBeacon = cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
  3589. if (!prBeacon) {
  3590. ASSERT(FALSE);
  3591. return WLAN_STATUS_FAILURE;
  3592. }
  3593. /* initialization */
  3594. kalMemZero(prBeacon, sizeof(WLAN_BEACON_FRAME_T) + sizeof(IE_SSID_T));
  3595. /* prBeacon initialization */
  3596. prBeacon->u2FrameCtrl = MAC_FRAME_BEACON;
  3597. COPY_MAC_ADDR(prBeacon->aucDestAddr, aucBCAddr);
  3598. COPY_MAC_ADDR(prBeacon->aucSrcAddr, aucZeroMacAddr);
  3599. COPY_MAC_ADDR(prBeacon->aucBSSID, aucZeroMacAddr);
  3600. prBeacon->u2BeaconInterval = 100;
  3601. prBeacon->u2CapInfo = CAP_INFO_ESS;
  3602. /* prSSID initialization */
  3603. prSsid = (P_IE_SSID_T) (&prBeacon->aucInfoElem[0]);
  3604. prSsid->ucId = ELEM_ID_SSID;
  3605. /* rConfiguration initialization */
  3606. rConfiguration.u4Length = sizeof(PARAM_802_11_CONFIG_T);
  3607. rConfiguration.u4BeaconPeriod = 100;
  3608. rConfiguration.u4ATIMWindow = 1;
  3609. rConfiguration.u4DSConfig = 2412;
  3610. rConfiguration.rFHConfig.u4Length = sizeof(PARAM_802_11_CONFIG_FH_T);
  3611. /* rSupportedRates initialization */
  3612. kalMemZero(rSupportedRates, sizeof(PARAM_RATES_EX));
  3613. }
  3614. #if (CFG_NVRAM_EXISTENCE_CHECK == 1)
  3615. #define NVRAM_ERR_MSG "NVRAM WARNING: Err = 0x01"
  3616. if ((kalIsConfigurationExist(prAdapter->prGlueInfo) == FALSE) && (prBeacon) && (prSsid)) {
  3617. COPY_SSID(prSsid->aucSSID, prSsid->ucLength, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
  3618. kalIndicateBssInfo(prAdapter->prGlueInfo,
  3619. (PUINT_8) prBeacon,
  3620. OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T,
  3621. aucSSID) + prSsid->ucLength,
  3622. 1, 0);
  3623. COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
  3624. nicAddScanResult(prAdapter,
  3625. prBeacon->aucBSSID,
  3626. &rSsid,
  3627. 0,
  3628. 0,
  3629. PARAM_NETWORK_TYPE_FH,
  3630. &rConfiguration,
  3631. NET_TYPE_INFRA,
  3632. rSupportedRates,
  3633. OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T,
  3634. aucSSID) + prSsid->ucLength -
  3635. WLAN_MAC_MGMT_HEADER_LEN, (PUINT_8) ((ULONG) (prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
  3636. }
  3637. #endif
  3638. #if (CFG_SW_NVRAM_VERSION_CHECK == 1)
  3639. #define VER_ERR_MSG "NVRAM WARNING: Err = 0x%02X"
  3640. if ((fgIsConfExist == TRUE) && (prBeacon) && (prSsid)) {
  3641. if ((CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part1CfgPeerVersion
  3642. || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2Part2CfgPeerVersion
  3643. || prAdapter->rVerInfo.u2Part1CfgOwnVersion <= CFG_DRV_PEER_VERSION
  3644. || prAdapter->rVerInfo.u2Part2CfgOwnVersion <= CFG_DRV_PEER_VERSION /* NVRAM */
  3645. || CFG_DRV_OWN_VERSION < prAdapter->rVerInfo.u2FwPeerVersion
  3646. || prAdapter->rVerInfo.u2FwOwnVersion <= CFG_DRV_PEER_VERSION))
  3647. u4ErrCode |= NVRAM_ERROR_VERSION_MISMATCH;
  3648. if (prRegInfo->ucTxPwrValid == 0)
  3649. u4ErrCode |= NVRAM_ERROR_INVALID_TXPWR;
  3650. if (prAdapter->fgIsEmbbededMacAddrValid == FALSE && (IS_BMCAST_MAC_ADDR(prRegInfo->aucMacAddr)
  3651. || EQUAL_MAC_ADDR(aucZeroMacAddr,
  3652. prRegInfo->aucMacAddr)))
  3653. u4ErrCode |= NVRAM_ERROR_INVALID_MAC_ADDR;
  3654. #if CFG_SUPPORT_PWR_LIMIT_COUNTRY
  3655. if (prAdapter->fgIsPowerLimitTableValid == FALSE)
  3656. u4ErrCode |= NVRAM_POWER_LIMIT_TABLE_INVALID;
  3657. #endif
  3658. if (u4ErrCode != 0) {
  3659. sprintf(aucErrMsg, VER_ERR_MSG, (unsigned int)u4ErrCode);
  3660. COPY_SSID(prSsid->aucSSID, prSsid->ucLength, aucErrMsg, strlen(aucErrMsg));
  3661. kalIndicateBssInfo(prAdapter->prGlueInfo,
  3662. (PUINT_8) prBeacon,
  3663. OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T,
  3664. aucSSID) +
  3665. prSsid->ucLength, 1, 0);
  3666. COPY_SSID(rSsid.aucSsid, rSsid.u4SsidLen, NVRAM_ERR_MSG, strlen(NVRAM_ERR_MSG));
  3667. nicAddScanResult(prAdapter,
  3668. prBeacon->aucBSSID,
  3669. &rSsid,
  3670. 0,
  3671. 0,
  3672. PARAM_NETWORK_TYPE_FH,
  3673. &rConfiguration,
  3674. NET_TYPE_INFRA,
  3675. rSupportedRates,
  3676. OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem) + OFFSET_OF(IE_SSID_T,
  3677. aucSSID) +
  3678. prSsid->ucLength - WLAN_MAC_MGMT_HEADER_LEN,
  3679. (PUINT_8) ((ULONG) (prBeacon) + WLAN_MAC_MGMT_HEADER_LEN));
  3680. }
  3681. }
  3682. #endif
  3683. if (fgGenErrMsg == TRUE)
  3684. cnmMemFree(prAdapter, prBeacon);
  3685. return WLAN_STATUS_SUCCESS;
  3686. }
  3687. WLAN_STATUS
  3688. wlanoidQueryStaStatistics(IN P_ADAPTER_T prAdapter,
  3689. IN PVOID pvQueryBuffer, IN UINT_32 u4QueryBufferLen, OUT PUINT_32 pu4QueryInfoLen)
  3690. {
  3691. WLAN_STATUS rResult = WLAN_STATUS_FAILURE;
  3692. P_STA_RECORD_T prStaRec, prTempStaRec;
  3693. P_PARAM_GET_STA_STATISTICS prQueryStaStatistics;
  3694. UINT_8 ucStaRecIdx;
  3695. P_QUE_MGT_T prQM = &prAdapter->rQM;
  3696. CMD_GET_STA_STATISTICS_T rQueryCmdStaStatistics;
  3697. UINT_8 ucIdx;
  3698. do {
  3699. ASSERT(pvQueryBuffer);
  3700. /* 4 1. Sanity test */
  3701. if ((prAdapter == NULL) || (pu4QueryInfoLen == NULL))
  3702. break;
  3703. if ((u4QueryBufferLen) && (pvQueryBuffer == NULL))
  3704. break;
  3705. if (u4QueryBufferLen < sizeof(PARAM_GET_STA_STA_STATISTICS)) {
  3706. *pu4QueryInfoLen = sizeof(PARAM_GET_STA_STA_STATISTICS);
  3707. rResult = WLAN_STATUS_BUFFER_TOO_SHORT;
  3708. break;
  3709. }
  3710. prQueryStaStatistics = (P_PARAM_GET_STA_STATISTICS) pvQueryBuffer;
  3711. *pu4QueryInfoLen = sizeof(PARAM_GET_STA_STA_STATISTICS);
  3712. /* 4 5. Get driver global QM counter */
  3713. for (ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++) {
  3714. prQueryStaStatistics->au4TcAverageQueLen[ucIdx] = prQM->au4AverageQueLen[ucIdx];
  3715. prQueryStaStatistics->au4TcCurrentQueLen[ucIdx] = prQM->au4CurrentTcResource[ucIdx];
  3716. }
  3717. /* 4 2. Get StaRec by MAC address */
  3718. prStaRec = NULL;
  3719. for (ucStaRecIdx = 0; ucStaRecIdx < CFG_NUM_OF_STA_RECORD; ucStaRecIdx++) {
  3720. prTempStaRec = &(prAdapter->arStaRec[ucStaRecIdx]);
  3721. if (prTempStaRec->fgIsValid && prTempStaRec->fgIsInUse) {
  3722. if (EQUAL_MAC_ADDR(prTempStaRec->aucMacAddr, prQueryStaStatistics->aucMacAddr)) {
  3723. prStaRec = prTempStaRec;
  3724. break;
  3725. }
  3726. }
  3727. }
  3728. if (!prStaRec) {
  3729. rResult = WLAN_STATUS_INVALID_DATA;
  3730. break;
  3731. }
  3732. prQueryStaStatistics->u4Flag |= BIT(0);
  3733. #if CFG_ENABLE_PER_STA_STATISTICS
  3734. /* 4 3. Get driver statistics */
  3735. prQueryStaStatistics->u4TxTotalCount = prStaRec->u4TotalTxPktsNumber;
  3736. prQueryStaStatistics->u4TxExceedThresholdCount = prStaRec->u4ThresholdCounter;
  3737. prQueryStaStatistics->u4TxMaxTime = prStaRec->u4MaxTxPktsTime;
  3738. if (prStaRec->u4TotalTxPktsNumber) {
  3739. prQueryStaStatistics->u4TxAverageProcessTime =
  3740. (prStaRec->u4TotalTxPktsTime / prStaRec->u4TotalTxPktsNumber);
  3741. } else
  3742. prQueryStaStatistics->u4TxAverageProcessTime = 0;
  3743. for (ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++) {
  3744. prQueryStaStatistics->au4TcResourceEmptyCount[ucIdx] =
  3745. prQM->au4QmTcResourceEmptyCounter[prStaRec->ucNetTypeIndex][ucIdx];
  3746. /* Reset */
  3747. prQM->au4QmTcResourceEmptyCounter[prStaRec->ucNetTypeIndex][ucIdx] = 0;
  3748. }
  3749. /* 4 4.1 Reset statistics */
  3750. prStaRec->u4ThresholdCounter = 0;
  3751. prStaRec->u4TotalTxPktsNumber = 0;
  3752. prStaRec->u4TotalTxPktsTime = 0;
  3753. prStaRec->u4MaxTxPktsTime = 0;
  3754. #endif
  3755. for (ucIdx = TC0_INDEX; ucIdx <= TC3_INDEX; ucIdx++)
  3756. prQueryStaStatistics->au4TcQueLen[ucIdx] = prStaRec->arTxQueue[ucIdx].u4NumElem;
  3757. rResult = WLAN_STATUS_SUCCESS;
  3758. /* 4 6. Ensure FW supports get station link status */
  3759. if (prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS) {
  3760. rQueryCmdStaStatistics.ucIndex = prStaRec->ucIndex;
  3761. COPY_MAC_ADDR(rQueryCmdStaStatistics.aucMacAddr, prQueryStaStatistics->aucMacAddr);
  3762. rQueryCmdStaStatistics.ucReadClear = TRUE;
  3763. rResult = wlanSendSetQueryCmd(prAdapter,
  3764. CMD_ID_GET_STA_STATISTICS,
  3765. FALSE,
  3766. TRUE,
  3767. TRUE,
  3768. nicCmdEventQueryStaStatistics,
  3769. nicOidCmdTimeoutCommon,
  3770. sizeof(CMD_GET_STA_STATISTICS_T),
  3771. (PUINT_8)&rQueryCmdStaStatistics,
  3772. pvQueryBuffer, u4QueryBufferLen);
  3773. prQueryStaStatistics->u4Flag |= BIT(1);
  3774. } else {
  3775. rResult = WLAN_STATUS_NOT_SUPPORTED;
  3776. }
  3777. } while (FALSE);
  3778. return rResult;
  3779. } /* wlanoidQueryP2pVersion */
  3780. #if CFG_AUTO_CHANNEL_SEL_SUPPORT
  3781. /* 4 Auto Channel Selection */
  3782. WLAN_STATUS
  3783. wlanoidQueryACSChannelList(IN P_ADAPTER_T prAdapter,
  3784. IN PVOID pvQueryBuffer, IN UINT_32 u4QueryBufferLen, OUT PUINT_32 pu4QueryInfoLen)
  3785. {
  3786. WLAN_STATUS rResult = WLAN_STATUS_FAILURE;
  3787. /* P_PARAM_GET_CHN_LOAD prQueryChnLoad; */
  3788. P_PARAM_GET_LTE_MODE prLteMode;
  3789. CMD_GET_LTE_SAFE_CHN_T rQuery_LTE_SAFE_CHN;
  3790. DBGLOG(P2P, INFO, "[Auto Channel]wlanoidQueryACSChannelList\n");
  3791. do {
  3792. ASSERT(pvQueryBuffer);
  3793. /* 4 1. Sanity test */
  3794. if ((prAdapter == NULL) || (pu4QueryInfoLen == NULL))
  3795. break;
  3796. if ((u4QueryBufferLen) && (pvQueryBuffer == NULL))
  3797. break;
  3798. prLteMode = (P_PARAM_GET_LTE_MODE) pvQueryBuffer;
  3799. /* 4 3. Ensure FW supports get station link status */
  3800. #if 0
  3801. if (prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS) {
  3802. CMD_ACCESS_REG rCmdAccessReg;
  3803. rCmdAccessReg.u4Address = 0xFFFFFFFF;
  3804. rCmdAccessReg.u4Data = ELEM_RM_TYPE_ACS_CHN;
  3805. rResult = wlanSendSetQueryCmd(prAdapter,
  3806. CMD_ID_ACCESS_REG,
  3807. TRUE,
  3808. TRUE,
  3809. TRUE,
  3810. /* The handler to receive firmware notification */
  3811. nicCmdEventQueryChannelLoad,
  3812. nicOidCmdTimeoutCommon,
  3813. sizeof(CMD_ACCESS_REG),
  3814. (PUINT_8)&rCmdAccessReg, pvQueryBuffer, u4QueryBufferLen);
  3815. prQueryChnLoad->u4Flag |= BIT(1);
  3816. } else {
  3817. rResult = WLAN_STATUS_NOT_SUPPORTED;
  3818. }
  3819. #endif
  3820. /* 4 4.Avoid LTE Channels */
  3821. prLteMode->u4Flags &= BIT(0);
  3822. /*if(prAdapter->u4FwCompileFlag0 & COMPILE_FLAG0_GET_STA_LINK_STATUS) */ {
  3823. rResult = wlanSendSetQueryCmd(prAdapter,
  3824. CMD_ID_GET_LTE_CHN,
  3825. FALSE,
  3826. TRUE,
  3827. /* Query ID */
  3828. TRUE,
  3829. /* The handler to receive firmware notification */
  3830. nicCmdEventQueryLTESafeChn,
  3831. nicOidCmdTimeoutCommon,
  3832. sizeof(CMD_GET_LTE_SAFE_CHN_T),
  3833. (PUINT_8)&rQuery_LTE_SAFE_CHN,
  3834. pvQueryBuffer, u4QueryBufferLen);
  3835. DBGLOG(P2P, INFO, "[Auto Channel] Get LTE Channels\n");
  3836. prLteMode->u4Flags |= BIT(1);
  3837. }
  3838. /* 4 5. Calc the value */
  3839. DBGLOG(P2P, INFO, "[Auto Channel] Candidated Channels\n");
  3840. } while (FALSE);
  3841. return rResult;
  3842. } /* wlanoidQueryP2pVersion */
  3843. #endif
  3844. #if CFG_SUPPORT_CFG_FILE
  3845. P_WLAN_CFG_ENTRY_T wlanCfgGetEntry(IN P_ADAPTER_T prAdapter, const PCHAR pucKey)
  3846. {
  3847. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3848. P_WLAN_CFG_T prWlanCfg;
  3849. UINT_32 i;
  3850. prWlanCfg = prAdapter->prWlanCfg;
  3851. ASSERT(prWlanCfg);
  3852. ASSERT(pucKey);
  3853. prWlanCfgEntry = NULL;
  3854. for (i = 0; i < WLAN_CFG_ENTRY_NUM_MAX; i++) {
  3855. prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[i];
  3856. if (prWlanCfgEntry->aucKey[0] != '\0') {
  3857. DBGLOG(INIT, LOUD, "compare key %s saved key %s\n", pucKey, prWlanCfgEntry->aucKey);
  3858. if (kalStrniCmp(pucKey, prWlanCfgEntry->aucKey, WLAN_CFG_KEY_LEN_MAX - 1) == 0)
  3859. return prWlanCfgEntry;
  3860. }
  3861. }
  3862. DBGLOG(INIT, LOUD, "wifi config there is no entry \'%s\'\n", pucKey);
  3863. return NULL;
  3864. }
  3865. WLAN_STATUS wlanCfgGet(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, PCHAR pucValue, PCHAR pucValueDef, UINT_32 u4Flags)
  3866. {
  3867. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3868. P_WLAN_CFG_T prWlanCfg;
  3869. prWlanCfg = prAdapter->prWlanCfg;
  3870. ASSERT(prWlanCfg);
  3871. ASSERT(pucValue);
  3872. /* Find the exist */
  3873. prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
  3874. if (prWlanCfgEntry) {
  3875. kalStrnCpy(pucValue, prWlanCfgEntry->aucValue, WLAN_CFG_VALUE_LEN_MAX - 1);
  3876. return WLAN_STATUS_SUCCESS;
  3877. }
  3878. if (pucValueDef)
  3879. kalStrnCpy(pucValue, pucValueDef, WLAN_CFG_VALUE_LEN_MAX - 1);
  3880. return WLAN_STATUS_FAILURE;
  3881. }
  3882. UINT_32 wlanCfgGetUint32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, UINT_32 u4ValueDef)
  3883. {
  3884. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3885. P_WLAN_CFG_T prWlanCfg;
  3886. UINT_32 u4Value;
  3887. INT_32 u4Ret;
  3888. prWlanCfg = prAdapter->prWlanCfg;
  3889. ASSERT(prWlanCfg);
  3890. u4Value = u4ValueDef;
  3891. /* Find the exist */
  3892. prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
  3893. if (prWlanCfgEntry) {
  3894. u4Ret = kalkStrtou32(prWlanCfgEntry->aucValue, 0, &u4Value);
  3895. if (u4Ret)
  3896. DBGLOG(INIT, ERROR, "parse prWlanCfgEntry->aucValue u4Ret=%u\n", u4Ret);
  3897. /* u4Value = kalStrtoul(prWlanCfgEntry->aucValue, NULL, 0); */
  3898. }
  3899. return u4Value;
  3900. }
  3901. INT_32 wlanCfgGetInt32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, INT_32 i4ValueDef)
  3902. {
  3903. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3904. P_WLAN_CFG_T prWlanCfg;
  3905. INT_32 i4Value;
  3906. INT_32 i4Ret;
  3907. prWlanCfg = prAdapter->prWlanCfg;
  3908. ASSERT(prWlanCfg);
  3909. i4Value = i4ValueDef;
  3910. /* Find the exist */
  3911. prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
  3912. if (prWlanCfgEntry) {
  3913. i4Ret = kalkStrtos32(prWlanCfgEntry->aucValue, 0, &i4Value);
  3914. /* i4Ret = kalStrtol(prWlanCfgEntry->aucValue, NULL, 0); */
  3915. if (i4Ret)
  3916. DBGLOG(INIT, ERROR, "parse prWlanCfgEntry->aucValue i4Ret=%u\n\r", i4Ret);
  3917. }
  3918. return i4Value;
  3919. }
  3920. WLAN_STATUS wlanCfgSet(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, PCHAR pucValue, UINT_32 u4Flags)
  3921. {
  3922. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3923. P_WLAN_CFG_T prWlanCfg;
  3924. UINT_32 u4EntryIndex;
  3925. UINT_32 i;
  3926. UINT_8 ucExist;
  3927. prWlanCfg = prAdapter->prWlanCfg;
  3928. ASSERT(prWlanCfg);
  3929. ASSERT(pucKey);
  3930. /* Find the exist */
  3931. ucExist = 0;
  3932. prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
  3933. if (!prWlanCfgEntry) {
  3934. /* Find the empty */
  3935. for (i = 0; i < WLAN_CFG_ENTRY_NUM_MAX; i++) {
  3936. prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[i];
  3937. if (prWlanCfgEntry->aucKey[0] == '\0')
  3938. break;
  3939. }
  3940. u4EntryIndex = i;
  3941. if (u4EntryIndex < WLAN_CFG_ENTRY_NUM_MAX) {
  3942. prWlanCfgEntry = &prWlanCfg->arWlanCfgBuf[u4EntryIndex];
  3943. kalMemZero(prWlanCfgEntry, sizeof(WLAN_CFG_ENTRY_T));
  3944. } else {
  3945. prWlanCfgEntry = NULL;
  3946. DBGLOG(INIT, ERROR, "wifi config there is no empty entry\n");
  3947. }
  3948. } /* !prWlanCfgEntry */
  3949. else
  3950. ucExist = 1;
  3951. if (prWlanCfgEntry) {
  3952. if (ucExist == 0) {
  3953. kalStrnCpy(prWlanCfgEntry->aucKey, pucKey, WLAN_CFG_KEY_LEN_MAX - 1);
  3954. prWlanCfgEntry->aucKey[WLAN_CFG_KEY_LEN_MAX - 1] = '\0';
  3955. }
  3956. if (pucValue && pucValue[0] != '\0') {
  3957. kalStrnCpy(prWlanCfgEntry->aucValue, pucValue, WLAN_CFG_VALUE_LEN_MAX - 1);
  3958. prWlanCfgEntry->aucValue[WLAN_CFG_VALUE_LEN_MAX - 1] = '\0';
  3959. if (ucExist) {
  3960. if (prWlanCfgEntry->pfSetCb)
  3961. prWlanCfgEntry->pfSetCb(prAdapter,
  3962. prWlanCfgEntry->aucKey,
  3963. prWlanCfgEntry->aucValue, prWlanCfgEntry->pPrivate, 0);
  3964. }
  3965. } else {
  3966. /* Call the pfSetCb if value is empty ? */
  3967. /* remove the entry if value is empty */
  3968. kalMemZero(prWlanCfgEntry, sizeof(WLAN_CFG_ENTRY_T));
  3969. }
  3970. }
  3971. /* prWlanCfgEntry */
  3972. if (prWlanCfgEntry) {
  3973. DBGLOG(INIT, LOUD, "Set wifi config exist %u \'%s\' \'%s\'\n",
  3974. ucExist, prWlanCfgEntry->aucKey, prWlanCfgEntry->aucValue);
  3975. return WLAN_STATUS_SUCCESS;
  3976. }
  3977. if (pucKey)
  3978. DBGLOG(INIT, ERROR, "Set wifi config error key \'%s\'\n", pucKey);
  3979. if (pucValue)
  3980. DBGLOG(INIT, ERROR, "Set wifi config error value \'%s\'\n", pucValue);
  3981. return WLAN_STATUS_FAILURE;
  3982. }
  3983. WLAN_STATUS
  3984. wlanCfgSetCb(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, WLAN_CFG_SET_CB pfSetCb, void *pPrivate, UINT_32 u4Flags)
  3985. {
  3986. P_WLAN_CFG_ENTRY_T prWlanCfgEntry;
  3987. P_WLAN_CFG_T prWlanCfg;
  3988. prWlanCfg = prAdapter->prWlanCfg;
  3989. ASSERT(prWlanCfg);
  3990. /* Find the exist */
  3991. prWlanCfgEntry = wlanCfgGetEntry(prAdapter, pucKey);
  3992. if (prWlanCfgEntry) {
  3993. prWlanCfgEntry->pfSetCb = pfSetCb;
  3994. prWlanCfgEntry->pPrivate = pPrivate;
  3995. }
  3996. if (prWlanCfgEntry)
  3997. return WLAN_STATUS_SUCCESS;
  3998. else
  3999. return WLAN_STATUS_FAILURE;
  4000. }
  4001. WLAN_STATUS wlanCfgSetUint32(IN P_ADAPTER_T prAdapter, const PCHAR pucKey, UINT_32 u4Value)
  4002. {
  4003. P_WLAN_CFG_T prWlanCfg;
  4004. UINT_8 aucBuf[WLAN_CFG_VALUE_LEN_MAX];
  4005. prWlanCfg = prAdapter->prWlanCfg;
  4006. ASSERT(prWlanCfg);
  4007. kalMemZero(aucBuf, sizeof(aucBuf));
  4008. kalSnprintf(aucBuf, WLAN_CFG_VALUE_LEN_MAX, "0x%x", (unsigned int)u4Value);
  4009. return wlanCfgSet(prAdapter, pucKey, aucBuf, 0);
  4010. }
  4011. enum {
  4012. STATE_EOF = 0,
  4013. STATE_TEXT = 1,
  4014. STATE_NEWLINE = 2
  4015. };
  4016. struct WLAN_CFG_PARSE_STATE_S {
  4017. CHAR *ptr;
  4018. CHAR *text;
  4019. INT_32 nexttoken;
  4020. UINT_32 maxSize;
  4021. };
  4022. INT_32 wlanCfgFindNextToken(struct WLAN_CFG_PARSE_STATE_S *state)
  4023. {
  4024. CHAR *x = state->ptr;
  4025. CHAR *s;
  4026. if (state->nexttoken) {
  4027. INT_32 t = state->nexttoken;
  4028. state->nexttoken = 0;
  4029. return t;
  4030. }
  4031. for (;;) {
  4032. switch (*x) {
  4033. case 0:
  4034. state->ptr = x;
  4035. return STATE_EOF;
  4036. case '\n':
  4037. x++;
  4038. state->ptr = x;
  4039. return STATE_NEWLINE;
  4040. case ' ':
  4041. case '\t':
  4042. case '\r':
  4043. x++;
  4044. continue;
  4045. case '#':
  4046. while (*x && (*x != '\n'))
  4047. x++;
  4048. if (*x == '\n') {
  4049. state->ptr = x + 1;
  4050. return STATE_NEWLINE;
  4051. }
  4052. state->ptr = x;
  4053. return STATE_EOF;
  4054. default:
  4055. goto text;
  4056. }
  4057. }
  4058. textdone:
  4059. state->ptr = x;
  4060. *s = 0;
  4061. return STATE_TEXT;
  4062. text:
  4063. state->text = s = x;
  4064. textresume:
  4065. for (;;) {
  4066. switch (*x) {
  4067. case 0:
  4068. goto textdone;
  4069. case ' ':
  4070. case '\t':
  4071. case '\r':
  4072. x++;
  4073. goto textdone;
  4074. case '\n':
  4075. state->nexttoken = STATE_NEWLINE;
  4076. x++;
  4077. goto textdone;
  4078. case '"':
  4079. x++;
  4080. for (;;) {
  4081. switch (*x) {
  4082. case 0:
  4083. /* unterminated quoted thing */
  4084. state->ptr = x;
  4085. return STATE_EOF;
  4086. case '"':
  4087. x++;
  4088. goto textresume;
  4089. default:
  4090. *s++ = *x++;
  4091. }
  4092. }
  4093. break;
  4094. case '\\':
  4095. x++;
  4096. switch (*x) {
  4097. case 0:
  4098. goto textdone;
  4099. case 'n':
  4100. *s++ = '\n';
  4101. break;
  4102. case 'r':
  4103. *s++ = '\r';
  4104. break;
  4105. case 't':
  4106. *s++ = '\t';
  4107. break;
  4108. case '\\':
  4109. *s++ = '\\';
  4110. break;
  4111. case '\r':
  4112. /* \ <cr> <lf> -> line continuation */
  4113. if (x[1] != '\n') {
  4114. x++;
  4115. continue;
  4116. }
  4117. case '\n':
  4118. /* \ <lf> -> line continuation */
  4119. x++;
  4120. /* eat any extra whitespace */
  4121. while ((*x == ' ') || (*x == '\t'))
  4122. x++;
  4123. continue;
  4124. default:
  4125. /* unknown escape -- just copy */
  4126. *s++ = *x++;
  4127. }
  4128. continue;
  4129. default:
  4130. *s++ = *x++;
  4131. }
  4132. }
  4133. return STATE_EOF;
  4134. }
  4135. WLAN_STATUS wlanCfgParseArgument(CHAR *cmdLine, INT_32 *argc, CHAR *argv[])
  4136. {
  4137. struct WLAN_CFG_PARSE_STATE_S state;
  4138. CHAR **args;
  4139. INT_32 nargs;
  4140. if (cmdLine == NULL || argc == NULL || argv == NULL) {
  4141. ASSERT(0);
  4142. return WLAN_STATUS_FAILURE;
  4143. }
  4144. args = argv;
  4145. nargs = 0;
  4146. state.ptr = cmdLine;
  4147. state.nexttoken = 0;
  4148. state.maxSize = 0;
  4149. if (kalStrnLen(cmdLine, 512) >= 512) {
  4150. ASSERT(0);
  4151. return WLAN_STATUS_FAILURE;
  4152. }
  4153. for (;;) {
  4154. switch (wlanCfgFindNextToken(&state)) {
  4155. case STATE_EOF:
  4156. goto exit;
  4157. case STATE_NEWLINE:
  4158. goto exit;
  4159. case STATE_TEXT:
  4160. if (nargs < WLAN_CFG_ARGV_MAX)
  4161. args[nargs++] = state.text;
  4162. break;
  4163. }
  4164. }
  4165. exit:
  4166. *argc = nargs;
  4167. return WLAN_STATUS_SUCCESS;
  4168. }
  4169. WLAN_STATUS
  4170. wlanCfgParseAddEntry(IN P_ADAPTER_T prAdapter,
  4171. PUINT_8 pucKeyHead, PUINT_8 pucKeyTail, PUINT_8 pucValueHead, PUINT_8 pucValueTail)
  4172. {
  4173. UINT_8 aucKey[WLAN_CFG_KEY_LEN_MAX];
  4174. UINT_8 aucValue[WLAN_CFG_VALUE_LEN_MAX];
  4175. UINT_32 u4Len;
  4176. kalMemZero(aucKey, sizeof(aucKey));
  4177. kalMemZero(aucValue, sizeof(aucValue));
  4178. if ((pucKeyHead == NULL)
  4179. || (pucValueHead == NULL)
  4180. )
  4181. return WLAN_STATUS_FAILURE;
  4182. if (pucKeyTail) {
  4183. if (pucKeyHead > pucKeyTail)
  4184. return WLAN_STATUS_FAILURE;
  4185. u4Len = pucKeyTail - pucKeyHead + 1;
  4186. } else
  4187. u4Len = kalStrnLen(pucKeyHead, WLAN_CFG_KEY_LEN_MAX - 1);
  4188. if (u4Len >= WLAN_CFG_KEY_LEN_MAX)
  4189. u4Len = WLAN_CFG_KEY_LEN_MAX - 1;
  4190. if (u4Len < WLAN_CFG_VALUE_LEN_MAX)
  4191. kalStrnCpy(aucKey, pucKeyHead, u4Len);
  4192. else
  4193. DBGLOG(INIT, ERROR, "wifi entry parse error: Data len > %d\n", u4Len);
  4194. if (pucValueTail) {
  4195. if (pucValueHead > pucValueTail)
  4196. return WLAN_STATUS_FAILURE;
  4197. u4Len = pucValueTail - pucValueHead + 1;
  4198. } else
  4199. u4Len = kalStrnLen(pucValueHead, WLAN_CFG_VALUE_LEN_MAX - 1);
  4200. if (u4Len >= WLAN_CFG_VALUE_LEN_MAX)
  4201. u4Len = WLAN_CFG_VALUE_LEN_MAX - 1;
  4202. if (u4Len < WLAN_CFG_VALUE_LEN_MAX)
  4203. kalStrnCpy(aucValue, pucValueHead, u4Len);
  4204. else
  4205. DBGLOG(INIT, ERROR, "wifi entry parse error: Data len > %d\n", u4Len);
  4206. return wlanCfgSet(prAdapter, aucKey, aucValue, 0);
  4207. }
  4208. enum {
  4209. WAIT_KEY_HEAD = 0,
  4210. WAIT_KEY_TAIL,
  4211. WAIT_VALUE_HEAD,
  4212. WAIT_VALUE_TAIL,
  4213. WAIT_COMMENT_TAIL
  4214. };
  4215. WLAN_STATUS wlanCfgParse(IN P_ADAPTER_T prAdapter, PUINT_8 pucConfigBuf, UINT_32 u4ConfigBufLen)
  4216. {
  4217. struct WLAN_CFG_PARSE_STATE_S state;
  4218. PCHAR apcArgv[WLAN_CFG_ARGV_MAX];
  4219. CHAR **args;
  4220. INT_32 nargs;
  4221. if (pucConfigBuf == NULL) {
  4222. ASSERT(0);
  4223. return WLAN_STATUS_FAILURE;
  4224. }
  4225. if (kalStrnLen(pucConfigBuf, 4000) >= 4000) {
  4226. ASSERT(0);
  4227. return WLAN_STATUS_FAILURE;
  4228. }
  4229. if (u4ConfigBufLen == 0)
  4230. return WLAN_STATUS_FAILURE;
  4231. args = apcArgv;
  4232. nargs = 0;
  4233. state.ptr = pucConfigBuf;
  4234. state.nexttoken = 0;
  4235. state.maxSize = u4ConfigBufLen;
  4236. for (;;) {
  4237. switch (wlanCfgFindNextToken(&state)) {
  4238. case STATE_EOF:
  4239. if (nargs > 1)
  4240. wlanCfgParseAddEntry(prAdapter, args[0], NULL, args[1], NULL);
  4241. goto exit;
  4242. case STATE_NEWLINE:
  4243. if (nargs > 1)
  4244. wlanCfgParseAddEntry(prAdapter, args[0], NULL, args[1], NULL);
  4245. nargs = 0;
  4246. break;
  4247. case STATE_TEXT:
  4248. if (nargs < WLAN_CFG_ARGV_MAX)
  4249. args[nargs++] = state.text;
  4250. break;
  4251. }
  4252. }
  4253. exit:
  4254. return WLAN_STATUS_SUCCESS;
  4255. #if 0
  4256. /* Old version */
  4257. UINT_32 i;
  4258. UINT_8 c;
  4259. PUINT_8 pbuf;
  4260. UINT_8 ucState;
  4261. PUINT_8 pucKeyTail = NULL;
  4262. PUINT_8 pucKeyHead = NULL;
  4263. PUINT_8 pucValueHead = NULL;
  4264. PUINT_8 pucValueTail = NULL;
  4265. ucState = WAIT_KEY_HEAD;
  4266. pbuf = pucConfigBuf;
  4267. for (i = 0; i < u4ConfigBufLen; i++) {
  4268. c = pbuf[i];
  4269. if (c == '\r' || c == '\n') {
  4270. if (ucState == WAIT_VALUE_TAIL) {
  4271. /* Entry found */
  4272. if (pucValueHead)
  4273. wlanCfgParseAddEntry(prAdapter, pucKeyHead, pucKeyTail,
  4274. pucValueHead, pucValueTail);
  4275. }
  4276. ucState = WAIT_KEY_HEAD;
  4277. pucKeyTail = NULL;
  4278. pucKeyHead = NULL;
  4279. pucValueHead = NULL;
  4280. pucValueTail = NULL;
  4281. } else if (c == '=') {
  4282. if (ucState == WAIT_KEY_TAIL) {
  4283. pucKeyTail = &pbuf[i - 1];
  4284. ucState = WAIT_VALUE_HEAD;
  4285. }
  4286. } else if (c == ' ' || c == '\t') {
  4287. if (ucState == WAIT_KEY_HEAD)
  4288. ;
  4289. else if (ucState == WAIT_KEY_TAIL) {
  4290. pucKeyTail = &pbuf[i - 1];
  4291. ucState = WAIT_VALUE_HEAD;
  4292. }
  4293. } else {
  4294. if (c == '#') {
  4295. /* comments */
  4296. if (ucState == WAIT_KEY_HEAD)
  4297. ucState = WAIT_COMMENT_TAIL;
  4298. else if (ucState == WAIT_VALUE_TAIL)
  4299. pucValueTail = &pbuf[i];
  4300. } else {
  4301. if (ucState == WAIT_KEY_HEAD) {
  4302. pucKeyHead = &pbuf[i];
  4303. pucKeyTail = &pbuf[i];
  4304. ucState = WAIT_KEY_TAIL;
  4305. } else if (ucState == WAIT_VALUE_HEAD) {
  4306. pucValueHead = &pbuf[i];
  4307. pucValueTail = &pbuf[i];
  4308. ucState = WAIT_VALUE_TAIL;
  4309. } else if (ucState == WAIT_VALUE_TAIL)
  4310. pucValueTail = &pbuf[i];
  4311. }
  4312. }
  4313. } /* for */
  4314. if (ucState == WAIT_VALUE_TAIL) {
  4315. /* Entry found */
  4316. if (pucValueTail)
  4317. wlanCfgParseAddEntry(prAdapter, pucKeyHead, pucKeyTail, pucValueHead, pucValueTail);
  4318. }
  4319. #endif
  4320. return WLAN_STATUS_SUCCESS;
  4321. }
  4322. #endif
  4323. #if CFG_SUPPORT_CFG_FILE
  4324. WLAN_STATUS wlanCfgInit(IN P_ADAPTER_T prAdapter, PUINT_8 pucConfigBuf, UINT_32 u4ConfigBufLen, UINT_32 u4Flags)
  4325. {
  4326. P_WLAN_CFG_T prWlanCfg;
  4327. /* P_WLAN_CFG_ENTRY_T prWlanCfgEntry; */
  4328. prAdapter->prWlanCfg = &prAdapter->rWlanCfg;
  4329. prWlanCfg = prAdapter->prWlanCfg;
  4330. kalMemZero(prWlanCfg, sizeof(WLAN_CFG_T));
  4331. ASSERT(prWlanCfg);
  4332. prWlanCfg->u4WlanCfgEntryNumMax = WLAN_CFG_ENTRY_NUM_MAX;
  4333. prWlanCfg->u4WlanCfgKeyLenMax = WLAN_CFG_KEY_LEN_MAX;
  4334. prWlanCfg->u4WlanCfgValueLenMax = WLAN_CFG_VALUE_LEN_MAX;
  4335. #if 0
  4336. DBGLOG(INIT, INFO, "Init wifi config len %u max entry %u\n", u4ConfigBufLen, prWlanCfg->u4WlanCfgEntryNumMax);
  4337. #endif
  4338. /* self test */
  4339. wlanCfgSet(prAdapter, "ConfigValid", "0x123", 0);
  4340. if (wlanCfgGetUint32(prAdapter, "ConfigValid", 0) != 0x123)
  4341. DBGLOG(INIT, ERROR, "wifi config error %u\n", __LINE__);
  4342. wlanCfgSet(prAdapter, "ConfigValid", "1", 0);
  4343. if (wlanCfgGetUint32(prAdapter, "ConfigValid", 0) != 1)
  4344. DBGLOG(INIT, ERROR, "wifi config error %u\n", __LINE__);
  4345. #if 0 /* soc chip didn't support these parameters now */
  4346. /* Add initil config */
  4347. /* use g,wlan,p2p,ap as prefix */
  4348. /* Don't set cb here , overwrite by another api */
  4349. wlanCfgSet(prAdapter, "TxLdpc", "1", 0);
  4350. wlanCfgSet(prAdapter, "RxLdpc", "1", 0);
  4351. wlanCfgSet(prAdapter, "RxBeamformee", "1", 0);
  4352. wlanCfgSet(prAdapter, "RoamTh1", "100", 0);
  4353. wlanCfgSet(prAdapter, "RoamTh2", "150", 0);
  4354. wlanCfgSet(prAdapter, "wlanRxLdpc", "1", 0);
  4355. wlanCfgSet(prAdapter, "apRxLdpc", "1", 0);
  4356. wlanCfgSet(prAdapter, "p2pRxLdpc", "1", 0);
  4357. #endif
  4358. /* Parse the pucConfigBuff */
  4359. if (pucConfigBuf && (u4ConfigBufLen > 0))
  4360. wlanCfgParse(prAdapter, pucConfigBuf, u4ConfigBufLen);
  4361. return WLAN_STATUS_SUCCESS;
  4362. }
  4363. /*----------------------------------------------------------------------------*/
  4364. /*!
  4365. * @brief This function is to initialize WLAN feature options
  4366. *
  4367. * @param prAdapter Pointer of ADAPTER_T
  4368. *
  4369. * @return none
  4370. */
  4371. /*----------------------------------------------------------------------------*/
  4372. VOID wlanCfgApply(IN P_ADAPTER_T prAdapter)
  4373. {
  4374. #define STR2BYTE(s) (((((PUINT_8)s)[0]-'0')*10)+(((PUINT_8)s)[1]-'0'))
  4375. CHAR aucValue[WLAN_CFG_VALUE_LEN_MAX];
  4376. P_WIFI_VAR_T prWifiVar = &prAdapter->rWifiVar;
  4377. P_REG_INFO_T prRegInfo = &prAdapter->prGlueInfo->rRegInfo;
  4378. P_TX_PWR_PARAM_T prTxPwr = &prRegInfo->rTxPwr;
  4379. kalMemZero(aucValue, sizeof(aucValue));
  4380. DBGLOG(INIT, LOUD, "CFG_FILE: Apply Config File\n");
  4381. /* Apply COUNTRY Config */
  4382. if (wlanCfgGet(prAdapter, "country", aucValue, "", 0) == WLAN_STATUS_SUCCESS) {
  4383. DBGLOG(INIT, LOUD, "CFG_FILE: Found Country Key, Value=%s\n", aucValue);
  4384. prAdapter->rWifiVar.rConnSettings.u2CountryCode =
  4385. (((UINT_16) aucValue[0]) << 8) | ((UINT_16) aucValue[1]);
  4386. }
  4387. prWifiVar->ucApWpsMode = (UINT_8) wlanCfgGetUint32(prAdapter, "ApWpsMode", 0);
  4388. prWifiVar->ucCert11nMode = (UINT_8)wlanCfgGetUint32(prAdapter, "Cert11nMode", 0);
  4389. DBGLOG(INIT, LOUD, "CFG_FILE: ucApWpsMode = %u, ucCert11nMode = %u\n",
  4390. prWifiVar->ucApWpsMode, prWifiVar->ucCert11nMode);
  4391. #if 0
  4392. if (prWifiVar->ucCert11nMode == 1)
  4393. nicWriteMcr(prAdapter, 0x11111115 , 1);
  4394. #endif
  4395. if (wlanCfgGet(prAdapter, "5G_support", aucValue, "", 0) == WLAN_STATUS_SUCCESS)
  4396. prRegInfo->ucSupport5GBand = (*aucValue == 'y') ? 1 : 0;
  4397. if (wlanCfgGet(prAdapter, "TxPower2G4CCK", aucValue, "", 0) == WLAN_STATUS_SUCCESS
  4398. && kalStrLen(aucValue) == 2) {
  4399. prTxPwr->cTxPwr2G4Cck = STR2BYTE(aucValue);
  4400. DBGLOG(INIT, LOUD, "2.4G cck=%d\n", prTxPwr->cTxPwr2G4Cck);
  4401. }
  4402. if (wlanCfgGet(prAdapter, "TxPower2G4OFDM", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
  4403. kalStrLen(aucValue) == 10) {
  4404. prTxPwr->cTxPwr2G4OFDM_BPSK = STR2BYTE(aucValue);
  4405. prTxPwr->cTxPwr2G4OFDM_QPSK = STR2BYTE(aucValue + 2);
  4406. prTxPwr->cTxPwr2G4OFDM_16QAM = STR2BYTE(aucValue + 4);
  4407. prTxPwr->cTxPwr2G4OFDM_48Mbps = STR2BYTE(aucValue + 6);
  4408. prTxPwr->cTxPwr2G4OFDM_54Mbps = STR2BYTE(aucValue + 8);
  4409. DBGLOG(INIT, LOUD, "2.4G OFDM=%d,%d,%d,%d,%d\n",
  4410. prTxPwr->cTxPwr2G4OFDM_BPSK, prTxPwr->cTxPwr2G4OFDM_QPSK,
  4411. prTxPwr->cTxPwr2G4OFDM_16QAM, prTxPwr->cTxPwr2G4OFDM_48Mbps,
  4412. prTxPwr->cTxPwr2G4OFDM_54Mbps);
  4413. }
  4414. if (wlanCfgGet(prAdapter, "TxPower2G4HT20", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
  4415. kalStrLen(aucValue) == 12) {
  4416. prTxPwr->cTxPwr2G4HT20_BPSK = STR2BYTE(aucValue);
  4417. prTxPwr->cTxPwr2G4HT20_QPSK = STR2BYTE(aucValue + 2);
  4418. prTxPwr->cTxPwr2G4HT20_16QAM = STR2BYTE(aucValue + 4);
  4419. prTxPwr->cTxPwr2G4HT20_MCS5 = STR2BYTE(aucValue + 6);
  4420. prTxPwr->cTxPwr2G4HT20_MCS6 = STR2BYTE(aucValue + 8);
  4421. prTxPwr->cTxPwr2G4HT20_MCS7 = STR2BYTE(aucValue + 10);
  4422. DBGLOG(INIT, LOUD, "2.4G HT20=%d,%d,%d,%d,%d,%d\n",
  4423. prTxPwr->cTxPwr2G4HT20_BPSK, prTxPwr->cTxPwr2G4HT20_QPSK,
  4424. prTxPwr->cTxPwr2G4HT20_16QAM, prTxPwr->cTxPwr2G4HT20_MCS5,
  4425. prTxPwr->cTxPwr2G4HT20_MCS6, prTxPwr->cTxPwr2G4HT20_MCS7);
  4426. }
  4427. if (wlanCfgGet(prAdapter, "TxPower2G4HT40", aucValue, "", 0) == WLAN_STATUS_SUCCESS &&
  4428. kalStrLen(aucValue) == 12) {
  4429. prTxPwr->cTxPwr2G4HT40_BPSK = STR2BYTE(aucValue);
  4430. prTxPwr->cTxPwr2G4HT40_QPSK = STR2BYTE(aucValue + 2);
  4431. prTxPwr->cTxPwr2G4HT40_16QAM = STR2BYTE(aucValue + 4);
  4432. prTxPwr->cTxPwr2G4HT40_MCS5 = STR2BYTE(aucValue + 6);
  4433. prTxPwr->cTxPwr2G4HT40_MCS6 = STR2BYTE(aucValue + 8);
  4434. prTxPwr->cTxPwr2G4HT40_MCS7 = STR2BYTE(aucValue + 10);
  4435. DBGLOG(INIT, LOUD, "2.4G HT40=%d,%d,%d,%d,%d,%d\n",
  4436. prTxPwr->cTxPwr2G4HT40_BPSK, prTxPwr->cTxPwr2G4HT40_QPSK,
  4437. prTxPwr->cTxPwr2G4HT40_16QAM, prTxPwr->cTxPwr2G4HT40_MCS5,
  4438. prTxPwr->cTxPwr2G4HT40_MCS6, prTxPwr->cTxPwr2G4HT40_MCS7);
  4439. }
  4440. if (wlanCfgGet(prAdapter, "TxPower5GOFDM", aucValue, "", 0) == WLAN_STATUS_SUCCESS
  4441. && kalStrLen(aucValue) == 10) {
  4442. prTxPwr->cTxPwr5GOFDM_BPSK = STR2BYTE(aucValue);
  4443. prTxPwr->cTxPwr5GOFDM_QPSK = STR2BYTE(aucValue + 2);
  4444. prTxPwr->cTxPwr5GOFDM_16QAM = STR2BYTE(aucValue + 4);
  4445. prTxPwr->cTxPwr5GOFDM_48Mbps = STR2BYTE(aucValue + 6);
  4446. prTxPwr->cTxPwr5GOFDM_54Mbps = STR2BYTE(aucValue + 8);
  4447. DBGLOG(INIT, LOUD, "5G OFDM=%d,%d,%d,%d,%d\n",
  4448. prTxPwr->cTxPwr5GOFDM_BPSK, prTxPwr->cTxPwr5GOFDM_QPSK,
  4449. prTxPwr->cTxPwr5GOFDM_16QAM, prTxPwr->cTxPwr5GOFDM_48Mbps,
  4450. prTxPwr->cTxPwr5GOFDM_54Mbps);
  4451. }
  4452. if (wlanCfgGet(prAdapter, "TxPower5GHT20", aucValue, "", 0) == WLAN_STATUS_SUCCESS
  4453. && kalStrLen(aucValue) == 12) {
  4454. prTxPwr->cTxPwr5GHT20_BPSK = STR2BYTE(aucValue);
  4455. prTxPwr->cTxPwr5GHT20_QPSK = STR2BYTE(aucValue + 2);
  4456. prTxPwr->cTxPwr5GHT20_16QAM = STR2BYTE(aucValue + 4);
  4457. prTxPwr->cTxPwr5GHT20_MCS5 = STR2BYTE(aucValue + 6);
  4458. prTxPwr->cTxPwr5GHT20_MCS6 = STR2BYTE(aucValue + 8);
  4459. prTxPwr->cTxPwr5GHT20_MCS7 = STR2BYTE(aucValue + 10);
  4460. DBGLOG(INIT, LOUD, "5G HT20=%d,%d,%d,%d,%d,%d\n",
  4461. prTxPwr->cTxPwr5GHT20_BPSK, prTxPwr->cTxPwr5GHT20_QPSK,
  4462. prTxPwr->cTxPwr5GHT20_16QAM, prTxPwr->cTxPwr5GHT20_MCS5, prTxPwr->cTxPwr5GHT20_MCS6,
  4463. prTxPwr->cTxPwr5GHT20_MCS7);
  4464. }
  4465. if (wlanCfgGet(prAdapter, "TxPower5GHT40", aucValue, "", 0) == WLAN_STATUS_SUCCESS
  4466. && kalStrLen(aucValue) == 12) {
  4467. prTxPwr->cTxPwr5GHT40_BPSK = STR2BYTE(aucValue);
  4468. prTxPwr->cTxPwr5GHT40_QPSK = STR2BYTE(aucValue + 2);
  4469. prTxPwr->cTxPwr5GHT40_16QAM = STR2BYTE(aucValue + 4);
  4470. prTxPwr->cTxPwr5GHT40_MCS5 = STR2BYTE(aucValue + 6);
  4471. prTxPwr->cTxPwr5GHT40_MCS6 = STR2BYTE(aucValue + 8);
  4472. prTxPwr->cTxPwr5GHT40_MCS7 = STR2BYTE(aucValue + 10);
  4473. DBGLOG(INIT, LOUD, "5G HT40=%d,%d,%d,%d,%d,%d\n",
  4474. prTxPwr->cTxPwr5GHT40_BPSK, prTxPwr->cTxPwr5GHT40_QPSK,
  4475. prTxPwr->cTxPwr5GHT40_16QAM, prTxPwr->cTxPwr5GHT40_MCS5, prTxPwr->cTxPwr5GHT40_MCS6,
  4476. prTxPwr->cTxPwr5GHT40_MCS7);
  4477. }
  4478. /* TODO: Apply other Config */
  4479. }
  4480. #endif /* CFG_SUPPORT_CFG_FILE */