wlan_lib.c 199 KB

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