ioctl_linux.c 359 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define _IOCTL_LINUX_C_
  16. #include <drv_types.h>
  17. #include <rtw_mp.h>
  18. #include <rtw_mp_ioctl.h>
  19. #include "../../hal/phydm/phydm_precomp.h"
  20. #ifdef RTW_HALMAC
  21. #include "../../hal/hal_halmac.h"
  22. #endif
  23. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27))
  24. #define iwe_stream_add_event(a, b, c, d, e) iwe_stream_add_event(b, c, d, e)
  25. #define iwe_stream_add_point(a, b, c, d, e) iwe_stream_add_point(b, c, d, e)
  26. #endif
  27. #ifdef CONFIG_80211N_HT
  28. extern int rtw_ht_enable;
  29. #endif
  30. #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV+30)
  31. #define SCAN_ITEM_SIZE 768
  32. #define MAX_CUSTOM_LEN 64
  33. #define RATE_COUNT 4
  34. #define MAX_SCAN_BUFFER_LEN 65535
  35. #ifdef CONFIG_GLOBAL_UI_PID
  36. extern int ui_pid[3];
  37. #endif
  38. /* combo scan */
  39. #define WEXT_CSCAN_AMOUNT 9
  40. #define WEXT_CSCAN_BUF_LEN 360
  41. #define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
  42. #define WEXT_CSCAN_HEADER_SIZE 12
  43. #define WEXT_CSCAN_SSID_SECTION 'S'
  44. #define WEXT_CSCAN_CHANNEL_SECTION 'C'
  45. #define WEXT_CSCAN_NPROBE_SECTION 'N'
  46. #define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
  47. #define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
  48. #define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
  49. #define WEXT_CSCAN_TYPE_SECTION 'T'
  50. extern u8 key_2char2num(u8 hch, u8 lch);
  51. extern u8 str_2char2num(u8 hch, u8 lch);
  52. extern void macstr2num(u8 *dst, u8 *src);
  53. extern u8 convert_ip_addr(u8 hch, u8 mch, u8 lch);
  54. u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
  55. 6000000, 9000000, 12000000, 18000000, 24000000, 36000000, 48000000, 54000000};
  56. static const char *const iw_operation_mode[] = {
  57. "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Monitor"
  58. };
  59. /**
  60. * hwaddr_aton - Convert ASCII string to MAC address
  61. * @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
  62. * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
  63. * Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
  64. */
  65. static int hwaddr_aton_i(const char *txt, u8 *addr)
  66. {
  67. int i;
  68. for (i = 0; i < 6; i++) {
  69. int a, b;
  70. a = hex2num_i(*txt++);
  71. if (a < 0)
  72. return -1;
  73. b = hex2num_i(*txt++);
  74. if (b < 0)
  75. return -1;
  76. *addr++ = (a << 4) | b;
  77. if (i < 5 && *txt++ != ':')
  78. return -1;
  79. }
  80. return 0;
  81. }
  82. static void indicate_wx_custom_event(_adapter *padapter, char *msg)
  83. {
  84. u8 *buff;
  85. union iwreq_data wrqu;
  86. if (strlen(msg) > IW_CUSTOM_MAX) {
  87. RTW_INFO("%s strlen(msg):%zu > IW_CUSTOM_MAX:%u\n", __FUNCTION__ , strlen(msg), IW_CUSTOM_MAX);
  88. return;
  89. }
  90. buff = rtw_zmalloc(IW_CUSTOM_MAX + 1);
  91. if (!buff)
  92. return;
  93. _rtw_memcpy(buff, msg, strlen(msg));
  94. _rtw_memset(&wrqu, 0, sizeof(wrqu));
  95. wrqu.data.length = strlen(msg);
  96. RTW_INFO("%s %s\n", __FUNCTION__, buff);
  97. #ifndef CONFIG_IOCTL_CFG80211
  98. wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
  99. #endif
  100. rtw_mfree(buff, IW_CUSTOM_MAX + 1);
  101. }
  102. static void request_wps_pbc_event(_adapter *padapter)
  103. {
  104. u8 *buff, *p;
  105. union iwreq_data wrqu;
  106. buff = rtw_malloc(IW_CUSTOM_MAX);
  107. if (!buff)
  108. return;
  109. _rtw_memset(buff, 0, IW_CUSTOM_MAX);
  110. p = buff;
  111. p += sprintf(p, "WPS_PBC_START.request=TRUE");
  112. _rtw_memset(&wrqu, 0, sizeof(wrqu));
  113. wrqu.data.length = p - buff;
  114. wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX;
  115. RTW_INFO("%s\n", __FUNCTION__);
  116. #ifndef CONFIG_IOCTL_CFG80211
  117. wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
  118. #endif
  119. if (buff)
  120. rtw_mfree(buff, IW_CUSTOM_MAX);
  121. }
  122. #ifdef CONFIG_SUPPORT_HW_WPS_PBC
  123. void rtw_request_wps_pbc_event(_adapter *padapter)
  124. {
  125. #ifdef RTK_DMP_PLATFORM
  126. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12))
  127. kobject_uevent(&padapter->pnetdev->dev.kobj, KOBJ_NET_PBC);
  128. #else
  129. kobject_hotplug(&padapter->pnetdev->class_dev.kobj, KOBJ_NET_PBC);
  130. #endif
  131. #else
  132. if (padapter->pid[0] == 0) {
  133. /* 0 is the default value and it means the application monitors the HW PBC doesn't privde its pid to driver. */
  134. return;
  135. }
  136. rtw_signal_process(padapter->pid[0], SIGUSR1);
  137. #endif
  138. rtw_led_control(padapter, LED_CTL_START_WPS_BOTTON);
  139. }
  140. #endif/* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
  141. void indicate_wx_scan_complete_event(_adapter *padapter)
  142. {
  143. union iwreq_data wrqu;
  144. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  145. /* RTW_INFO("+rtw_indicate_wx_scan_complete_event\n"); */
  146. #ifndef CONFIG_IOCTL_CFG80211
  147. wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
  148. #endif
  149. }
  150. void rtw_indicate_wx_assoc_event(_adapter *padapter)
  151. {
  152. union iwreq_data wrqu;
  153. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  154. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  155. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  156. WLAN_BSSID_EX *pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
  157. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  158. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  159. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)
  160. _rtw_memcpy(wrqu.ap_addr.sa_data, pnetwork->MacAddress, ETH_ALEN);
  161. else
  162. _rtw_memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
  163. RTW_PRINT("assoc success\n");
  164. #ifndef CONFIG_IOCTL_CFG80211
  165. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  166. #endif
  167. }
  168. void rtw_indicate_wx_disassoc_event(_adapter *padapter)
  169. {
  170. union iwreq_data wrqu;
  171. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  172. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  173. _rtw_memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  174. #ifndef CONFIG_IOCTL_CFG80211
  175. RTW_PRINT("indicate disassoc\n");
  176. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  177. #endif
  178. }
  179. /*
  180. uint rtw_is_cckrates_included(u8 *rate)
  181. {
  182. u32 i = 0;
  183. while(rate[i]!=0)
  184. {
  185. if ( (((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
  186. (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22) )
  187. return _TRUE;
  188. i++;
  189. }
  190. return _FALSE;
  191. }
  192. uint rtw_is_cckratesonly_included(u8 *rate)
  193. {
  194. u32 i = 0;
  195. while(rate[i]!=0)
  196. {
  197. if ( (((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
  198. (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22) )
  199. return _FALSE;
  200. i++;
  201. }
  202. return _TRUE;
  203. }
  204. */
  205. static int search_p2p_wfd_ie(_adapter *padapter,
  206. struct iw_request_info *info, struct wlan_network *pnetwork,
  207. char *start, char *stop)
  208. {
  209. #ifdef CONFIG_P2P
  210. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  211. #ifdef CONFIG_WFD
  212. if (SCAN_RESULT_ALL == pwdinfo->wfd_info->scan_result_type) {
  213. } else if ((SCAN_RESULT_P2P_ONLY == pwdinfo->wfd_info->scan_result_type) ||
  214. (SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type))
  215. #endif /* CONFIG_WFD */
  216. {
  217. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  218. u32 blnGotP2PIE = _FALSE;
  219. /* User is doing the P2P device discovery */
  220. /* The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE. */
  221. /* If not, the driver should ignore this AP and go to the next AP. */
  222. /* Verifying the SSID */
  223. if (_rtw_memcmp(pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN)) {
  224. u32 p2pielen = 0;
  225. /* Verifying the P2P IE */
  226. if (rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen))
  227. blnGotP2PIE = _TRUE;
  228. }
  229. if (blnGotP2PIE == _FALSE)
  230. return _FALSE;
  231. }
  232. }
  233. #ifdef CONFIG_WFD
  234. if (SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type) {
  235. u32 blnGotWFD = _FALSE;
  236. u8 *wfd_ie;
  237. uint wfd_ielen = 0;
  238. wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
  239. if (wfd_ie) {
  240. u8 *wfd_devinfo;
  241. uint wfd_devlen;
  242. wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
  243. if (wfd_devinfo) {
  244. if (pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_PSINK) {
  245. /* the first two bits will indicate the WFD device type */
  246. if ((wfd_devinfo[1] & 0x03) == WFD_DEVINFO_SOURCE) {
  247. /* If this device is Miracast PSink device, the scan reuslt should just provide the Miracast source. */
  248. blnGotWFD = _TRUE;
  249. }
  250. } else if (pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_SOURCE) {
  251. /* the first two bits will indicate the WFD device type */
  252. if ((wfd_devinfo[1] & 0x03) == WFD_DEVINFO_PSINK) {
  253. /* If this device is Miracast source device, the scan reuslt should just provide the Miracast PSink. */
  254. /* Todo: How about the SSink?! */
  255. blnGotWFD = _TRUE;
  256. }
  257. }
  258. }
  259. }
  260. if (blnGotWFD == _FALSE)
  261. return _FALSE;
  262. }
  263. #endif /* CONFIG_WFD */
  264. #endif /* CONFIG_P2P */
  265. return _TRUE;
  266. }
  267. static inline char *iwe_stream_mac_addr_proess(_adapter *padapter,
  268. struct iw_request_info *info, struct wlan_network *pnetwork,
  269. char *start, char *stop, struct iw_event *iwe)
  270. {
  271. /* AP MAC address */
  272. iwe->cmd = SIOCGIWAP;
  273. iwe->u.ap_addr.sa_family = ARPHRD_ETHER;
  274. _rtw_memcpy(iwe->u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
  275. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_ADDR_LEN);
  276. return start;
  277. }
  278. static inline char *iwe_stream_essid_proess(_adapter *padapter,
  279. struct iw_request_info *info, struct wlan_network *pnetwork,
  280. char *start, char *stop, struct iw_event *iwe)
  281. {
  282. /* Add the ESSID */
  283. iwe->cmd = SIOCGIWESSID;
  284. iwe->u.data.flags = 1;
  285. iwe->u.data.length = min((u16)pnetwork->network.Ssid.SsidLength, (u16)32);
  286. start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
  287. return start;
  288. }
  289. static inline char *iwe_stream_chan_process(_adapter *padapter,
  290. struct iw_request_info *info, struct wlan_network *pnetwork,
  291. char *start, char *stop, struct iw_event *iwe)
  292. {
  293. if (pnetwork->network.Configuration.DSConfig < 1 /*|| pnetwork->network.Configuration.DSConfig>14*/)
  294. pnetwork->network.Configuration.DSConfig = 1;
  295. /* Add frequency/channel */
  296. iwe->cmd = SIOCGIWFREQ;
  297. iwe->u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
  298. iwe->u.freq.e = 1;
  299. iwe->u.freq.i = pnetwork->network.Configuration.DSConfig;
  300. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_FREQ_LEN);
  301. return start;
  302. }
  303. static inline char *iwe_stream_mode_process(_adapter *padapter,
  304. struct iw_request_info *info, struct wlan_network *pnetwork,
  305. char *start, char *stop, struct iw_event *iwe, u16 cap)
  306. {
  307. /* Add mode */
  308. if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
  309. iwe->cmd = SIOCGIWMODE;
  310. if (cap & WLAN_CAPABILITY_BSS)
  311. iwe->u.mode = IW_MODE_MASTER;
  312. else
  313. iwe->u.mode = IW_MODE_ADHOC;
  314. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_UINT_LEN);
  315. }
  316. return start;
  317. }
  318. static inline char *iwe_stream_encryption_process(_adapter *padapter,
  319. struct iw_request_info *info, struct wlan_network *pnetwork,
  320. char *start, char *stop, struct iw_event *iwe, u16 cap)
  321. {
  322. /* Add encryption capability */
  323. iwe->cmd = SIOCGIWENCODE;
  324. if (cap & WLAN_CAPABILITY_PRIVACY)
  325. iwe->u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  326. else
  327. iwe->u.data.flags = IW_ENCODE_DISABLED;
  328. iwe->u.data.length = 0;
  329. start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
  330. return start;
  331. }
  332. static inline char *iwe_stream_protocol_process(_adapter *padapter,
  333. struct iw_request_info *info, struct wlan_network *pnetwork,
  334. char *start, char *stop, struct iw_event *iwe)
  335. {
  336. u16 ht_cap = _FALSE, vht_cap = _FALSE;
  337. u32 ht_ielen = 0, vht_ielen = 0;
  338. char *p;
  339. u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12); /* Probe Request */
  340. #ifdef CONFIG_80211N_HT
  341. /* parsing HT_CAP_IE */
  342. if(padapter->registrypriv.ht_enable && is_supported_ht(padapter->registrypriv.wireless_mode)) {
  343. p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - ie_offset);
  344. if (p && ht_ielen > 0)
  345. ht_cap = _TRUE;
  346. }
  347. #endif
  348. #ifdef CONFIG_80211AC_VHT
  349. /* parsing VHT_CAP_IE */
  350. if(padapter->registrypriv.wireless_mode & WIRELESS_11AC) {
  351. p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength - ie_offset);
  352. if (p && vht_ielen > 0)
  353. vht_cap = _TRUE;
  354. }
  355. #endif
  356. /* Add the protocol name */
  357. iwe->cmd = SIOCGIWNAME;
  358. if ((rtw_is_cckratesonly_included((u8 *)&pnetwork->network.SupportedRates)) == _TRUE) {
  359. if (ht_cap == _TRUE)
  360. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bn");
  361. else
  362. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11b");
  363. } else if ((rtw_is_cckrates_included((u8 *)&pnetwork->network.SupportedRates)) == _TRUE) {
  364. if (ht_cap == _TRUE)
  365. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bgn");
  366. else
  367. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bg");
  368. } else {
  369. if (pnetwork->network.Configuration.DSConfig > 14) {
  370. #ifdef CONFIG_80211AC_VHT
  371. if (vht_cap == _TRUE)
  372. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11AC");
  373. else
  374. #endif
  375. {
  376. if (ht_cap == _TRUE)
  377. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11an");
  378. else
  379. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11a");
  380. }
  381. } else {
  382. if (ht_cap == _TRUE)
  383. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11gn");
  384. else
  385. snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11g");
  386. }
  387. }
  388. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_CHAR_LEN);
  389. return start;
  390. }
  391. static inline char *iwe_stream_rate_process(_adapter *padapter,
  392. struct iw_request_info *info, struct wlan_network *pnetwork,
  393. char *start, char *stop, struct iw_event *iwe)
  394. {
  395. u32 ht_ielen = 0, vht_ielen = 0;
  396. char *p;
  397. u16 max_rate = 0, rate, ht_cap = _FALSE, vht_cap = _FALSE;
  398. u32 i = 0;
  399. u8 bw_40MHz = 0, short_GI = 0, bw_160MHz = 0, vht_highest_rate = 0;
  400. u16 mcs_rate = 0, vht_data_rate = 0;
  401. char custom[MAX_CUSTOM_LEN] = {0};
  402. u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12); /* Probe Request */
  403. /* parsing HT_CAP_IE */
  404. if(is_supported_ht(padapter->registrypriv.wireless_mode)) {
  405. p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - ie_offset);
  406. if (p && ht_ielen > 0) {
  407. struct rtw_ieee80211_ht_cap *pht_capie;
  408. ht_cap = _TRUE;
  409. pht_capie = (struct rtw_ieee80211_ht_cap *)(p + 2);
  410. _rtw_memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
  411. bw_40MHz = (pht_capie->cap_info & IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
  412. short_GI = (pht_capie->cap_info & (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
  413. }
  414. }
  415. #ifdef CONFIG_80211AC_VHT
  416. /* parsing VHT_CAP_IE */
  417. if(padapter->registrypriv.wireless_mode & WIRELESS_11AC){
  418. p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength - ie_offset);
  419. if (p && vht_ielen > 0) {
  420. u8 mcs_map[2];
  421. vht_cap = _TRUE;
  422. bw_160MHz = GET_VHT_CAPABILITY_ELE_CHL_WIDTH(p + 2);
  423. if (bw_160MHz)
  424. short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI160M(p + 2);
  425. else
  426. short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI80M(p + 2);
  427. _rtw_memcpy(mcs_map, GET_VHT_CAPABILITY_ELE_TX_MCS(p + 2), 2);
  428. vht_highest_rate = rtw_get_vht_highest_rate(mcs_map);
  429. vht_data_rate = rtw_vht_mcs_to_data_rate(CHANNEL_WIDTH_80, short_GI, vht_highest_rate);
  430. }
  431. }
  432. #endif
  433. /*Add basic and extended rates */
  434. p = custom;
  435. p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
  436. while (pnetwork->network.SupportedRates[i] != 0) {
  437. rate = pnetwork->network.SupportedRates[i] & 0x7F;
  438. if (rate > max_rate)
  439. max_rate = rate;
  440. p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
  441. "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
  442. i++;
  443. }
  444. #ifdef CONFIG_80211AC_VHT
  445. if (vht_cap == _TRUE)
  446. max_rate = vht_data_rate;
  447. else
  448. #endif
  449. if (ht_cap == _TRUE) {
  450. if (mcs_rate & 0x8000) /* MCS15 */
  451. max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
  452. else if (mcs_rate & 0x0080) /* MCS7 */
  453. max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
  454. else { /* default MCS7 */
  455. /* RTW_INFO("wx_get_scan, mcs_rate_bitmap=0x%x\n", mcs_rate); */
  456. max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
  457. }
  458. max_rate = max_rate * 2; /* Mbps/2; */
  459. }
  460. iwe->cmd = SIOCGIWRATE;
  461. iwe->u.bitrate.fixed = iwe->u.bitrate.disabled = 0;
  462. iwe->u.bitrate.value = max_rate * 500000;
  463. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_PARAM_LEN);
  464. return start ;
  465. }
  466. static inline char *iwe_stream_wpa_wpa2_process(_adapter *padapter,
  467. struct iw_request_info *info, struct wlan_network *pnetwork,
  468. char *start, char *stop, struct iw_event *iwe)
  469. {
  470. int buf_size = MAX_WPA_IE_LEN * 2;
  471. /* u8 pbuf[buf_size]={0}; */
  472. u8 *pbuf = rtw_zmalloc(buf_size);
  473. u8 wpa_ie[255] = {0}, rsn_ie[255] = {0};
  474. u16 i, wpa_len = 0, rsn_len = 0;
  475. u8 *p;
  476. sint out_len = 0;
  477. if (pbuf) {
  478. p = pbuf;
  479. /* parsing WPA/WPA2 IE */
  480. if (pnetwork->network.Reserved[0] != BSS_TYPE_PROB_REQ) { /* Probe Request */
  481. out_len = rtw_get_sec_ie(pnetwork->network.IEs , pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len);
  482. if (wpa_len > 0) {
  483. _rtw_memset(pbuf, 0, buf_size);
  484. p += sprintf(p, "wpa_ie=");
  485. for (i = 0; i < wpa_len; i++)
  486. p += sprintf(p, "%02x", wpa_ie[i]);
  487. if (wpa_len > 100) {
  488. printk("-----------------Len %d----------------\n", wpa_len);
  489. for (i = 0; i < wpa_len; i++)
  490. printk("%02x ", wpa_ie[i]);
  491. printk("\n");
  492. printk("-----------------Len %d----------------\n", wpa_len);
  493. }
  494. _rtw_memset(iwe, 0, sizeof(*iwe));
  495. iwe->cmd = IWEVCUSTOM;
  496. iwe->u.data.length = strlen(pbuf);
  497. start = iwe_stream_add_point(info, start, stop, iwe, pbuf);
  498. _rtw_memset(iwe, 0, sizeof(*iwe));
  499. iwe->cmd = IWEVGENIE;
  500. iwe->u.data.length = wpa_len;
  501. start = iwe_stream_add_point(info, start, stop, iwe, wpa_ie);
  502. }
  503. if (rsn_len > 0) {
  504. _rtw_memset(pbuf, 0, buf_size);
  505. p += sprintf(p, "rsn_ie=");
  506. for (i = 0; i < rsn_len; i++)
  507. p += sprintf(p, "%02x", rsn_ie[i]);
  508. _rtw_memset(iwe, 0, sizeof(*iwe));
  509. iwe->cmd = IWEVCUSTOM;
  510. iwe->u.data.length = strlen(pbuf);
  511. start = iwe_stream_add_point(info, start, stop, iwe, pbuf);
  512. _rtw_memset(iwe, 0, sizeof(*iwe));
  513. iwe->cmd = IWEVGENIE;
  514. iwe->u.data.length = rsn_len;
  515. start = iwe_stream_add_point(info, start, stop, iwe, rsn_ie);
  516. }
  517. }
  518. rtw_mfree(pbuf, buf_size);
  519. }
  520. return start;
  521. }
  522. static inline char *iwe_stream_wps_process(_adapter *padapter,
  523. struct iw_request_info *info, struct wlan_network *pnetwork,
  524. char *start, char *stop, struct iw_event *iwe)
  525. {
  526. /* parsing WPS IE */
  527. uint cnt = 0, total_ielen;
  528. u8 *wpsie_ptr = NULL;
  529. uint wps_ielen = 0;
  530. u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12);
  531. u8 *ie_ptr = pnetwork->network.IEs + ie_offset;
  532. total_ielen = pnetwork->network.IELength - ie_offset;
  533. if (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ) { /* Probe Request */
  534. ie_ptr = pnetwork->network.IEs;
  535. total_ielen = pnetwork->network.IELength;
  536. } else { /* Beacon or Probe Respones */
  537. ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
  538. total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
  539. }
  540. while (cnt < total_ielen) {
  541. if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) {
  542. wpsie_ptr = &ie_ptr[cnt];
  543. iwe->cmd = IWEVGENIE;
  544. iwe->u.data.length = (u16)wps_ielen;
  545. start = iwe_stream_add_point(info, start, stop, iwe, wpsie_ptr);
  546. }
  547. cnt += ie_ptr[cnt + 1] + 2; /* goto next */
  548. }
  549. return start;
  550. }
  551. static inline char *iwe_stream_wapi_process(_adapter *padapter,
  552. struct iw_request_info *info, struct wlan_network *pnetwork,
  553. char *start, char *stop, struct iw_event *iwe)
  554. {
  555. #ifdef CONFIG_WAPI_SUPPORT
  556. char *p;
  557. if (pnetwork->network.Reserved[0] != BSS_TYPE_PROB_REQ) { /* Probe Request */
  558. sint out_len_wapi = 0;
  559. /* here use static for stack size */
  560. static u8 buf_wapi[MAX_WAPI_IE_LEN * 2] = {0};
  561. static u8 wapi_ie[MAX_WAPI_IE_LEN] = {0};
  562. u16 wapi_len = 0;
  563. u16 i;
  564. out_len_wapi = rtw_get_wapi_ie(pnetwork->network.IEs , pnetwork->network.IELength, wapi_ie, &wapi_len);
  565. RTW_INFO("rtw_wx_get_scan: %s ", pnetwork->network.Ssid.Ssid);
  566. RTW_INFO("rtw_wx_get_scan: ssid = %d ", wapi_len);
  567. if (wapi_len > 0) {
  568. p = buf_wapi;
  569. /* _rtw_memset(buf_wapi, 0, MAX_WAPI_IE_LEN*2); */
  570. p += sprintf(p, "wapi_ie=");
  571. for (i = 0; i < wapi_len; i++)
  572. p += sprintf(p, "%02x", wapi_ie[i]);
  573. _rtw_memset(iwe, 0, sizeof(*iwe));
  574. iwe->cmd = IWEVCUSTOM;
  575. iwe->u.data.length = strlen(buf_wapi);
  576. start = iwe_stream_add_point(info, start, stop, iwe, buf_wapi);
  577. _rtw_memset(iwe, 0, sizeof(*iwe));
  578. iwe->cmd = IWEVGENIE;
  579. iwe->u.data.length = wapi_len;
  580. start = iwe_stream_add_point(info, start, stop, iwe, wapi_ie);
  581. }
  582. }
  583. #endif/* #ifdef CONFIG_WAPI_SUPPORT */
  584. return start;
  585. }
  586. static inline char *iwe_stream_rssi_process(_adapter *padapter,
  587. struct iw_request_info *info, struct wlan_network *pnetwork,
  588. char *start, char *stop, struct iw_event *iwe)
  589. {
  590. u8 ss, sq;
  591. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  592. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  593. s16 noise = 0;
  594. #endif
  595. /* Add quality statistics */
  596. iwe->cmd = IWEVQUAL;
  597. iwe->u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
  598. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  599. | IW_QUAL_NOISE_UPDATED
  600. #else
  601. | IW_QUAL_NOISE_INVALID
  602. #endif
  603. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  604. | IW_QUAL_DBM
  605. #endif
  606. ;
  607. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
  608. is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
  609. ss = padapter->recvpriv.signal_strength;
  610. sq = padapter->recvpriv.signal_qual;
  611. } else {
  612. ss = pnetwork->network.PhyInfo.SignalStrength;
  613. sq = pnetwork->network.PhyInfo.SignalQuality;
  614. }
  615. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  616. iwe->u.qual.level = (u8) translate_percentage_to_dbm(ss); /* dbm */
  617. #else
  618. iwe->u.qual.level = (u8)ss; /* % */
  619. #endif
  620. iwe->u.qual.qual = (u8)sq; /* signal quality */
  621. #ifdef CONFIG_PLATFORM_ROCKCHIPS
  622. iwe->u.qual.noise = -100; /* noise level suggest by zhf@rockchips */
  623. #else
  624. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  625. if (IS_NM_ENABLE(padapter)) {
  626. noise = rtw_noise_query_by_chan_num(padapter, pnetwork->network.Configuration.DSConfig);
  627. #ifndef CONFIG_SIGNAL_DISPLAY_DBM
  628. noise = translate_dbm_to_percentage(noise);/*percentage*/
  629. #endif
  630. iwe->u.qual.noise = noise;
  631. }
  632. #else
  633. iwe->u.qual.noise = 0; /* noise level */
  634. #endif
  635. #endif /* CONFIG_PLATFORM_ROCKCHIPS */
  636. /* RTW_INFO("iqual=%d, ilevel=%d, inoise=%d, iupdated=%d\n", iwe.u.qual.qual, iwe.u.qual.level , iwe.u.qual.noise, iwe.u.qual.updated); */
  637. start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_QUAL_LEN);
  638. return start;
  639. }
  640. static inline char *iwe_stream_net_rsv_process(_adapter *padapter,
  641. struct iw_request_info *info, struct wlan_network *pnetwork,
  642. char *start, char *stop, struct iw_event *iwe)
  643. {
  644. u8 buf[32] = {0};
  645. u8 *p, *pos;
  646. p = buf;
  647. pos = pnetwork->network.Reserved;
  648. p += sprintf(p, "fm=%02X%02X", pos[1], pos[0]);
  649. _rtw_memset(iwe, 0, sizeof(*iwe));
  650. iwe->cmd = IWEVCUSTOM;
  651. iwe->u.data.length = strlen(buf);
  652. start = iwe_stream_add_point(info, start, stop, iwe, buf);
  653. return start;
  654. }
  655. static char *translate_scan(_adapter *padapter,
  656. struct iw_request_info *info, struct wlan_network *pnetwork,
  657. char *start, char *stop)
  658. {
  659. struct iw_event iwe;
  660. u16 cap = 0;
  661. _rtw_memset(&iwe, 0, sizeof(iwe));
  662. if (_FALSE == search_p2p_wfd_ie(padapter, info, pnetwork, start, stop))
  663. return start;
  664. start = iwe_stream_mac_addr_proess(padapter, info, pnetwork, start, stop, &iwe);
  665. start = iwe_stream_essid_proess(padapter, info, pnetwork, start, stop, &iwe);
  666. start = iwe_stream_protocol_process(padapter, info, pnetwork, start, stop, &iwe);
  667. if (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ) /* Probe Request */
  668. cap = 0;
  669. else {
  670. _rtw_memcpy((u8 *)&cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
  671. cap = le16_to_cpu(cap);
  672. }
  673. start = iwe_stream_mode_process(padapter, info, pnetwork, start, stop, &iwe, cap);
  674. start = iwe_stream_chan_process(padapter, info, pnetwork, start, stop, &iwe);
  675. start = iwe_stream_encryption_process(padapter, info, pnetwork, start, stop, &iwe, cap);
  676. start = iwe_stream_rate_process(padapter, info, pnetwork, start, stop, &iwe);
  677. start = iwe_stream_wpa_wpa2_process(padapter, info, pnetwork, start, stop, &iwe);
  678. start = iwe_stream_wps_process(padapter, info, pnetwork, start, stop, &iwe);
  679. start = iwe_stream_wapi_process(padapter, info, pnetwork, start, stop, &iwe);
  680. start = iwe_stream_rssi_process(padapter, info, pnetwork, start, stop, &iwe);
  681. start = iwe_stream_net_rsv_process(padapter, info, pnetwork, start, stop, &iwe);
  682. return start;
  683. }
  684. static int wpa_set_auth_algs(struct net_device *dev, u32 value)
  685. {
  686. _adapter *padapter = (_adapter *) rtw_netdev_priv(dev);
  687. int ret = 0;
  688. if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
  689. RTW_INFO("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n", value);
  690. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  691. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  692. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  693. } else if (value & AUTH_ALG_SHARED_KEY) {
  694. RTW_INFO("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY [value:0x%x]\n", value);
  695. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  696. #ifdef CONFIG_PLATFORM_MT53XX
  697. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  698. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  699. #else
  700. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
  701. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  702. #endif
  703. } else if (value & AUTH_ALG_OPEN_SYSTEM) {
  704. RTW_INFO("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n");
  705. /* padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; */
  706. if (padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK) {
  707. #ifdef CONFIG_PLATFORM_MT53XX
  708. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  709. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  710. #else
  711. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  712. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  713. #endif
  714. }
  715. } else if (value & AUTH_ALG_LEAP)
  716. RTW_INFO("wpa_set_auth_algs, AUTH_ALG_LEAP\n");
  717. else {
  718. RTW_INFO("wpa_set_auth_algs, error!\n");
  719. ret = -EINVAL;
  720. }
  721. return ret;
  722. }
  723. static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  724. {
  725. int ret = 0;
  726. u32 wep_key_idx, wep_key_len;
  727. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  728. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  729. struct security_priv *psecuritypriv = &padapter->securitypriv;
  730. #ifdef CONFIG_P2P
  731. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  732. #endif /* CONFIG_P2P */
  733. param->u.crypt.err = 0;
  734. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  735. if (param_len < (u32)((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) {
  736. ret = -EINVAL;
  737. goto exit;
  738. }
  739. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  740. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  741. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  742. if (param->u.crypt.idx >= WEP_KEYS
  743. #ifdef CONFIG_IEEE80211W
  744. && param->u.crypt.idx > BIP_MAX_KEYID
  745. #endif /* CONFIG_IEEE80211W */
  746. ) {
  747. ret = -EINVAL;
  748. goto exit;
  749. }
  750. } else {
  751. #ifdef CONFIG_WAPI_SUPPORT
  752. if (strcmp(param->u.crypt.alg, "SMS4"))
  753. #endif
  754. {
  755. ret = -EINVAL;
  756. goto exit;
  757. }
  758. }
  759. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  760. RTW_INFO("wpa_set_encryption, crypt.alg = WEP\n");
  761. wep_key_idx = param->u.crypt.idx;
  762. wep_key_len = param->u.crypt.key_len;
  763. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  764. ret = -EINVAL;
  765. goto exit;
  766. }
  767. if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
  768. /* wep default key has not been set, so use this key index as default key.*/
  769. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  770. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  771. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  772. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  773. if (wep_key_len == 13) {
  774. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  775. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  776. }
  777. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  778. }
  779. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  780. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  781. psecuritypriv->key_mask |= BIT(wep_key_idx);
  782. padapter->mlmeextpriv.mlmext_info.key_index = wep_key_idx;
  783. goto exit;
  784. }
  785. if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
  786. struct sta_info *psta, *pbcmc_sta;
  787. struct sta_priv *pstapriv = &padapter->stapriv;
  788. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) { /* sta mode */
  789. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  790. if (psta == NULL) {
  791. /* DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail\n")); */
  792. } else {
  793. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  794. if (strcmp(param->u.crypt.alg, "none") != 0)
  795. psta->ieee8021x_blocked = _FALSE;
  796. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  797. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  798. psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  799. if (param->u.crypt.set_tx == 1) { /* pairwise key */
  800. RTW_INFO(FUNC_ADPT_FMT" set %s PTK idx:%u, len:%u\n"
  801. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  802. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  803. if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
  804. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  805. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  806. padapter->securitypriv.busetkipkey = _FALSE;
  807. }
  808. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  809. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  810. psta->bpairwise_key_installed = _TRUE;
  811. rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _TRUE);
  812. } else { /* group key */
  813. if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) {
  814. RTW_INFO(FUNC_ADPT_FMT" set %s GTK idx:%u, len:%u\n"
  815. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  816. _rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key,
  817. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  818. /* only TKIP group key need to install this */
  819. if (param->u.crypt.key_len > 16) {
  820. _rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  821. _rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  822. }
  823. padapter->securitypriv.binstallGrpkey = _TRUE;
  824. if (param->u.crypt.idx < 4)
  825. _rtw_memcpy(padapter->securitypriv.iv_seq[param->u.crypt.idx], param->u.crypt.seq, 8);
  826. padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
  827. rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, _TRUE);
  828. #ifdef CONFIG_IEEE80211W
  829. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  830. RTW_INFO(FUNC_ADPT_FMT" set IGTK idx:%u, len:%u\n"
  831. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  832. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key,
  833. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  834. psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
  835. psecuritypriv->dot11wBIPrxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  836. psecuritypriv->binstallBIPkey = _TRUE;
  837. #endif /* CONFIG_IEEE80211W */
  838. }
  839. #ifdef CONFIG_P2P
  840. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  841. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
  842. #endif /* CONFIG_P2P */
  843. /* WPA/WPA2 key-handshake has completed */
  844. clr_fwstate(pmlmepriv, WIFI_UNDER_KEY_HANDSHAKE);
  845. }
  846. }
  847. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  848. if (pbcmc_sta == NULL) {
  849. /* DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */
  850. } else {
  851. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  852. if (strcmp(param->u.crypt.alg, "none") != 0)
  853. pbcmc_sta->ieee8021x_blocked = _FALSE;
  854. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  855. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  856. pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  857. }
  858. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
  859. }
  860. }
  861. #ifdef CONFIG_WAPI_SUPPORT
  862. if (strcmp(param->u.crypt.alg, "SMS4") == 0)
  863. rtw_wapi_set_set_encryption(padapter, param);
  864. #endif
  865. exit:
  866. return ret;
  867. }
  868. static int rtw_set_wpa_ie(_adapter *padapter, char *pie, unsigned short ielen)
  869. {
  870. u8 *buf = NULL, *pos = NULL;
  871. int group_cipher = 0, pairwise_cipher = 0;
  872. u8 mfp_opt = MFP_NO;
  873. int ret = 0;
  874. u8 null_addr[] = {0, 0, 0, 0, 0, 0};
  875. #ifdef CONFIG_P2P
  876. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  877. #endif /* CONFIG_P2P */
  878. if ((ielen > MAX_WPA_IE_LEN) || (pie == NULL)) {
  879. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  880. if (pie == NULL)
  881. return ret;
  882. else
  883. return -EINVAL;
  884. }
  885. if (ielen) {
  886. buf = rtw_zmalloc(ielen);
  887. if (buf == NULL) {
  888. ret = -ENOMEM;
  889. goto exit;
  890. }
  891. _rtw_memcpy(buf, pie , ielen);
  892. /* dump */
  893. {
  894. int i;
  895. RTW_INFO("\n wpa_ie(length:%d):\n", ielen);
  896. for (i = 0; i < ielen; i = i + 8)
  897. RTW_INFO("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7]);
  898. }
  899. pos = buf;
  900. if (ielen < RSN_HEADER_LEN) {
  901. ret = -1;
  902. goto exit;
  903. }
  904. if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  905. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  906. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
  907. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
  908. }
  909. if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL, &mfp_opt) == _SUCCESS) {
  910. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  911. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  912. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
  913. }
  914. if (group_cipher == 0)
  915. group_cipher = WPA_CIPHER_NONE;
  916. if (pairwise_cipher == 0)
  917. pairwise_cipher = WPA_CIPHER_NONE;
  918. switch (group_cipher) {
  919. case WPA_CIPHER_NONE:
  920. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  921. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  922. break;
  923. case WPA_CIPHER_WEP40:
  924. padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
  925. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  926. break;
  927. case WPA_CIPHER_TKIP:
  928. padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
  929. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  930. break;
  931. case WPA_CIPHER_CCMP:
  932. padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
  933. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  934. break;
  935. case WPA_CIPHER_WEP104:
  936. padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
  937. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  938. break;
  939. }
  940. switch (pairwise_cipher) {
  941. case WPA_CIPHER_NONE:
  942. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  943. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  944. break;
  945. case WPA_CIPHER_WEP40:
  946. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  947. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  948. break;
  949. case WPA_CIPHER_TKIP:
  950. padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
  951. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  952. break;
  953. case WPA_CIPHER_CCMP:
  954. padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
  955. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  956. break;
  957. case WPA_CIPHER_WEP104:
  958. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  959. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  960. break;
  961. }
  962. if (mfp_opt == MFP_INVALID) {
  963. RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
  964. ret = -EINVAL;
  965. goto exit;
  966. }
  967. padapter->securitypriv.mfp_opt = mfp_opt;
  968. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  969. {/* set wps_ie */
  970. u16 cnt = 0;
  971. u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  972. while (cnt < ielen) {
  973. eid = buf[cnt];
  974. if ((eid == _VENDOR_SPECIFIC_IE_) && (_rtw_memcmp(&buf[cnt + 2], wps_oui, 4) == _TRUE)) {
  975. RTW_INFO("SET WPS_IE\n");
  976. padapter->securitypriv.wps_ie_len = ((buf[cnt + 1] + 2) < MAX_WPS_IE_LEN) ? (buf[cnt + 1] + 2) : MAX_WPS_IE_LEN;
  977. _rtw_memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
  978. set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
  979. #ifdef CONFIG_P2P
  980. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK))
  981. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_ING);
  982. #endif /* CONFIG_P2P */
  983. cnt += buf[cnt + 1] + 2;
  984. break;
  985. } else {
  986. cnt += buf[cnt + 1] + 2; /* goto next */
  987. }
  988. }
  989. }
  990. }
  991. /* TKIP and AES disallow multicast packets until installing group key */
  992. if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
  993. || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
  994. || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
  995. /* WPS open need to enable multicast
  996. * || check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE) */
  997. rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
  998. exit:
  999. if (buf)
  1000. rtw_mfree(buf, ielen);
  1001. return ret;
  1002. }
  1003. static int rtw_wx_get_name(struct net_device *dev,
  1004. struct iw_request_info *info,
  1005. union iwreq_data *wrqu, char *extra)
  1006. {
  1007. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1008. u32 ht_ielen = 0;
  1009. char *p;
  1010. u8 ht_cap = _FALSE, vht_cap = _FALSE;
  1011. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1012. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1013. NDIS_802_11_RATES_EX *prates = NULL;
  1014. if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  1015. /* parsing HT_CAP_IE */
  1016. if( is_supported_ht(padapter->registrypriv.wireless_mode)&&(padapter->registrypriv.ht_enable)) {
  1017. p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength - 12);
  1018. if (p && ht_ielen > 0 )
  1019. ht_cap = _TRUE;
  1020. }
  1021. #ifdef CONFIG_80211AC_VHT
  1022. if ((padapter->registrypriv.wireless_mode & WIRELESS_11AC) &&
  1023. (pmlmepriv->vhtpriv.vht_option == _TRUE))
  1024. vht_cap = _TRUE;
  1025. #endif
  1026. prates = &pcur_bss->SupportedRates;
  1027. if (rtw_is_cckratesonly_included((u8 *)prates) == _TRUE) {
  1028. if (ht_cap == _TRUE)
  1029. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
  1030. else
  1031. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
  1032. } else if ((rtw_is_cckrates_included((u8 *)prates)) == _TRUE) {
  1033. if (ht_cap == _TRUE)
  1034. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
  1035. else {
  1036. if(padapter->registrypriv.wireless_mode & WIRELESS_11G)
  1037. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg");
  1038. else
  1039. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
  1040. }
  1041. } else {
  1042. if (pcur_bss->Configuration.DSConfig > 14) {
  1043. #ifdef CONFIG_80211AC_VHT
  1044. if (vht_cap == _TRUE)
  1045. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11AC");
  1046. else
  1047. #endif
  1048. {
  1049. if (ht_cap == _TRUE)
  1050. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11an");
  1051. else
  1052. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11a");
  1053. }
  1054. } else {
  1055. if (ht_cap == _TRUE)
  1056. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn");
  1057. else
  1058. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
  1059. }
  1060. }
  1061. } else {
  1062. /* prates = &padapter->registrypriv.dev_network.SupportedRates; */
  1063. /* snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g"); */
  1064. snprintf(wrqu->name, IFNAMSIZ, "unassociated");
  1065. }
  1066. return 0;
  1067. }
  1068. static int rtw_wx_set_freq(struct net_device *dev,
  1069. struct iw_request_info *info,
  1070. union iwreq_data *wrqu, char *extra)
  1071. {
  1072. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1073. int exp = 1, freq = 0, div = 0;
  1074. rtw_ps_deny(padapter, PS_DENY_IOCTL);
  1075. if (rtw_pwr_wakeup(padapter) == _FALSE)
  1076. goto exit;
  1077. if (wrqu->freq.m <= 1000) {
  1078. if (wrqu->freq.flags == IW_FREQ_AUTO) {
  1079. if (rtw_chset_search_ch(adapter_to_chset(padapter), wrqu->freq.m) > 0) {
  1080. padapter->mlmeextpriv.cur_channel = wrqu->freq.m;
  1081. RTW_INFO("%s: channel is auto, set to channel %d\n", __func__, wrqu->freq.m);
  1082. } else {
  1083. padapter->mlmeextpriv.cur_channel = 1;
  1084. RTW_INFO("%s: channel is auto, Channel Plan don't match just set to channel 1\n", __func__);
  1085. }
  1086. } else {
  1087. padapter->mlmeextpriv.cur_channel = wrqu->freq.m;
  1088. RTW_INFO("%s: set to channel %d\n", __func__, padapter->mlmeextpriv.cur_channel);
  1089. }
  1090. } else {
  1091. while (wrqu->freq.e) {
  1092. exp *= 10;
  1093. wrqu->freq.e--;
  1094. }
  1095. freq = wrqu->freq.m;
  1096. while (!(freq % 10)) {
  1097. freq /= 10;
  1098. exp *= 10;
  1099. }
  1100. /* freq unit is MHz here */
  1101. div = 1000000 / exp;
  1102. if (div)
  1103. freq /= div;
  1104. else {
  1105. div = exp / 1000000;
  1106. freq *= div;
  1107. }
  1108. /* If freq is invalid, rtw_freq2ch() will return channel 1 */
  1109. padapter->mlmeextpriv.cur_channel = rtw_freq2ch(freq);
  1110. RTW_INFO("%s: set to channel %d\n", __func__, padapter->mlmeextpriv.cur_channel);
  1111. }
  1112. set_channel_bwmode(padapter, padapter->mlmeextpriv.cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  1113. exit:
  1114. rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
  1115. return 0;
  1116. }
  1117. static int rtw_wx_get_freq(struct net_device *dev,
  1118. struct iw_request_info *info,
  1119. union iwreq_data *wrqu, char *extra)
  1120. {
  1121. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1122. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1123. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1124. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE && check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE) {
  1125. wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000;
  1126. wrqu->freq.e = 1;
  1127. wrqu->freq.i = pcur_bss->Configuration.DSConfig;
  1128. } else {
  1129. wrqu->freq.m = rtw_ch2freq(padapter->mlmeextpriv.cur_channel) * 100000;
  1130. wrqu->freq.e = 1;
  1131. wrqu->freq.i = padapter->mlmeextpriv.cur_channel;
  1132. }
  1133. return 0;
  1134. }
  1135. static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
  1136. union iwreq_data *wrqu, char *b)
  1137. {
  1138. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1139. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1140. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType ;
  1141. int ret = 0;
  1142. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1143. ret = -EPERM;
  1144. goto exit;
  1145. }
  1146. if (!rtw_is_hw_init_completed(padapter)) {
  1147. ret = -EPERM;
  1148. goto exit;
  1149. }
  1150. /* initial default type */
  1151. dev->type = ARPHRD_ETHER;
  1152. if (wrqu->mode == IW_MODE_MONITOR) {
  1153. rtw_ps_deny(padapter, PS_DENY_MONITOR_MODE);
  1154. LeaveAllPowerSaveMode(padapter);
  1155. } else {
  1156. rtw_ps_deny_cancel(padapter, PS_DENY_MONITOR_MODE);
  1157. }
  1158. switch (wrqu->mode) {
  1159. case IW_MODE_MONITOR:
  1160. networkType = Ndis802_11Monitor;
  1161. #if 0
  1162. dev->type = ARPHRD_IEEE80211; /* IEEE 802.11 : 801 */
  1163. #endif
  1164. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
  1165. dev->type = ARPHRD_IEEE80211_RADIOTAP; /* IEEE 802.11 + radiotap header : 803 */
  1166. RTW_INFO("set_mode = IW_MODE_MONITOR\n");
  1167. #else
  1168. RTW_INFO("kernel version < 2.6.24 not support IW_MODE_MONITOR\n");
  1169. #endif
  1170. break;
  1171. case IW_MODE_AUTO:
  1172. networkType = Ndis802_11AutoUnknown;
  1173. RTW_INFO("set_mode = IW_MODE_AUTO\n");
  1174. break;
  1175. case IW_MODE_ADHOC:
  1176. networkType = Ndis802_11IBSS;
  1177. RTW_INFO("set_mode = IW_MODE_ADHOC\n");
  1178. break;
  1179. case IW_MODE_MASTER:
  1180. networkType = Ndis802_11APMode;
  1181. RTW_INFO("set_mode = IW_MODE_MASTER\n");
  1182. break;
  1183. case IW_MODE_INFRA:
  1184. networkType = Ndis802_11Infrastructure;
  1185. RTW_INFO("set_mode = IW_MODE_INFRA\n");
  1186. break;
  1187. default:
  1188. ret = -EINVAL;;
  1189. goto exit;
  1190. }
  1191. if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == _FALSE) {
  1192. ret = -EPERM;
  1193. goto exit;
  1194. }
  1195. rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
  1196. if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) == _TRUE)
  1197. rtw_indicate_connect(padapter);
  1198. exit:
  1199. return ret;
  1200. }
  1201. static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
  1202. union iwreq_data *wrqu, char *b)
  1203. {
  1204. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1205. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1206. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1207. wrqu->mode = IW_MODE_INFRA;
  1208. else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
  1209. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
  1210. wrqu->mode = IW_MODE_ADHOC;
  1211. else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1212. wrqu->mode = IW_MODE_MASTER;
  1213. else if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) == _TRUE)
  1214. wrqu->mode = IW_MODE_MONITOR;
  1215. else
  1216. wrqu->mode = IW_MODE_AUTO;
  1217. return 0;
  1218. }
  1219. static int rtw_wx_set_pmkid(struct net_device *dev,
  1220. struct iw_request_info *a,
  1221. union iwreq_data *wrqu, char *extra)
  1222. {
  1223. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1224. u8 j, blInserted = _FALSE;
  1225. int intReturn = _FALSE;
  1226. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1227. struct iw_pmksa *pPMK = (struct iw_pmksa *) extra;
  1228. u8 strZeroMacAddress[ETH_ALEN] = { 0x00 };
  1229. u8 strIssueBssid[ETH_ALEN] = { 0x00 };
  1230. #if 0
  1231. struct iw_pmksa {
  1232. __u32 cmd;
  1233. struct sockaddr bssid;
  1234. __u8 pmkid[IW_PMKID_LEN]; /* IW_PMKID_LEN=16 */
  1235. }
  1236. There are the BSSID information in the bssid.sa_data array.
  1237. If cmd is IW_PMKSA_FLUSH, it means the wpa_suppplicant wants to clear all the PMKID information.
  1238. If cmd is IW_PMKSA_ADD, it means the wpa_supplicant wants to add a PMKID / BSSID to driver.
  1239. If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to remove a PMKID / BSSID from driver.
  1240. #endif
  1241. _rtw_memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
  1242. if (pPMK->cmd == IW_PMKSA_ADD) {
  1243. RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_ADD!\n");
  1244. if (_rtw_memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN) == _TRUE)
  1245. return intReturn ;
  1246. else
  1247. intReturn = _TRUE;
  1248. blInserted = _FALSE;
  1249. /* overwrite PMKID */
  1250. for (j = 0 ; j < NUM_PMKID_CACHE; j++) {
  1251. if (_rtw_memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) == _TRUE) {
  1252. /* BSSID is matched, the same AP => rewrite with new PMKID. */
  1253. RTW_INFO("[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n");
  1254. _rtw_memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
  1255. psecuritypriv->PMKIDList[j].bUsed = _TRUE;
  1256. psecuritypriv->PMKIDIndex = j + 1;
  1257. blInserted = _TRUE;
  1258. break;
  1259. }
  1260. }
  1261. if (!blInserted) {
  1262. /* Find a new entry */
  1263. RTW_INFO("[rtw_wx_set_pmkid] Use the new entry index = %d for this PMKID.\n",
  1264. psecuritypriv->PMKIDIndex);
  1265. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
  1266. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
  1267. psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
  1268. psecuritypriv->PMKIDIndex++ ;
  1269. if (psecuritypriv->PMKIDIndex == 16)
  1270. psecuritypriv->PMKIDIndex = 0;
  1271. }
  1272. } else if (pPMK->cmd == IW_PMKSA_REMOVE) {
  1273. RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n");
  1274. intReturn = _TRUE;
  1275. for (j = 0 ; j < NUM_PMKID_CACHE; j++) {
  1276. if (_rtw_memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) == _TRUE) {
  1277. /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
  1278. _rtw_memset(psecuritypriv->PMKIDList[j].Bssid, 0x00, ETH_ALEN);
  1279. psecuritypriv->PMKIDList[j].bUsed = _FALSE;
  1280. break;
  1281. }
  1282. }
  1283. } else if (pPMK->cmd == IW_PMKSA_FLUSH) {
  1284. RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n");
  1285. _rtw_memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
  1286. psecuritypriv->PMKIDIndex = 0;
  1287. intReturn = _TRUE;
  1288. }
  1289. return intReturn ;
  1290. }
  1291. static int rtw_wx_get_sens(struct net_device *dev,
  1292. struct iw_request_info *info,
  1293. union iwreq_data *wrqu, char *extra)
  1294. {
  1295. #ifdef CONFIG_PLATFORM_ROCKCHIPS
  1296. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1297. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1298. /*
  1299. * 20110311 Commented by Jeff
  1300. * For rockchip platform's wpa_driver_wext_get_rssi
  1301. */
  1302. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  1303. /* wrqu->sens.value=-padapter->recvpriv.signal_strength; */
  1304. wrqu->sens.value = -padapter->recvpriv.rssi;
  1305. /* RTW_INFO("%s: %d\n", __FUNCTION__, wrqu->sens.value); */
  1306. wrqu->sens.fixed = 0; /* no auto select */
  1307. } else
  1308. #endif
  1309. {
  1310. wrqu->sens.value = 0;
  1311. wrqu->sens.fixed = 0; /* no auto select */
  1312. wrqu->sens.disabled = 1;
  1313. }
  1314. return 0;
  1315. }
  1316. static int rtw_wx_get_range(struct net_device *dev,
  1317. struct iw_request_info *info,
  1318. union iwreq_data *wrqu, char *extra)
  1319. {
  1320. struct iw_range *range = (struct iw_range *)extra;
  1321. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1322. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  1323. u16 val;
  1324. int i;
  1325. wrqu->data.length = sizeof(*range);
  1326. _rtw_memset(range, 0, sizeof(*range));
  1327. /* Let's try to keep this struct in the same order as in
  1328. * linux/include/wireless.h
  1329. */
  1330. /* TODO: See what values we can set, and remove the ones we can't
  1331. * set, or fill them with some default data.
  1332. */
  1333. /* ~5 Mb/s real (802.11b) */
  1334. range->throughput = 5 * 1000 * 1000;
  1335. /* TODO: Not used in 802.11b?
  1336. * range->min_nwid; Minimal NWID we are able to set */
  1337. /* TODO: Not used in 802.11b?
  1338. * range->max_nwid; Maximal NWID we are able to set */
  1339. /* Old Frequency (backward compat - moved lower ) */
  1340. /* range->old_num_channels;
  1341. * range->old_num_frequency;
  1342. * range->old_freq[6]; Filler to keep "version" at the same offset */
  1343. /* signal level threshold range */
  1344. /* Quality of link & SNR stuff */
  1345. /* Quality range (link, level, noise)
  1346. * If the quality is absolute, it will be in the range [0 ; max_qual],
  1347. * if the quality is dBm, it will be in the range [max_qual ; 0].
  1348. * Don't forget that we use 8 bit arithmetics...
  1349. *
  1350. * If percentage range is 0~100
  1351. * Signal strength dbm range logical is -100 ~ 0
  1352. * but usually value is -90 ~ -20
  1353. */
  1354. range->max_qual.qual = 100;
  1355. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  1356. range->max_qual.level = (u8)-100;
  1357. range->max_qual.noise = (u8)-100;
  1358. range->max_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
  1359. range->max_qual.updated |= IW_QUAL_DBM;
  1360. #else /* !CONFIG_SIGNAL_DISPLAY_DBM */
  1361. /* percent values between 0 and 100. */
  1362. range->max_qual.level = 100;
  1363. range->max_qual.noise = 100;
  1364. range->max_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
  1365. #endif /* !CONFIG_SIGNAL_DISPLAY_DBM */
  1366. /* This should contain the average/typical values of the quality
  1367. * indicator. This should be the threshold between a "good" and
  1368. * a "bad" link (example : monitor going from green to orange).
  1369. * Currently, user space apps like quality monitors don't have any
  1370. * way to calibrate the measurement. With this, they can split
  1371. * the range between 0 and max_qual in different quality level
  1372. * (using a geometric subdivision centered on the average).
  1373. * I expect that people doing the user space apps will feedback
  1374. * us on which value we need to put in each driver... */
  1375. range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
  1376. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  1377. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  1378. range->avg_qual.level = (u8)-70;
  1379. range->avg_qual.noise = 0;
  1380. range->avg_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
  1381. range->avg_qual.updated |= IW_QUAL_DBM;
  1382. #else /* !CONFIG_SIGNAL_DISPLAY_DBM */
  1383. /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
  1384. range->avg_qual.level = 30;
  1385. range->avg_qual.noise = 100;
  1386. range->avg_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
  1387. #endif /* !CONFIG_SIGNAL_DISPLAY_DBM */
  1388. range->num_bitrates = RATE_COUNT;
  1389. for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
  1390. range->bitrate[i] = rtw_rates[i];
  1391. range->min_frag = MIN_FRAG_THRESHOLD;
  1392. range->max_frag = MAX_FRAG_THRESHOLD;
  1393. range->pm_capa = 0;
  1394. range->we_version_compiled = WIRELESS_EXT;
  1395. range->we_version_source = 16;
  1396. /* range->retry_capa; What retry options are supported
  1397. * range->retry_flags; How to decode max/min retry limit
  1398. * range->r_time_flags; How to decode max/min retry life
  1399. * range->min_retry; Minimal number of retries
  1400. * range->max_retry; Maximal number of retries
  1401. * range->min_r_time; Minimal retry lifetime
  1402. * range->max_r_time; Maximal retry lifetime */
  1403. for (i = 0, val = 0; i < rfctl->max_chan_nums; i++) {
  1404. /* Include only legal frequencies for some countries */
  1405. if (rfctl->channel_set[i].ChannelNum != 0) {
  1406. range->freq[val].i = rfctl->channel_set[i].ChannelNum;
  1407. range->freq[val].m = rtw_ch2freq(rfctl->channel_set[i].ChannelNum) * 100000;
  1408. range->freq[val].e = 1;
  1409. val++;
  1410. }
  1411. if (val == IW_MAX_FREQUENCIES)
  1412. break;
  1413. }
  1414. range->num_channels = val;
  1415. range->num_frequency = val;
  1416. /* Commented by Albert 2009/10/13
  1417. * The following code will proivde the security capability to network manager.
  1418. * If the driver doesn't provide this capability to network manager,
  1419. * the WPA/WPA2 routers can't be choosen in the network manager. */
  1420. /*
  1421. #define IW_SCAN_CAPA_NONE 0x00
  1422. #define IW_SCAN_CAPA_ESSID 0x01
  1423. #define IW_SCAN_CAPA_BSSID 0x02
  1424. #define IW_SCAN_CAPA_CHANNEL 0x04
  1425. #define IW_SCAN_CAPA_MODE 0x08
  1426. #define IW_SCAN_CAPA_RATE 0x10
  1427. #define IW_SCAN_CAPA_TYPE 0x20
  1428. #define IW_SCAN_CAPA_TIME 0x40
  1429. */
  1430. #if WIRELESS_EXT > 17
  1431. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  1432. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  1433. #endif
  1434. #ifdef IW_SCAN_CAPA_ESSID /* WIRELESS_EXT > 21 */
  1435. range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE | IW_SCAN_CAPA_BSSID |
  1436. IW_SCAN_CAPA_CHANNEL | IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE;
  1437. #endif
  1438. return 0;
  1439. }
  1440. /* set bssid flow
  1441. * s1. rtw_set_802_11_infrastructure_mode()
  1442. * s2. rtw_set_802_11_authentication_mode()
  1443. * s3. set_802_11_encryption_mode()
  1444. * s4. rtw_set_802_11_bssid() */
  1445. static int rtw_wx_set_wap(struct net_device *dev,
  1446. struct iw_request_info *info,
  1447. union iwreq_data *awrq,
  1448. char *extra)
  1449. {
  1450. _irqL irqL;
  1451. uint ret = 0;
  1452. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1453. struct sockaddr *temp = (struct sockaddr *)awrq;
  1454. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1455. _list *phead;
  1456. u8 *dst_bssid, *src_bssid;
  1457. _queue *queue = &(pmlmepriv->scanned_queue);
  1458. struct wlan_network *pnetwork = NULL;
  1459. NDIS_802_11_AUTHENTICATION_MODE authmode;
  1460. /*
  1461. #ifdef CONFIG_CONCURRENT_MODE
  1462. if(padapter->adapter_type > PRIMARY_IFACE)
  1463. {
  1464. ret = -EINVAL;
  1465. goto exit;
  1466. }
  1467. #endif
  1468. */
  1469. #ifdef CONFIG_CONCURRENT_MODE
  1470. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) {
  1471. RTW_INFO("set bssid, but buddy_intf is under scanning or linking\n");
  1472. ret = -EINVAL;
  1473. goto exit;
  1474. }
  1475. #endif
  1476. rtw_ps_deny(padapter, PS_DENY_JOIN);
  1477. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1478. ret = -1;
  1479. goto cancel_ps_deny;
  1480. }
  1481. if (!padapter->bup) {
  1482. ret = -1;
  1483. goto cancel_ps_deny;
  1484. }
  1485. if (temp->sa_family != ARPHRD_ETHER) {
  1486. ret = -EINVAL;
  1487. goto cancel_ps_deny;
  1488. }
  1489. authmode = padapter->securitypriv.ndisauthtype;
  1490. _enter_critical_bh(&queue->lock, &irqL);
  1491. phead = get_list_head(queue);
  1492. pmlmepriv->pscanned = get_next(phead);
  1493. while (1) {
  1494. if ((rtw_end_of_queue_search(phead, pmlmepriv->pscanned)) == _TRUE) {
  1495. #if 0
  1496. ret = -EINVAL;
  1497. goto cancel_ps_deny;
  1498. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
  1499. rtw_set_802_11_bssid(padapter, temp->sa_data);
  1500. goto cancel_ps_deny;
  1501. } else {
  1502. ret = -EINVAL;
  1503. goto cancel_ps_deny;
  1504. }
  1505. #endif
  1506. break;
  1507. }
  1508. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  1509. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  1510. dst_bssid = pnetwork->network.MacAddress;
  1511. src_bssid = temp->sa_data;
  1512. if ((_rtw_memcmp(dst_bssid, src_bssid, ETH_ALEN)) == _TRUE) {
  1513. if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) {
  1514. ret = -1;
  1515. _exit_critical_bh(&queue->lock, &irqL);
  1516. goto cancel_ps_deny;
  1517. }
  1518. break;
  1519. }
  1520. }
  1521. _exit_critical_bh(&queue->lock, &irqL);
  1522. rtw_set_802_11_authentication_mode(padapter, authmode);
  1523. /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
  1524. if (rtw_set_802_11_bssid(padapter, temp->sa_data) == _FALSE) {
  1525. ret = -1;
  1526. goto cancel_ps_deny;
  1527. }
  1528. cancel_ps_deny:
  1529. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  1530. exit:
  1531. return ret;
  1532. }
  1533. static int rtw_wx_get_wap(struct net_device *dev,
  1534. struct iw_request_info *info,
  1535. union iwreq_data *wrqu, char *extra)
  1536. {
  1537. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1538. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1539. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1540. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1541. _rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  1542. if (((check_fwstate(pmlmepriv, _FW_LINKED)) == _TRUE) ||
  1543. ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) == _TRUE) ||
  1544. ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) == _TRUE))
  1545. _rtw_memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
  1546. else
  1547. _rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  1548. return 0;
  1549. }
  1550. static int rtw_wx_set_mlme(struct net_device *dev,
  1551. struct iw_request_info *info,
  1552. union iwreq_data *wrqu, char *extra)
  1553. {
  1554. #if 0
  1555. /* SIOCSIWMLME data */
  1556. struct iw_mlme {
  1557. __u16 cmd; /* IW_MLME_* */
  1558. __u16 reason_code;
  1559. struct sockaddr addr;
  1560. };
  1561. #endif
  1562. int ret = 0;
  1563. u16 reason;
  1564. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1565. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  1566. if (mlme == NULL)
  1567. return -1;
  1568. RTW_INFO("%s\n", __FUNCTION__);
  1569. reason = cpu_to_le16(mlme->reason_code);
  1570. RTW_INFO("%s, cmd=%d, reason=%d\n", __FUNCTION__, mlme->cmd, reason);
  1571. switch (mlme->cmd) {
  1572. case IW_MLME_DEAUTH:
  1573. if (!rtw_set_802_11_disassociate(padapter))
  1574. ret = -1;
  1575. break;
  1576. case IW_MLME_DISASSOC:
  1577. if (!rtw_set_802_11_disassociate(padapter))
  1578. ret = -1;
  1579. break;
  1580. default:
  1581. return -EOPNOTSUPP;
  1582. }
  1583. #ifdef CONFIG_RTW_REPEATER_SON
  1584. rtw_rson_do_disconnect(padapter);
  1585. #endif
  1586. return ret;
  1587. }
  1588. static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
  1589. union iwreq_data *wrqu, char *extra)
  1590. {
  1591. u8 _status = _FALSE;
  1592. int ret = 0;
  1593. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1594. /*struct mlme_priv *pmlmepriv = &padapter->mlmepriv;*/
  1595. struct sitesurvey_parm parm;
  1596. u8 ssc_chk;
  1597. #ifdef CONFIG_P2P
  1598. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  1599. #endif /* CONFIG_P2P */
  1600. #ifdef DBG_IOCTL
  1601. RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
  1602. #endif
  1603. #if 1
  1604. ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
  1605. #ifdef CONFIG_DOSCAN_IN_BUSYTRAFFIC
  1606. if ((ssc_chk != SS_ALLOW) && (ssc_chk != SS_DENY_BUSY_TRAFFIC))
  1607. #else
  1608. /* When Busy Traffic, driver do not site survey. So driver return success. */
  1609. /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
  1610. /* modify by thomas 2011-02-22. */
  1611. if (ssc_chk != SS_ALLOW)
  1612. #endif
  1613. {
  1614. if (ssc_chk == SS_DENY_MP_MODE)
  1615. ret = -EPERM;
  1616. #ifdef DBG_LA_MODE
  1617. else if (ssc_chk == SS_DENY_LA_MODE)
  1618. ret = -EPERM;
  1619. #endif
  1620. else
  1621. indicate_wx_scan_complete_event(padapter);
  1622. goto exit;
  1623. } else
  1624. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  1625. rtw_ps_deny(padapter, PS_DENY_SCAN);
  1626. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1627. ret = -1;
  1628. goto cancel_ps_deny;
  1629. }
  1630. if (!rtw_is_adapter_up(padapter)) {
  1631. ret = -1;
  1632. goto cancel_ps_deny;
  1633. }
  1634. #else
  1635. #ifdef CONFIG_MP_INCLUDED
  1636. if (rtw_mp_mode_check(padapter)) {
  1637. RTW_INFO("MP mode block Scan request\n");
  1638. ret = -EPERM;
  1639. goto exit;
  1640. }
  1641. #endif
  1642. if (rtw_is_scan_deny(padapter)) {
  1643. indicate_wx_scan_complete_event(padapter);
  1644. goto exit;
  1645. }
  1646. rtw_ps_deny(padapter, PS_DENY_SCAN);
  1647. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1648. ret = -1;
  1649. goto cancel_ps_deny;
  1650. }
  1651. if (!rtw_is_adapter_up(padapter)) {
  1652. ret = -1;
  1653. goto cancel_ps_deny;
  1654. }
  1655. #ifndef CONFIG_DOSCAN_IN_BUSYTRAFFIC
  1656. /* When Busy Traffic, driver do not site survey. So driver return success. */
  1657. /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
  1658. /* modify by thomas 2011-02-22. */
  1659. if (rtw_mi_busy_traffic_check(padapter, _FALSE)) {
  1660. indicate_wx_scan_complete_event(padapter);
  1661. goto cancel_ps_deny;
  1662. }
  1663. #endif
  1664. #ifdef CONFIG_RTW_REPEATER_SON
  1665. if (padapter->rtw_rson_scanstage == RSON_SCAN_PROCESS) {
  1666. RTW_INFO(FUNC_ADPT_FMT" blocking scan for under rson scanning process\n", FUNC_ADPT_ARG(padapter));
  1667. indicate_wx_scan_complete_event(padapter);
  1668. goto cancel_ps_deny;
  1669. }
  1670. #endif
  1671. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) && check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
  1672. RTW_INFO("AP mode process WPS\n");
  1673. indicate_wx_scan_complete_event(padapter);
  1674. goto cancel_ps_deny;
  1675. }
  1676. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) {
  1677. indicate_wx_scan_complete_event(padapter);
  1678. goto cancel_ps_deny;
  1679. }
  1680. #ifdef CONFIG_CONCURRENT_MODE
  1681. if (rtw_mi_buddy_check_fwstate(padapter,
  1682. _FW_UNDER_SURVEY | _FW_UNDER_LINKING | WIFI_UNDER_WPS)) {
  1683. indicate_wx_scan_complete_event(padapter);
  1684. goto cancel_ps_deny;
  1685. }
  1686. #endif
  1687. #endif
  1688. #ifdef CONFIG_P2P
  1689. if (pwdinfo->p2p_state != P2P_STATE_NONE) {
  1690. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  1691. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  1692. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_FULL);
  1693. rtw_free_network_queue(padapter, _TRUE);
  1694. }
  1695. #endif /* CONFIG_P2P */
  1696. #if WIRELESS_EXT >= 17
  1697. if (wrqu->data.length == sizeof(struct iw_scan_req)) {
  1698. struct iw_scan_req *req = (struct iw_scan_req *)extra;
  1699. if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  1700. int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE);
  1701. rtw_init_sitesurvey_parm(padapter, &parm);
  1702. _rtw_memcpy(&parm.ssid[0].Ssid, &req->essid, len);
  1703. parm.ssid[0].SsidLength = len;
  1704. parm.ssid_num = 1;
  1705. RTW_INFO("IW_SCAN_THIS_ESSID, ssid=%s, len=%d\n", req->essid, req->essid_len);
  1706. _status = rtw_set_802_11_bssid_list_scan(padapter, &parm);
  1707. } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE)
  1708. RTW_INFO("rtw_wx_set_scan, req->scan_type == IW_SCAN_TYPE_PASSIVE\n");
  1709. } else
  1710. #endif
  1711. if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE
  1712. && _rtw_memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
  1713. ) {
  1714. int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE;
  1715. char *pos = extra + WEXT_CSCAN_HEADER_SIZE;
  1716. char section;
  1717. char sec_len;
  1718. int ssid_index = 0;
  1719. /* RTW_INFO("%s COMBO_SCAN header is recognized\n", __FUNCTION__); */
  1720. rtw_init_sitesurvey_parm(padapter, &parm);
  1721. while (len >= 1) {
  1722. section = *(pos++);
  1723. len -= 1;
  1724. switch (section) {
  1725. case WEXT_CSCAN_SSID_SECTION:
  1726. /* RTW_INFO("WEXT_CSCAN_SSID_SECTION\n"); */
  1727. if (len < 1) {
  1728. len = 0;
  1729. break;
  1730. }
  1731. sec_len = *(pos++);
  1732. len -= 1;
  1733. if (sec_len > 0 && sec_len <= len) {
  1734. parm.ssid[ssid_index].SsidLength = sec_len;
  1735. _rtw_memcpy(&parm.ssid[ssid_index].Ssid, pos, sec_len);
  1736. /* RTW_INFO("%s COMBO_SCAN with specific parm.ssid:%s, %d\n", __FUNCTION__ */
  1737. /* , parm.ssid[ssid_index].Ssid, parm.ssid[ssid_index].SsidLength); */
  1738. ssid_index++;
  1739. }
  1740. pos += sec_len;
  1741. len -= sec_len;
  1742. break;
  1743. case WEXT_CSCAN_CHANNEL_SECTION:
  1744. /* RTW_INFO("WEXT_CSCAN_CHANNEL_SECTION\n"); */
  1745. pos += 1;
  1746. len -= 1;
  1747. break;
  1748. case WEXT_CSCAN_ACTV_DWELL_SECTION:
  1749. /* RTW_INFO("WEXT_CSCAN_ACTV_DWELL_SECTION\n"); */
  1750. pos += 2;
  1751. len -= 2;
  1752. break;
  1753. case WEXT_CSCAN_PASV_DWELL_SECTION:
  1754. /* RTW_INFO("WEXT_CSCAN_PASV_DWELL_SECTION\n"); */
  1755. pos += 2;
  1756. len -= 2;
  1757. break;
  1758. case WEXT_CSCAN_HOME_DWELL_SECTION:
  1759. /* RTW_INFO("WEXT_CSCAN_HOME_DWELL_SECTION\n"); */
  1760. pos += 2;
  1761. len -= 2;
  1762. break;
  1763. case WEXT_CSCAN_TYPE_SECTION:
  1764. /* RTW_INFO("WEXT_CSCAN_TYPE_SECTION\n"); */
  1765. pos += 1;
  1766. len -= 1;
  1767. break;
  1768. #if 0
  1769. case WEXT_CSCAN_NPROBE_SECTION:
  1770. RTW_INFO("WEXT_CSCAN_NPROBE_SECTION\n");
  1771. break;
  1772. #endif
  1773. default:
  1774. /* RTW_INFO("Unknown CSCAN section %c\n", section); */
  1775. len = 0; /* stop parsing */
  1776. }
  1777. /* RTW_INFO("len:%d\n", len); */
  1778. }
  1779. parm.ssid_num = ssid_index;
  1780. /* jeff: it has still some scan paramater to parse, we only do this now... */
  1781. _status = rtw_set_802_11_bssid_list_scan(padapter, &parm);
  1782. } else
  1783. _status = rtw_set_802_11_bssid_list_scan(padapter, NULL);
  1784. if (_status == _FALSE)
  1785. ret = -1;
  1786. cancel_ps_deny:
  1787. rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
  1788. exit:
  1789. #ifdef DBG_IOCTL
  1790. RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
  1791. #endif
  1792. return ret;
  1793. }
  1794. static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
  1795. union iwreq_data *wrqu, char *extra)
  1796. {
  1797. _irqL irqL;
  1798. _list *plist, *phead;
  1799. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1800. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  1801. RT_CHANNEL_INFO *chset = rfctl->channel_set;
  1802. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1803. _queue *queue = &(pmlmepriv->scanned_queue);
  1804. struct wlan_network *pnetwork = NULL;
  1805. char *ev = extra;
  1806. char *stop = ev + wrqu->data.length;
  1807. u32 ret = 0;
  1808. u32 wait_for_surveydone;
  1809. sint wait_status;
  1810. u8 ch;
  1811. #ifdef CONFIG_P2P
  1812. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  1813. #endif /* CONFIG_P2P */
  1814. #ifdef DBG_IOCTL
  1815. RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
  1816. #endif
  1817. if (adapter_to_pwrctl(padapter)->brfoffbyhw && rtw_is_drv_stopped(padapter)) {
  1818. ret = -EINVAL;
  1819. goto exit;
  1820. }
  1821. #ifdef CONFIG_P2P
  1822. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1823. wait_for_surveydone = 200;
  1824. else {
  1825. /* P2P is disabled */
  1826. wait_for_surveydone = 100;
  1827. }
  1828. #else
  1829. {
  1830. wait_for_surveydone = 100;
  1831. }
  1832. #endif /* CONFIG_P2P */
  1833. #if 1 /* Wireless Extension use EAGAIN to try */
  1834. wait_status = _FW_UNDER_SURVEY
  1835. #ifndef CONFIG_ANDROID
  1836. | _FW_UNDER_LINKING
  1837. #endif
  1838. ;
  1839. while (check_fwstate(pmlmepriv, wait_status) == _TRUE)
  1840. return -EAGAIN;
  1841. #else
  1842. wait_status = _FW_UNDER_SURVEY
  1843. #ifndef CONFIG_ANDROID
  1844. | _FW_UNDER_LINKING
  1845. #endif
  1846. ;
  1847. while (check_fwstate(pmlmepriv, wait_status) == _TRUE) {
  1848. rtw_msleep_os(30);
  1849. cnt++;
  1850. if (cnt > wait_for_surveydone)
  1851. break;
  1852. }
  1853. #endif
  1854. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1855. phead = get_list_head(queue);
  1856. plist = get_next(phead);
  1857. while (1) {
  1858. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  1859. break;
  1860. if ((stop - ev) < SCAN_ITEM_SIZE) {
  1861. if(wrqu->data.length == MAX_SCAN_BUFFER_LEN){ /*max buffer len defined by iwlist*/
  1862. ret = 0;
  1863. RTW_INFO("%s: Scan results incomplete\n", __FUNCTION__);
  1864. break;
  1865. }
  1866. ret = -E2BIG;
  1867. break;
  1868. }
  1869. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1870. ch = pnetwork->network.Configuration.DSConfig;
  1871. /* report network only if the current channel set contains the channel to which this network belongs */
  1872. if (rtw_chset_search_ch(chset, ch) >= 0
  1873. && rtw_mlme_band_check(padapter, ch) == _TRUE
  1874. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
  1875. && (!IS_DFS_SLAVE_WITH_RD(rfctl)
  1876. || rtw_odm_dfs_domain_unknown(rfctl_to_dvobj(rfctl))
  1877. || !rtw_chset_is_ch_non_ocp(chset, ch))
  1878. )
  1879. ev = translate_scan(padapter, a, pnetwork, ev, stop);
  1880. plist = get_next(plist);
  1881. }
  1882. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1883. wrqu->data.length = ev - extra;
  1884. wrqu->data.flags = 0;
  1885. exit:
  1886. #ifdef DBG_IOCTL
  1887. RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
  1888. #endif
  1889. return ret ;
  1890. }
  1891. /* set ssid flow
  1892. * s1. rtw_set_802_11_infrastructure_mode()
  1893. * s2. set_802_11_authenticaion_mode()
  1894. * s3. set_802_11_encryption_mode()
  1895. * s4. rtw_set_802_11_ssid() */
  1896. static int rtw_wx_set_essid(struct net_device *dev,
  1897. struct iw_request_info *a,
  1898. union iwreq_data *wrqu, char *extra)
  1899. {
  1900. _irqL irqL;
  1901. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1902. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1903. _queue *queue = &pmlmepriv->scanned_queue;
  1904. _list *phead;
  1905. struct wlan_network *pnetwork = NULL;
  1906. NDIS_802_11_AUTHENTICATION_MODE authmode;
  1907. NDIS_802_11_SSID ndis_ssid;
  1908. u8 *dst_ssid, *src_ssid;
  1909. uint ret = 0, len;
  1910. #ifdef DBG_IOCTL
  1911. RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
  1912. #endif
  1913. #ifdef CONFIG_WEXT_DONT_JOIN_BYSSID
  1914. RTW_INFO("%s: CONFIG_WEXT_DONT_JOIN_BYSSID be defined!! only allow bssid joining\n", __func__);
  1915. return -EPERM;
  1916. #endif
  1917. #if WIRELESS_EXT <= 20
  1918. if ((wrqu->essid.length - 1) > IW_ESSID_MAX_SIZE) {
  1919. #else
  1920. if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
  1921. #endif
  1922. ret = -E2BIG;
  1923. goto exit;
  1924. }
  1925. rtw_ps_deny(padapter, PS_DENY_JOIN);
  1926. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1927. ret = -1;
  1928. goto cancel_ps_deny;
  1929. }
  1930. if (!padapter->bup) {
  1931. ret = -1;
  1932. goto cancel_ps_deny;
  1933. }
  1934. if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  1935. ret = -1;
  1936. goto cancel_ps_deny;
  1937. }
  1938. #ifdef CONFIG_CONCURRENT_MODE
  1939. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) {
  1940. RTW_INFO("set ssid, but buddy_intf is under scanning or linking\n");
  1941. ret = -EINVAL;
  1942. goto cancel_ps_deny;
  1943. }
  1944. #endif
  1945. authmode = padapter->securitypriv.ndisauthtype;
  1946. RTW_INFO("=>%s\n", __FUNCTION__);
  1947. if (wrqu->essid.flags && wrqu->essid.length) {
  1948. /* Commented by Albert 20100519 */
  1949. /* We got the codes in "set_info" function of iwconfig source code. */
  1950. /* ========================================= */
  1951. /* wrq.u.essid.length = strlen(essid) + 1; */
  1952. /* if(we_kernel_version > 20) */
  1953. /* wrq.u.essid.length--; */
  1954. /* ========================================= */
  1955. /* That means, if the WIRELESS_EXT less than or equal to 20, the correct ssid len should subtract 1. */
  1956. #if WIRELESS_EXT <= 20
  1957. len = ((wrqu->essid.length - 1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length - 1) : IW_ESSID_MAX_SIZE;
  1958. #else
  1959. len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
  1960. #endif
  1961. if (wrqu->essid.length != 33)
  1962. RTW_INFO("ssid=%s, len=%d\n", extra, wrqu->essid.length);
  1963. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  1964. ndis_ssid.SsidLength = len;
  1965. _rtw_memcpy(ndis_ssid.Ssid, extra, len);
  1966. src_ssid = ndis_ssid.Ssid;
  1967. _enter_critical_bh(&queue->lock, &irqL);
  1968. phead = get_list_head(queue);
  1969. pmlmepriv->pscanned = get_next(phead);
  1970. while (1) {
  1971. if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == _TRUE) {
  1972. #if 0
  1973. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
  1974. rtw_set_802_11_ssid(padapter, &ndis_ssid);
  1975. goto cancel_ps_deny;
  1976. } else {
  1977. ret = -EINVAL;
  1978. goto cancel_ps_deny;
  1979. }
  1980. #endif
  1981. break;
  1982. }
  1983. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  1984. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  1985. dst_ssid = pnetwork->network.Ssid.Ssid;
  1986. if ((_rtw_memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength) == _TRUE) &&
  1987. (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) {
  1988. if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
  1989. if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
  1990. continue;
  1991. }
  1992. if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode) == _FALSE) {
  1993. ret = -1;
  1994. _exit_critical_bh(&queue->lock, &irqL);
  1995. goto cancel_ps_deny;
  1996. }
  1997. break;
  1998. }
  1999. }
  2000. _exit_critical_bh(&queue->lock, &irqL);
  2001. rtw_set_802_11_authentication_mode(padapter, authmode);
  2002. /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
  2003. if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
  2004. ret = -1;
  2005. goto cancel_ps_deny;
  2006. }
  2007. }
  2008. cancel_ps_deny:
  2009. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  2010. exit:
  2011. RTW_INFO("<=%s, ret %d\n", __FUNCTION__, ret);
  2012. #ifdef DBG_IOCTL
  2013. RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
  2014. #endif
  2015. return ret;
  2016. }
  2017. static int rtw_wx_get_essid(struct net_device *dev,
  2018. struct iw_request_info *a,
  2019. union iwreq_data *wrqu, char *extra)
  2020. {
  2021. u32 len, ret = 0;
  2022. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2023. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2024. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  2025. if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) ||
  2026. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
  2027. len = pcur_bss->Ssid.SsidLength;
  2028. wrqu->essid.length = len;
  2029. _rtw_memcpy(extra, pcur_bss->Ssid.Ssid, len);
  2030. wrqu->essid.flags = 1;
  2031. } else {
  2032. ret = -1;
  2033. goto exit;
  2034. }
  2035. exit:
  2036. return ret;
  2037. }
  2038. static int rtw_wx_set_rate(struct net_device *dev,
  2039. struct iw_request_info *a,
  2040. union iwreq_data *wrqu, char *extra)
  2041. {
  2042. int i, ret = 0;
  2043. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2044. u8 datarates[NumRates];
  2045. u32 target_rate = wrqu->bitrate.value;
  2046. u32 fixed = wrqu->bitrate.fixed;
  2047. u32 ratevalue = 0;
  2048. u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
  2049. if (target_rate == -1) {
  2050. ratevalue = 11;
  2051. goto set_rate;
  2052. }
  2053. target_rate = target_rate / 100000;
  2054. switch (target_rate) {
  2055. case 10:
  2056. ratevalue = 0;
  2057. break;
  2058. case 20:
  2059. ratevalue = 1;
  2060. break;
  2061. case 55:
  2062. ratevalue = 2;
  2063. break;
  2064. case 60:
  2065. ratevalue = 3;
  2066. break;
  2067. case 90:
  2068. ratevalue = 4;
  2069. break;
  2070. case 110:
  2071. ratevalue = 5;
  2072. break;
  2073. case 120:
  2074. ratevalue = 6;
  2075. break;
  2076. case 180:
  2077. ratevalue = 7;
  2078. break;
  2079. case 240:
  2080. ratevalue = 8;
  2081. break;
  2082. case 360:
  2083. ratevalue = 9;
  2084. break;
  2085. case 480:
  2086. ratevalue = 10;
  2087. break;
  2088. case 540:
  2089. ratevalue = 11;
  2090. break;
  2091. default:
  2092. ratevalue = 11;
  2093. break;
  2094. }
  2095. set_rate:
  2096. for (i = 0; i < NumRates; i++) {
  2097. if (ratevalue == mpdatarate[i]) {
  2098. datarates[i] = mpdatarate[i];
  2099. if (fixed == 0)
  2100. break;
  2101. } else
  2102. datarates[i] = 0xff;
  2103. }
  2104. if (rtw_setdatarate_cmd(padapter, datarates) != _SUCCESS) {
  2105. ret = -1;
  2106. }
  2107. return ret;
  2108. }
  2109. static int rtw_wx_get_rate(struct net_device *dev,
  2110. struct iw_request_info *info,
  2111. union iwreq_data *wrqu, char *extra)
  2112. {
  2113. u16 max_rate = 0;
  2114. max_rate = rtw_get_cur_max_rate((_adapter *)rtw_netdev_priv(dev));
  2115. if (max_rate == 0)
  2116. return -EPERM;
  2117. wrqu->bitrate.fixed = 0; /* no auto select */
  2118. wrqu->bitrate.value = max_rate * 100000;
  2119. return 0;
  2120. }
  2121. static int rtw_wx_set_rts(struct net_device *dev,
  2122. struct iw_request_info *info,
  2123. union iwreq_data *wrqu, char *extra)
  2124. {
  2125. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2126. if (wrqu->rts.disabled)
  2127. padapter->registrypriv.rts_thresh = 2347;
  2128. else {
  2129. if (wrqu->rts.value < 0 ||
  2130. wrqu->rts.value > 2347)
  2131. return -EINVAL;
  2132. padapter->registrypriv.rts_thresh = wrqu->rts.value;
  2133. }
  2134. RTW_INFO("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
  2135. return 0;
  2136. }
  2137. static int rtw_wx_get_rts(struct net_device *dev,
  2138. struct iw_request_info *info,
  2139. union iwreq_data *wrqu, char *extra)
  2140. {
  2141. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2142. RTW_INFO("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
  2143. wrqu->rts.value = padapter->registrypriv.rts_thresh;
  2144. wrqu->rts.fixed = 0; /* no auto select */
  2145. /* wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); */
  2146. return 0;
  2147. }
  2148. static int rtw_wx_set_frag(struct net_device *dev,
  2149. struct iw_request_info *info,
  2150. union iwreq_data *wrqu, char *extra)
  2151. {
  2152. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2153. if (wrqu->frag.disabled)
  2154. padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
  2155. else {
  2156. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  2157. wrqu->frag.value > MAX_FRAG_THRESHOLD)
  2158. return -EINVAL;
  2159. padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
  2160. }
  2161. RTW_INFO("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
  2162. return 0;
  2163. }
  2164. static int rtw_wx_get_frag(struct net_device *dev,
  2165. struct iw_request_info *info,
  2166. union iwreq_data *wrqu, char *extra)
  2167. {
  2168. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2169. RTW_INFO("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
  2170. wrqu->frag.value = padapter->xmitpriv.frag_len;
  2171. wrqu->frag.fixed = 0; /* no auto select */
  2172. /* wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD); */
  2173. return 0;
  2174. }
  2175. static int rtw_wx_get_retry(struct net_device *dev,
  2176. struct iw_request_info *info,
  2177. union iwreq_data *wrqu, char *extra)
  2178. {
  2179. /* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
  2180. wrqu->retry.value = 7;
  2181. wrqu->retry.fixed = 0; /* no auto select */
  2182. wrqu->retry.disabled = 1;
  2183. return 0;
  2184. }
  2185. #if 0
  2186. #define IW_ENCODE_INDEX 0x00FF /* Token index (if needed) */
  2187. #define IW_ENCODE_FLAGS 0xFF00 /* Flags defined below */
  2188. #define IW_ENCODE_MODE 0xF000 /* Modes defined below */
  2189. #define IW_ENCODE_DISABLED 0x8000 /* Encoding disabled */
  2190. #define IW_ENCODE_ENABLED 0x0000 /* Encoding enabled */
  2191. #define IW_ENCODE_RESTRICTED 0x4000 /* Refuse non-encoded packets */
  2192. #define IW_ENCODE_OPEN 0x2000 /* Accept non-encoded packets */
  2193. #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
  2194. #define IW_ENCODE_TEMP 0x0400 /* Temporary key */
  2195. /*
  2196. iwconfig wlan0 key on->flags = 0x6001->maybe it means auto
  2197. iwconfig wlan0 key off->flags = 0x8800
  2198. iwconfig wlan0 key open->flags = 0x2800
  2199. iwconfig wlan0 key open 1234567890->flags = 0x2000
  2200. iwconfig wlan0 key restricted->flags = 0x4800
  2201. iwconfig wlan0 key open [3] 1234567890->flags = 0x2003
  2202. iwconfig wlan0 key restricted [2] 1234567890->flags = 0x4002
  2203. iwconfig wlan0 key open [3] -> flags = 0x2803
  2204. iwconfig wlan0 key restricted [2] -> flags = 0x4802
  2205. */
  2206. #endif
  2207. static int rtw_wx_set_enc(struct net_device *dev,
  2208. struct iw_request_info *info,
  2209. union iwreq_data *wrqu, char *keybuf)
  2210. {
  2211. u32 key, ret = 0;
  2212. u32 keyindex_provided;
  2213. NDIS_802_11_WEP wep;
  2214. NDIS_802_11_AUTHENTICATION_MODE authmode;
  2215. struct iw_point *erq = &(wrqu->encoding);
  2216. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2217. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  2218. RTW_INFO("+rtw_wx_set_enc, flags=0x%x\n", erq->flags);
  2219. _rtw_memset(&wep, 0, sizeof(NDIS_802_11_WEP));
  2220. key = erq->flags & IW_ENCODE_INDEX;
  2221. if (erq->flags & IW_ENCODE_DISABLED) {
  2222. RTW_INFO("EncryptionDisabled\n");
  2223. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2224. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2225. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2226. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  2227. authmode = Ndis802_11AuthModeOpen;
  2228. padapter->securitypriv.ndisauthtype = authmode;
  2229. goto exit;
  2230. }
  2231. if (key) {
  2232. if (key > WEP_KEYS)
  2233. return -EINVAL;
  2234. key--;
  2235. keyindex_provided = 1;
  2236. } else {
  2237. keyindex_provided = 0;
  2238. key = padapter->securitypriv.dot11PrivacyKeyIndex;
  2239. RTW_INFO("rtw_wx_set_enc, key=%d\n", key);
  2240. }
  2241. /* set authentication mode */
  2242. if (erq->flags & IW_ENCODE_OPEN) {
  2243. RTW_INFO("rtw_wx_set_enc():IW_ENCODE_OPEN\n");
  2244. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
  2245. #ifdef CONFIG_PLATFORM_MT53XX
  2246. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2247. #else
  2248. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  2249. #endif
  2250. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2251. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2252. authmode = Ndis802_11AuthModeOpen;
  2253. padapter->securitypriv.ndisauthtype = authmode;
  2254. } else if (erq->flags & IW_ENCODE_RESTRICTED) {
  2255. RTW_INFO("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n");
  2256. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2257. #ifdef CONFIG_PLATFORM_MT53XX
  2258. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2259. #else
  2260. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  2261. #endif
  2262. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  2263. padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
  2264. authmode = Ndis802_11AuthModeShared;
  2265. padapter->securitypriv.ndisauthtype = authmode;
  2266. } else {
  2267. RTW_INFO("rtw_wx_set_enc():erq->flags=0x%x\n", erq->flags);
  2268. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
  2269. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  2270. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2271. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2272. authmode = Ndis802_11AuthModeOpen;
  2273. padapter->securitypriv.ndisauthtype = authmode;
  2274. }
  2275. wep.KeyIndex = key;
  2276. if (erq->length > 0) {
  2277. wep.KeyLength = erq->length <= 5 ? 5 : 13;
  2278. wep.Length = wep.KeyLength + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  2279. } else {
  2280. wep.KeyLength = 0 ;
  2281. if (keyindex_provided == 1) { /* set key_id only, no given KeyMaterial(erq->length==0). */
  2282. padapter->securitypriv.dot11PrivacyKeyIndex = key;
  2283. RTW_INFO("(keyindex_provided == 1), keyid=%d, key_len=%d\n", key, padapter->securitypriv.dot11DefKeylen[key]);
  2284. switch (padapter->securitypriv.dot11DefKeylen[key]) {
  2285. case 5:
  2286. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  2287. break;
  2288. case 13:
  2289. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  2290. break;
  2291. default:
  2292. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2293. break;
  2294. }
  2295. goto exit;
  2296. }
  2297. }
  2298. wep.KeyIndex |= 0x80000000;
  2299. _rtw_memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
  2300. if (rtw_set_802_11_add_wep(padapter, &wep) == _FALSE) {
  2301. if (rf_on == pwrpriv->rf_pwrstate)
  2302. ret = -EOPNOTSUPP;
  2303. goto exit;
  2304. }
  2305. exit:
  2306. return ret;
  2307. }
  2308. static int rtw_wx_get_enc(struct net_device *dev,
  2309. struct iw_request_info *info,
  2310. union iwreq_data *wrqu, char *keybuf)
  2311. {
  2312. uint key, ret = 0;
  2313. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2314. struct iw_point *erq = &(wrqu->encoding);
  2315. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2316. if (check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE) {
  2317. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE) {
  2318. erq->length = 0;
  2319. erq->flags |= IW_ENCODE_DISABLED;
  2320. return 0;
  2321. }
  2322. }
  2323. key = erq->flags & IW_ENCODE_INDEX;
  2324. if (key) {
  2325. if (key > WEP_KEYS)
  2326. return -EINVAL;
  2327. key--;
  2328. } else
  2329. key = padapter->securitypriv.dot11PrivacyKeyIndex;
  2330. erq->flags = key + 1;
  2331. /* if(padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen) */
  2332. /* { */
  2333. /* erq->flags |= IW_ENCODE_OPEN; */
  2334. /* } */
  2335. switch (padapter->securitypriv.ndisencryptstatus) {
  2336. case Ndis802_11EncryptionNotSupported:
  2337. case Ndis802_11EncryptionDisabled:
  2338. erq->length = 0;
  2339. erq->flags |= IW_ENCODE_DISABLED;
  2340. break;
  2341. case Ndis802_11Encryption1Enabled:
  2342. erq->length = padapter->securitypriv.dot11DefKeylen[key];
  2343. if (erq->length) {
  2344. _rtw_memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]);
  2345. erq->flags |= IW_ENCODE_ENABLED;
  2346. if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
  2347. erq->flags |= IW_ENCODE_OPEN;
  2348. else if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared)
  2349. erq->flags |= IW_ENCODE_RESTRICTED;
  2350. } else {
  2351. erq->length = 0;
  2352. erq->flags |= IW_ENCODE_DISABLED;
  2353. }
  2354. break;
  2355. case Ndis802_11Encryption2Enabled:
  2356. case Ndis802_11Encryption3Enabled:
  2357. erq->length = 16;
  2358. erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY);
  2359. break;
  2360. default:
  2361. erq->length = 0;
  2362. erq->flags |= IW_ENCODE_DISABLED;
  2363. break;
  2364. }
  2365. return ret;
  2366. }
  2367. static int rtw_wx_get_power(struct net_device *dev,
  2368. struct iw_request_info *info,
  2369. union iwreq_data *wrqu, char *extra)
  2370. {
  2371. /* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
  2372. wrqu->power.value = 0;
  2373. wrqu->power.fixed = 0; /* no auto select */
  2374. wrqu->power.disabled = 1;
  2375. return 0;
  2376. }
  2377. static int rtw_wx_set_gen_ie(struct net_device *dev,
  2378. struct iw_request_info *info,
  2379. union iwreq_data *wrqu, char *extra)
  2380. {
  2381. int ret;
  2382. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2383. ret = rtw_set_wpa_ie(padapter, extra, wrqu->data.length);
  2384. return ret;
  2385. }
  2386. static int rtw_wx_set_auth(struct net_device *dev,
  2387. struct iw_request_info *info,
  2388. union iwreq_data *wrqu, char *extra)
  2389. {
  2390. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2391. struct iw_param *param = (struct iw_param *)&(wrqu->param);
  2392. #ifdef CONFIG_WAPI_SUPPORT
  2393. #ifndef CONFIG_IOCTL_CFG80211
  2394. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2395. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2396. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2397. u32 value = param->value;
  2398. #endif
  2399. #endif
  2400. int ret = 0;
  2401. switch (param->flags & IW_AUTH_INDEX) {
  2402. case IW_AUTH_WPA_VERSION:
  2403. #ifdef CONFIG_WAPI_SUPPORT
  2404. #ifndef CONFIG_IOCTL_CFG80211
  2405. padapter->wapiInfo.bWapiEnable = false;
  2406. if (value == IW_AUTH_WAPI_VERSION_1) {
  2407. padapter->wapiInfo.bWapiEnable = true;
  2408. psecuritypriv->dot11PrivacyAlgrthm = _SMS4_;
  2409. psecuritypriv->dot118021XGrpPrivacy = _SMS4_;
  2410. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2411. pmlmeinfo->auth_algo = psecuritypriv->dot11AuthAlgrthm;
  2412. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  2413. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  2414. }
  2415. #endif
  2416. #endif
  2417. break;
  2418. case IW_AUTH_CIPHER_PAIRWISE:
  2419. break;
  2420. case IW_AUTH_CIPHER_GROUP:
  2421. break;
  2422. case IW_AUTH_KEY_MGMT:
  2423. #ifdef CONFIG_WAPI_SUPPORT
  2424. #ifndef CONFIG_IOCTL_CFG80211
  2425. RTW_INFO("rtw_wx_set_auth: IW_AUTH_KEY_MGMT case\n");
  2426. if (value == IW_AUTH_KEY_MGMT_WAPI_PSK)
  2427. padapter->wapiInfo.bWapiPSK = true;
  2428. else
  2429. padapter->wapiInfo.bWapiPSK = false;
  2430. RTW_INFO("rtw_wx_set_auth: IW_AUTH_KEY_MGMT bwapipsk %d\n", padapter->wapiInfo.bWapiPSK);
  2431. #endif
  2432. #endif
  2433. /*
  2434. * ??? does not use these parameters
  2435. */
  2436. break;
  2437. case IW_AUTH_TKIP_COUNTERMEASURES: {
  2438. if (param->value) {
  2439. /* wpa_supplicant is enabling the tkip countermeasure. */
  2440. padapter->securitypriv.btkip_countermeasure = _TRUE;
  2441. } else {
  2442. /* wpa_supplicant is disabling the tkip countermeasure. */
  2443. padapter->securitypriv.btkip_countermeasure = _FALSE;
  2444. }
  2445. break;
  2446. }
  2447. case IW_AUTH_DROP_UNENCRYPTED: {
  2448. /* HACK:
  2449. *
  2450. * wpa_supplicant calls set_wpa_enabled when the driver
  2451. * is loaded and unloaded, regardless of if WPA is being
  2452. * used. No other calls are made which can be used to
  2453. * determine if encryption will be used or not prior to
  2454. * association being expected. If encryption is not being
  2455. * used, drop_unencrypted is set to false, else true -- we
  2456. * can use this to determine if the CAP_PRIVACY_ON bit should
  2457. * be set.
  2458. */
  2459. if (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled) {
  2460. break;/* it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled, */
  2461. /* then it needn't reset it; */
  2462. }
  2463. if (param->value) {
  2464. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2465. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2466. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2467. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  2468. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  2469. }
  2470. break;
  2471. }
  2472. case IW_AUTH_80211_AUTH_ALG:
  2473. #if defined(CONFIG_ANDROID) || 1
  2474. /*
  2475. * It's the starting point of a link layer connection using wpa_supplicant
  2476. */
  2477. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  2478. LeaveAllPowerSaveMode(padapter);
  2479. rtw_disassoc_cmd(padapter, 500, RTW_CMDF_WAIT_ACK);
  2480. RTW_INFO("%s...call rtw_indicate_disconnect\n ", __FUNCTION__);
  2481. rtw_indicate_disconnect(padapter, 0, _FALSE);
  2482. rtw_free_assoc_resources_cmd(padapter, _TRUE, RTW_CMDF_WAIT_ACK);
  2483. }
  2484. #endif
  2485. ret = wpa_set_auth_algs(dev, (u32)param->value);
  2486. break;
  2487. case IW_AUTH_WPA_ENABLED:
  2488. /* if(param->value) */
  2489. /* padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; */ /* 802.1x */
  2490. /* else */
  2491. /* padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; */ /* open system */
  2492. /* _disassociate(priv); */
  2493. break;
  2494. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2495. /* ieee->ieee802_1x = param->value; */
  2496. break;
  2497. case IW_AUTH_PRIVACY_INVOKED:
  2498. /* ieee->privacy_invoked = param->value; */
  2499. break;
  2500. #ifdef CONFIG_WAPI_SUPPORT
  2501. #ifndef CONFIG_IOCTL_CFG80211
  2502. case IW_AUTH_WAPI_ENABLED:
  2503. break;
  2504. #endif
  2505. #endif
  2506. default:
  2507. return -EOPNOTSUPP;
  2508. }
  2509. return ret;
  2510. }
  2511. static int rtw_wx_set_enc_ext(struct net_device *dev,
  2512. struct iw_request_info *info,
  2513. union iwreq_data *wrqu, char *extra)
  2514. {
  2515. char *alg_name;
  2516. u32 param_len;
  2517. struct ieee_param *param = NULL;
  2518. struct iw_point *pencoding = &wrqu->encoding;
  2519. struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
  2520. int ret = 0;
  2521. param_len = sizeof(struct ieee_param) + pext->key_len;
  2522. param = (struct ieee_param *)rtw_malloc(param_len);
  2523. if (param == NULL)
  2524. return -1;
  2525. _rtw_memset(param, 0, param_len);
  2526. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  2527. _rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
  2528. switch (pext->alg) {
  2529. case IW_ENCODE_ALG_NONE:
  2530. /* todo: remove key */
  2531. /* remove = 1; */
  2532. alg_name = "none";
  2533. break;
  2534. case IW_ENCODE_ALG_WEP:
  2535. alg_name = "WEP";
  2536. break;
  2537. case IW_ENCODE_ALG_TKIP:
  2538. alg_name = "TKIP";
  2539. break;
  2540. case IW_ENCODE_ALG_CCMP:
  2541. alg_name = "CCMP";
  2542. break;
  2543. #ifdef CONFIG_IEEE80211W
  2544. case IW_ENCODE_ALG_AES_CMAC:
  2545. alg_name = "BIP";
  2546. break;
  2547. #endif /* CONFIG_IEEE80211W */
  2548. #ifdef CONFIG_WAPI_SUPPORT
  2549. #ifndef CONFIG_IOCTL_CFG80211
  2550. case IW_ENCODE_ALG_SM4:
  2551. alg_name = "SMS4";
  2552. _rtw_memcpy(param->sta_addr, pext->addr.sa_data, ETH_ALEN);
  2553. RTW_INFO("rtw_wx_set_enc_ext: SMS4 case\n");
  2554. break;
  2555. #endif
  2556. #endif
  2557. default:
  2558. ret = -1;
  2559. goto exit;
  2560. }
  2561. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  2562. if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2563. param->u.crypt.set_tx = 1;
  2564. /* cliW: WEP does not have group key
  2565. * just not checking GROUP key setting
  2566. */
  2567. if ((pext->alg != IW_ENCODE_ALG_WEP) &&
  2568. ((pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
  2569. #ifdef CONFIG_IEEE80211W
  2570. || (pext->ext_flags & IW_ENCODE_ALG_AES_CMAC)
  2571. #endif /* CONFIG_IEEE80211W */
  2572. ))
  2573. param->u.crypt.set_tx = 0;
  2574. param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1 ;
  2575. if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
  2576. #ifdef CONFIG_WAPI_SUPPORT
  2577. #ifndef CONFIG_IOCTL_CFG80211
  2578. if (pext->alg == IW_ENCODE_ALG_SM4)
  2579. _rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 16);
  2580. else
  2581. #endif /* CONFIG_IOCTL_CFG80211 */
  2582. #endif /* CONFIG_WAPI_SUPPORT */
  2583. _rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 8);
  2584. }
  2585. if (pext->key_len) {
  2586. param->u.crypt.key_len = pext->key_len;
  2587. /* _rtw_memcpy(param + 1, pext + 1, pext->key_len); */
  2588. _rtw_memcpy(param->u.crypt.key, pext + 1, pext->key_len);
  2589. }
  2590. if (pencoding->flags & IW_ENCODE_DISABLED) {
  2591. /* todo: remove key */
  2592. /* remove = 1; */
  2593. }
  2594. ret = wpa_set_encryption(dev, param, param_len);
  2595. exit:
  2596. if (param)
  2597. rtw_mfree((u8 *)param, param_len);
  2598. return ret;
  2599. }
  2600. static int rtw_wx_get_nick(struct net_device *dev,
  2601. struct iw_request_info *info,
  2602. union iwreq_data *wrqu, char *extra)
  2603. {
  2604. /* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
  2605. /* struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); */
  2606. /* struct security_priv *psecuritypriv = &padapter->securitypriv; */
  2607. if (extra) {
  2608. wrqu->data.length = 14;
  2609. wrqu->data.flags = 1;
  2610. _rtw_memcpy(extra, "<WIFI@REALTEK>", 14);
  2611. }
  2612. /* rtw_signal_process(pid, SIGUSR1); */ /* for test */
  2613. /* dump debug info here */
  2614. #if 0
  2615. u32 dot11AuthAlgrthm; /* 802.11 auth, could be open, shared, and 8021x */
  2616. u32 dot11PrivacyAlgrthm; /* This specify the privacy for shared auth. algorithm. */
  2617. u32 dot118021XGrpPrivacy; /* This specify the privacy algthm. used for Grp key */
  2618. u32 ndisauthtype;
  2619. u32 ndisencryptstatus;
  2620. #endif
  2621. /* RTW_INFO("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n", */
  2622. /* psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, */
  2623. /* psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus); */
  2624. /* RTW_INFO("enc_alg=0x%x\n", psecuritypriv->dot11PrivacyAlgrthm); */
  2625. /* RTW_INFO("auth_type=0x%x\n", psecuritypriv->ndisauthtype); */
  2626. /* RTW_INFO("enc_type=0x%x\n", psecuritypriv->ndisencryptstatus); */
  2627. #if 0
  2628. RTW_INFO("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
  2629. RTW_INFO("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
  2630. RTW_INFO("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
  2631. RTW_INFO("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
  2632. RTW_INFO("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
  2633. RTW_INFO("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
  2634. RTW_INFO("\n");
  2635. RTW_INFO("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
  2636. RTW_INFO("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
  2637. RTW_INFO("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
  2638. RTW_INFO("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
  2639. RTW_INFO("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
  2640. RTW_INFO("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
  2641. RTW_INFO("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
  2642. RTW_INFO("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
  2643. RTW_INFO("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
  2644. RTW_INFO("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
  2645. #endif
  2646. return 0;
  2647. }
  2648. static int rtw_wx_read32(struct net_device *dev,
  2649. struct iw_request_info *info,
  2650. union iwreq_data *wrqu, char *extra)
  2651. {
  2652. PADAPTER padapter;
  2653. struct iw_point *p;
  2654. u16 len;
  2655. u32 addr;
  2656. u32 data32;
  2657. u32 bytes;
  2658. u8 *ptmp;
  2659. int ret;
  2660. ret = 0;
  2661. padapter = (PADAPTER)rtw_netdev_priv(dev);
  2662. p = &wrqu->data;
  2663. len = p->length;
  2664. if (0 == len)
  2665. return -EINVAL;
  2666. ptmp = (u8 *)rtw_malloc(len);
  2667. if (NULL == ptmp)
  2668. return -ENOMEM;
  2669. if (copy_from_user(ptmp, p->pointer, len)) {
  2670. ret = -EFAULT;
  2671. goto exit;
  2672. }
  2673. bytes = 0;
  2674. addr = 0;
  2675. sscanf(ptmp, "%d,%x", &bytes, &addr);
  2676. switch (bytes) {
  2677. case 1:
  2678. data32 = rtw_read8(padapter, addr);
  2679. sprintf(extra, "0x%02X", data32);
  2680. break;
  2681. case 2:
  2682. data32 = rtw_read16(padapter, addr);
  2683. sprintf(extra, "0x%04X", data32);
  2684. break;
  2685. case 4:
  2686. data32 = rtw_read32(padapter, addr);
  2687. sprintf(extra, "0x%08X", data32);
  2688. break;
  2689. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_SDIO_INDIRECT_ACCESS) && defined(DBG_SDIO_INDIRECT_ACCESS)
  2690. case 11:
  2691. data32 = rtw_sd_iread8(padapter, addr);
  2692. sprintf(extra, "0x%02X", data32);
  2693. break;
  2694. case 12:
  2695. data32 = rtw_sd_iread16(padapter, addr);
  2696. sprintf(extra, "0x%04X", data32);
  2697. break;
  2698. case 14:
  2699. data32 = rtw_sd_iread32(padapter, addr);
  2700. sprintf(extra, "0x%08X", data32);
  2701. break;
  2702. #endif
  2703. default:
  2704. RTW_INFO("%s: usage> read [bytes],[address(hex)]\n", __func__);
  2705. ret = -EINVAL;
  2706. goto exit;
  2707. }
  2708. RTW_INFO("%s: addr=0x%08X data=%s\n", __func__, addr, extra);
  2709. exit:
  2710. rtw_mfree(ptmp, len);
  2711. return 0;
  2712. }
  2713. static int rtw_wx_write32(struct net_device *dev,
  2714. struct iw_request_info *info,
  2715. union iwreq_data *wrqu, char *extra)
  2716. {
  2717. PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
  2718. u32 addr;
  2719. u32 data32;
  2720. u32 bytes;
  2721. bytes = 0;
  2722. addr = 0;
  2723. data32 = 0;
  2724. sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
  2725. switch (bytes) {
  2726. case 1:
  2727. rtw_write8(padapter, addr, (u8)data32);
  2728. RTW_INFO("%s: addr=0x%08X data=0x%02X\n", __func__, addr, (u8)data32);
  2729. break;
  2730. case 2:
  2731. rtw_write16(padapter, addr, (u16)data32);
  2732. RTW_INFO("%s: addr=0x%08X data=0x%04X\n", __func__, addr, (u16)data32);
  2733. break;
  2734. case 4:
  2735. rtw_write32(padapter, addr, data32);
  2736. RTW_INFO("%s: addr=0x%08X data=0x%08X\n", __func__, addr, data32);
  2737. break;
  2738. default:
  2739. RTW_INFO("%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
  2740. return -EINVAL;
  2741. }
  2742. return 0;
  2743. }
  2744. static int rtw_wx_read_rf(struct net_device *dev,
  2745. struct iw_request_info *info,
  2746. union iwreq_data *wrqu, char *extra)
  2747. {
  2748. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2749. u32 path, addr, data32;
  2750. path = *(u32 *)extra;
  2751. addr = *((u32 *)extra + 1);
  2752. data32 = rtw_hal_read_rfreg(padapter, path, addr, 0xFFFFF);
  2753. /* RTW_INFO("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32); */
  2754. /*
  2755. * IMPORTANT!!
  2756. * Only when wireless private ioctl is at odd order,
  2757. * "extra" would be copied to user space.
  2758. */
  2759. sprintf(extra, "0x%05x", data32);
  2760. return 0;
  2761. }
  2762. static int rtw_wx_write_rf(struct net_device *dev,
  2763. struct iw_request_info *info,
  2764. union iwreq_data *wrqu, char *extra)
  2765. {
  2766. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2767. u32 path, addr, data32;
  2768. path = *(u32 *)extra;
  2769. addr = *((u32 *)extra + 1);
  2770. data32 = *((u32 *)extra + 2);
  2771. /* RTW_INFO("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32); */
  2772. rtw_hal_write_rfreg(padapter, path, addr, 0xFFFFF, data32);
  2773. return 0;
  2774. }
  2775. static int rtw_wx_priv_null(struct net_device *dev, struct iw_request_info *a,
  2776. union iwreq_data *wrqu, char *b)
  2777. {
  2778. return -1;
  2779. }
  2780. #ifdef CONFIG_RTW_80211K
  2781. extern void rm_dbg_cmd(_adapter *padapter, char *s);
  2782. static int rtw_wx_priv_rrm(struct net_device *dev, struct iw_request_info *a,
  2783. union iwreq_data *wrqu, char *b)
  2784. {
  2785. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2786. u32 path, addr, data32;
  2787. rm_dbg_cmd(padapter, b);
  2788. wrqu->data.length = strlen(b);
  2789. return 0;
  2790. }
  2791. #endif
  2792. static int dummy(struct net_device *dev, struct iw_request_info *a,
  2793. union iwreq_data *wrqu, char *b)
  2794. {
  2795. /* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
  2796. /* struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); */
  2797. /* RTW_INFO("cmd_code=%x, fwstate=0x%x\n", a->cmd, get_fwstate(pmlmepriv)); */
  2798. return -1;
  2799. }
  2800. static int rtw_wx_set_channel_plan(struct net_device *dev,
  2801. struct iw_request_info *info,
  2802. union iwreq_data *wrqu, char *extra)
  2803. {
  2804. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2805. u8 channel_plan_req = (u8)(*((int *)wrqu));
  2806. if (_SUCCESS != rtw_set_channel_plan(padapter, channel_plan_req))
  2807. return -EPERM;
  2808. return 0;
  2809. }
  2810. static int rtw_wx_set_mtk_wps_probe_ie(struct net_device *dev,
  2811. struct iw_request_info *a,
  2812. union iwreq_data *wrqu, char *b)
  2813. {
  2814. #ifdef CONFIG_PLATFORM_MT53XX
  2815. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2816. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2817. #endif
  2818. return 0;
  2819. }
  2820. static int rtw_wx_get_sensitivity(struct net_device *dev,
  2821. struct iw_request_info *info,
  2822. union iwreq_data *wrqu, char *buf)
  2823. {
  2824. #ifdef CONFIG_PLATFORM_MT53XX
  2825. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2826. /* Modified by Albert 20110914 */
  2827. /* This is in dbm format for MTK platform. */
  2828. wrqu->qual.level = padapter->recvpriv.rssi;
  2829. RTW_INFO(" level = %u\n", wrqu->qual.level);
  2830. #endif
  2831. return 0;
  2832. }
  2833. static int rtw_wx_set_mtk_wps_ie(struct net_device *dev,
  2834. struct iw_request_info *info,
  2835. union iwreq_data *wrqu, char *extra)
  2836. {
  2837. #ifdef CONFIG_PLATFORM_MT53XX
  2838. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2839. return rtw_set_wpa_ie(padapter, wrqu->data.pointer, wrqu->data.length);
  2840. #else
  2841. return 0;
  2842. #endif
  2843. }
  2844. static void rtw_dbg_mode_hdl(_adapter *padapter, u32 id, u8 *pdata, u32 len)
  2845. {
  2846. pRW_Reg RegRWStruct;
  2847. struct rf_reg_param *prfreg;
  2848. u8 path;
  2849. u8 offset;
  2850. u32 value;
  2851. RTW_INFO("%s\n", __FUNCTION__);
  2852. switch (id) {
  2853. case GEN_MP_IOCTL_SUBCODE(MP_START):
  2854. RTW_INFO("871x_driver is only for normal mode, can't enter mp mode\n");
  2855. break;
  2856. case GEN_MP_IOCTL_SUBCODE(READ_REG):
  2857. RegRWStruct = (pRW_Reg)pdata;
  2858. switch (RegRWStruct->width) {
  2859. case 1:
  2860. RegRWStruct->value = rtw_read8(padapter, RegRWStruct->offset);
  2861. break;
  2862. case 2:
  2863. RegRWStruct->value = rtw_read16(padapter, RegRWStruct->offset);
  2864. break;
  2865. case 4:
  2866. RegRWStruct->value = rtw_read32(padapter, RegRWStruct->offset);
  2867. break;
  2868. default:
  2869. break;
  2870. }
  2871. break;
  2872. case GEN_MP_IOCTL_SUBCODE(WRITE_REG):
  2873. RegRWStruct = (pRW_Reg)pdata;
  2874. switch (RegRWStruct->width) {
  2875. case 1:
  2876. rtw_write8(padapter, RegRWStruct->offset, (u8)RegRWStruct->value);
  2877. break;
  2878. case 2:
  2879. rtw_write16(padapter, RegRWStruct->offset, (u16)RegRWStruct->value);
  2880. break;
  2881. case 4:
  2882. rtw_write32(padapter, RegRWStruct->offset, (u32)RegRWStruct->value);
  2883. break;
  2884. default:
  2885. break;
  2886. }
  2887. break;
  2888. case GEN_MP_IOCTL_SUBCODE(READ_RF_REG):
  2889. prfreg = (struct rf_reg_param *)pdata;
  2890. path = (u8)prfreg->path;
  2891. offset = (u8)prfreg->offset;
  2892. value = rtw_hal_read_rfreg(padapter, path, offset, 0xffffffff);
  2893. prfreg->value = value;
  2894. break;
  2895. case GEN_MP_IOCTL_SUBCODE(WRITE_RF_REG):
  2896. prfreg = (struct rf_reg_param *)pdata;
  2897. path = (u8)prfreg->path;
  2898. offset = (u8)prfreg->offset;
  2899. value = prfreg->value;
  2900. rtw_hal_write_rfreg(padapter, path, offset, 0xffffffff, value);
  2901. break;
  2902. case GEN_MP_IOCTL_SUBCODE(TRIGGER_GPIO):
  2903. RTW_INFO("==> trigger gpio 0\n");
  2904. rtw_hal_set_hwreg(padapter, HW_VAR_TRIGGER_GPIO_0, 0);
  2905. break;
  2906. #ifdef CONFIG_BT_COEXIST
  2907. case GEN_MP_IOCTL_SUBCODE(SET_DM_BT):
  2908. RTW_INFO("==> set dm_bt_coexist:%x\n", *(u8 *)pdata);
  2909. rtw_hal_set_hwreg(padapter, HW_VAR_BT_SET_COEXIST, pdata);
  2910. break;
  2911. case GEN_MP_IOCTL_SUBCODE(DEL_BA):
  2912. RTW_INFO("==> delete ba:%x\n", *(u8 *)pdata);
  2913. rtw_hal_set_hwreg(padapter, HW_VAR_BT_ISSUE_DELBA, pdata);
  2914. break;
  2915. #endif
  2916. #ifdef DBG_CONFIG_ERROR_DETECT
  2917. case GEN_MP_IOCTL_SUBCODE(GET_WIFI_STATUS):
  2918. *pdata = rtw_hal_sreset_get_wifi_status(padapter);
  2919. break;
  2920. #endif
  2921. default:
  2922. break;
  2923. }
  2924. }
  2925. #ifdef MP_IOCTL_HDL
  2926. static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info,
  2927. union iwreq_data *wrqu, char *extra)
  2928. {
  2929. int ret = 0;
  2930. u32 BytesRead, BytesWritten, BytesNeeded;
  2931. struct oid_par_priv oid_par;
  2932. struct mp_ioctl_handler *phandler;
  2933. struct mp_ioctl_param *poidparam;
  2934. uint status = 0;
  2935. u16 len;
  2936. u8 *pparmbuf = NULL, bset;
  2937. PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
  2938. struct iw_point *p = &wrqu->data;
  2939. /* RTW_INFO("+rtw_mp_ioctl_hdl\n"); */
  2940. /* mutex_lock(&ioctl_mutex); */
  2941. if ((!p->length) || (!p->pointer)) {
  2942. ret = -EINVAL;
  2943. goto _rtw_mp_ioctl_hdl_exit;
  2944. }
  2945. pparmbuf = NULL;
  2946. bset = (u8)(p->flags & 0xFFFF);
  2947. len = p->length;
  2948. pparmbuf = (u8 *)rtw_malloc(len);
  2949. if (pparmbuf == NULL) {
  2950. ret = -ENOMEM;
  2951. goto _rtw_mp_ioctl_hdl_exit;
  2952. }
  2953. if (copy_from_user(pparmbuf, p->pointer, len)) {
  2954. ret = -EFAULT;
  2955. goto _rtw_mp_ioctl_hdl_exit;
  2956. }
  2957. poidparam = (struct mp_ioctl_param *)pparmbuf;
  2958. if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
  2959. ret = -EINVAL;
  2960. goto _rtw_mp_ioctl_hdl_exit;
  2961. }
  2962. /* RTW_INFO("%s: %d\n", __func__, poidparam->subcode); */
  2963. #ifdef CONFIG_MP_INCLUDED
  2964. if (padapter->registrypriv.mp_mode == 1) {
  2965. phandler = mp_ioctl_hdl + poidparam->subcode;
  2966. if ((phandler->paramsize != 0) && (poidparam->len < phandler->paramsize)) {
  2967. ret = -EINVAL;
  2968. goto _rtw_mp_ioctl_hdl_exit;
  2969. }
  2970. if (phandler->handler) {
  2971. oid_par.adapter_context = padapter;
  2972. oid_par.oid = phandler->oid;
  2973. oid_par.information_buf = poidparam->data;
  2974. oid_par.information_buf_len = poidparam->len;
  2975. oid_par.dbg = 0;
  2976. BytesWritten = 0;
  2977. BytesNeeded = 0;
  2978. if (bset) {
  2979. oid_par.bytes_rw = &BytesRead;
  2980. oid_par.bytes_needed = &BytesNeeded;
  2981. oid_par.type_of_oid = SET_OID;
  2982. } else {
  2983. oid_par.bytes_rw = &BytesWritten;
  2984. oid_par.bytes_needed = &BytesNeeded;
  2985. oid_par.type_of_oid = QUERY_OID;
  2986. }
  2987. status = phandler->handler(&oid_par);
  2988. /* todo:check status, BytesNeeded, etc. */
  2989. } else {
  2990. RTW_INFO("rtw_mp_ioctl_hdl(): err!, subcode=%d, oid=%d, handler=%p\n",
  2991. poidparam->subcode, phandler->oid, phandler->handler);
  2992. ret = -EFAULT;
  2993. goto _rtw_mp_ioctl_hdl_exit;
  2994. }
  2995. } else
  2996. #endif
  2997. {
  2998. rtw_dbg_mode_hdl(padapter, poidparam->subcode, poidparam->data, poidparam->len);
  2999. }
  3000. if (bset == 0x00) {/* query info */
  3001. if (copy_to_user(p->pointer, pparmbuf, len))
  3002. ret = -EFAULT;
  3003. }
  3004. if (status) {
  3005. ret = -EFAULT;
  3006. goto _rtw_mp_ioctl_hdl_exit;
  3007. }
  3008. _rtw_mp_ioctl_hdl_exit:
  3009. if (pparmbuf)
  3010. rtw_mfree(pparmbuf, len);
  3011. /* mutex_unlock(&ioctl_mutex); */
  3012. return ret;
  3013. }
  3014. #endif
  3015. static int rtw_get_ap_info(struct net_device *dev,
  3016. struct iw_request_info *info,
  3017. union iwreq_data *wrqu, char *extra)
  3018. {
  3019. int ret = 0;
  3020. u32 cnt = 0, wpa_ielen;
  3021. _irqL irqL;
  3022. _list *plist, *phead;
  3023. unsigned char *pbuf;
  3024. u8 bssid[ETH_ALEN];
  3025. char data[32];
  3026. struct wlan_network *pnetwork = NULL;
  3027. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3028. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3029. _queue *queue = &(pmlmepriv->scanned_queue);
  3030. struct iw_point *pdata = &wrqu->data;
  3031. RTW_INFO("+rtw_get_aplist_info\n");
  3032. if (rtw_is_drv_stopped(padapter) || (pdata == NULL)) {
  3033. ret = -EINVAL;
  3034. goto exit;
  3035. }
  3036. while ((check_fwstate(pmlmepriv, (_FW_UNDER_SURVEY | _FW_UNDER_LINKING))) == _TRUE) {
  3037. rtw_msleep_os(30);
  3038. cnt++;
  3039. if (cnt > 100)
  3040. break;
  3041. }
  3042. /* pdata->length = 0; */ /* ? */
  3043. pdata->flags = 0;
  3044. if (pdata->length >= 32) {
  3045. if (copy_from_user(data, pdata->pointer, 32)) {
  3046. ret = -EINVAL;
  3047. goto exit;
  3048. }
  3049. } else {
  3050. ret = -EINVAL;
  3051. goto exit;
  3052. }
  3053. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3054. phead = get_list_head(queue);
  3055. plist = get_next(phead);
  3056. while (1) {
  3057. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3058. break;
  3059. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3060. /* if(hwaddr_aton_i(pdata->pointer, bssid)) */
  3061. if (hwaddr_aton_i(data, bssid)) {
  3062. RTW_INFO("Invalid BSSID '%s'.\n", (u8 *)data);
  3063. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3064. return -EINVAL;
  3065. }
  3066. if (_rtw_memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN) == _TRUE) { /* BSSID match, then check if supporting wpa/wpa2 */
  3067. RTW_INFO("BSSID:" MAC_FMT "\n", MAC_ARG(bssid));
  3068. pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
  3069. if (pbuf && (wpa_ielen > 0)) {
  3070. pdata->flags = 1;
  3071. break;
  3072. }
  3073. pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
  3074. if (pbuf && (wpa_ielen > 0)) {
  3075. pdata->flags = 2;
  3076. break;
  3077. }
  3078. }
  3079. plist = get_next(plist);
  3080. }
  3081. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3082. if (pdata->length >= 34) {
  3083. if (copy_to_user((u8 *)pdata->pointer + 32, (u8 *)&pdata->flags, 1)) {
  3084. ret = -EINVAL;
  3085. goto exit;
  3086. }
  3087. }
  3088. exit:
  3089. return ret;
  3090. }
  3091. static int rtw_set_pid(struct net_device *dev,
  3092. struct iw_request_info *info,
  3093. union iwreq_data *wrqu, char *extra)
  3094. {
  3095. int ret = 0;
  3096. _adapter *padapter = rtw_netdev_priv(dev);
  3097. int *pdata = (int *)wrqu;
  3098. int selector;
  3099. if (rtw_is_drv_stopped(padapter) || (pdata == NULL)) {
  3100. ret = -EINVAL;
  3101. goto exit;
  3102. }
  3103. selector = *pdata;
  3104. if (selector < 3 && selector >= 0) {
  3105. padapter->pid[selector] = *(pdata + 1);
  3106. #ifdef CONFIG_GLOBAL_UI_PID
  3107. ui_pid[selector] = *(pdata + 1);
  3108. #endif
  3109. RTW_INFO("%s set pid[%d]=%d\n", __FUNCTION__, selector , padapter->pid[selector]);
  3110. } else
  3111. RTW_INFO("%s selector %d error\n", __FUNCTION__, selector);
  3112. exit:
  3113. return ret;
  3114. }
  3115. static int rtw_wps_start(struct net_device *dev,
  3116. struct iw_request_info *info,
  3117. union iwreq_data *wrqu, char *extra)
  3118. {
  3119. int ret = 0;
  3120. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3121. struct iw_point *pdata = &wrqu->data;
  3122. u32 u32wps_start = 0;
  3123. unsigned int uintRet = 0;
  3124. if (RTW_CANNOT_RUN(padapter) || (NULL == pdata)) {
  3125. ret = -EINVAL;
  3126. goto exit;
  3127. }
  3128. uintRet = copy_from_user((void *) &u32wps_start, pdata->pointer, 4);
  3129. if (u32wps_start == 0)
  3130. u32wps_start = *extra;
  3131. RTW_INFO("[%s] wps_start = %d\n", __FUNCTION__, u32wps_start);
  3132. if (u32wps_start == 1) /* WPS Start */
  3133. rtw_led_control(padapter, LED_CTL_START_WPS);
  3134. else if (u32wps_start == 2) /* WPS Stop because of wps success */
  3135. rtw_led_control(padapter, LED_CTL_STOP_WPS);
  3136. else if (u32wps_start == 3) /* WPS Stop because of wps fail */
  3137. rtw_led_control(padapter, LED_CTL_STOP_WPS_FAIL);
  3138. #ifdef CONFIG_INTEL_WIDI
  3139. process_intel_widi_wps_status(padapter, u32wps_start);
  3140. #endif /* CONFIG_INTEL_WIDI */
  3141. exit:
  3142. return ret;
  3143. }
  3144. #ifdef CONFIG_P2P
  3145. static int rtw_wext_p2p_enable(struct net_device *dev,
  3146. struct iw_request_info *info,
  3147. union iwreq_data *wrqu, char *extra)
  3148. {
  3149. int ret = 0;
  3150. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3151. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3152. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3153. enum P2P_ROLE init_role = P2P_ROLE_DISABLE;
  3154. if (*extra == '0')
  3155. init_role = P2P_ROLE_DISABLE;
  3156. else if (*extra == '1')
  3157. init_role = P2P_ROLE_DEVICE;
  3158. else if (*extra == '2')
  3159. init_role = P2P_ROLE_CLIENT;
  3160. else if (*extra == '3')
  3161. init_role = P2P_ROLE_GO;
  3162. if (_FAIL == rtw_p2p_enable(padapter, init_role)) {
  3163. ret = -EFAULT;
  3164. goto exit;
  3165. }
  3166. /* set channel/bandwidth */
  3167. if (init_role != P2P_ROLE_DISABLE) {
  3168. u8 channel, ch_offset;
  3169. u16 bwmode;
  3170. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)) {
  3171. /* Stay at the listen state and wait for discovery. */
  3172. channel = pwdinfo->listen_channel;
  3173. pwdinfo->operating_channel = pwdinfo->listen_channel;
  3174. ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3175. bwmode = CHANNEL_WIDTH_20;
  3176. }
  3177. #ifdef CONFIG_CONCURRENT_MODE
  3178. else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
  3179. _set_timer(&pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_interval);
  3180. channel = rtw_mi_get_union_chan(padapter);
  3181. ch_offset = rtw_mi_get_union_offset(padapter);
  3182. bwmode = rtw_mi_get_union_bw(padapter);
  3183. pwdinfo->operating_channel = channel;
  3184. }
  3185. #endif
  3186. else {
  3187. pwdinfo->operating_channel = pmlmeext->cur_channel;
  3188. channel = pwdinfo->operating_channel;
  3189. ch_offset = pmlmeext->cur_ch_offset;
  3190. bwmode = pmlmeext->cur_bwmode;
  3191. }
  3192. set_channel_bwmode(padapter, channel, ch_offset, bwmode);
  3193. }
  3194. exit:
  3195. return ret;
  3196. }
  3197. static int rtw_p2p_set_go_nego_ssid(struct net_device *dev,
  3198. struct iw_request_info *info,
  3199. union iwreq_data *wrqu, char *extra)
  3200. {
  3201. int ret = 0;
  3202. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3203. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3204. RTW_INFO("[%s] ssid = %s, len = %zu\n", __FUNCTION__, extra, strlen(extra));
  3205. _rtw_memcpy(pwdinfo->nego_ssid, extra, strlen(extra));
  3206. pwdinfo->nego_ssidlen = strlen(extra);
  3207. return ret;
  3208. }
  3209. static int rtw_p2p_set_intent(struct net_device *dev,
  3210. struct iw_request_info *info,
  3211. union iwreq_data *wrqu, char *extra)
  3212. {
  3213. int ret = 0;
  3214. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3215. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3216. u8 intent = pwdinfo->intent;
  3217. extra[wrqu->data.length] = 0x00;
  3218. intent = rtw_atoi(extra);
  3219. if (intent <= 15)
  3220. pwdinfo->intent = intent;
  3221. else
  3222. ret = -1;
  3223. RTW_INFO("[%s] intent = %d\n", __FUNCTION__, intent);
  3224. return ret;
  3225. }
  3226. static int rtw_p2p_set_listen_ch(struct net_device *dev,
  3227. struct iw_request_info *info,
  3228. union iwreq_data *wrqu, char *extra)
  3229. {
  3230. int ret = 0;
  3231. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3232. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3233. u8 listen_ch = pwdinfo->listen_channel; /* Listen channel number */
  3234. extra[wrqu->data.length] = 0x00;
  3235. listen_ch = rtw_atoi(extra);
  3236. if ((listen_ch == 1) || (listen_ch == 6) || (listen_ch == 11)) {
  3237. pwdinfo->listen_channel = listen_ch;
  3238. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3239. } else
  3240. ret = -1;
  3241. RTW_INFO("[%s] listen_ch = %d\n", __FUNCTION__, pwdinfo->listen_channel);
  3242. return ret;
  3243. }
  3244. static int rtw_p2p_set_op_ch(struct net_device *dev,
  3245. struct iw_request_info *info,
  3246. union iwreq_data *wrqu, char *extra)
  3247. {
  3248. /* Commented by Albert 20110524
  3249. * This function is used to set the operating channel if the driver will become the group owner */
  3250. int ret = 0;
  3251. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3252. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3253. u8 op_ch = pwdinfo->operating_channel; /* Operating channel number */
  3254. extra[wrqu->data.length] = 0x00;
  3255. op_ch = (u8) rtw_atoi(extra);
  3256. if (op_ch > 0)
  3257. pwdinfo->operating_channel = op_ch;
  3258. else
  3259. ret = -1;
  3260. RTW_INFO("[%s] op_ch = %d\n", __FUNCTION__, pwdinfo->operating_channel);
  3261. return ret;
  3262. }
  3263. static int rtw_p2p_profilefound(struct net_device *dev,
  3264. struct iw_request_info *info,
  3265. union iwreq_data *wrqu, char *extra)
  3266. {
  3267. int ret = 0;
  3268. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3269. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3270. /* Comment by Albert 2010/10/13 */
  3271. /* Input data format: */
  3272. /* Ex: 0 */
  3273. /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
  3274. /* 0 => Reflush the profile record list. */
  3275. /* 1 => Add the profile list */
  3276. /* XX:XX:XX:XX:XX:XX => peer's MAC Address ( ex: 00:E0:4C:00:00:01 ) */
  3277. /* YY => SSID Length */
  3278. /* SSID => SSID for persistence group */
  3279. RTW_INFO("[%s] In value = %s, len = %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  3280. /* The upper application should pass the SSID to driver by using this rtw_p2p_profilefound function. */
  3281. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  3282. if (extra[0] == '0') {
  3283. /* Remove all the profile information of wifidirect_info structure. */
  3284. _rtw_memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
  3285. pwdinfo->profileindex = 0;
  3286. } else {
  3287. if (pwdinfo->profileindex >= P2P_MAX_PERSISTENT_GROUP_NUM)
  3288. ret = -1;
  3289. else {
  3290. int jj, kk;
  3291. /* Add this profile information into pwdinfo->profileinfo */
  3292. /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
  3293. for (jj = 0, kk = 1; jj < ETH_ALEN; jj++, kk += 3)
  3294. pwdinfo->profileinfo[pwdinfo->profileindex].peermac[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  3295. /* pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen = ( extra[18] - '0' ) * 10 + ( extra[19] - '0' ); */
  3296. /* _rtw_memcpy( pwdinfo->profileinfo[pwdinfo->profileindex].ssid, &extra[20], pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen ); */
  3297. pwdinfo->profileindex++;
  3298. }
  3299. }
  3300. }
  3301. return ret;
  3302. }
  3303. static int rtw_p2p_setDN(struct net_device *dev,
  3304. struct iw_request_info *info,
  3305. union iwreq_data *wrqu, char *extra)
  3306. {
  3307. int ret = 0;
  3308. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3309. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3310. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  3311. _rtw_memset(pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN);
  3312. _rtw_memcpy(pwdinfo->device_name, extra, wrqu->data.length - 1);
  3313. pwdinfo->device_name_len = wrqu->data.length - 1;
  3314. return ret;
  3315. }
  3316. static int rtw_p2p_get_status(struct net_device *dev,
  3317. struct iw_request_info *info,
  3318. union iwreq_data *wrqu, char *extra)
  3319. {
  3320. int ret = 0;
  3321. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3322. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3323. if (padapter->bShowGetP2PState) {
  3324. RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3325. pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
  3326. pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
  3327. }
  3328. /* Commented by Albert 2010/10/12 */
  3329. /* Because of the output size limitation, I had removed the "Role" information. */
  3330. /* About the "Role" information, we will use the new private IOCTL to get the "Role" information. */
  3331. sprintf(extra, "\n\nStatus=%.2d\n", rtw_p2p_state(pwdinfo));
  3332. wrqu->data.length = strlen(extra);
  3333. return ret;
  3334. }
  3335. /* Commented by Albert 20110520
  3336. * This function will return the config method description
  3337. * This config method description will show us which config method the remote P2P device is intented to use
  3338. * by sending the provisioning discovery request frame. */
  3339. static int rtw_p2p_get_req_cm(struct net_device *dev,
  3340. struct iw_request_info *info,
  3341. union iwreq_data *wrqu, char *extra)
  3342. {
  3343. int ret = 0;
  3344. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3345. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3346. sprintf(extra, "\n\nCM=%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req);
  3347. wrqu->data.length = strlen(extra);
  3348. return ret;
  3349. }
  3350. static int rtw_p2p_get_role(struct net_device *dev,
  3351. struct iw_request_info *info,
  3352. union iwreq_data *wrqu, char *extra)
  3353. {
  3354. int ret = 0;
  3355. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3356. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3357. RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3358. pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
  3359. pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
  3360. sprintf(extra, "\n\nRole=%.2d\n", rtw_p2p_role(pwdinfo));
  3361. wrqu->data.length = strlen(extra);
  3362. return ret;
  3363. }
  3364. static int rtw_p2p_get_peer_ifaddr(struct net_device *dev,
  3365. struct iw_request_info *info,
  3366. union iwreq_data *wrqu, char *extra)
  3367. {
  3368. int ret = 0;
  3369. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3370. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3371. RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3372. pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
  3373. pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
  3374. sprintf(extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3375. pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
  3376. pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
  3377. wrqu->data.length = strlen(extra);
  3378. return ret;
  3379. }
  3380. static int rtw_p2p_get_peer_devaddr(struct net_device *dev,
  3381. struct iw_request_info *info,
  3382. union iwreq_data *wrqu, char *extra)
  3383. {
  3384. int ret = 0;
  3385. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3386. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3387. RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3388. pwdinfo->rx_prov_disc_info.peerDevAddr[0], pwdinfo->rx_prov_disc_info.peerDevAddr[1],
  3389. pwdinfo->rx_prov_disc_info.peerDevAddr[2], pwdinfo->rx_prov_disc_info.peerDevAddr[3],
  3390. pwdinfo->rx_prov_disc_info.peerDevAddr[4], pwdinfo->rx_prov_disc_info.peerDevAddr[5]);
  3391. sprintf(extra, "\n%.2X%.2X%.2X%.2X%.2X%.2X",
  3392. pwdinfo->rx_prov_disc_info.peerDevAddr[0], pwdinfo->rx_prov_disc_info.peerDevAddr[1],
  3393. pwdinfo->rx_prov_disc_info.peerDevAddr[2], pwdinfo->rx_prov_disc_info.peerDevAddr[3],
  3394. pwdinfo->rx_prov_disc_info.peerDevAddr[4], pwdinfo->rx_prov_disc_info.peerDevAddr[5]);
  3395. wrqu->data.length = strlen(extra);
  3396. return ret;
  3397. }
  3398. static int rtw_p2p_get_peer_devaddr_by_invitation(struct net_device *dev,
  3399. struct iw_request_info *info,
  3400. union iwreq_data *wrqu, char *extra)
  3401. {
  3402. int ret = 0;
  3403. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3404. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3405. RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3406. pwdinfo->p2p_peer_device_addr[0], pwdinfo->p2p_peer_device_addr[1],
  3407. pwdinfo->p2p_peer_device_addr[2], pwdinfo->p2p_peer_device_addr[3],
  3408. pwdinfo->p2p_peer_device_addr[4], pwdinfo->p2p_peer_device_addr[5]);
  3409. sprintf(extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3410. pwdinfo->p2p_peer_device_addr[0], pwdinfo->p2p_peer_device_addr[1],
  3411. pwdinfo->p2p_peer_device_addr[2], pwdinfo->p2p_peer_device_addr[3],
  3412. pwdinfo->p2p_peer_device_addr[4], pwdinfo->p2p_peer_device_addr[5]);
  3413. wrqu->data.length = strlen(extra);
  3414. return ret;
  3415. }
  3416. static int rtw_p2p_get_groupid(struct net_device *dev,
  3417. struct iw_request_info *info,
  3418. union iwreq_data *wrqu, char *extra)
  3419. {
  3420. int ret = 0;
  3421. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3422. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3423. sprintf(extra, "\n%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s",
  3424. pwdinfo->groupid_info.go_device_addr[0], pwdinfo->groupid_info.go_device_addr[1],
  3425. pwdinfo->groupid_info.go_device_addr[2], pwdinfo->groupid_info.go_device_addr[3],
  3426. pwdinfo->groupid_info.go_device_addr[4], pwdinfo->groupid_info.go_device_addr[5],
  3427. pwdinfo->groupid_info.ssid);
  3428. wrqu->data.length = strlen(extra);
  3429. return ret;
  3430. }
  3431. static int rtw_p2p_get_op_ch(struct net_device *dev,
  3432. struct iw_request_info *info,
  3433. union iwreq_data *wrqu, char *extra)
  3434. {
  3435. int ret = 0;
  3436. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3437. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3438. RTW_INFO("[%s] Op_ch = %02x\n", __FUNCTION__, pwdinfo->operating_channel);
  3439. sprintf(extra, "\n\nOp_ch=%.2d\n", pwdinfo->operating_channel);
  3440. wrqu->data.length = strlen(extra);
  3441. return ret;
  3442. }
  3443. static int rtw_p2p_get_wps_configmethod(struct net_device *dev,
  3444. struct iw_request_info *info,
  3445. union iwreq_data *wrqu, char *extra, char *subcmd)
  3446. {
  3447. int ret = 0;
  3448. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3449. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3450. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3451. _irqL irqL;
  3452. _list *plist, *phead;
  3453. _queue *queue = &(pmlmepriv->scanned_queue);
  3454. struct wlan_network *pnetwork = NULL;
  3455. u8 blnMatch = 0;
  3456. u16 attr_content = 0;
  3457. uint attr_contentlen = 0;
  3458. u8 attr_content_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3459. /* Commented by Albert 20110727 */
  3460. /* The input data is the MAC address which the application wants to know its WPS config method. */
  3461. /* After knowing its WPS config method, the application can decide the config method for provisioning discovery. */
  3462. /* Format: iwpriv wlanx p2p_get_wpsCM 00:E0:4C:00:00:05 */
  3463. RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
  3464. macstr2num(peerMAC, subcmd);
  3465. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3466. phead = get_list_head(queue);
  3467. plist = get_next(phead);
  3468. while (1) {
  3469. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3470. break;
  3471. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3472. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3473. u8 *wpsie;
  3474. uint wpsie_len = 0;
  3475. /* The mac address is matched. */
  3476. wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
  3477. if (wpsie) {
  3478. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *)&attr_content, &attr_contentlen);
  3479. if (attr_contentlen) {
  3480. attr_content = be16_to_cpu(attr_content);
  3481. sprintf(attr_content_str, "\n\nM=%.4d", attr_content);
  3482. blnMatch = 1;
  3483. }
  3484. }
  3485. break;
  3486. }
  3487. plist = get_next(plist);
  3488. }
  3489. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3490. if (!blnMatch)
  3491. sprintf(attr_content_str, "\n\nM=0000");
  3492. wrqu->data.length = strlen(attr_content_str);
  3493. _rtw_memcpy(extra, attr_content_str, wrqu->data.length);
  3494. return ret;
  3495. }
  3496. #ifdef CONFIG_WFD
  3497. static int rtw_p2p_get_peer_wfd_port(struct net_device *dev,
  3498. struct iw_request_info *info,
  3499. union iwreq_data *wrqu, char *extra)
  3500. {
  3501. int ret = 0;
  3502. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3503. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3504. RTW_INFO("[%s] p2p_state = %d\n", __FUNCTION__, rtw_p2p_state(pwdinfo));
  3505. sprintf(extra, "\n\nPort=%d\n", pwdinfo->wfd_info->peer_rtsp_ctrlport);
  3506. RTW_INFO("[%s] remote port = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_rtsp_ctrlport);
  3507. wrqu->data.length = strlen(extra);
  3508. return ret;
  3509. }
  3510. static int rtw_p2p_get_peer_wfd_preferred_connection(struct net_device *dev,
  3511. struct iw_request_info *info,
  3512. union iwreq_data *wrqu, char *extra)
  3513. {
  3514. int ret = 0;
  3515. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3516. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3517. sprintf(extra, "\n\nwfd_pc=%d\n", pwdinfo->wfd_info->wfd_pc);
  3518. RTW_INFO("[%s] wfd_pc = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_pc);
  3519. wrqu->data.length = strlen(extra);
  3520. pwdinfo->wfd_info->wfd_pc = _FALSE; /* Reset the WFD preferred connection to P2P */
  3521. return ret;
  3522. }
  3523. static int rtw_p2p_get_peer_wfd_session_available(struct net_device *dev,
  3524. struct iw_request_info *info,
  3525. union iwreq_data *wrqu, char *extra)
  3526. {
  3527. int ret = 0;
  3528. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3529. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3530. sprintf(extra, "\n\nwfd_sa=%d\n", pwdinfo->wfd_info->peer_session_avail);
  3531. RTW_INFO("[%s] wfd_sa = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_session_avail);
  3532. wrqu->data.length = strlen(extra);
  3533. pwdinfo->wfd_info->peer_session_avail = _TRUE; /* Reset the WFD session available */
  3534. return ret;
  3535. }
  3536. #endif /* CONFIG_WFD */
  3537. static int rtw_p2p_get_go_device_address(struct net_device *dev,
  3538. struct iw_request_info *info,
  3539. union iwreq_data *wrqu, char *extra, char *subcmd)
  3540. {
  3541. int ret = 0;
  3542. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3543. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3544. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3545. _irqL irqL;
  3546. _list *plist, *phead;
  3547. _queue *queue = &(pmlmepriv->scanned_queue);
  3548. struct wlan_network *pnetwork = NULL;
  3549. u8 blnMatch = 0;
  3550. u8 *p2pie;
  3551. uint p2pielen = 0, attr_contentlen = 0;
  3552. u8 attr_content[100] = { 0x00 };
  3553. u8 go_devadd_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3554. /* Commented by Albert 20121209 */
  3555. /* The input data is the GO's interface address which the application wants to know its device address. */
  3556. /* Format: iwpriv wlanx p2p_get2 go_devadd=00:E0:4C:00:00:05 */
  3557. RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
  3558. macstr2num(peerMAC, subcmd);
  3559. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3560. phead = get_list_head(queue);
  3561. plist = get_next(phead);
  3562. while (1) {
  3563. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3564. break;
  3565. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3566. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3567. /* Commented by Albert 2011/05/18 */
  3568. /* Match the device address located in the P2P IE */
  3569. /* This is for the case that the P2P device address is not the same as the P2P interface address. */
  3570. p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
  3571. if (p2pie) {
  3572. while (p2pie) {
  3573. /* The P2P Device ID attribute is included in the Beacon frame. */
  3574. /* The P2P Device Info attribute is included in the probe response frame. */
  3575. _rtw_memset(attr_content, 0x00, 100);
  3576. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
  3577. /* Handle the P2P Device ID attribute of Beacon first */
  3578. blnMatch = 1;
  3579. break;
  3580. } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
  3581. /* Handle the P2P Device Info attribute of probe response */
  3582. blnMatch = 1;
  3583. break;
  3584. }
  3585. /* Get the next P2P IE */
  3586. p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
  3587. }
  3588. }
  3589. }
  3590. plist = get_next(plist);
  3591. }
  3592. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3593. if (!blnMatch)
  3594. sprintf(go_devadd_str, "\n\ndev_add=NULL");
  3595. else {
  3596. sprintf(go_devadd_str, "\n\ndev_add=%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3597. attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
  3598. }
  3599. wrqu->data.length = strlen(go_devadd_str);
  3600. _rtw_memcpy(extra, go_devadd_str, wrqu->data.length);
  3601. return ret;
  3602. }
  3603. static int rtw_p2p_get_device_type(struct net_device *dev,
  3604. struct iw_request_info *info,
  3605. union iwreq_data *wrqu, char *extra, char *subcmd)
  3606. {
  3607. int ret = 0;
  3608. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3609. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3610. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3611. _irqL irqL;
  3612. _list *plist, *phead;
  3613. _queue *queue = &(pmlmepriv->scanned_queue);
  3614. struct wlan_network *pnetwork = NULL;
  3615. u8 blnMatch = 0;
  3616. u8 dev_type[8] = { 0x00 };
  3617. uint dev_type_len = 0;
  3618. u8 dev_type_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 }; /* +9 is for the str "dev_type=", we have to clear it at wrqu->data.pointer */
  3619. /* Commented by Albert 20121209 */
  3620. /* The input data is the MAC address which the application wants to know its device type. */
  3621. /* Such user interface could know the device type. */
  3622. /* Format: iwpriv wlanx p2p_get2 dev_type=00:E0:4C:00:00:05 */
  3623. RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
  3624. macstr2num(peerMAC, subcmd);
  3625. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3626. phead = get_list_head(queue);
  3627. plist = get_next(phead);
  3628. while (1) {
  3629. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3630. break;
  3631. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3632. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3633. u8 *wpsie;
  3634. uint wpsie_len = 0;
  3635. /* The mac address is matched. */
  3636. wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
  3637. if (wpsie) {
  3638. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_PRIMARY_DEV_TYPE, dev_type, &dev_type_len);
  3639. if (dev_type_len) {
  3640. u16 type = 0;
  3641. _rtw_memcpy(&type, dev_type, 2);
  3642. type = be16_to_cpu(type);
  3643. sprintf(dev_type_str, "\n\nN=%.2d", type);
  3644. blnMatch = 1;
  3645. }
  3646. }
  3647. break;
  3648. }
  3649. plist = get_next(plist);
  3650. }
  3651. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3652. if (!blnMatch)
  3653. sprintf(dev_type_str, "\n\nN=00");
  3654. wrqu->data.length = strlen(dev_type_str);
  3655. _rtw_memcpy(extra, dev_type_str, wrqu->data.length);
  3656. return ret;
  3657. }
  3658. static int rtw_p2p_get_device_name(struct net_device *dev,
  3659. struct iw_request_info *info,
  3660. union iwreq_data *wrqu, char *extra, char *subcmd)
  3661. {
  3662. int ret = 0;
  3663. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3664. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3665. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3666. _irqL irqL;
  3667. _list *plist, *phead;
  3668. _queue *queue = &(pmlmepriv->scanned_queue);
  3669. struct wlan_network *pnetwork = NULL;
  3670. u8 blnMatch = 0;
  3671. u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = { 0x00 };
  3672. uint dev_len = 0;
  3673. u8 dev_name_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3674. /* Commented by Albert 20121225 */
  3675. /* The input data is the MAC address which the application wants to know its device name. */
  3676. /* Such user interface could show peer device's device name instead of ssid. */
  3677. /* Format: iwpriv wlanx p2p_get2 devN=00:E0:4C:00:00:05 */
  3678. RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
  3679. macstr2num(peerMAC, subcmd);
  3680. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3681. phead = get_list_head(queue);
  3682. plist = get_next(phead);
  3683. while (1) {
  3684. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3685. break;
  3686. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3687. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3688. u8 *wpsie;
  3689. uint wpsie_len = 0;
  3690. /* The mac address is matched. */
  3691. wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
  3692. if (wpsie) {
  3693. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len);
  3694. if (dev_len) {
  3695. sprintf(dev_name_str, "\n\nN=%s", dev_name);
  3696. blnMatch = 1;
  3697. }
  3698. }
  3699. break;
  3700. }
  3701. plist = get_next(plist);
  3702. }
  3703. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3704. if (!blnMatch)
  3705. sprintf(dev_name_str, "\n\nN=0000");
  3706. wrqu->data.length = strlen(dev_name_str);
  3707. _rtw_memcpy(extra, dev_name_str, wrqu->data.length);
  3708. return ret;
  3709. }
  3710. static int rtw_p2p_get_invitation_procedure(struct net_device *dev,
  3711. struct iw_request_info *info,
  3712. union iwreq_data *wrqu, char *extra, char *subcmd)
  3713. {
  3714. int ret = 0;
  3715. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3716. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3717. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3718. _irqL irqL;
  3719. _list *plist, *phead;
  3720. _queue *queue = &(pmlmepriv->scanned_queue);
  3721. struct wlan_network *pnetwork = NULL;
  3722. u8 blnMatch = 0;
  3723. u8 *p2pie;
  3724. uint p2pielen = 0, attr_contentlen = 0;
  3725. u8 attr_content[2] = { 0x00 };
  3726. u8 inv_proc_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3727. /* Commented by Ouden 20121226 */
  3728. /* The application wants to know P2P initation procedure is support or not. */
  3729. /* Format: iwpriv wlanx p2p_get2 InvProc=00:E0:4C:00:00:05 */
  3730. RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
  3731. macstr2num(peerMAC, subcmd);
  3732. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3733. phead = get_list_head(queue);
  3734. plist = get_next(phead);
  3735. while (1) {
  3736. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3737. break;
  3738. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3739. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3740. /* Commented by Albert 20121226 */
  3741. /* Match the device address located in the P2P IE */
  3742. /* This is for the case that the P2P device address is not the same as the P2P interface address. */
  3743. p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
  3744. if (p2pie) {
  3745. while (p2pie) {
  3746. /* _rtw_memset( attr_content, 0x00, 2); */
  3747. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_CAPABILITY, attr_content, &attr_contentlen)) {
  3748. /* Handle the P2P capability attribute */
  3749. blnMatch = 1;
  3750. break;
  3751. }
  3752. /* Get the next P2P IE */
  3753. p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
  3754. }
  3755. }
  3756. }
  3757. plist = get_next(plist);
  3758. }
  3759. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3760. if (!blnMatch)
  3761. sprintf(inv_proc_str, "\nIP=-1");
  3762. else {
  3763. if ((attr_content[0] & 0x20) == 0x20)
  3764. sprintf(inv_proc_str, "\nIP=1");
  3765. else
  3766. sprintf(inv_proc_str, "\nIP=0");
  3767. }
  3768. wrqu->data.length = strlen(inv_proc_str);
  3769. _rtw_memcpy(extra, inv_proc_str, wrqu->data.length);
  3770. return ret;
  3771. }
  3772. static int rtw_p2p_connect(struct net_device *dev,
  3773. struct iw_request_info *info,
  3774. union iwreq_data *wrqu, char *extra)
  3775. {
  3776. int ret = 0;
  3777. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3778. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3779. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3780. int jj, kk;
  3781. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3782. _irqL irqL;
  3783. _list *plist, *phead;
  3784. _queue *queue = &(pmlmepriv->scanned_queue);
  3785. struct wlan_network *pnetwork = NULL;
  3786. uint uintPeerChannel = 0;
  3787. /* Commented by Albert 20110304 */
  3788. /* The input data contains two informations. */
  3789. /* 1. First information is the MAC address which wants to formate with */
  3790. /* 2. Second information is the WPS PINCode or "pbc" string for push button method */
  3791. /* Format: 00:E0:4C:00:00:05 */
  3792. /* Format: 00:E0:4C:00:00:05 */
  3793. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  3794. if (pwdinfo->p2p_state == P2P_STATE_NONE) {
  3795. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  3796. return ret;
  3797. }
  3798. #ifdef CONFIG_INTEL_WIDI
  3799. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  3800. RTW_INFO("[%s] WiFi is under survey!\n", __FUNCTION__);
  3801. return ret;
  3802. }
  3803. #endif /* CONFIG_INTEL_WIDI */
  3804. if (pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO)
  3805. return -1;
  3806. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  3807. peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  3808. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3809. phead = get_list_head(queue);
  3810. plist = get_next(phead);
  3811. while (1) {
  3812. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3813. break;
  3814. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3815. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  3816. if (pnetwork->network.Configuration.DSConfig != 0)
  3817. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  3818. else if (pwdinfo->nego_req_info.peer_ch != 0)
  3819. uintPeerChannel = pnetwork->network.Configuration.DSConfig = pwdinfo->nego_req_info.peer_ch;
  3820. else {
  3821. /* Unexpected case */
  3822. uintPeerChannel = 0;
  3823. RTW_INFO("%s uintPeerChannel = 0\n", __func__);
  3824. }
  3825. break;
  3826. }
  3827. plist = get_next(plist);
  3828. }
  3829. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3830. if (uintPeerChannel) {
  3831. #ifdef CONFIG_CONCURRENT_MODE
  3832. if (rtw_mi_check_status(padapter, MI_LINKED))
  3833. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  3834. #endif /* CONFIG_CONCURRENT_MODE */
  3835. _rtw_memset(&pwdinfo->nego_req_info, 0x00, sizeof(struct tx_nego_req_info));
  3836. _rtw_memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
  3837. pwdinfo->nego_req_info.peer_channel_num[0] = uintPeerChannel;
  3838. _rtw_memcpy(pwdinfo->nego_req_info.peerDevAddr, pnetwork->network.MacAddress, ETH_ALEN);
  3839. pwdinfo->nego_req_info.benable = _TRUE;
  3840. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  3841. if (rtw_p2p_state(pwdinfo) != P2P_STATE_GONEGO_OK) {
  3842. /* Restore to the listen state if the current p2p state is not nego OK */
  3843. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  3844. }
  3845. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  3846. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
  3847. #ifdef CONFIG_CONCURRENT_MODE
  3848. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  3849. u8 union_ch = rtw_mi_get_union_chan(padapter);
  3850. u8 union_bw = rtw_mi_get_union_bw(padapter);
  3851. u8 union_offset = rtw_mi_get_union_offset(padapter);
  3852. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  3853. rtw_leave_opch(padapter);
  3854. }
  3855. #endif /* CONFIG_CONCURRENT_MODE */
  3856. RTW_INFO("[%s] Start PreTx Procedure!\n", __FUNCTION__);
  3857. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  3858. #ifdef CONFIG_CONCURRENT_MODE
  3859. if (rtw_mi_check_status(padapter, MI_LINKED))
  3860. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_GO_NEGO_TIMEOUT);
  3861. else
  3862. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
  3863. #else
  3864. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
  3865. #endif /* CONFIG_CONCURRENT_MODE */
  3866. } else {
  3867. RTW_INFO("[%s] Not Found in Scanning Queue~\n", __FUNCTION__);
  3868. #ifdef CONFIG_INTEL_WIDI
  3869. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  3870. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  3871. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  3872. rtw_free_network_queue(padapter, _TRUE);
  3873. /**
  3874. * For WiDi, if we can't find candidate device in scanning queue,
  3875. * driver will do scanning itself
  3876. */
  3877. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  3878. rtw_sitesurvey_cmd(padapter, NULL);
  3879. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  3880. #endif /* CONFIG_INTEL_WIDI */
  3881. ret = -1;
  3882. }
  3883. exit:
  3884. return ret;
  3885. }
  3886. static int rtw_p2p_invite_req(struct net_device *dev,
  3887. struct iw_request_info *info,
  3888. union iwreq_data *wrqu, char *extra)
  3889. {
  3890. int ret = 0;
  3891. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3892. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3893. int jj, kk;
  3894. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3895. _list *plist, *phead;
  3896. _queue *queue = &(pmlmepriv->scanned_queue);
  3897. struct wlan_network *pnetwork = NULL;
  3898. uint uintPeerChannel = 0;
  3899. u8 attr_content[50] = { 0x00 };
  3900. u8 *p2pie;
  3901. uint p2pielen = 0, attr_contentlen = 0;
  3902. _irqL irqL;
  3903. struct tx_invite_req_info *pinvite_req_info = &pwdinfo->invitereq_info;
  3904. /* Commented by Albert 20120321 */
  3905. /* The input data contains two informations. */
  3906. /* 1. First information is the P2P device address which you want to send to. */
  3907. /* 2. Second information is the group id which combines with GO's mac address, space and GO's ssid. */
  3908. /* Command line sample: iwpriv wlan0 p2p_set invite="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */
  3909. /* Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy */
  3910. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  3911. if (wrqu->data.length <= 37) {
  3912. RTW_INFO("[%s] Wrong format!\n", __FUNCTION__);
  3913. return ret;
  3914. }
  3915. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  3916. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  3917. return ret;
  3918. } else {
  3919. /* Reset the content of struct tx_invite_req_info */
  3920. pinvite_req_info->benable = _FALSE;
  3921. _rtw_memset(pinvite_req_info->go_bssid, 0x00, ETH_ALEN);
  3922. _rtw_memset(pinvite_req_info->go_ssid, 0x00, WLAN_SSID_MAXLEN);
  3923. pinvite_req_info->ssidlen = 0x00;
  3924. pinvite_req_info->operating_ch = pwdinfo->operating_channel;
  3925. _rtw_memset(pinvite_req_info->peer_macaddr, 0x00, ETH_ALEN);
  3926. pinvite_req_info->token = 3;
  3927. }
  3928. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  3929. pinvite_req_info->peer_macaddr[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  3930. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3931. phead = get_list_head(queue);
  3932. plist = get_next(phead);
  3933. while (1) {
  3934. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  3935. break;
  3936. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3937. /* Commented by Albert 2011/05/18 */
  3938. /* Match the device address located in the P2P IE */
  3939. /* This is for the case that the P2P device address is not the same as the P2P interface address. */
  3940. p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
  3941. if (p2pie) {
  3942. /* The P2P Device ID attribute is included in the Beacon frame. */
  3943. /* The P2P Device Info attribute is included in the probe response frame. */
  3944. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
  3945. /* Handle the P2P Device ID attribute of Beacon first */
  3946. if (_rtw_memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
  3947. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  3948. break;
  3949. }
  3950. } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
  3951. /* Handle the P2P Device Info attribute of probe response */
  3952. if (_rtw_memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
  3953. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  3954. break;
  3955. }
  3956. }
  3957. }
  3958. plist = get_next(plist);
  3959. }
  3960. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3961. #ifdef CONFIG_WFD
  3962. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST) && uintPeerChannel) {
  3963. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  3964. u8 *wfd_ie;
  3965. uint wfd_ielen = 0;
  3966. wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
  3967. if (wfd_ie) {
  3968. u8 *wfd_devinfo;
  3969. uint wfd_devlen;
  3970. RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
  3971. wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
  3972. if (wfd_devinfo) {
  3973. u16 wfd_devinfo_field = 0;
  3974. /* Commented by Albert 20120319 */
  3975. /* The first two bytes are the WFD device information field of WFD device information subelement. */
  3976. /* In big endian format. */
  3977. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  3978. if (wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL)
  3979. pwfd_info->peer_session_avail = _TRUE;
  3980. else
  3981. pwfd_info->peer_session_avail = _FALSE;
  3982. }
  3983. }
  3984. if (_FALSE == pwfd_info->peer_session_avail) {
  3985. RTW_INFO("[%s] WFD Session not avaiable!\n", __FUNCTION__);
  3986. goto exit;
  3987. }
  3988. }
  3989. #endif /* CONFIG_WFD */
  3990. if (uintPeerChannel) {
  3991. #ifdef CONFIG_CONCURRENT_MODE
  3992. if (rtw_mi_check_status(padapter, MI_LINKED))
  3993. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  3994. #endif /* CONFIG_CONCURRENT_MODE */
  3995. /* Store the GO's bssid */
  3996. for (jj = 0, kk = 18; jj < ETH_ALEN; jj++, kk += 3)
  3997. pinvite_req_info->go_bssid[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  3998. /* Store the GO's ssid */
  3999. pinvite_req_info->ssidlen = wrqu->data.length - 36;
  4000. _rtw_memcpy(pinvite_req_info->go_ssid, &extra[36], (u32) pinvite_req_info->ssidlen);
  4001. pinvite_req_info->benable = _TRUE;
  4002. pinvite_req_info->peer_ch = uintPeerChannel;
  4003. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  4004. rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INVITE_REQ);
  4005. #ifdef CONFIG_CONCURRENT_MODE
  4006. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  4007. u8 union_ch = rtw_mi_get_union_chan(padapter);
  4008. u8 union_bw = rtw_mi_get_union_bw(padapter);
  4009. u8 union_offset = rtw_mi_get_union_offset(padapter);
  4010. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  4011. rtw_leave_opch(padapter);
  4012. } else
  4013. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4014. #else
  4015. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4016. #endif/*CONFIG_CONCURRENT_MODE*/
  4017. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  4018. #ifdef CONFIG_CONCURRENT_MODE
  4019. if (rtw_mi_check_status(padapter, MI_LINKED))
  4020. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_INVITE_TIMEOUT);
  4021. else
  4022. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
  4023. #else
  4024. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
  4025. #endif /* CONFIG_CONCURRENT_MODE */
  4026. } else
  4027. RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
  4028. exit:
  4029. return ret;
  4030. }
  4031. static int rtw_p2p_set_persistent(struct net_device *dev,
  4032. struct iw_request_info *info,
  4033. union iwreq_data *wrqu, char *extra)
  4034. {
  4035. int ret = 0;
  4036. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4037. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4038. /* Commented by Albert 20120328 */
  4039. /* The input data is 0 or 1 */
  4040. /* 0: disable persistent group functionality */
  4041. /* 1: enable persistent group founctionality */
  4042. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4043. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  4044. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  4045. return ret;
  4046. } else {
  4047. if (extra[0] == '0') /* Disable the persistent group function. */
  4048. pwdinfo->persistent_supported = _FALSE;
  4049. else if (extra[0] == '1') /* Enable the persistent group function. */
  4050. pwdinfo->persistent_supported = _TRUE;
  4051. else
  4052. pwdinfo->persistent_supported = _FALSE;
  4053. }
  4054. printk("[%s] persistent_supported = %d\n", __FUNCTION__, pwdinfo->persistent_supported);
  4055. exit:
  4056. return ret;
  4057. }
  4058. static int uuid_str2bin(const char *str, u8 *bin)
  4059. {
  4060. const char *pos;
  4061. u8 *opos;
  4062. pos = str;
  4063. opos = bin;
  4064. if (hexstr2bin(pos, opos, 4))
  4065. return -1;
  4066. pos += 8;
  4067. opos += 4;
  4068. if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
  4069. return -1;
  4070. pos += 4;
  4071. opos += 2;
  4072. if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
  4073. return -1;
  4074. pos += 4;
  4075. opos += 2;
  4076. if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
  4077. return -1;
  4078. pos += 4;
  4079. opos += 2;
  4080. if (*pos++ != '-' || hexstr2bin(pos, opos, 6))
  4081. return -1;
  4082. return 0;
  4083. }
  4084. static int rtw_p2p_set_wps_uuid(struct net_device *dev,
  4085. struct iw_request_info *info,
  4086. union iwreq_data *wrqu, char *extra)
  4087. {
  4088. int ret = 0;
  4089. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4090. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4091. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4092. if ((36 == strlen(extra)) && (uuid_str2bin(extra, pwdinfo->uuid) == 0))
  4093. pwdinfo->external_uuid = 1;
  4094. else {
  4095. pwdinfo->external_uuid = 0;
  4096. ret = -EINVAL;
  4097. }
  4098. return ret;
  4099. }
  4100. #ifdef CONFIG_WFD
  4101. static int rtw_p2p_set_pc(struct net_device *dev,
  4102. struct iw_request_info *info,
  4103. union iwreq_data *wrqu, char *extra)
  4104. {
  4105. int ret = 0;
  4106. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4107. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4108. u8 peerMAC[ETH_ALEN] = { 0x00 };
  4109. int jj, kk;
  4110. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4111. _list *plist, *phead;
  4112. _queue *queue = &(pmlmepriv->scanned_queue);
  4113. struct wlan_network *pnetwork = NULL;
  4114. u8 attr_content[50] = { 0x00 };
  4115. u8 *p2pie;
  4116. uint p2pielen = 0, attr_contentlen = 0;
  4117. _irqL irqL;
  4118. uint uintPeerChannel = 0;
  4119. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  4120. /* Commented by Albert 20120512 */
  4121. /* 1. Input information is the MAC address which wants to know the Preferred Connection bit (PC bit) */
  4122. /* Format: 00:E0:4C:00:00:05 */
  4123. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4124. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  4125. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  4126. return ret;
  4127. }
  4128. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  4129. peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  4130. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4131. phead = get_list_head(queue);
  4132. plist = get_next(phead);
  4133. while (1) {
  4134. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  4135. break;
  4136. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4137. /* Commented by Albert 2011/05/18 */
  4138. /* Match the device address located in the P2P IE */
  4139. /* This is for the case that the P2P device address is not the same as the P2P interface address. */
  4140. p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
  4141. if (p2pie) {
  4142. /* The P2P Device ID attribute is included in the Beacon frame. */
  4143. /* The P2P Device Info attribute is included in the probe response frame. */
  4144. printk("[%s] Got P2P IE\n", __FUNCTION__);
  4145. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
  4146. /* Handle the P2P Device ID attribute of Beacon first */
  4147. printk("[%s] P2P_ATTR_DEVICE_ID\n", __FUNCTION__);
  4148. if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
  4149. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4150. break;
  4151. }
  4152. } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
  4153. /* Handle the P2P Device Info attribute of probe response */
  4154. printk("[%s] P2P_ATTR_DEVICE_INFO\n", __FUNCTION__);
  4155. if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
  4156. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4157. break;
  4158. }
  4159. }
  4160. }
  4161. plist = get_next(plist);
  4162. }
  4163. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4164. printk("[%s] channel = %d\n", __FUNCTION__, uintPeerChannel);
  4165. if (uintPeerChannel) {
  4166. u8 *wfd_ie;
  4167. uint wfd_ielen = 0;
  4168. wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
  4169. if (wfd_ie) {
  4170. u8 *wfd_devinfo;
  4171. uint wfd_devlen;
  4172. RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
  4173. wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
  4174. if (wfd_devinfo) {
  4175. u16 wfd_devinfo_field = 0;
  4176. /* Commented by Albert 20120319 */
  4177. /* The first two bytes are the WFD device information field of WFD device information subelement. */
  4178. /* In big endian format. */
  4179. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  4180. if (wfd_devinfo_field & WFD_DEVINFO_PC_TDLS)
  4181. pwfd_info->wfd_pc = _TRUE;
  4182. else
  4183. pwfd_info->wfd_pc = _FALSE;
  4184. }
  4185. }
  4186. } else
  4187. RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
  4188. exit:
  4189. return ret;
  4190. }
  4191. static int rtw_p2p_set_wfd_device_type(struct net_device *dev,
  4192. struct iw_request_info *info,
  4193. union iwreq_data *wrqu, char *extra)
  4194. {
  4195. int ret = 0;
  4196. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4197. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4198. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  4199. /* Commented by Albert 20120328 */
  4200. /* The input data is 0 or 1 */
  4201. /* 0: specify to Miracast source device */
  4202. /* 1 or others: specify to Miracast sink device (display device) */
  4203. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4204. if (extra[0] == '0') /* Set to Miracast source device. */
  4205. pwfd_info->wfd_device_type = WFD_DEVINFO_SOURCE;
  4206. else /* Set to Miracast sink device. */
  4207. pwfd_info->wfd_device_type = WFD_DEVINFO_PSINK;
  4208. exit:
  4209. return ret;
  4210. }
  4211. static int rtw_p2p_set_wfd_enable(struct net_device *dev,
  4212. struct iw_request_info *info,
  4213. union iwreq_data *wrqu, char *extra)
  4214. {
  4215. /* Commented by Kurt 20121206
  4216. * This function is used to set wfd enabled */
  4217. int ret = 0;
  4218. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4219. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4220. if (*extra == '0')
  4221. rtw_wfd_enable(padapter, 0);
  4222. else if (*extra == '1')
  4223. rtw_wfd_enable(padapter, 1);
  4224. RTW_INFO("[%s] wfd_enable = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_enable);
  4225. return ret;
  4226. }
  4227. static int rtw_p2p_set_driver_iface(struct net_device *dev,
  4228. struct iw_request_info *info,
  4229. union iwreq_data *wrqu, char *extra)
  4230. {
  4231. /* Commented by Kurt 20121206
  4232. * This function is used to set driver iface is WEXT or CFG80211 */
  4233. int ret = 0;
  4234. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4235. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4236. if (*extra == '1') {
  4237. pwdinfo->driver_interface = DRIVER_WEXT;
  4238. RTW_INFO("[%s] driver_interface = WEXT\n", __FUNCTION__);
  4239. } else if (*extra == '2') {
  4240. pwdinfo->driver_interface = DRIVER_CFG80211;
  4241. RTW_INFO("[%s] driver_interface = CFG80211\n", __FUNCTION__);
  4242. }
  4243. return ret;
  4244. }
  4245. /* To set the WFD session available to enable or disable */
  4246. static int rtw_p2p_set_sa(struct net_device *dev,
  4247. struct iw_request_info *info,
  4248. union iwreq_data *wrqu, char *extra)
  4249. {
  4250. int ret = 0;
  4251. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4252. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4253. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4254. if (0) {
  4255. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  4256. return ret;
  4257. } else {
  4258. if (extra[0] == '0') /* Disable the session available. */
  4259. pwdinfo->session_available = _FALSE;
  4260. else if (extra[0] == '1') /* Enable the session available. */
  4261. pwdinfo->session_available = _TRUE;
  4262. else
  4263. pwdinfo->session_available = _FALSE;
  4264. }
  4265. printk("[%s] session available = %d\n", __FUNCTION__, pwdinfo->session_available);
  4266. exit:
  4267. return ret;
  4268. }
  4269. #endif /* CONFIG_WFD */
  4270. static int rtw_p2p_prov_disc(struct net_device *dev,
  4271. struct iw_request_info *info,
  4272. union iwreq_data *wrqu, char *extra)
  4273. {
  4274. int ret = 0;
  4275. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4276. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4277. u8 peerMAC[ETH_ALEN] = { 0x00 };
  4278. int jj, kk;
  4279. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4280. _list *plist, *phead;
  4281. _queue *queue = &(pmlmepriv->scanned_queue);
  4282. struct wlan_network *pnetwork = NULL;
  4283. uint uintPeerChannel = 0;
  4284. u8 attr_content[100] = { 0x00 };
  4285. u8 *p2pie;
  4286. uint p2pielen = 0, attr_contentlen = 0;
  4287. _irqL irqL;
  4288. /* Commented by Albert 20110301 */
  4289. /* The input data contains two informations. */
  4290. /* 1. First information is the MAC address which wants to issue the provisioning discovery request frame. */
  4291. /* 2. Second information is the WPS configuration method which wants to discovery */
  4292. /* Format: 00:E0:4C:00:00:05_display */
  4293. /* Format: 00:E0:4C:00:00:05_keypad */
  4294. /* Format: 00:E0:4C:00:00:05_pbc */
  4295. /* Format: 00:E0:4C:00:00:05_label */
  4296. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4297. if (pwdinfo->p2p_state == P2P_STATE_NONE) {
  4298. RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
  4299. return ret;
  4300. } else {
  4301. #ifdef CONFIG_INTEL_WIDI
  4302. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  4303. RTW_INFO("[%s] WiFi is under survey!\n", __FUNCTION__);
  4304. return ret;
  4305. }
  4306. #endif /* CONFIG_INTEL_WIDI */
  4307. /* Reset the content of struct tx_provdisc_req_info excluded the wps_config_method_request. */
  4308. _rtw_memset(pwdinfo->tx_prov_disc_info.peerDevAddr, 0x00, ETH_ALEN);
  4309. _rtw_memset(pwdinfo->tx_prov_disc_info.peerIFAddr, 0x00, ETH_ALEN);
  4310. _rtw_memset(&pwdinfo->tx_prov_disc_info.ssid, 0x00, sizeof(NDIS_802_11_SSID));
  4311. pwdinfo->tx_prov_disc_info.peer_channel_num[0] = 0;
  4312. pwdinfo->tx_prov_disc_info.peer_channel_num[1] = 0;
  4313. pwdinfo->tx_prov_disc_info.benable = _FALSE;
  4314. }
  4315. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  4316. peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
  4317. if (_rtw_memcmp(&extra[18], "display", 7))
  4318. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
  4319. else if (_rtw_memcmp(&extra[18], "keypad", 7))
  4320. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
  4321. else if (_rtw_memcmp(&extra[18], "pbc", 3))
  4322. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  4323. else if (_rtw_memcmp(&extra[18], "label", 5))
  4324. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
  4325. else {
  4326. RTW_INFO("[%s] Unknown WPS config methodn", __FUNCTION__);
  4327. return ret ;
  4328. }
  4329. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4330. phead = get_list_head(queue);
  4331. plist = get_next(phead);
  4332. while (1) {
  4333. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  4334. break;
  4335. if (uintPeerChannel != 0)
  4336. break;
  4337. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4338. /* Commented by Albert 2011/05/18 */
  4339. /* Match the device address located in the P2P IE */
  4340. /* This is for the case that the P2P device address is not the same as the P2P interface address. */
  4341. p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
  4342. if (p2pie) {
  4343. while (p2pie) {
  4344. /* The P2P Device ID attribute is included in the Beacon frame. */
  4345. /* The P2P Device Info attribute is included in the probe response frame. */
  4346. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
  4347. /* Handle the P2P Device ID attribute of Beacon first */
  4348. if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
  4349. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4350. break;
  4351. }
  4352. } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
  4353. /* Handle the P2P Device Info attribute of probe response */
  4354. if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
  4355. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4356. break;
  4357. }
  4358. }
  4359. /* Get the next P2P IE */
  4360. p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
  4361. }
  4362. }
  4363. #ifdef CONFIG_INTEL_WIDI
  4364. /* Some Intel WiDi source may not provide P2P IE, */
  4365. /* so we could only compare mac addr by 802.11 Source Address */
  4366. if (pmlmepriv->widi_state == INTEL_WIDI_STATE_WFD_CONNECTION
  4367. && uintPeerChannel == 0) {
  4368. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
  4369. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4370. break;
  4371. }
  4372. }
  4373. #endif /* CONFIG_INTEL_WIDI */
  4374. plist = get_next(plist);
  4375. }
  4376. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4377. if (uintPeerChannel) {
  4378. #ifdef CONFIG_WFD
  4379. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  4380. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  4381. u8 *wfd_ie;
  4382. uint wfd_ielen = 0;
  4383. wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
  4384. if (wfd_ie) {
  4385. u8 *wfd_devinfo;
  4386. uint wfd_devlen;
  4387. RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
  4388. wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
  4389. if (wfd_devinfo) {
  4390. u16 wfd_devinfo_field = 0;
  4391. /* Commented by Albert 20120319 */
  4392. /* The first two bytes are the WFD device information field of WFD device information subelement. */
  4393. /* In big endian format. */
  4394. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  4395. if (wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL)
  4396. pwfd_info->peer_session_avail = _TRUE;
  4397. else
  4398. pwfd_info->peer_session_avail = _FALSE;
  4399. }
  4400. }
  4401. if (_FALSE == pwfd_info->peer_session_avail) {
  4402. RTW_INFO("[%s] WFD Session not avaiable!\n", __FUNCTION__);
  4403. goto exit;
  4404. }
  4405. }
  4406. #endif /* CONFIG_WFD */
  4407. RTW_INFO("[%s] peer channel: %d!\n", __FUNCTION__, uintPeerChannel);
  4408. #ifdef CONFIG_CONCURRENT_MODE
  4409. if (rtw_mi_check_status(padapter, MI_LINKED))
  4410. _cancel_timer_ex(&pwdinfo->ap_p2p_switch_timer);
  4411. #endif /* CONFIG_CONCURRENT_MODE */
  4412. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, pnetwork->network.MacAddress, ETH_ALEN);
  4413. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, peerMAC, ETH_ALEN);
  4414. pwdinfo->tx_prov_disc_info.peer_channel_num[0] = (u16) uintPeerChannel;
  4415. pwdinfo->tx_prov_disc_info.benable = _TRUE;
  4416. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  4417. rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ);
  4418. if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT))
  4419. _rtw_memcpy(&pwdinfo->tx_prov_disc_info.ssid, &pnetwork->network.Ssid, sizeof(NDIS_802_11_SSID));
  4420. else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
  4421. _rtw_memcpy(pwdinfo->tx_prov_disc_info.ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN);
  4422. pwdinfo->tx_prov_disc_info.ssid.SsidLength = P2P_WILDCARD_SSID_LEN;
  4423. }
  4424. #ifdef CONFIG_CONCURRENT_MODE
  4425. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  4426. u8 union_ch = rtw_mi_get_union_chan(padapter);
  4427. u8 union_bw = rtw_mi_get_union_bw(padapter);
  4428. u8 union_offset = rtw_mi_get_union_offset(padapter);
  4429. set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
  4430. rtw_leave_opch(padapter);
  4431. } else
  4432. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4433. #else
  4434. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4435. #endif
  4436. _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
  4437. #ifdef CONFIG_CONCURRENT_MODE
  4438. if (rtw_mi_check_status(padapter, MI_LINKED))
  4439. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_PROVISION_TIMEOUT);
  4440. else
  4441. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
  4442. #else
  4443. _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
  4444. #endif /* CONFIG_CONCURRENT_MODE */
  4445. } else {
  4446. RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
  4447. #ifdef CONFIG_INTEL_WIDI
  4448. _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
  4449. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  4450. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  4451. rtw_free_network_queue(padapter, _TRUE);
  4452. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  4453. rtw_sitesurvey_cmd(padapter, NULL);
  4454. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  4455. #endif /* CONFIG_INTEL_WIDI */
  4456. }
  4457. exit:
  4458. return ret;
  4459. }
  4460. /* Added by Albert 20110328
  4461. * This function is used to inform the driver the user had specified the pin code value or pbc
  4462. * to application. */
  4463. static int rtw_p2p_got_wpsinfo(struct net_device *dev,
  4464. struct iw_request_info *info,
  4465. union iwreq_data *wrqu, char *extra)
  4466. {
  4467. int ret = 0;
  4468. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4469. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  4470. RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
  4471. /* Added by Albert 20110328 */
  4472. /* if the input data is P2P_NO_WPSINFO -> reset the wpsinfo */
  4473. /* if the input data is P2P_GOT_WPSINFO_PEER_DISPLAY_PIN -> the utility just input the PIN code got from the peer P2P device. */
  4474. /* if the input data is P2P_GOT_WPSINFO_SELF_DISPLAY_PIN -> the utility just got the PIN code from itself. */
  4475. /* if the input data is P2P_GOT_WPSINFO_PBC -> the utility just determine to use the PBC */
  4476. if (*extra == '0')
  4477. pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
  4478. else if (*extra == '1')
  4479. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PEER_DISPLAY_PIN;
  4480. else if (*extra == '2')
  4481. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_SELF_DISPLAY_PIN;
  4482. else if (*extra == '3')
  4483. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PBC;
  4484. else
  4485. pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
  4486. return ret;
  4487. }
  4488. #endif /* CONFIG_P2P */
  4489. static int rtw_p2p_set(struct net_device *dev,
  4490. struct iw_request_info *info,
  4491. union iwreq_data *wrqu, char *extra)
  4492. {
  4493. int ret = 0;
  4494. #ifdef CONFIG_P2P
  4495. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4496. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
  4497. if (_rtw_memcmp(extra, "enable=", 7))
  4498. rtw_wext_p2p_enable(dev, info, wrqu, &extra[7]);
  4499. else if (_rtw_memcmp(extra, "setDN=", 6)) {
  4500. wrqu->data.length -= 6;
  4501. rtw_p2p_setDN(dev, info, wrqu, &extra[6]);
  4502. } else if (_rtw_memcmp(extra, "profilefound=", 13)) {
  4503. wrqu->data.length -= 13;
  4504. rtw_p2p_profilefound(dev, info, wrqu, &extra[13]);
  4505. } else if (_rtw_memcmp(extra, "prov_disc=", 10)) {
  4506. wrqu->data.length -= 10;
  4507. rtw_p2p_prov_disc(dev, info, wrqu, &extra[10]);
  4508. } else if (_rtw_memcmp(extra, "nego=", 5)) {
  4509. wrqu->data.length -= 5;
  4510. rtw_p2p_connect(dev, info, wrqu, &extra[5]);
  4511. } else if (_rtw_memcmp(extra, "intent=", 7)) {
  4512. /* Commented by Albert 2011/03/23 */
  4513. /* The wrqu->data.length will include the null character */
  4514. /* So, we will decrease 7 + 1 */
  4515. wrqu->data.length -= 8;
  4516. rtw_p2p_set_intent(dev, info, wrqu, &extra[7]);
  4517. } else if (_rtw_memcmp(extra, "ssid=", 5)) {
  4518. wrqu->data.length -= 5;
  4519. rtw_p2p_set_go_nego_ssid(dev, info, wrqu, &extra[5]);
  4520. } else if (_rtw_memcmp(extra, "got_wpsinfo=", 12)) {
  4521. wrqu->data.length -= 12;
  4522. rtw_p2p_got_wpsinfo(dev, info, wrqu, &extra[12]);
  4523. } else if (_rtw_memcmp(extra, "listen_ch=", 10)) {
  4524. /* Commented by Albert 2011/05/24 */
  4525. /* The wrqu->data.length will include the null character */
  4526. /* So, we will decrease (10 + 1) */
  4527. wrqu->data.length -= 11;
  4528. rtw_p2p_set_listen_ch(dev, info, wrqu, &extra[10]);
  4529. } else if (_rtw_memcmp(extra, "op_ch=", 6)) {
  4530. /* Commented by Albert 2011/05/24 */
  4531. /* The wrqu->data.length will include the null character */
  4532. /* So, we will decrease (6 + 1) */
  4533. wrqu->data.length -= 7;
  4534. rtw_p2p_set_op_ch(dev, info, wrqu, &extra[6]);
  4535. } else if (_rtw_memcmp(extra, "invite=", 7)) {
  4536. wrqu->data.length -= 8;
  4537. rtw_p2p_invite_req(dev, info, wrqu, &extra[7]);
  4538. } else if (_rtw_memcmp(extra, "persistent=", 11)) {
  4539. wrqu->data.length -= 11;
  4540. rtw_p2p_set_persistent(dev, info, wrqu, &extra[11]);
  4541. } else if (_rtw_memcmp(extra, "uuid=", 5)) {
  4542. wrqu->data.length -= 5;
  4543. ret = rtw_p2p_set_wps_uuid(dev, info, wrqu, &extra[5]);
  4544. }
  4545. #ifdef CONFIG_WFD
  4546. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  4547. if (_rtw_memcmp(extra, "sa=", 3)) {
  4548. /* sa: WFD Session Available information */
  4549. wrqu->data.length -= 3;
  4550. rtw_p2p_set_sa(dev, info, wrqu, &extra[3]);
  4551. } else if (_rtw_memcmp(extra, "pc=", 3)) {
  4552. /* pc: WFD Preferred Connection */
  4553. wrqu->data.length -= 3;
  4554. rtw_p2p_set_pc(dev, info, wrqu, &extra[3]);
  4555. } else if (_rtw_memcmp(extra, "wfd_type=", 9)) {
  4556. wrqu->data.length -= 9;
  4557. rtw_p2p_set_wfd_device_type(dev, info, wrqu, &extra[9]);
  4558. } else if (_rtw_memcmp(extra, "wfd_enable=", 11)) {
  4559. wrqu->data.length -= 11;
  4560. rtw_p2p_set_wfd_enable(dev, info, wrqu, &extra[11]);
  4561. } else if (_rtw_memcmp(extra, "driver_iface=", 13)) {
  4562. wrqu->data.length -= 13;
  4563. rtw_p2p_set_driver_iface(dev, info, wrqu, &extra[13]);
  4564. }
  4565. }
  4566. #endif /* CONFIG_WFD */
  4567. #endif /* CONFIG_P2P */
  4568. return ret;
  4569. }
  4570. static int rtw_p2p_get(struct net_device *dev,
  4571. struct iw_request_info *info,
  4572. union iwreq_data *wrqu, char *extra)
  4573. {
  4574. int ret = 0;
  4575. #ifdef CONFIG_P2P
  4576. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4577. if (padapter->bShowGetP2PState)
  4578. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, (char *) wrqu->data.pointer);
  4579. if (_rtw_memcmp(wrqu->data.pointer, "status", 6))
  4580. rtw_p2p_get_status(dev, info, wrqu, extra);
  4581. else if (_rtw_memcmp(wrqu->data.pointer, "role", 4))
  4582. rtw_p2p_get_role(dev, info, wrqu, extra);
  4583. else if (_rtw_memcmp(wrqu->data.pointer, "peer_ifa", 8))
  4584. rtw_p2p_get_peer_ifaddr(dev, info, wrqu, extra);
  4585. else if (_rtw_memcmp(wrqu->data.pointer, "req_cm", 6))
  4586. rtw_p2p_get_req_cm(dev, info, wrqu, extra);
  4587. else if (_rtw_memcmp(wrqu->data.pointer, "peer_deva", 9)) {
  4588. /* Get the P2P device address when receiving the provision discovery request frame. */
  4589. rtw_p2p_get_peer_devaddr(dev, info, wrqu, extra);
  4590. } else if (_rtw_memcmp(wrqu->data.pointer, "group_id", 8))
  4591. rtw_p2p_get_groupid(dev, info, wrqu, extra);
  4592. else if (_rtw_memcmp(wrqu->data.pointer, "inv_peer_deva", 13)) {
  4593. /* Get the P2P device address when receiving the P2P Invitation request frame. */
  4594. rtw_p2p_get_peer_devaddr_by_invitation(dev, info, wrqu, extra);
  4595. } else if (_rtw_memcmp(wrqu->data.pointer, "op_ch", 5))
  4596. rtw_p2p_get_op_ch(dev, info, wrqu, extra);
  4597. #ifdef CONFIG_WFD
  4598. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  4599. if (_rtw_memcmp(wrqu->data.pointer, "peer_port", 9))
  4600. rtw_p2p_get_peer_wfd_port(dev, info, wrqu, extra);
  4601. else if (_rtw_memcmp(wrqu->data.pointer, "wfd_sa", 6))
  4602. rtw_p2p_get_peer_wfd_session_available(dev, info, wrqu, extra);
  4603. else if (_rtw_memcmp(wrqu->data.pointer, "wfd_pc", 6))
  4604. rtw_p2p_get_peer_wfd_preferred_connection(dev, info, wrqu, extra);
  4605. }
  4606. #endif /* CONFIG_WFD */
  4607. #endif /* CONFIG_P2P */
  4608. return ret;
  4609. }
  4610. static int rtw_p2p_get2(struct net_device *dev,
  4611. struct iw_request_info *info,
  4612. union iwreq_data *wrqu, char *extra)
  4613. {
  4614. int ret = 0;
  4615. #ifdef CONFIG_P2P
  4616. int length = wrqu->data.length;
  4617. char *buffer = (u8 *)rtw_malloc(length);
  4618. if (buffer == NULL) {
  4619. ret = -ENOMEM;
  4620. goto bad;
  4621. }
  4622. if (copy_from_user(buffer, wrqu->data.pointer, wrqu->data.length)) {
  4623. ret = -EFAULT;
  4624. goto bad;
  4625. }
  4626. RTW_INFO("[%s] buffer = %s\n", __FUNCTION__, buffer);
  4627. if (_rtw_memcmp(buffer, "wpsCM=", 6))
  4628. ret = rtw_p2p_get_wps_configmethod(dev, info, wrqu, extra, &buffer[6]);
  4629. else if (_rtw_memcmp(buffer, "devN=", 5))
  4630. ret = rtw_p2p_get_device_name(dev, info, wrqu, extra, &buffer[5]);
  4631. else if (_rtw_memcmp(buffer, "dev_type=", 9))
  4632. ret = rtw_p2p_get_device_type(dev, info, wrqu, extra, &buffer[9]);
  4633. else if (_rtw_memcmp(buffer, "go_devadd=", 10))
  4634. ret = rtw_p2p_get_go_device_address(dev, info, wrqu, extra, &buffer[10]);
  4635. else if (_rtw_memcmp(buffer, "InvProc=", 8))
  4636. ret = rtw_p2p_get_invitation_procedure(dev, info, wrqu, extra, &buffer[8]);
  4637. else {
  4638. snprintf(extra, sizeof("Command not found."), "Command not found.");
  4639. wrqu->data.length = strlen(extra);
  4640. }
  4641. bad:
  4642. if (buffer)
  4643. rtw_mfree(buffer, length);
  4644. #endif /* CONFIG_P2P */
  4645. return ret;
  4646. }
  4647. static int rtw_cta_test_start(struct net_device *dev,
  4648. struct iw_request_info *info,
  4649. union iwreq_data *wrqu, char *extra)
  4650. {
  4651. int ret = 0;
  4652. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4653. HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
  4654. RTW_INFO("%s %s\n", __func__, extra);
  4655. if (!strcmp(extra, "1"))
  4656. hal_data->in_cta_test = 1;
  4657. else
  4658. hal_data->in_cta_test = 0;
  4659. rtw_hal_rcr_set_chk_bssid(padapter, MLME_ACTION_NONE);
  4660. return ret;
  4661. }
  4662. extern int rtw_change_ifname(_adapter *padapter, const char *ifname);
  4663. static int rtw_rereg_nd_name(struct net_device *dev,
  4664. struct iw_request_info *info,
  4665. union iwreq_data *wrqu, char *extra)
  4666. {
  4667. int ret = 0;
  4668. _adapter *padapter = rtw_netdev_priv(dev);
  4669. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  4670. struct rereg_nd_name_data *rereg_priv = &padapter->rereg_nd_name_priv;
  4671. char new_ifname[IFNAMSIZ];
  4672. if (rereg_priv->old_ifname[0] == 0) {
  4673. char *reg_ifname;
  4674. #ifdef CONFIG_CONCURRENT_MODE
  4675. if (padapter->isprimary)
  4676. reg_ifname = padapter->registrypriv.ifname;
  4677. else
  4678. #endif
  4679. reg_ifname = padapter->registrypriv.if2name;
  4680. strncpy(rereg_priv->old_ifname, reg_ifname, IFNAMSIZ);
  4681. rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
  4682. }
  4683. /* RTW_INFO("%s wrqu->data.length:%d\n", __FUNCTION__, wrqu->data.length); */
  4684. if (wrqu->data.length > IFNAMSIZ)
  4685. return -EFAULT;
  4686. if (copy_from_user(new_ifname, wrqu->data.pointer, IFNAMSIZ))
  4687. return -EFAULT;
  4688. if (0 == strcmp(rereg_priv->old_ifname, new_ifname))
  4689. return ret;
  4690. RTW_INFO("%s new_ifname:%s\n", __FUNCTION__, new_ifname);
  4691. rtw_set_rtnl_lock_holder(dvobj, current);
  4692. ret = rtw_change_ifname(padapter, new_ifname);
  4693. rtw_set_rtnl_lock_holder(dvobj, NULL);
  4694. if (0 != ret)
  4695. goto exit;
  4696. if (_rtw_memcmp(rereg_priv->old_ifname, "disable%d", 9) == _TRUE) {
  4697. /* rtw_ips_mode_req(&padapter->pwrctrlpriv, rereg_priv->old_ips_mode); */
  4698. }
  4699. strncpy(rereg_priv->old_ifname, new_ifname, IFNAMSIZ);
  4700. rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
  4701. if (_rtw_memcmp(new_ifname, "disable%d", 9) == _TRUE) {
  4702. RTW_INFO("%s disable\n", __FUNCTION__);
  4703. /* free network queue for Android's timming issue */
  4704. rtw_free_network_queue(padapter, _TRUE);
  4705. /* the interface is being "disabled", we can do deeper IPS */
  4706. /* rereg_priv->old_ips_mode = rtw_get_ips_mode_req(&padapter->pwrctrlpriv); */
  4707. /* rtw_ips_mode_req(&padapter->pwrctrlpriv, IPS_NORMAL); */
  4708. }
  4709. exit:
  4710. return ret;
  4711. }
  4712. #ifdef CONFIG_IOL
  4713. #include <rtw_iol.h>
  4714. #endif
  4715. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  4716. #include "../../hal/hal_dm_acs.h"
  4717. #endif
  4718. #ifdef DBG_CMD_QUEUE
  4719. u8 dump_cmd_id = 0;
  4720. #endif
  4721. static int rtw_dbg_port(struct net_device *dev,
  4722. struct iw_request_info *info,
  4723. union iwreq_data *wrqu, char *extra)
  4724. {
  4725. _irqL irqL;
  4726. int ret = 0;
  4727. u8 major_cmd, minor_cmd;
  4728. u16 arg;
  4729. u32 extra_arg, *pdata, val32;
  4730. struct sta_info *psta;
  4731. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4732. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4733. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  4734. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4735. struct security_priv *psecuritypriv = &padapter->securitypriv;
  4736. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  4737. struct sta_priv *pstapriv = &padapter->stapriv;
  4738. pdata = (u32 *)&wrqu->data;
  4739. val32 = *pdata;
  4740. arg = (u16)(val32 & 0x0000ffff);
  4741. major_cmd = (u8)(val32 >> 24);
  4742. minor_cmd = (u8)((val32 >> 16) & 0x00ff);
  4743. extra_arg = *(pdata + 1);
  4744. switch (major_cmd) {
  4745. case 0x70: /* read_reg */
  4746. switch (minor_cmd) {
  4747. case 1:
  4748. RTW_INFO("rtw_read8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
  4749. break;
  4750. case 2:
  4751. RTW_INFO("rtw_read16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
  4752. break;
  4753. case 4:
  4754. RTW_INFO("rtw_read32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
  4755. break;
  4756. }
  4757. break;
  4758. case 0x71: /* write_reg */
  4759. switch (minor_cmd) {
  4760. case 1:
  4761. rtw_write8(padapter, arg, extra_arg);
  4762. RTW_INFO("rtw_write8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
  4763. break;
  4764. case 2:
  4765. rtw_write16(padapter, arg, extra_arg);
  4766. RTW_INFO("rtw_write16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
  4767. break;
  4768. case 4:
  4769. rtw_write32(padapter, arg, extra_arg);
  4770. RTW_INFO("rtw_write32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
  4771. break;
  4772. }
  4773. break;
  4774. case 0x72: /* read_bb */
  4775. RTW_INFO("read_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
  4776. break;
  4777. case 0x73: /* write_bb */
  4778. rtw_hal_write_bbreg(padapter, arg, 0xffffffff, extra_arg);
  4779. RTW_INFO("write_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
  4780. break;
  4781. case 0x74: /* read_rf */
  4782. RTW_INFO("read RF_reg path(0x%02x),offset(0x%x),value(0x%08x)\n", minor_cmd, arg, rtw_hal_read_rfreg(padapter, minor_cmd, arg, 0xffffffff));
  4783. break;
  4784. case 0x75: /* write_rf */
  4785. rtw_hal_write_rfreg(padapter, minor_cmd, arg, 0xffffffff, extra_arg);
  4786. RTW_INFO("write RF_reg path(0x%02x),offset(0x%x),value(0x%08x)\n", minor_cmd, arg, rtw_hal_read_rfreg(padapter, minor_cmd, arg, 0xffffffff));
  4787. break;
  4788. case 0x76:
  4789. switch (minor_cmd) {
  4790. case 0x00: /* normal mode, */
  4791. padapter->recvpriv.is_signal_dbg = 0;
  4792. break;
  4793. case 0x01: /* dbg mode */
  4794. padapter->recvpriv.is_signal_dbg = 1;
  4795. extra_arg = extra_arg > 100 ? 100 : extra_arg;
  4796. padapter->recvpriv.signal_strength_dbg = extra_arg;
  4797. break;
  4798. }
  4799. break;
  4800. case 0x78: /* IOL test */
  4801. switch (minor_cmd) {
  4802. #ifdef CONFIG_IOL
  4803. case 0x04: { /* LLT table initialization test */
  4804. u8 page_boundary = 0xf9;
  4805. {
  4806. struct xmit_frame *xmit_frame;
  4807. xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
  4808. if (xmit_frame == NULL) {
  4809. ret = -ENOMEM;
  4810. break;
  4811. }
  4812. rtw_IOL_append_LLT_cmd(xmit_frame, page_boundary);
  4813. if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 500, 0))
  4814. ret = -EPERM;
  4815. }
  4816. }
  4817. break;
  4818. case 0x05: { /* blink LED test */
  4819. u16 reg = 0x4c;
  4820. u32 blink_num = 50;
  4821. u32 blink_delay_ms = 200;
  4822. int i;
  4823. {
  4824. struct xmit_frame *xmit_frame;
  4825. xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
  4826. if (xmit_frame == NULL) {
  4827. ret = -ENOMEM;
  4828. break;
  4829. }
  4830. for (i = 0; i < blink_num; i++) {
  4831. #ifdef CONFIG_IOL_NEW_GENERATION
  4832. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00, 0xff);
  4833. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  4834. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08, 0xff);
  4835. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  4836. #else
  4837. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00);
  4838. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  4839. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08);
  4840. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  4841. #endif
  4842. }
  4843. if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, (blink_delay_ms * blink_num * 2) + 200, 0))
  4844. ret = -EPERM;
  4845. }
  4846. }
  4847. break;
  4848. case 0x06: { /* continuous wirte byte test */
  4849. u16 reg = arg;
  4850. u16 start_value = 0;
  4851. u32 write_num = extra_arg;
  4852. int i;
  4853. u8 final;
  4854. {
  4855. struct xmit_frame *xmit_frame;
  4856. xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
  4857. if (xmit_frame == NULL) {
  4858. ret = -ENOMEM;
  4859. break;
  4860. }
  4861. for (i = 0; i < write_num; i++) {
  4862. #ifdef CONFIG_IOL_NEW_GENERATION
  4863. rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value, 0xFF);
  4864. #else
  4865. rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value);
  4866. #endif
  4867. }
  4868. if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
  4869. ret = -EPERM;
  4870. }
  4871. final = rtw_read8(padapter, reg);
  4872. if (start_value + write_num - 1 == final)
  4873. RTW_INFO("continuous IOL_CMD_WB_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  4874. else
  4875. RTW_INFO("continuous IOL_CMD_WB_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  4876. }
  4877. break;
  4878. case 0x07: { /* continuous wirte word test */
  4879. u16 reg = arg;
  4880. u16 start_value = 200;
  4881. u32 write_num = extra_arg;
  4882. int i;
  4883. u16 final;
  4884. {
  4885. struct xmit_frame *xmit_frame;
  4886. xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
  4887. if (xmit_frame == NULL) {
  4888. ret = -ENOMEM;
  4889. break;
  4890. }
  4891. for (i = 0; i < write_num; i++) {
  4892. #ifdef CONFIG_IOL_NEW_GENERATION
  4893. rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value, 0xFFFF);
  4894. #else
  4895. rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value);
  4896. #endif
  4897. }
  4898. if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
  4899. ret = -EPERM;
  4900. }
  4901. final = rtw_read16(padapter, reg);
  4902. if (start_value + write_num - 1 == final)
  4903. RTW_INFO("continuous IOL_CMD_WW_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  4904. else
  4905. RTW_INFO("continuous IOL_CMD_WW_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  4906. }
  4907. break;
  4908. case 0x08: { /* continuous wirte dword test */
  4909. u16 reg = arg;
  4910. u32 start_value = 0x110000c7;
  4911. u32 write_num = extra_arg;
  4912. int i;
  4913. u32 final;
  4914. {
  4915. struct xmit_frame *xmit_frame;
  4916. xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
  4917. if (xmit_frame == NULL) {
  4918. ret = -ENOMEM;
  4919. break;
  4920. }
  4921. for (i = 0; i < write_num; i++) {
  4922. #ifdef CONFIG_IOL_NEW_GENERATION
  4923. rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value, 0xFFFFFFFF);
  4924. #else
  4925. rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value);
  4926. #endif
  4927. }
  4928. if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
  4929. ret = -EPERM;
  4930. }
  4931. final = rtw_read32(padapter, reg);
  4932. if (start_value + write_num - 1 == final)
  4933. RTW_INFO("continuous IOL_CMD_WD_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  4934. else
  4935. RTW_INFO("continuous IOL_CMD_WD_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  4936. }
  4937. break;
  4938. #endif /* CONFIG_IOL */
  4939. }
  4940. break;
  4941. case 0x79: {
  4942. /*
  4943. * dbg 0x79000000 [value], set RESP_TXAGC to + value, value:0~15
  4944. * dbg 0x79010000 [value], set RESP_TXAGC to - value, value:0~15
  4945. */
  4946. u8 value = extra_arg & 0x0f;
  4947. u8 sign = minor_cmd;
  4948. u16 write_value = 0;
  4949. RTW_INFO("%s set RESP_TXAGC to %s %u\n", __func__, sign ? "minus" : "plus", value);
  4950. if (sign)
  4951. value = value | 0x10;
  4952. write_value = value | (value << 5);
  4953. rtw_write16(padapter, 0x6d9, write_value);
  4954. }
  4955. break;
  4956. case 0x7a:
  4957. receive_disconnect(padapter, pmlmeinfo->network.MacAddress
  4958. , WLAN_REASON_EXPIRATION_CHK, _FALSE);
  4959. break;
  4960. case 0x7F:
  4961. switch (minor_cmd) {
  4962. case 0x0:
  4963. RTW_INFO("fwstate=0x%x\n", get_fwstate(pmlmepriv));
  4964. break;
  4965. case 0x01:
  4966. RTW_INFO("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
  4967. psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
  4968. psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
  4969. break;
  4970. case 0x03:
  4971. RTW_INFO("qos_option=%d\n", pmlmepriv->qospriv.qos_option);
  4972. #ifdef CONFIG_80211N_HT
  4973. RTW_INFO("ht_option=%d\n", pmlmepriv->htpriv.ht_option);
  4974. #endif /* CONFIG_80211N_HT */
  4975. break;
  4976. case 0x04:
  4977. RTW_INFO("cur_ch=%d\n", pmlmeext->cur_channel);
  4978. RTW_INFO("cur_bw=%d\n", pmlmeext->cur_bwmode);
  4979. RTW_INFO("cur_ch_off=%d\n", pmlmeext->cur_ch_offset);
  4980. RTW_INFO("oper_ch=%d\n", rtw_get_oper_ch(padapter));
  4981. RTW_INFO("oper_bw=%d\n", rtw_get_oper_bw(padapter));
  4982. RTW_INFO("oper_ch_offet=%d\n", rtw_get_oper_choffset(padapter));
  4983. break;
  4984. case 0x05:
  4985. psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
  4986. if (psta) {
  4987. RTW_INFO("SSID=%s\n", cur_network->network.Ssid.Ssid);
  4988. RTW_INFO("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->cmn.mac_addr));
  4989. RTW_INFO("cur_channel=%d, cur_bwmode=%d, cur_ch_offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
  4990. RTW_INFO("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
  4991. RTW_INFO("state=0x%x, aid=%d, macid=%d, raid=%d\n",
  4992. psta->state, psta->cmn.aid, psta->cmn.mac_id, psta->cmn.ra_info.rate_id);
  4993. #ifdef CONFIG_80211N_HT
  4994. RTW_INFO("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
  4995. RTW_INFO("bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n"
  4996. , psta->cmn.bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m, psta->htpriv.sgi_40m);
  4997. RTW_INFO("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
  4998. RTW_INFO("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
  4999. #endif /* CONFIG_80211N_HT */
  5000. sta_rx_reorder_ctl_dump(RTW_DBGDUMP, psta);
  5001. } else
  5002. RTW_INFO("can't get sta's macaddr, cur_network's macaddr:" MAC_FMT "\n", MAC_ARG(cur_network->network.MacAddress));
  5003. break;
  5004. case 0x06: {
  5005. u64 tsf = 0;
  5006. tsf = rtw_hal_get_tsftr_by_port(padapter, extra_arg);
  5007. RTW_INFO(" PORT-%d TSF :%21lld\n", extra_arg, tsf);
  5008. }
  5009. break;
  5010. case 0x07:
  5011. RTW_INFO("bSurpriseRemoved=%s, bDriverStopped=%s\n"
  5012. , rtw_is_surprise_removed(padapter) ? "True" : "False"
  5013. , rtw_is_drv_stopped(padapter) ? "True" : "False");
  5014. break;
  5015. case 0x08: {
  5016. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  5017. struct recv_priv *precvpriv = &padapter->recvpriv;
  5018. RTW_INFO("free_xmitbuf_cnt=%d, free_xmitframe_cnt=%d"
  5019. ", free_xmit_extbuf_cnt=%d, free_xframe_ext_cnt=%d"
  5020. ", free_recvframe_cnt=%d\n",
  5021. pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt,
  5022. pxmitpriv->free_xmit_extbuf_cnt, pxmitpriv->free_xframe_ext_cnt,
  5023. precvpriv->free_recvframe_cnt);
  5024. #ifdef CONFIG_USB_HCI
  5025. RTW_INFO("rx_urb_pending_cn=%d\n", ATOMIC_READ(&(precvpriv->rx_pending_cnt)));
  5026. #endif
  5027. }
  5028. break;
  5029. case 0x09: {
  5030. int i;
  5031. _list *plist, *phead;
  5032. #ifdef CONFIG_AP_MODE
  5033. RTW_INFO_DUMP("sta_dz_bitmap:", pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
  5034. RTW_INFO_DUMP("tim_bitmap:", pstapriv->tim_bitmap, pstapriv->aid_bmp_len);
  5035. #endif
  5036. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  5037. for (i = 0; i < NUM_STA; i++) {
  5038. phead = &(pstapriv->sta_hash[i]);
  5039. plist = get_next(phead);
  5040. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  5041. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  5042. plist = get_next(plist);
  5043. if (extra_arg == psta->cmn.aid) {
  5044. RTW_INFO("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->cmn.mac_addr));
  5045. RTW_INFO("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
  5046. RTW_INFO("state=0x%x, aid=%d, macid=%d, raid=%d\n",
  5047. psta->state, psta->cmn.aid, psta->cmn.mac_id, psta->cmn.ra_info.rate_id);
  5048. #ifdef CONFIG_80211N_HT
  5049. RTW_INFO("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
  5050. RTW_INFO("bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n",
  5051. psta->cmn.bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m,
  5052. psta->htpriv.sgi_40m);
  5053. RTW_INFO("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
  5054. RTW_INFO("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
  5055. #endif /* CONFIG_80211N_HT */
  5056. #ifdef CONFIG_AP_MODE
  5057. RTW_INFO("capability=0x%x\n", psta->capability);
  5058. RTW_INFO("flags=0x%x\n", psta->flags);
  5059. RTW_INFO("wpa_psk=0x%x\n", psta->wpa_psk);
  5060. RTW_INFO("wpa2_group_cipher=0x%x\n", psta->wpa2_group_cipher);
  5061. RTW_INFO("wpa2_pairwise_cipher=0x%x\n", psta->wpa2_pairwise_cipher);
  5062. RTW_INFO("qos_info=0x%x\n", psta->qos_info);
  5063. #endif
  5064. RTW_INFO("dot118021XPrivacy=0x%x\n", psta->dot118021XPrivacy);
  5065. sta_rx_reorder_ctl_dump(RTW_DBGDUMP, psta);
  5066. }
  5067. }
  5068. }
  5069. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  5070. }
  5071. break;
  5072. case 0x0b: { /* Enable=1, Disable=0 driver control vrtl_carrier_sense. */
  5073. /* u8 driver_vcs_en; */ /* Enable=1, Disable=0 driver control vrtl_carrier_sense. */
  5074. /* u8 driver_vcs_type; */ /* force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en=1. */
  5075. if (arg == 0) {
  5076. RTW_INFO("disable driver ctrl vcs\n");
  5077. padapter->driver_vcs_en = 0;
  5078. } else if (arg == 1) {
  5079. RTW_INFO("enable driver ctrl vcs = %d\n", extra_arg);
  5080. padapter->driver_vcs_en = 1;
  5081. if (extra_arg > 2)
  5082. padapter->driver_vcs_type = 1;
  5083. else
  5084. padapter->driver_vcs_type = extra_arg;
  5085. }
  5086. }
  5087. break;
  5088. case 0x0c: { /* dump rx/tx packet */
  5089. if (arg == 0) {
  5090. RTW_INFO("dump rx packet (%d)\n", extra_arg);
  5091. /* pHalData->bDumpRxPkt =extra_arg; */
  5092. rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_RXPKT, &(extra_arg));
  5093. } else if (arg == 1) {
  5094. RTW_INFO("dump tx packet (%d)\n", extra_arg);
  5095. rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_TXPKT, &(extra_arg));
  5096. }
  5097. }
  5098. break;
  5099. case 0x0e: {
  5100. if (arg == 0) {
  5101. RTW_INFO("disable driver ctrl rx_ampdu_factor\n");
  5102. padapter->driver_rx_ampdu_factor = 0xFF;
  5103. } else if (arg == 1) {
  5104. RTW_INFO("enable driver ctrl rx_ampdu_factor = %d\n", extra_arg);
  5105. if (extra_arg > 0x03)
  5106. padapter->driver_rx_ampdu_factor = 0xFF;
  5107. else
  5108. padapter->driver_rx_ampdu_factor = extra_arg;
  5109. }
  5110. }
  5111. break;
  5112. #ifdef DBG_CONFIG_ERROR_DETECT
  5113. case 0x0f: {
  5114. if (extra_arg == 0) {
  5115. RTW_INFO("###### silent reset test.......#####\n");
  5116. rtw_hal_sreset_reset(padapter);
  5117. } else {
  5118. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  5119. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  5120. psrtpriv->dbg_trigger_point = extra_arg;
  5121. }
  5122. }
  5123. break;
  5124. case 0x15: {
  5125. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  5126. RTW_INFO("==>silent resete cnts:%d\n", pwrpriv->ips_enter_cnts);
  5127. }
  5128. break;
  5129. #endif
  5130. case 0x10: /* driver version display */
  5131. dump_drv_version(RTW_DBGDUMP);
  5132. break;
  5133. case 0x11: { /* dump linked status */
  5134. int pre_mode;
  5135. pre_mode = padapter->bLinkInfoDump;
  5136. /* linked_info_dump(padapter,extra_arg); */
  5137. if (extra_arg == 1 || (extra_arg == 0 && pre_mode == 1)) /* not consider pwr_saving 0: */
  5138. padapter->bLinkInfoDump = extra_arg;
  5139. else if ((extra_arg == 2) || (extra_arg == 0 && pre_mode == 2)) { /* consider power_saving */
  5140. /* RTW_INFO("linked_info_dump =%s\n", (padapter->bLinkInfoDump)?"enable":"disable") */
  5141. linked_info_dump(padapter, extra_arg);
  5142. }
  5143. }
  5144. break;
  5145. #ifdef CONFIG_80211N_HT
  5146. case 0x12: { /* set rx_stbc */
  5147. struct registry_priv *pregpriv = &padapter->registrypriv;
  5148. /* 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, 0x3: enable both 2.4g and 5g */
  5149. /* default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ */
  5150. if (pregpriv && (extra_arg == 0 || extra_arg == 1 || extra_arg == 2 || extra_arg == 3)) {
  5151. pregpriv->rx_stbc = extra_arg;
  5152. RTW_INFO("set rx_stbc=%d\n", pregpriv->rx_stbc);
  5153. } else
  5154. RTW_INFO("get rx_stbc=%d\n", pregpriv->rx_stbc);
  5155. }
  5156. break;
  5157. case 0x13: { /* set ampdu_enable */
  5158. struct registry_priv *pregpriv = &padapter->registrypriv;
  5159. /* 0: disable, 0x1:enable */
  5160. if (pregpriv && extra_arg < 2) {
  5161. pregpriv->ampdu_enable = extra_arg;
  5162. RTW_INFO("set ampdu_enable=%d\n", pregpriv->ampdu_enable);
  5163. } else
  5164. RTW_INFO("get ampdu_enable=%d\n", pregpriv->ampdu_enable);
  5165. }
  5166. break;
  5167. #endif
  5168. case 0x14: { /* get wifi_spec */
  5169. struct registry_priv *pregpriv = &padapter->registrypriv;
  5170. RTW_INFO("get wifi_spec=%d\n", pregpriv->wifi_spec);
  5171. }
  5172. break;
  5173. #ifdef DBG_FIXED_CHAN
  5174. case 0x17: {
  5175. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5176. printk("===> Fixed channel to %d\n", extra_arg);
  5177. pmlmeext->fixed_chan = extra_arg;
  5178. }
  5179. break;
  5180. #endif
  5181. #ifdef CONFIG_80211N_HT
  5182. case 0x19: {
  5183. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  5184. /* extra_arg : */
  5185. /* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, */
  5186. /* BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */
  5187. if (arg == 0) {
  5188. RTW_INFO("driver disable LDPC\n");
  5189. pregistrypriv->ldpc_cap = 0x00;
  5190. } else if (arg == 1) {
  5191. RTW_INFO("driver set LDPC cap = 0x%x\n", extra_arg);
  5192. pregistrypriv->ldpc_cap = (u8)(extra_arg & 0x33);
  5193. }
  5194. }
  5195. break;
  5196. case 0x1a: {
  5197. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  5198. /* extra_arg : */
  5199. /* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, */
  5200. /* BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */
  5201. if (arg == 0) {
  5202. RTW_INFO("driver disable STBC\n");
  5203. pregistrypriv->stbc_cap = 0x00;
  5204. } else if (arg == 1) {
  5205. RTW_INFO("driver set STBC cap = 0x%x\n", extra_arg);
  5206. pregistrypriv->stbc_cap = (u8)(extra_arg & 0x33);
  5207. }
  5208. }
  5209. break;
  5210. #endif /* CONFIG_80211N_HT */
  5211. case 0x1b: {
  5212. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  5213. if (arg == 0) {
  5214. RTW_INFO("disable driver ctrl max_rx_rate, reset to default_rate_set\n");
  5215. init_mlme_default_rate_set(padapter);
  5216. #ifdef CONFIG_80211N_HT
  5217. pregistrypriv->ht_enable = (u8)rtw_ht_enable;
  5218. #endif /* CONFIG_80211N_HT */
  5219. } else if (arg == 1) {
  5220. int i;
  5221. u8 max_rx_rate;
  5222. RTW_INFO("enable driver ctrl max_rx_rate = 0x%x\n", extra_arg);
  5223. max_rx_rate = (u8)extra_arg;
  5224. if (max_rx_rate < 0xc) { /* max_rx_rate < MSC0->B or G -> disable HT */
  5225. #ifdef CONFIG_80211N_HT
  5226. pregistrypriv->ht_enable = 0;
  5227. #endif /* CONFIG_80211N_HT */
  5228. for (i = 0; i < NumRates; i++) {
  5229. if (pmlmeext->datarate[i] > max_rx_rate)
  5230. pmlmeext->datarate[i] = 0xff;
  5231. }
  5232. }
  5233. #ifdef CONFIG_80211N_HT
  5234. else if (max_rx_rate < 0x1c) { /* mcs0~mcs15 */
  5235. u32 mcs_bitmap = 0x0;
  5236. for (i = 0; i < ((max_rx_rate + 1) - 0xc); i++)
  5237. mcs_bitmap |= BIT(i);
  5238. set_mcs_rate_by_mask(pmlmeext->default_supported_mcs_set, mcs_bitmap);
  5239. }
  5240. #endif /* CONFIG_80211N_HT */
  5241. }
  5242. }
  5243. break;
  5244. case 0x1c: { /* enable/disable driver control AMPDU Density for peer sta's rx */
  5245. if (arg == 0) {
  5246. RTW_INFO("disable driver ctrl ampdu density\n");
  5247. padapter->driver_ampdu_spacing = 0xFF;
  5248. } else if (arg == 1) {
  5249. RTW_INFO("enable driver ctrl ampdu density = %d\n", extra_arg);
  5250. if (extra_arg > 0x07)
  5251. padapter->driver_ampdu_spacing = 0xFF;
  5252. else
  5253. padapter->driver_ampdu_spacing = extra_arg;
  5254. }
  5255. }
  5256. break;
  5257. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  5258. case 0x1e: {
  5259. RTW_INFO("===========================================\n");
  5260. rtw_noise_measure_curchan(padapter);
  5261. RTW_INFO("===========================================\n");
  5262. }
  5263. break;
  5264. #endif
  5265. #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_SDIO_INDIRECT_ACCESS) && defined(DBG_SDIO_INDIRECT_ACCESS)
  5266. case 0x1f:
  5267. {
  5268. int i, j = 0, test_cnts = 0;
  5269. static u8 test_code = 0x5A;
  5270. static u32 data_misatch_cnt = 0, d_acc_err_cnt = 0;
  5271. u32 d_data, i_data;
  5272. u32 imr;
  5273. test_cnts = extra_arg;
  5274. for (i = 0; i < test_cnts; i++) {
  5275. if (RTW_CANNOT_IO(padapter))
  5276. break;
  5277. rtw_write8(padapter, 0x07, test_code);
  5278. d_data = rtw_read32(padapter, 0x04);
  5279. imr = rtw_read32(padapter, 0x10250014);
  5280. rtw_write32(padapter, 0x10250014, 0);
  5281. rtw_msleep_os(50);
  5282. i_data = rtw_sd_iread32(padapter, 0x04);
  5283. rtw_write32(padapter, 0x10250014, imr);
  5284. if (d_data != i_data) {
  5285. data_misatch_cnt++;
  5286. RTW_ERR("d_data :0x%08x, i_data : 0x%08x\n", d_data, i_data);
  5287. }
  5288. if (test_code != (i_data >> 24)) {
  5289. d_acc_err_cnt++;
  5290. rtw_write8(padapter, 0x07, 0xAA);
  5291. RTW_ERR("test_code :0x%02x, i_data : 0x%08x\n", test_code, i_data);
  5292. }
  5293. if ((j++) == 100) {
  5294. rtw_msleep_os(2000);
  5295. RTW_INFO(" Indirect access testing..........%d/%d\n", i, test_cnts);
  5296. j = 0;
  5297. }
  5298. test_code = ~test_code;
  5299. rtw_msleep_os(50);
  5300. }
  5301. RTW_INFO("========Indirect access test=========\n");
  5302. RTW_INFO(" test_cnts = %d\n", test_cnts);
  5303. RTW_INFO(" direct & indirect read32 data missatch cnts = %d\n", data_misatch_cnt);
  5304. RTW_INFO(" indirect rdata is not equal to wdata cnts = %d\n", d_acc_err_cnt);
  5305. RTW_INFO("========Indirect access test=========\n\n");
  5306. data_misatch_cnt = d_acc_err_cnt = 0;
  5307. }
  5308. break;
  5309. #endif
  5310. case 0x20:
  5311. {
  5312. if (arg == 0xAA) {
  5313. u8 page_offset, page_num;
  5314. page_offset = (u8)(extra_arg >> 16);
  5315. page_num = (u8)(extra_arg & 0xFF);
  5316. rtw_dump_rsvd_page(RTW_DBGDUMP, padapter, page_offset, page_num);
  5317. }
  5318. #ifdef CONFIG_SUPPORT_FIFO_DUMP
  5319. else {
  5320. u8 fifo_sel;
  5321. u32 addr, size;
  5322. fifo_sel = (u8)(arg & 0x0F);
  5323. addr = (extra_arg >> 16) & 0xFFFF;
  5324. size = extra_arg & 0xFFFF;
  5325. rtw_dump_fifo(RTW_DBGDUMP, padapter, fifo_sel, addr, size);
  5326. }
  5327. #endif
  5328. }
  5329. break;
  5330. case 0x23: {
  5331. RTW_INFO("turn %s the bNotifyChannelChange Variable\n", (extra_arg == 1) ? "on" : "off");
  5332. padapter->bNotifyChannelChange = extra_arg;
  5333. break;
  5334. }
  5335. case 0x24: {
  5336. #ifdef CONFIG_P2P
  5337. RTW_INFO("turn %s the bShowGetP2PState Variable\n", (extra_arg == 1) ? "on" : "off");
  5338. padapter->bShowGetP2PState = extra_arg;
  5339. #endif /* CONFIG_P2P */
  5340. break;
  5341. }
  5342. #ifdef CONFIG_GPIO_API
  5343. case 0x25: { /* Get GPIO register */
  5344. /*
  5345. * dbg 0x7f250000 [gpio_num], Get gpio value, gpio_num:0~7
  5346. */
  5347. u8 value;
  5348. RTW_INFO("Read GPIO Value extra_arg = %d\n", extra_arg);
  5349. value = rtw_hal_get_gpio(padapter, extra_arg);
  5350. RTW_INFO("Read GPIO Value = %d\n", value);
  5351. break;
  5352. }
  5353. case 0x26: { /* Set GPIO direction */
  5354. /* dbg 0x7f26000x [y], Set gpio direction,
  5355. * x: gpio_num,4~7 y: indicate direction, 0~1
  5356. */
  5357. int value;
  5358. RTW_INFO("Set GPIO Direction! arg = %d ,extra_arg=%d\n", arg , extra_arg);
  5359. value = rtw_hal_config_gpio(padapter, arg, extra_arg);
  5360. RTW_INFO("Set GPIO Direction %s\n", (value == -1) ? "Fail!!!" : "Success");
  5361. break;
  5362. }
  5363. case 0x27: { /* Set GPIO output direction value */
  5364. /*
  5365. * dbg 0x7f27000x [y], Set gpio output direction value,
  5366. * x: gpio_num,4~7 y: indicate direction, 0~1
  5367. */
  5368. int value;
  5369. RTW_INFO("Set GPIO Value! arg = %d ,extra_arg=%d\n", arg , extra_arg);
  5370. value = rtw_hal_set_gpio_output_value(padapter, arg, extra_arg);
  5371. RTW_INFO("Set GPIO Value %s\n", (value == -1) ? "Fail!!!" : "Success");
  5372. break;
  5373. }
  5374. #endif
  5375. #ifdef DBG_CMD_QUEUE
  5376. case 0x28: {
  5377. dump_cmd_id = extra_arg;
  5378. RTW_INFO("dump_cmd_id:%d\n", dump_cmd_id);
  5379. }
  5380. break;
  5381. #endif /* DBG_CMD_QUEUE */
  5382. case 0xaa: {
  5383. if ((extra_arg & 0x7F) > 0x3F)
  5384. extra_arg = 0xFF;
  5385. RTW_INFO("chang data rate to :0x%02x\n", extra_arg);
  5386. padapter->fix_rate = extra_arg;
  5387. }
  5388. break;
  5389. case 0xdd: { /* registers dump , 0 for mac reg,1 for bb reg, 2 for rf reg */
  5390. if (extra_arg == 0)
  5391. mac_reg_dump(RTW_DBGDUMP, padapter);
  5392. else if (extra_arg == 1)
  5393. bb_reg_dump(RTW_DBGDUMP, padapter);
  5394. else if (extra_arg == 2)
  5395. rf_reg_dump(RTW_DBGDUMP, padapter);
  5396. else if (extra_arg == 11)
  5397. bb_reg_dump_ex(RTW_DBGDUMP, padapter);
  5398. }
  5399. break;
  5400. case 0xee: {
  5401. RTW_INFO(" === please control /proc to trun on/off PHYDM func ===\n");
  5402. }
  5403. break;
  5404. case 0xfd:
  5405. rtw_write8(padapter, 0xc50, arg);
  5406. RTW_INFO("wr(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
  5407. rtw_write8(padapter, 0xc58, arg);
  5408. RTW_INFO("wr(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
  5409. break;
  5410. case 0xfe:
  5411. RTW_INFO("rd(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
  5412. RTW_INFO("rd(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
  5413. break;
  5414. case 0xff: {
  5415. RTW_INFO("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
  5416. RTW_INFO("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
  5417. RTW_INFO("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
  5418. RTW_INFO("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
  5419. RTW_INFO("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
  5420. RTW_INFO("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
  5421. RTW_INFO("\n");
  5422. RTW_INFO("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
  5423. RTW_INFO("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
  5424. RTW_INFO("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
  5425. RTW_INFO("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
  5426. RTW_INFO("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
  5427. RTW_INFO("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
  5428. RTW_INFO("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
  5429. RTW_INFO("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
  5430. RTW_INFO("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
  5431. RTW_INFO("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
  5432. }
  5433. break;
  5434. }
  5435. break;
  5436. default:
  5437. RTW_INFO("error dbg cmd!\n");
  5438. break;
  5439. }
  5440. return ret;
  5441. }
  5442. static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
  5443. {
  5444. uint ret = 0;
  5445. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5446. switch (name) {
  5447. case IEEE_PARAM_WPA_ENABLED:
  5448. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; /* 802.1x */
  5449. /* ret = ieee80211_wpa_enable(ieee, value); */
  5450. switch ((value) & 0xff) {
  5451. case 1: /* WPA */
  5452. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; /* WPA_PSK */
  5453. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  5454. break;
  5455. case 2: /* WPA2 */
  5456. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; /* WPA2_PSK */
  5457. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  5458. break;
  5459. }
  5460. break;
  5461. case IEEE_PARAM_TKIP_COUNTERMEASURES:
  5462. /* ieee->tkip_countermeasures=value; */
  5463. break;
  5464. case IEEE_PARAM_DROP_UNENCRYPTED: {
  5465. /* HACK:
  5466. *
  5467. * wpa_supplicant calls set_wpa_enabled when the driver
  5468. * is loaded and unloaded, regardless of if WPA is being
  5469. * used. No other calls are made which can be used to
  5470. * determine if encryption will be used or not prior to
  5471. * association being expected. If encryption is not being
  5472. * used, drop_unencrypted is set to false, else true -- we
  5473. * can use this to determine if the CAP_PRIVACY_ON bit should
  5474. * be set.
  5475. */
  5476. #if 0
  5477. struct ieee80211_security sec = {
  5478. .flags = SEC_ENABLED,
  5479. .enabled = value,
  5480. };
  5481. ieee->drop_unencrypted = value;
  5482. /* We only change SEC_LEVEL for open mode. Others
  5483. * are set by ipw_wpa_set_encryption.
  5484. */
  5485. if (!value) {
  5486. sec.flags |= SEC_LEVEL;
  5487. sec.level = SEC_LEVEL_0;
  5488. } else {
  5489. sec.flags |= SEC_LEVEL;
  5490. sec.level = SEC_LEVEL_1;
  5491. }
  5492. if (ieee->set_security)
  5493. ieee->set_security(ieee->dev, &sec);
  5494. #endif
  5495. break;
  5496. }
  5497. case IEEE_PARAM_PRIVACY_INVOKED:
  5498. /* ieee->privacy_invoked=value; */
  5499. break;
  5500. case IEEE_PARAM_AUTH_ALGS:
  5501. ret = wpa_set_auth_algs(dev, value);
  5502. break;
  5503. case IEEE_PARAM_IEEE_802_1X:
  5504. /* ieee->ieee802_1x=value; */
  5505. break;
  5506. case IEEE_PARAM_WPAX_SELECT:
  5507. /* added for WPA2 mixed mode */
  5508. /*RTW_WARN("------------------------>wpax value = %x\n", value);*/
  5509. /*
  5510. spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
  5511. ieee->wpax_type_set = 1;
  5512. ieee->wpax_type_notify = value;
  5513. spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
  5514. */
  5515. break;
  5516. default:
  5517. ret = -EOPNOTSUPP;
  5518. break;
  5519. }
  5520. return ret;
  5521. }
  5522. static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
  5523. {
  5524. int ret = 0;
  5525. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5526. switch (command) {
  5527. case IEEE_MLME_STA_DEAUTH:
  5528. if (!rtw_set_802_11_disassociate(padapter))
  5529. ret = -1;
  5530. break;
  5531. case IEEE_MLME_STA_DISASSOC:
  5532. if (!rtw_set_802_11_disassociate(padapter))
  5533. ret = -1;
  5534. break;
  5535. default:
  5536. ret = -EOPNOTSUPP;
  5537. break;
  5538. }
  5539. #ifdef CONFIG_RTW_REPEATER_SON
  5540. rtw_rson_do_disconnect(padapter);
  5541. #endif
  5542. return ret;
  5543. }
  5544. static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
  5545. {
  5546. struct ieee_param *param;
  5547. uint ret = 0;
  5548. /* down(&ieee->wx_sem); */
  5549. if (p->length < sizeof(struct ieee_param) || !p->pointer) {
  5550. ret = -EINVAL;
  5551. goto out;
  5552. }
  5553. param = (struct ieee_param *)rtw_malloc(p->length);
  5554. if (param == NULL) {
  5555. ret = -ENOMEM;
  5556. goto out;
  5557. }
  5558. if (copy_from_user(param, p->pointer, p->length)) {
  5559. rtw_mfree((u8 *)param, p->length);
  5560. ret = -EFAULT;
  5561. goto out;
  5562. }
  5563. switch (param->cmd) {
  5564. case IEEE_CMD_SET_WPA_PARAM:
  5565. ret = wpa_set_param(dev, param->u.wpa_param.name, param->u.wpa_param.value);
  5566. break;
  5567. case IEEE_CMD_SET_WPA_IE:
  5568. /* ret = wpa_set_wpa_ie(dev, param, p->length); */
  5569. ret = rtw_set_wpa_ie((_adapter *)rtw_netdev_priv(dev), (char *)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len);
  5570. break;
  5571. case IEEE_CMD_SET_ENCRYPTION:
  5572. ret = wpa_set_encryption(dev, param, p->length);
  5573. break;
  5574. case IEEE_CMD_MLME:
  5575. ret = wpa_mlme(dev, param->u.mlme.command, param->u.mlme.reason_code);
  5576. break;
  5577. default:
  5578. RTW_INFO("Unknown WPA supplicant request: %d\n", param->cmd);
  5579. ret = -EOPNOTSUPP;
  5580. break;
  5581. }
  5582. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  5583. ret = -EFAULT;
  5584. rtw_mfree((u8 *)param, p->length);
  5585. out:
  5586. /* up(&ieee->wx_sem); */
  5587. return ret;
  5588. }
  5589. #ifdef CONFIG_AP_MODE
  5590. static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  5591. {
  5592. int ret = 0;
  5593. u32 wep_key_idx, wep_key_len, wep_total_len;
  5594. NDIS_802_11_WEP *pwep = NULL;
  5595. struct sta_info *psta = NULL, *pbcmc_sta = NULL;
  5596. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5597. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  5598. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  5599. struct sta_priv *pstapriv = &padapter->stapriv;
  5600. RTW_INFO("%s\n", __FUNCTION__);
  5601. param->u.crypt.err = 0;
  5602. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  5603. /* sizeof(struct ieee_param) = 64 bytes; */
  5604. /* if (param_len != (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) */
  5605. if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) {
  5606. ret = -EINVAL;
  5607. goto exit;
  5608. }
  5609. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5610. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  5611. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  5612. if (param->u.crypt.idx >= WEP_KEYS
  5613. #ifdef CONFIG_IEEE80211W
  5614. && param->u.crypt.idx > BIP_MAX_KEYID
  5615. #endif /* CONFIG_IEEE80211W */
  5616. ) {
  5617. ret = -EINVAL;
  5618. goto exit;
  5619. }
  5620. } else {
  5621. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  5622. if (!psta) {
  5623. /* ret = -EINVAL; */
  5624. RTW_INFO("rtw_set_encryption(), sta has already been removed or never been added\n");
  5625. goto exit;
  5626. }
  5627. }
  5628. if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) {
  5629. /* todo:clear default encryption keys */
  5630. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  5631. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  5632. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  5633. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  5634. RTW_INFO("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
  5635. goto exit;
  5636. }
  5637. if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) {
  5638. RTW_INFO("r871x_set_encryption, crypt.alg = WEP\n");
  5639. wep_key_idx = param->u.crypt.idx;
  5640. wep_key_len = param->u.crypt.key_len;
  5641. RTW_INFO("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
  5642. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  5643. ret = -EINVAL;
  5644. goto exit;
  5645. }
  5646. if (wep_key_len > 0) {
  5647. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  5648. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  5649. pwep = (NDIS_802_11_WEP *)rtw_malloc(wep_total_len);
  5650. if (pwep == NULL) {
  5651. RTW_INFO(" r871x_set_encryption: pwep allocate fail !!!\n");
  5652. goto exit;
  5653. }
  5654. _rtw_memset(pwep, 0, wep_total_len);
  5655. pwep->KeyLength = wep_key_len;
  5656. pwep->Length = wep_total_len;
  5657. }
  5658. pwep->KeyIndex = wep_key_idx;
  5659. _rtw_memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
  5660. if (param->u.crypt.set_tx) {
  5661. RTW_INFO("wep, set_tx=1\n");
  5662. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  5663. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  5664. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  5665. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  5666. if (pwep->KeyLength == 13) {
  5667. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  5668. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  5669. }
  5670. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  5671. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
  5672. psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
  5673. rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 1);
  5674. } else {
  5675. RTW_INFO("wep, set_tx=0\n");
  5676. /* don't update "psecuritypriv->dot11PrivacyAlgrthm" and */
  5677. /* "psecuritypriv->dot11PrivacyKeyIndex=keyid", but can rtw_set_key to cam */
  5678. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
  5679. psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
  5680. rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 0);
  5681. }
  5682. goto exit;
  5683. }
  5684. if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) /* */ { /* group key */
  5685. if (param->u.crypt.set_tx == 1) {
  5686. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  5687. RTW_INFO(FUNC_ADPT_FMT" set WEP TX GTK idx:%u, len:%u\n"
  5688. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  5689. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  5690. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  5691. if (param->u.crypt.key_len == 13)
  5692. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  5693. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5694. RTW_INFO(FUNC_ADPT_FMT" set TKIP TX GTK idx:%u, len:%u\n"
  5695. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  5696. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  5697. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  5698. /* set mic key */
  5699. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  5700. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  5701. psecuritypriv->busetkipkey = _TRUE;
  5702. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5703. RTW_INFO(FUNC_ADPT_FMT" set CCMP TX GTK idx:%u, len:%u\n"
  5704. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  5705. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  5706. _rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  5707. #ifdef CONFIG_IEEE80211W
  5708. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  5709. RTW_INFO(FUNC_ADPT_FMT" set TX IGTK idx:%u, len:%u\n"
  5710. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  5711. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  5712. psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
  5713. psecuritypriv->dot11wBIPtxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  5714. psecuritypriv->binstallBIPkey = _TRUE;
  5715. goto exit;
  5716. #endif /* CONFIG_IEEE80211W */
  5717. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  5718. RTW_INFO(FUNC_ADPT_FMT" clear group key, idx:%u\n"
  5719. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx);
  5720. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  5721. } else {
  5722. RTW_WARN(FUNC_ADPT_FMT" set group key, not support\n"
  5723. , FUNC_ADPT_ARG(padapter));
  5724. goto exit;
  5725. }
  5726. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  5727. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  5728. if (pbcmc_sta) {
  5729. pbcmc_sta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  5730. pbcmc_sta->ieee8021x_blocked = _FALSE;
  5731. pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy; /* rx will use bmc_sta's dot118021XPrivacy */
  5732. }
  5733. psecuritypriv->binstallGrpkey = _TRUE;
  5734. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* !!! */
  5735. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  5736. }
  5737. goto exit;
  5738. }
  5739. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
  5740. if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  5741. if (param->u.crypt.set_tx == 1) {
  5742. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  5743. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  5744. RTW_INFO(FUNC_ADPT_FMT" set WEP PTK of "MAC_FMT" idx:%u, len:%u\n"
  5745. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  5746. , param->u.crypt.idx, param->u.crypt.key_len);
  5747. psta->dot118021XPrivacy = _WEP40_;
  5748. if (param->u.crypt.key_len == 13)
  5749. psta->dot118021XPrivacy = _WEP104_;
  5750. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5751. RTW_INFO(FUNC_ADPT_FMT" set TKIP PTK of "MAC_FMT" idx:%u, len:%u\n"
  5752. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  5753. , param->u.crypt.idx, param->u.crypt.key_len);
  5754. psta->dot118021XPrivacy = _TKIP_;
  5755. /* set mic key */
  5756. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  5757. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  5758. psecuritypriv->busetkipkey = _TRUE;
  5759. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5760. RTW_INFO(FUNC_ADPT_FMT" set CCMP PTK of "MAC_FMT" idx:%u, len:%u\n"
  5761. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  5762. , param->u.crypt.idx, param->u.crypt.key_len);
  5763. psta->dot118021XPrivacy = _AES_;
  5764. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  5765. RTW_INFO(FUNC_ADPT_FMT" clear pairwise key of "MAC_FMT" idx:%u\n"
  5766. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  5767. , param->u.crypt.idx);
  5768. psta->dot118021XPrivacy = _NO_PRIVACY_;
  5769. } else {
  5770. RTW_WARN(FUNC_ADPT_FMT" set pairwise key of "MAC_FMT", not support\n"
  5771. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  5772. goto exit;
  5773. }
  5774. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  5775. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  5776. psta->ieee8021x_blocked = _FALSE;
  5777. if (psta->dot118021XPrivacy != _NO_PRIVACY_) {
  5778. psta->bpairwise_key_installed = _TRUE;
  5779. /* WPA2 key-handshake has completed */
  5780. if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK)
  5781. psta->state &= (~WIFI_UNDER_KEY_HANDSHAKE);
  5782. }
  5783. rtw_ap_set_pairwise_key(padapter, psta);
  5784. } else {
  5785. RTW_WARN(FUNC_ADPT_FMT" set group key of "MAC_FMT", not support\n"
  5786. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  5787. goto exit;
  5788. }
  5789. }
  5790. }
  5791. exit:
  5792. if (pwep)
  5793. rtw_mfree((u8 *)pwep, wep_total_len);
  5794. return ret;
  5795. }
  5796. static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int len)
  5797. {
  5798. int ret = 0;
  5799. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5800. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5801. struct sta_priv *pstapriv = &padapter->stapriv;
  5802. unsigned char *pbuf = param->u.bcn_ie.buf;
  5803. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  5804. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  5805. return -EINVAL;
  5806. _rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2);
  5807. if ((pstapriv->max_num_sta > NUM_STA) || (pstapriv->max_num_sta <= 0))
  5808. pstapriv->max_num_sta = NUM_STA;
  5809. if (rtw_check_beacon_data(padapter, pbuf, (len - 12 - 2)) == _SUCCESS) /* 12 = param header, 2:no packed */
  5810. ret = 0;
  5811. else
  5812. ret = -EINVAL;
  5813. return ret;
  5814. }
  5815. static int rtw_hostapd_sta_flush(struct net_device *dev)
  5816. {
  5817. /* _irqL irqL; */
  5818. /* _list *phead, *plist; */
  5819. int ret = 0;
  5820. /* struct sta_info *psta = NULL; */
  5821. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5822. /* struct sta_priv *pstapriv = &padapter->stapriv; */
  5823. RTW_INFO("%s\n", __FUNCTION__);
  5824. flush_all_cam_entry(padapter); /* clear CAM */
  5825. #ifdef CONFIG_AP_MODE
  5826. ret = rtw_sta_flush(padapter, _TRUE);
  5827. #endif
  5828. return ret;
  5829. }
  5830. static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
  5831. {
  5832. int ret = 0;
  5833. struct sta_info *psta = NULL;
  5834. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5835. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5836. struct sta_priv *pstapriv = &padapter->stapriv;
  5837. RTW_INFO("rtw_add_sta(aid=%d)=" MAC_FMT "\n", param->u.add_sta.aid, MAC_ARG(param->sta_addr));
  5838. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != _TRUE)
  5839. return -EINVAL;
  5840. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5841. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  5842. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  5843. return -EINVAL;
  5844. #if 0
  5845. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  5846. if (psta) {
  5847. RTW_INFO("rtw_add_sta(), free has been added psta=%p\n", psta);
  5848. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  5849. rtw_free_stainfo(padapter, psta);
  5850. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
  5851. psta = NULL;
  5852. }
  5853. #endif
  5854. /* psta = rtw_alloc_stainfo(pstapriv, param->sta_addr); */
  5855. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  5856. if (psta) {
  5857. int flags = param->u.add_sta.flags;
  5858. /* RTW_INFO("rtw_add_sta(), init sta's variables, psta=%p\n", psta); */
  5859. psta->cmn.aid = param->u.add_sta.aid;/* aid=1~2007 */
  5860. _rtw_memcpy(psta->bssrateset, param->u.add_sta.tx_supp_rates, 16);
  5861. /* check wmm cap. */
  5862. if (WLAN_STA_WME & flags)
  5863. psta->qos_option = 1;
  5864. else
  5865. psta->qos_option = 0;
  5866. if (pmlmepriv->qospriv.qos_option == 0)
  5867. psta->qos_option = 0;
  5868. #ifdef CONFIG_80211N_HT
  5869. /* chec 802.11n ht cap. */
  5870. if (padapter->registrypriv.ht_enable &&
  5871. is_supported_ht(padapter->registrypriv.wireless_mode) &&
  5872. (WLAN_STA_HT & flags)) {
  5873. psta->htpriv.ht_option = _TRUE;
  5874. psta->qos_option = 1;
  5875. _rtw_memcpy((void *)&psta->htpriv.ht_cap, (void *)&param->u.add_sta.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
  5876. } else
  5877. psta->htpriv.ht_option = _FALSE;
  5878. if (pmlmepriv->htpriv.ht_option == _FALSE)
  5879. psta->htpriv.ht_option = _FALSE;
  5880. #endif
  5881. update_sta_info_apmode(padapter, psta);
  5882. } else
  5883. ret = -ENOMEM;
  5884. return ret;
  5885. }
  5886. static int rtw_del_sta(struct net_device *dev, struct ieee_param *param)
  5887. {
  5888. _irqL irqL;
  5889. int ret = 0;
  5890. struct sta_info *psta = NULL;
  5891. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5892. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5893. struct sta_priv *pstapriv = &padapter->stapriv;
  5894. RTW_INFO("rtw_del_sta=" MAC_FMT "\n", MAC_ARG(param->sta_addr));
  5895. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != _TRUE)
  5896. return -EINVAL;
  5897. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5898. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  5899. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  5900. return -EINVAL;
  5901. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  5902. if (psta) {
  5903. u8 updated = _FALSE;
  5904. /* RTW_INFO("free psta=%p, aid=%d\n", psta, psta->cmn.aid); */
  5905. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  5906. if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
  5907. rtw_list_delete(&psta->asoc_list);
  5908. pstapriv->asoc_list_cnt--;
  5909. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
  5910. }
  5911. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  5912. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  5913. psta = NULL;
  5914. } else {
  5915. RTW_INFO("rtw_del_sta(), sta has already been removed or never been added\n");
  5916. /* ret = -1; */
  5917. }
  5918. return ret;
  5919. }
  5920. static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *param, int len)
  5921. {
  5922. int ret = 0;
  5923. struct sta_info *psta = NULL;
  5924. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5925. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5926. struct sta_priv *pstapriv = &padapter->stapriv;
  5927. struct ieee_param_ex *param_ex = (struct ieee_param_ex *)param;
  5928. struct sta_data *psta_data = (struct sta_data *)param_ex->data;
  5929. RTW_INFO("rtw_ioctl_get_sta_info, sta_addr: " MAC_FMT "\n", MAC_ARG(param_ex->sta_addr));
  5930. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != _TRUE)
  5931. return -EINVAL;
  5932. if (param_ex->sta_addr[0] == 0xff && param_ex->sta_addr[1] == 0xff &&
  5933. param_ex->sta_addr[2] == 0xff && param_ex->sta_addr[3] == 0xff &&
  5934. param_ex->sta_addr[4] == 0xff && param_ex->sta_addr[5] == 0xff)
  5935. return -EINVAL;
  5936. psta = rtw_get_stainfo(pstapriv, param_ex->sta_addr);
  5937. if (psta) {
  5938. #if 0
  5939. struct {
  5940. u16 aid;
  5941. u16 capability;
  5942. int flags;
  5943. u32 sta_set;
  5944. u8 tx_supp_rates[16];
  5945. u32 tx_supp_rates_len;
  5946. struct rtw_ieee80211_ht_cap ht_cap;
  5947. u64 rx_pkts;
  5948. u64 rx_bytes;
  5949. u64 rx_drops;
  5950. u64 tx_pkts;
  5951. u64 tx_bytes;
  5952. u64 tx_drops;
  5953. } get_sta;
  5954. #endif
  5955. psta_data->aid = (u16)psta->cmn.aid;
  5956. psta_data->capability = psta->capability;
  5957. psta_data->flags = psta->flags;
  5958. /*
  5959. nonerp_set : BIT(0)
  5960. no_short_slot_time_set : BIT(1)
  5961. no_short_preamble_set : BIT(2)
  5962. no_ht_gf_set : BIT(3)
  5963. no_ht_set : BIT(4)
  5964. ht_20mhz_set : BIT(5)
  5965. */
  5966. psta_data->sta_set = ((psta->nonerp_set) |
  5967. (psta->no_short_slot_time_set << 1) |
  5968. (psta->no_short_preamble_set << 2) |
  5969. (psta->no_ht_gf_set << 3) |
  5970. (psta->no_ht_set << 4) |
  5971. (psta->ht_20mhz_set << 5));
  5972. psta_data->tx_supp_rates_len = psta->bssratelen;
  5973. _rtw_memcpy(psta_data->tx_supp_rates, psta->bssrateset, psta->bssratelen);
  5974. #ifdef CONFIG_80211N_HT
  5975. if(padapter->registrypriv.ht_enable && is_supported_ht(padapter->registrypriv.wireless_mode))
  5976. _rtw_memcpy(&psta_data->ht_cap, &psta->htpriv.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
  5977. #endif /* CONFIG_80211N_HT */
  5978. psta_data->rx_pkts = psta->sta_stats.rx_data_pkts;
  5979. psta_data->rx_bytes = psta->sta_stats.rx_bytes;
  5980. psta_data->rx_drops = psta->sta_stats.rx_drops;
  5981. psta_data->tx_pkts = psta->sta_stats.tx_pkts;
  5982. psta_data->tx_bytes = psta->sta_stats.tx_bytes;
  5983. psta_data->tx_drops = psta->sta_stats.tx_drops;
  5984. } else
  5985. ret = -1;
  5986. return ret;
  5987. }
  5988. static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
  5989. {
  5990. int ret = 0;
  5991. struct sta_info *psta = NULL;
  5992. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5993. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5994. struct sta_priv *pstapriv = &padapter->stapriv;
  5995. RTW_INFO("rtw_get_sta_wpaie, sta_addr: " MAC_FMT "\n", MAC_ARG(param->sta_addr));
  5996. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE)) != _TRUE)
  5997. return -EINVAL;
  5998. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5999. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6000. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6001. return -EINVAL;
  6002. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6003. if (psta) {
  6004. if ((psta->wpa_ie[0] == WLAN_EID_RSN) || (psta->wpa_ie[0] == WLAN_EID_GENERIC)) {
  6005. int wpa_ie_len;
  6006. int copy_len;
  6007. wpa_ie_len = psta->wpa_ie[1];
  6008. copy_len = ((wpa_ie_len + 2) > sizeof(psta->wpa_ie)) ? (sizeof(psta->wpa_ie)) : (wpa_ie_len + 2);
  6009. param->u.wpa_ie.len = copy_len;
  6010. _rtw_memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len);
  6011. } else {
  6012. /* ret = -1; */
  6013. RTW_INFO("sta's wpa_ie is NONE\n");
  6014. }
  6015. } else
  6016. ret = -1;
  6017. return ret;
  6018. }
  6019. static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len)
  6020. {
  6021. int ret = 0;
  6022. unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  6023. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6024. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6025. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6026. int ie_len;
  6027. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  6028. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6029. return -EINVAL;
  6030. ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
  6031. if (pmlmepriv->wps_beacon_ie) {
  6032. rtw_mfree(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len);
  6033. pmlmepriv->wps_beacon_ie = NULL;
  6034. }
  6035. if (ie_len > 0) {
  6036. pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
  6037. pmlmepriv->wps_beacon_ie_len = ie_len;
  6038. if (pmlmepriv->wps_beacon_ie == NULL) {
  6039. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6040. return -EINVAL;
  6041. }
  6042. _rtw_memcpy(pmlmepriv->wps_beacon_ie, param->u.bcn_ie.buf, ie_len);
  6043. update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
  6044. pmlmeext->bstart_bss = _TRUE;
  6045. }
  6046. return ret;
  6047. }
  6048. static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len)
  6049. {
  6050. int ret = 0;
  6051. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6052. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6053. int ie_len;
  6054. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  6055. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6056. return -EINVAL;
  6057. ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
  6058. if (pmlmepriv->wps_probe_resp_ie) {
  6059. rtw_mfree(pmlmepriv->wps_probe_resp_ie, pmlmepriv->wps_probe_resp_ie_len);
  6060. pmlmepriv->wps_probe_resp_ie = NULL;
  6061. }
  6062. if (ie_len > 0) {
  6063. pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
  6064. pmlmepriv->wps_probe_resp_ie_len = ie_len;
  6065. if (pmlmepriv->wps_probe_resp_ie == NULL) {
  6066. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6067. return -EINVAL;
  6068. }
  6069. _rtw_memcpy(pmlmepriv->wps_probe_resp_ie, param->u.bcn_ie.buf, ie_len);
  6070. }
  6071. return ret;
  6072. }
  6073. static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len)
  6074. {
  6075. int ret = 0;
  6076. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6077. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6078. int ie_len;
  6079. RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
  6080. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6081. return -EINVAL;
  6082. ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
  6083. if (pmlmepriv->wps_assoc_resp_ie) {
  6084. rtw_mfree(pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
  6085. pmlmepriv->wps_assoc_resp_ie = NULL;
  6086. }
  6087. if (ie_len > 0) {
  6088. pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
  6089. pmlmepriv->wps_assoc_resp_ie_len = ie_len;
  6090. if (pmlmepriv->wps_assoc_resp_ie == NULL) {
  6091. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6092. return -EINVAL;
  6093. }
  6094. _rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len);
  6095. }
  6096. return ret;
  6097. }
  6098. static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len)
  6099. {
  6100. int ret = 0;
  6101. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6102. struct mlme_priv *mlmepriv = &(adapter->mlmepriv);
  6103. struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
  6104. struct mlme_ext_info *mlmeinfo = &(mlmeext->mlmext_info);
  6105. int ie_len;
  6106. u8 *ssid_ie;
  6107. char ssid[NDIS_802_11_LENGTH_SSID + 1];
  6108. sint ssid_len = 0;
  6109. u8 ignore_broadcast_ssid;
  6110. if (check_fwstate(mlmepriv, WIFI_AP_STATE) != _TRUE)
  6111. return -EPERM;
  6112. if (param->u.bcn_ie.reserved[0] != 0xea)
  6113. return -EINVAL;
  6114. mlmeinfo->hidden_ssid_mode = ignore_broadcast_ssid = param->u.bcn_ie.reserved[1];
  6115. ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
  6116. ssid_ie = rtw_get_ie(param->u.bcn_ie.buf, WLAN_EID_SSID, &ssid_len, ie_len);
  6117. if (ssid_ie && ssid_len > 0 && ssid_len <= NDIS_802_11_LENGTH_SSID) {
  6118. WLAN_BSSID_EX *pbss_network = &mlmepriv->cur_network.network;
  6119. WLAN_BSSID_EX *pbss_network_ext = &mlmeinfo->network;
  6120. _rtw_memcpy(ssid, ssid_ie + 2, ssid_len);
  6121. ssid[ssid_len] = 0x0;
  6122. if (0)
  6123. RTW_INFO(FUNC_ADPT_FMT" ssid:(%s,%d), from ie:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  6124. ssid, ssid_len,
  6125. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  6126. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  6127. _rtw_memcpy(pbss_network->Ssid.Ssid, (void *)ssid, ssid_len);
  6128. pbss_network->Ssid.SsidLength = ssid_len;
  6129. _rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)ssid, ssid_len);
  6130. pbss_network_ext->Ssid.SsidLength = ssid_len;
  6131. if (0)
  6132. RTW_INFO(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  6133. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  6134. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  6135. }
  6136. RTW_INFO(FUNC_ADPT_FMT" ignore_broadcast_ssid:%d, %s,%d\n", FUNC_ADPT_ARG(adapter),
  6137. ignore_broadcast_ssid, ssid, ssid_len);
  6138. return ret;
  6139. }
  6140. #if CONFIG_RTW_MACADDR_ACL
  6141. static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
  6142. {
  6143. int ret = 0;
  6144. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6145. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6146. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6147. return -EINVAL;
  6148. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6149. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6150. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6151. return -EINVAL;
  6152. ret = rtw_acl_remove_sta(padapter, RTW_ACL_PERIOD_BSS, param->sta_addr);
  6153. return ret;
  6154. }
  6155. static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len)
  6156. {
  6157. int ret = 0;
  6158. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6159. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6160. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6161. return -EINVAL;
  6162. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6163. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6164. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6165. return -EINVAL;
  6166. ret = rtw_acl_add_sta(padapter, RTW_ACL_PERIOD_BSS, param->sta_addr);
  6167. return ret;
  6168. }
  6169. static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
  6170. {
  6171. int ret = 0;
  6172. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6173. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6174. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6175. return -EINVAL;
  6176. rtw_set_macaddr_acl(padapter, RTW_ACL_PERIOD_BSS, param->u.mlme.command);
  6177. return ret;
  6178. }
  6179. #endif /* CONFIG_RTW_MACADDR_ACL */
  6180. static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
  6181. {
  6182. struct ieee_param *param;
  6183. int ret = 0;
  6184. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6185. /* RTW_INFO("%s\n", __FUNCTION__); */
  6186. /*
  6187. * this function is expect to call in master mode, which allows no power saving
  6188. * so, we just check hw_init_completed
  6189. */
  6190. if (!rtw_is_hw_init_completed(padapter)) {
  6191. ret = -EPERM;
  6192. goto out;
  6193. }
  6194. /* if (p->length < sizeof(struct ieee_param) || !p->pointer){ */
  6195. if (!p->pointer) {
  6196. ret = -EINVAL;
  6197. goto out;
  6198. }
  6199. param = (struct ieee_param *)rtw_malloc(p->length);
  6200. if (param == NULL) {
  6201. ret = -ENOMEM;
  6202. goto out;
  6203. }
  6204. if (copy_from_user(param, p->pointer, p->length)) {
  6205. rtw_mfree((u8 *)param, p->length);
  6206. ret = -EFAULT;
  6207. goto out;
  6208. }
  6209. /* RTW_INFO("%s, cmd=%d\n", __FUNCTION__, param->cmd); */
  6210. switch (param->cmd) {
  6211. case RTL871X_HOSTAPD_FLUSH:
  6212. ret = rtw_hostapd_sta_flush(dev);
  6213. break;
  6214. case RTL871X_HOSTAPD_ADD_STA:
  6215. ret = rtw_add_sta(dev, param);
  6216. break;
  6217. case RTL871X_HOSTAPD_REMOVE_STA:
  6218. ret = rtw_del_sta(dev, param);
  6219. break;
  6220. case RTL871X_HOSTAPD_SET_BEACON:
  6221. ret = rtw_set_beacon(dev, param, p->length);
  6222. break;
  6223. case RTL871X_SET_ENCRYPTION:
  6224. ret = rtw_set_encryption(dev, param, p->length);
  6225. break;
  6226. case RTL871X_HOSTAPD_GET_WPAIE_STA:
  6227. ret = rtw_get_sta_wpaie(dev, param);
  6228. break;
  6229. case RTL871X_HOSTAPD_SET_WPS_BEACON:
  6230. ret = rtw_set_wps_beacon(dev, param, p->length);
  6231. break;
  6232. case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP:
  6233. ret = rtw_set_wps_probe_resp(dev, param, p->length);
  6234. break;
  6235. case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP:
  6236. ret = rtw_set_wps_assoc_resp(dev, param, p->length);
  6237. break;
  6238. case RTL871X_HOSTAPD_SET_HIDDEN_SSID:
  6239. ret = rtw_set_hidden_ssid(dev, param, p->length);
  6240. break;
  6241. case RTL871X_HOSTAPD_GET_INFO_STA:
  6242. ret = rtw_ioctl_get_sta_data(dev, param, p->length);
  6243. break;
  6244. #if CONFIG_RTW_MACADDR_ACL
  6245. case RTL871X_HOSTAPD_SET_MACADDR_ACL:
  6246. ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length);
  6247. break;
  6248. case RTL871X_HOSTAPD_ACL_ADD_STA:
  6249. ret = rtw_ioctl_acl_add_sta(dev, param, p->length);
  6250. break;
  6251. case RTL871X_HOSTAPD_ACL_REMOVE_STA:
  6252. ret = rtw_ioctl_acl_remove_sta(dev, param, p->length);
  6253. break;
  6254. #endif /* CONFIG_RTW_MACADDR_ACL */
  6255. default:
  6256. RTW_INFO("Unknown hostapd request: %d\n", param->cmd);
  6257. ret = -EOPNOTSUPP;
  6258. break;
  6259. }
  6260. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  6261. ret = -EFAULT;
  6262. rtw_mfree((u8 *)param, p->length);
  6263. out:
  6264. return ret;
  6265. }
  6266. #endif
  6267. static int rtw_wx_set_priv(struct net_device *dev,
  6268. struct iw_request_info *info,
  6269. union iwreq_data *awrq,
  6270. char *extra)
  6271. {
  6272. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6273. char *ext_dbg;
  6274. #endif
  6275. int ret = 0;
  6276. int len = 0;
  6277. char *ext;
  6278. #ifdef CONFIG_ANDROID
  6279. int i;
  6280. #endif
  6281. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6282. struct iw_point *dwrq = (struct iw_point *)awrq;
  6283. if (dwrq->length == 0)
  6284. return -EFAULT;
  6285. len = dwrq->length;
  6286. ext = rtw_vmalloc(len);
  6287. if (!ext)
  6288. return -ENOMEM;
  6289. if (copy_from_user(ext, dwrq->pointer, len)) {
  6290. rtw_vmfree(ext, len);
  6291. return -EFAULT;
  6292. }
  6293. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6294. ext_dbg = rtw_vmalloc(len);
  6295. if (!ext_dbg) {
  6296. rtw_vmfree(ext, len);
  6297. return -ENOMEM;
  6298. }
  6299. _rtw_memcpy(ext_dbg, ext, len);
  6300. #endif
  6301. /* added for wps2.0 @20110524 */
  6302. if (dwrq->flags == 0x8766 && len > 8) {
  6303. u32 cp_sz;
  6304. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6305. u8 *probereq_wpsie = ext;
  6306. int probereq_wpsie_len = len;
  6307. u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
  6308. if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
  6309. (_rtw_memcmp(&probereq_wpsie[2], wps_oui, 4) == _TRUE)) {
  6310. cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
  6311. if (pmlmepriv->wps_probe_req_ie) {
  6312. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  6313. pmlmepriv->wps_probe_req_ie_len = 0;
  6314. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  6315. pmlmepriv->wps_probe_req_ie = NULL;
  6316. }
  6317. pmlmepriv->wps_probe_req_ie = rtw_malloc(cp_sz);
  6318. if (pmlmepriv->wps_probe_req_ie == NULL) {
  6319. printk("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6320. ret = -EINVAL;
  6321. goto FREE_EXT;
  6322. }
  6323. _rtw_memcpy(pmlmepriv->wps_probe_req_ie, probereq_wpsie, cp_sz);
  6324. pmlmepriv->wps_probe_req_ie_len = cp_sz;
  6325. }
  6326. goto FREE_EXT;
  6327. }
  6328. if (len >= WEXT_CSCAN_HEADER_SIZE
  6329. && _rtw_memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
  6330. ) {
  6331. ret = rtw_wx_set_scan(dev, info, awrq, ext);
  6332. goto FREE_EXT;
  6333. }
  6334. #ifdef CONFIG_ANDROID
  6335. /* RTW_INFO("rtw_wx_set_priv: %s req=%s\n", dev->name, ext); */
  6336. i = rtw_android_cmdstr_to_num(ext);
  6337. switch (i) {
  6338. case ANDROID_WIFI_CMD_START:
  6339. indicate_wx_custom_event(padapter, "START");
  6340. break;
  6341. case ANDROID_WIFI_CMD_STOP:
  6342. indicate_wx_custom_event(padapter, "STOP");
  6343. break;
  6344. case ANDROID_WIFI_CMD_RSSI: {
  6345. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6346. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  6347. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  6348. sprintf(ext, "%s rssi %d", pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
  6349. else
  6350. sprintf(ext, "OK");
  6351. }
  6352. break;
  6353. case ANDROID_WIFI_CMD_LINKSPEED: {
  6354. u16 mbps = rtw_get_cur_max_rate(padapter) / 10;
  6355. sprintf(ext, "LINKSPEED %d", mbps);
  6356. }
  6357. break;
  6358. case ANDROID_WIFI_CMD_MACADDR:
  6359. sprintf(ext, "MACADDR = " MAC_FMT, MAC_ARG(dev->dev_addr));
  6360. break;
  6361. case ANDROID_WIFI_CMD_SCAN_ACTIVE: {
  6362. /* rtw_set_scan_mode(padapter, SCAN_ACTIVE); */
  6363. sprintf(ext, "OK");
  6364. }
  6365. break;
  6366. case ANDROID_WIFI_CMD_SCAN_PASSIVE: {
  6367. /* rtw_set_scan_mode(padapter, SCAN_PASSIVE); */
  6368. sprintf(ext, "OK");
  6369. }
  6370. break;
  6371. case ANDROID_WIFI_CMD_COUNTRY: {
  6372. char country_code[10];
  6373. sscanf(ext, "%*s %s", country_code);
  6374. rtw_set_country(padapter, country_code);
  6375. sprintf(ext, "OK");
  6376. }
  6377. break;
  6378. default:
  6379. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6380. RTW_INFO("%s: %s unknowned req=%s\n", __FUNCTION__,
  6381. dev->name, ext_dbg);
  6382. #endif
  6383. sprintf(ext, "OK");
  6384. }
  6385. if (copy_to_user(dwrq->pointer, ext, min(dwrq->length, (u16)(strlen(ext) + 1))))
  6386. ret = -EFAULT;
  6387. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6388. RTW_INFO("%s: %s req=%s rep=%s dwrq->length=%d, strlen(ext)+1=%d\n", __FUNCTION__,
  6389. dev->name, ext_dbg , ext, dwrq->length, (u16)(strlen(ext) + 1));
  6390. #endif
  6391. #endif /* end of CONFIG_ANDROID */
  6392. FREE_EXT:
  6393. rtw_vmfree(ext, len);
  6394. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6395. rtw_vmfree(ext_dbg, len);
  6396. #endif
  6397. /* RTW_INFO("rtw_wx_set_priv: (SIOCSIWPRIV) %s ret=%d\n", */
  6398. /* dev->name, ret); */
  6399. return ret;
  6400. }
  6401. #ifdef CONFIG_WOWLAN
  6402. static int rtw_wowlan_ctrl(struct net_device *dev,
  6403. struct iw_request_info *info,
  6404. union iwreq_data *wrqu, char *extra)
  6405. {
  6406. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6407. struct wowlan_ioctl_param poidparam;
  6408. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
  6409. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  6410. struct sta_info *psta = NULL;
  6411. int ret = 0;
  6412. systime start_time = rtw_get_current_time();
  6413. poidparam.subcode = 0;
  6414. RTW_INFO("+rtw_wowlan_ctrl: %s\n", extra);
  6415. if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
  6416. check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  6417. #ifdef CONFIG_PNO_SUPPORT
  6418. pwrctrlpriv->wowlan_pno_enable = _TRUE;
  6419. #else
  6420. RTW_INFO("[%s] WARNING: Please Connect With AP First!!\n", __func__);
  6421. goto _rtw_wowlan_ctrl_exit_free;
  6422. #endif /* CONFIG_PNO_SUPPORT */
  6423. }
  6424. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
  6425. rtw_scan_abort(padapter);
  6426. if (_rtw_memcmp(extra, "enable", 6))
  6427. rtw_suspend_common(padapter);
  6428. else if (_rtw_memcmp(extra, "disable", 7)) {
  6429. #ifdef CONFIG_USB_HCI
  6430. RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
  6431. RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
  6432. #endif
  6433. rtw_resume_common(padapter);
  6434. #ifdef CONFIG_PNO_SUPPORT
  6435. pwrctrlpriv->wowlan_pno_enable = _FALSE;
  6436. #endif /* CONFIG_PNO_SUPPORT */
  6437. } else {
  6438. RTW_INFO("[%s] Invalid Parameter.\n", __func__);
  6439. goto _rtw_wowlan_ctrl_exit_free;
  6440. }
  6441. /* mutex_lock(&ioctl_mutex); */
  6442. _rtw_wowlan_ctrl_exit_free:
  6443. RTW_INFO("-rtw_wowlan_ctrl( subcode = %d)\n", poidparam.subcode);
  6444. RTW_PRINT("%s in %d ms\n", __func__,
  6445. rtw_get_passing_time_ms(start_time));
  6446. _rtw_wowlan_ctrl_exit:
  6447. return ret;
  6448. }
  6449. /*
  6450. * IP filter This pattern if for a frame containing a ip packet:
  6451. * AA:AA:AA:AA:AA:AA:BB:BB:BB:BB:BB:BB:CC:CC:DD:-:-:-:-:-:-:-:-:EE:-:-:FF:FF:FF:FF:GG:GG:GG:GG:HH:HH:II:II
  6452. *
  6453. * A: Ethernet destination address
  6454. * B: Ethernet source address
  6455. * C: Ethernet protocol type
  6456. * D: IP header VER+Hlen, use: 0x45 (4 is for ver 4, 5 is for len 20)
  6457. * E: IP protocol
  6458. * F: IP source address ( 192.168.0.4: C0:A8:00:2C )
  6459. * G: IP destination address ( 192.168.0.4: C0:A8:00:2C )
  6460. * H: Source port (1024: 04:00)
  6461. * I: Destination port (1024: 04:00)
  6462. */
  6463. static int rtw_wowlan_set_pattern(struct net_device *dev,
  6464. struct iw_request_info *info,
  6465. union iwreq_data *wrqu, char *extra)
  6466. {
  6467. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6468. struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
  6469. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  6470. struct wowlan_ioctl_param poidparam;
  6471. int ret = 0, len = 0, i = 0;
  6472. systime start_time = rtw_get_current_time();
  6473. u8 input[wrqu->data.length];
  6474. u8 index = 0;
  6475. poidparam.subcode = 0;
  6476. if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
  6477. check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
  6478. ret = -EFAULT;
  6479. RTW_INFO("Please Connect With AP First!!\n");
  6480. goto _rtw_wowlan_set_pattern_exit;
  6481. }
  6482. if (wrqu->data.length <= 0) {
  6483. ret = -EFAULT;
  6484. RTW_INFO("ERROR: parameter length <= 0\n");
  6485. goto _rtw_wowlan_set_pattern_exit;
  6486. } else {
  6487. /* set pattern */
  6488. if (copy_from_user(input,
  6489. wrqu->data.pointer, wrqu->data.length))
  6490. return -EFAULT;
  6491. /* leave PS first */
  6492. rtw_ps_deny(padapter, PS_DENY_IOCTL);
  6493. LeaveAllPowerSaveModeDirect(padapter);
  6494. if (strncmp(input, "pattern=", 8) == 0) {
  6495. if (pwrpriv->wowlan_pattern_idx >= MAX_WKFM_CAM_NUM) {
  6496. RTW_INFO("WARNING: priv-pattern is full(idx: %d)\n",
  6497. pwrpriv->wowlan_pattern_idx);
  6498. RTW_INFO("WARNING: please clean priv-pattern first\n");
  6499. ret = -EINVAL;
  6500. goto _rtw_wowlan_set_pattern_exit;
  6501. } else {
  6502. index = pwrpriv->wowlan_pattern_idx;
  6503. ret = rtw_wowlan_parser_pattern_cmd(input,
  6504. pwrpriv->patterns[index].content,
  6505. &pwrpriv->patterns[index].len,
  6506. pwrpriv->patterns[index].mask);
  6507. if (ret == _TRUE)
  6508. pwrpriv->wowlan_pattern_idx++;
  6509. }
  6510. } else if (strncmp(input, "clean", 5) == 0) {
  6511. poidparam.subcode = WOWLAN_PATTERN_CLEAN;
  6512. rtw_hal_set_hwreg(padapter,
  6513. HW_VAR_WOWLAN, (u8 *)&poidparam);
  6514. } else if (strncmp(input, "show", 4) == 0) {
  6515. rtw_wow_pattern_cam_dump(padapter);
  6516. rtw_wow_pattern_sw_dump(padapter);
  6517. } else {
  6518. RTW_INFO("ERROR: incorrect parameter!\n");
  6519. ret = -EINVAL;
  6520. }
  6521. rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
  6522. }
  6523. _rtw_wowlan_set_pattern_exit:
  6524. return ret;
  6525. }
  6526. #endif /* CONFIG_WOWLAN */
  6527. #ifdef CONFIG_AP_WOWLAN
  6528. static int rtw_ap_wowlan_ctrl(struct net_device *dev,
  6529. struct iw_request_info *info,
  6530. union iwreq_data *wrqu, char *extra)
  6531. {
  6532. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6533. struct wowlan_ioctl_param poidparam;
  6534. struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
  6535. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  6536. struct sta_info *psta = NULL;
  6537. int ret = 0;
  6538. systime start_time = rtw_get_current_time();
  6539. poidparam.subcode = 0;
  6540. RTW_INFO("+rtw_ap_wowlan_ctrl: %s\n", extra);
  6541. if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  6542. RTW_INFO("[%s] It is not AP mode!!\n", __func__);
  6543. goto _rtw_ap_wowlan_ctrl_exit_free;
  6544. }
  6545. if (_rtw_memcmp(extra, "enable", 6)) {
  6546. pwrctrlpriv->wowlan_ap_mode = _TRUE;
  6547. rtw_suspend_common(padapter);
  6548. } else if (_rtw_memcmp(extra, "disable", 7)) {
  6549. #ifdef CONFIG_USB_HCI
  6550. RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
  6551. RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
  6552. #endif
  6553. rtw_resume_common(padapter);
  6554. } else {
  6555. RTW_INFO("[%s] Invalid Parameter.\n", __func__);
  6556. goto _rtw_ap_wowlan_ctrl_exit_free;
  6557. }
  6558. /* mutex_lock(&ioctl_mutex); */
  6559. _rtw_ap_wowlan_ctrl_exit_free:
  6560. RTW_INFO("-rtw_ap_wowlan_ctrl( subcode = %d)\n", poidparam.subcode);
  6561. RTW_PRINT("%s in %d ms\n", __func__,
  6562. rtw_get_passing_time_ms(start_time));
  6563. _rtw_ap_wowlan_ctrl_exit:
  6564. return ret;
  6565. }
  6566. #endif /* CONFIG_AP_WOWLAN */
  6567. static int rtw_pm_set(struct net_device *dev,
  6568. struct iw_request_info *info,
  6569. union iwreq_data *wrqu, char *extra)
  6570. {
  6571. int ret = 0;
  6572. unsigned mode = 0;
  6573. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6574. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
  6575. if (_rtw_memcmp(extra, "lps=", 4)) {
  6576. sscanf(extra + 4, "%u", &mode);
  6577. ret = rtw_pm_set_lps(padapter, mode);
  6578. } else if (_rtw_memcmp(extra, "ips=", 4)) {
  6579. sscanf(extra + 4, "%u", &mode);
  6580. ret = rtw_pm_set_ips(padapter, mode);
  6581. } else if (_rtw_memcmp(extra, "lps_level=", 10)) {
  6582. if (sscanf(extra + 10, "%u", &mode) > 0)
  6583. ret = rtw_pm_set_lps_level(padapter, mode);
  6584. } else
  6585. ret = -EINVAL;
  6586. return ret;
  6587. }
  6588. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  6589. int rtw_vendor_ie_get_raw_data(struct net_device *dev, u32 vendor_ie_num,
  6590. char *extra, u32 length)
  6591. {
  6592. int j;
  6593. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6594. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6595. u32 vendor_ie_mask = 0;
  6596. char *pstring;
  6597. if (vendor_ie_num >= WLAN_MAX_VENDOR_IE_NUM) {
  6598. RTW_INFO("[%s] only support %d vendor ie\n", __func__ ,
  6599. WLAN_MAX_VENDOR_IE_NUM);
  6600. return -EFAULT;
  6601. }
  6602. if (pmlmepriv->vendor_ielen[vendor_ie_num] == 0) {
  6603. RTW_INFO("[%s] Fail, vendor_ie_num: %d is not set\n", __func__,
  6604. vendor_ie_num);
  6605. return -EFAULT;
  6606. }
  6607. if (length < 2 * pmlmepriv->vendor_ielen[vendor_ie_num] + 5) {
  6608. RTW_INFO("[%s] Fail, buffer size is too small\n", __func__);
  6609. return -EFAULT;
  6610. }
  6611. vendor_ie_mask = pmlmepriv->vendor_ie_mask[vendor_ie_num];
  6612. _rtw_memset(extra, 0, length);
  6613. pstring = extra;
  6614. pstring += sprintf(pstring, "%d,%x,", vendor_ie_num, vendor_ie_mask);
  6615. for (j = 0; j < pmlmepriv->vendor_ielen[vendor_ie_num]; j++)
  6616. pstring += sprintf(pstring, "%02x", pmlmepriv->vendor_ie[vendor_ie_num][j]);
  6617. length = pstring - extra;
  6618. return length;
  6619. }
  6620. int rtw_vendor_ie_get_data(struct net_device *dev, int vendor_ie_num, char *extra)
  6621. {
  6622. int j;
  6623. char *pstring;
  6624. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6625. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6626. u32 vendor_ie_mask = 0;
  6627. __u16 length = 0;
  6628. vendor_ie_mask = pmlmepriv->vendor_ie_mask[vendor_ie_num];
  6629. pstring = extra;
  6630. pstring += sprintf(pstring , "\nVendor IE num %d , Mask:%x " , vendor_ie_num , vendor_ie_mask);
  6631. if (vendor_ie_mask & WIFI_BEACON_VENDOR_IE_BIT)
  6632. pstring += sprintf(pstring , "[Beacon]");
  6633. if (vendor_ie_mask & WIFI_PROBEREQ_VENDOR_IE_BIT)
  6634. pstring += sprintf(pstring , "[Probe Req]");
  6635. if (vendor_ie_mask & WIFI_PROBERESP_VENDOR_IE_BIT)
  6636. pstring += sprintf(pstring , "[Probe Resp]");
  6637. if (vendor_ie_mask & WIFI_ASSOCREQ_VENDOR_IE_BIT)
  6638. pstring += sprintf(pstring , "[Assoc Req]");
  6639. if (vendor_ie_mask & WIFI_ASSOCRESP_VENDOR_IE_BIT)
  6640. pstring += sprintf(pstring , "[Assoc Resp]");
  6641. pstring += sprintf(pstring , "\nVendor IE:\n");
  6642. for (j = 0 ; j < pmlmepriv->vendor_ielen[vendor_ie_num] ; j++)
  6643. pstring += sprintf(pstring , "%02x" , pmlmepriv->vendor_ie[vendor_ie_num][j]);
  6644. length = pstring - extra;
  6645. return length;
  6646. }
  6647. int rtw_vendor_ie_get(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  6648. {
  6649. int ret = 0, vendor_ie_num = 0, cmdlen;
  6650. struct iw_point *p;
  6651. u8 *ptmp;
  6652. p = &wrqu->data;
  6653. cmdlen = p->length;
  6654. if (0 == cmdlen)
  6655. return -EINVAL;
  6656. ptmp = (u8 *)rtw_malloc(cmdlen);
  6657. if (NULL == ptmp)
  6658. return -ENOMEM;
  6659. if (copy_from_user(ptmp, p->pointer, cmdlen)) {
  6660. ret = -EFAULT;
  6661. goto exit;
  6662. }
  6663. ret = sscanf(ptmp , "%d", &vendor_ie_num);
  6664. if (vendor_ie_num > WLAN_MAX_VENDOR_IE_NUM - 1) {
  6665. ret = -EFAULT;
  6666. goto exit;
  6667. }
  6668. wrqu->data.length = rtw_vendor_ie_get_data(dev, vendor_ie_num, extra);
  6669. exit:
  6670. rtw_mfree(ptmp, cmdlen);
  6671. return 0;
  6672. }
  6673. int rtw_vendor_ie_set(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
  6674. {
  6675. int ret = 0, i , len = 0 , totoal_ie_len = 0 , total_ie_len_byte = 0;
  6676. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6677. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6678. u32 vendor_ie_mask = 0;
  6679. u32 vendor_ie_num = 0;
  6680. u32 id, elen;
  6681. ret = sscanf(extra, "%d,%x,%*s", &vendor_ie_num , &vendor_ie_mask);
  6682. if (strrchr(extra , ','))
  6683. extra = strrchr(extra , ',') + 1;
  6684. else
  6685. return -EINVAL;
  6686. totoal_ie_len = strlen(extra);
  6687. RTW_INFO("[%s] vendor_ie_num = %d , vendor_ie_mask = %x , vendor_ie = %s , len = %d\n", __func__ , vendor_ie_num , vendor_ie_mask , extra , totoal_ie_len);
  6688. if (vendor_ie_num > WLAN_MAX_VENDOR_IE_NUM - 1) {
  6689. RTW_INFO("[%s] only support %d vendor ie\n", __func__ , WLAN_MAX_VENDOR_IE_NUM);
  6690. return -EFAULT;
  6691. }
  6692. if (totoal_ie_len > WLAN_MAX_VENDOR_IE_LEN) {
  6693. RTW_INFO("[%s] Fail , not support ie length extend %d\n", __func__ , WLAN_MAX_VENDOR_IE_LEN);
  6694. return -EFAULT;
  6695. }
  6696. if (vendor_ie_mask == 0) {
  6697. RTW_INFO("[%s] Clear vendor_ie_num %d group\n", __func__ , vendor_ie_num);
  6698. goto _clear_path;
  6699. }
  6700. if (totoal_ie_len % 2 != 0) {
  6701. RTW_INFO("[%s] Fail , IE length = %zu is odd\n" , __func__ , strlen(extra));
  6702. return -EFAULT;
  6703. }
  6704. if (totoal_ie_len > 0) {
  6705. for (i = 0 ; i < strlen(extra) ; i += 2) {
  6706. pmlmepriv->vendor_ie[vendor_ie_num][len] = key_2char2num(extra[i] , extra[i + 1]);
  6707. if (len == 0) {
  6708. id = pmlmepriv->vendor_ie[vendor_ie_num][len];
  6709. if (id != WLAN_EID_VENDOR_SPECIFIC) {
  6710. RTW_INFO("[%s] Fail , VENDOR SPECIFIC IE ID \"%x\" was not correct\n", __func__ , id);
  6711. goto _clear_path;
  6712. }
  6713. } else if (len == 1) {
  6714. total_ie_len_byte = (totoal_ie_len / 2) - 2;
  6715. elen = pmlmepriv->vendor_ie[vendor_ie_num][len];
  6716. if (elen != total_ie_len_byte) {
  6717. RTW_INFO("[%s] Fail , Input IE length = \"%d\"(hex:%x) bytes , not match input total IE context length \"%d\" bytes\n", __func__ , elen , elen ,
  6718. total_ie_len_byte);
  6719. goto _clear_path;
  6720. }
  6721. }
  6722. len++;
  6723. }
  6724. pmlmepriv->vendor_ielen[vendor_ie_num] = len;
  6725. } else
  6726. pmlmepriv->vendor_ielen[vendor_ie_num] = 0;
  6727. if (vendor_ie_mask & WIFI_BEACON_VENDOR_IE_BIT)
  6728. RTW_INFO("[%s] Beacon append vendor ie\n", __func__);
  6729. if (vendor_ie_mask & WIFI_PROBEREQ_VENDOR_IE_BIT)
  6730. RTW_INFO("[%s] Probe Req append vendor ie\n", __func__);
  6731. if (vendor_ie_mask & WIFI_PROBERESP_VENDOR_IE_BIT)
  6732. RTW_INFO("[%s] Probe Resp append vendor ie\n", __func__);
  6733. if (vendor_ie_mask & WIFI_ASSOCREQ_VENDOR_IE_BIT)
  6734. RTW_INFO("[%s] Assoc Req append vendor ie\n", __func__);
  6735. if (vendor_ie_mask & WIFI_ASSOCRESP_VENDOR_IE_BIT)
  6736. RTW_INFO("[%s] Assoc Resp append vendor ie\n", __func__);
  6737. pmlmepriv->vendor_ie_mask[vendor_ie_num] = vendor_ie_mask;
  6738. return ret;
  6739. _clear_path:
  6740. _rtw_memset(pmlmepriv->vendor_ie[vendor_ie_num] , 0 , sizeof(u32) * WLAN_MAX_VENDOR_IE_LEN);
  6741. pmlmepriv->vendor_ielen[vendor_ie_num] = 0;
  6742. pmlmepriv->vendor_ie_mask[vendor_ie_num] = 0;
  6743. return -EFAULT;
  6744. }
  6745. #endif
  6746. static int rtw_mp_efuse_get(struct net_device *dev,
  6747. struct iw_request_info *info,
  6748. union iwreq_data *wdata, char *extra)
  6749. {
  6750. PADAPTER padapter = rtw_netdev_priv(dev);
  6751. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  6752. PEFUSE_HAL pEfuseHal;
  6753. struct iw_point *wrqu;
  6754. u8 ips_mode = IPS_NUM; /* init invalid value */
  6755. u8 lps_mode = PS_MODE_NUM; /* init invalid value */
  6756. struct pwrctrl_priv *pwrctrlpriv ;
  6757. u8 *data = NULL;
  6758. u8 *rawdata = NULL;
  6759. char *pch, *ptmp, *token, *tmp[3] = {0x00, 0x00, 0x00};
  6760. u16 i = 0, j = 0, mapLen = 0, addr = 0, cnts = 0;
  6761. u16 max_available_len = 0, raw_cursize = 0, raw_maxsize = 0;
  6762. u16 mask_len;
  6763. u8 mask_buf[64] = "";
  6764. int err;
  6765. char *pextra = NULL;
  6766. #ifdef CONFIG_IOL
  6767. u8 org_fw_iol = padapter->registrypriv.fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
  6768. #endif
  6769. wrqu = (struct iw_point *)wdata;
  6770. pwrctrlpriv = adapter_to_pwrctl(padapter);
  6771. pEfuseHal = &pHalData->EfuseHal;
  6772. err = 0;
  6773. data = rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
  6774. if (data == NULL) {
  6775. err = -ENOMEM;
  6776. goto exit;
  6777. }
  6778. rawdata = rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
  6779. if (rawdata == NULL) {
  6780. err = -ENOMEM;
  6781. goto exit;
  6782. }
  6783. if (copy_from_user(extra, wrqu->pointer, wrqu->length)) {
  6784. err = -EFAULT;
  6785. goto exit;
  6786. }
  6787. *(extra + wrqu->length) = '\0';
  6788. #ifdef CONFIG_LPS
  6789. lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
  6790. rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
  6791. #endif
  6792. #ifdef CONFIG_IPS
  6793. ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
  6794. rtw_pm_set_ips(padapter, IPS_NONE);
  6795. #endif
  6796. pch = extra;
  6797. RTW_INFO("%s: in=%s\n", __FUNCTION__, extra);
  6798. i = 0;
  6799. /* mac 16 "00e04c871200" rmap,00,2 */
  6800. while ((token = strsep(&pch, ",")) != NULL) {
  6801. if (i > 2)
  6802. break;
  6803. tmp[i] = token;
  6804. i++;
  6805. }
  6806. #ifdef CONFIG_IOL
  6807. padapter->registrypriv.fw_iol = 0;/* 0:Disable, 1:enable, 2:by usb speed */
  6808. #endif
  6809. if (strcmp(tmp[0], "status") == 0) {
  6810. sprintf(extra, "Load File efuse=%s,Load File MAC=%s"
  6811. , pHalData->efuse_file_status == EFUSE_FILE_FAILED ? "FAIL" : "OK"
  6812. , pHalData->macaddr_file_status == MACADDR_FILE_FAILED ? "FAIL" : "OK"
  6813. );
  6814. goto exit;
  6815. } else if (strcmp(tmp[0], "drvmap") == 0) {
  6816. static u8 drvmaporder = 0;
  6817. u8 *efuse;
  6818. u32 shift, cnt;
  6819. u32 blksz = 0x200; /* The size of one time show, default 512 */
  6820. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, _FALSE);
  6821. efuse = pHalData->efuse_eeprom_data;
  6822. shift = blksz * drvmaporder;
  6823. efuse += shift;
  6824. cnt = mapLen - shift;
  6825. if (cnt > blksz) {
  6826. cnt = blksz;
  6827. drvmaporder++;
  6828. } else
  6829. drvmaporder = 0;
  6830. sprintf(extra, "\n");
  6831. for (i = 0; i < cnt; i += 16) {
  6832. pextra = extra + strlen(extra);
  6833. pextra += sprintf(pextra, "0x%02x\t", shift + i);
  6834. for (j = 0; j < 8; j++)
  6835. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  6836. pextra += sprintf(pextra, "\t");
  6837. for (; j < 16; j++)
  6838. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  6839. pextra += sprintf(pextra, "\n");
  6840. }
  6841. if ((shift + cnt) < mapLen)
  6842. pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
  6843. } else if (strcmp(tmp[0], "realmap") == 0) {
  6844. static u8 order = 0;
  6845. u8 *efuse;
  6846. u32 shift, cnt;
  6847. u32 blksz = 0x200; /* The size of one time show, default 512 */
  6848. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&mapLen, _FALSE);
  6849. efuse = pEfuseHal->fakeEfuseInitMap;
  6850. if (rtw_efuse_mask_map_read(padapter, 0, mapLen, efuse) == _FAIL) {
  6851. RTW_INFO("%s: read realmap Fail!!\n", __FUNCTION__);
  6852. err = -EFAULT;
  6853. goto exit;
  6854. }
  6855. #if 0
  6856. RTW_INFO("OFFSET\tVALUE(hex)\n");
  6857. for (i = 0; i < mapLen; i += 16) {
  6858. RTW_INFO("0x%02x\t", i);
  6859. for (j = 0; j < 8; j++)
  6860. RTW_INFO("%02X ", efuse[i + j]);
  6861. RTW_INFO("\t");
  6862. for (; j < 16; j++)
  6863. RTW_INFO("%02X ", efuse[i + j]);
  6864. RTW_INFO("\n");
  6865. }
  6866. RTW_INFO("\n");
  6867. #endif
  6868. shift = blksz * order;
  6869. efuse += shift;
  6870. cnt = mapLen - shift;
  6871. if (cnt > blksz) {
  6872. cnt = blksz;
  6873. order++;
  6874. } else
  6875. order = 0;
  6876. sprintf(extra, "\n");
  6877. for (i = 0; i < cnt; i += 16) {
  6878. pextra = extra + strlen(extra);
  6879. pextra += sprintf(pextra, "0x%02x\t", shift + i);
  6880. for (j = 0; j < 8; j++)
  6881. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  6882. pextra += sprintf(pextra, "\t");
  6883. for (; j < 16; j++)
  6884. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  6885. pextra += sprintf(pextra, "\n");
  6886. }
  6887. if ((shift + cnt) < mapLen)
  6888. pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
  6889. } else if (strcmp(tmp[0], "rmap") == 0) {
  6890. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  6891. RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
  6892. err = -EINVAL;
  6893. goto exit;
  6894. }
  6895. /* rmap addr cnts */
  6896. addr = simple_strtoul(tmp[1], &ptmp, 16);
  6897. RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
  6898. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  6899. if (cnts == 0) {
  6900. RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
  6901. err = -EINVAL;
  6902. goto exit;
  6903. }
  6904. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  6905. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (PVOID)&max_available_len, _FALSE);
  6906. if ((addr + cnts) > max_available_len) {
  6907. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  6908. err = -EINVAL;
  6909. goto exit;
  6910. }
  6911. if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
  6912. RTW_INFO("%s: rtw_efuse_mask_map_read error!\n", __func__);
  6913. err = -EFAULT;
  6914. goto exit;
  6915. }
  6916. /* RTW_INFO("%s: data={", __FUNCTION__); */
  6917. *extra = 0;
  6918. pextra = extra;
  6919. for (i = 0; i < cnts; i++) {
  6920. /* RTW_INFO("0x%02x ", data[i]); */
  6921. pextra += sprintf(pextra, "0x%02X ", data[i]);
  6922. }
  6923. /* RTW_INFO("}\n"); */
  6924. } else if (strcmp(tmp[0], "realraw") == 0) {
  6925. static u8 raw_order = 0;
  6926. u32 shift, cnt;
  6927. u32 blksz = 0x200; /* The size of one time show, default 512 */
  6928. addr = 0;
  6929. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN , (PVOID)&mapLen, _FALSE);
  6930. RTW_INFO("Real content len = %d\n",mapLen );
  6931. if (rtw_efuse_access(padapter, _FALSE, addr, mapLen, rawdata) == _FAIL) {
  6932. RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
  6933. err = -EFAULT;
  6934. goto exit;
  6935. }
  6936. _rtw_memset(extra, '\0', strlen(extra));
  6937. shift = blksz * raw_order;
  6938. rawdata += shift;
  6939. cnt = mapLen - shift;
  6940. if (cnt > blksz) {
  6941. cnt = blksz;
  6942. raw_order++;
  6943. } else
  6944. raw_order = 0;
  6945. sprintf(extra, "\n");
  6946. for (i = 0; i < cnt; i += 16) {
  6947. pextra = extra + strlen(extra);
  6948. pextra += sprintf(pextra, "0x%02x\t", shift + i);
  6949. for (j = 0; j < 8; j++)
  6950. pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
  6951. pextra += sprintf(pextra, "\t");
  6952. for (; j < 16; j++)
  6953. pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
  6954. pextra += sprintf(pextra, "\n");
  6955. }
  6956. if ((shift + cnt) < mapLen)
  6957. pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
  6958. } else if (strcmp(tmp[0], "btrealraw") == 0) {
  6959. static u8 bt_raw_order = 0;
  6960. u32 shift, cnt;
  6961. u32 blksz = 0x200; /* The size of one time show, default 512 */
  6962. addr = 0;
  6963. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_REAL_CONTENT_LEN, (PVOID)&mapLen, _FALSE);
  6964. RTW_INFO("Real content len = %d\n", mapLen);
  6965. #ifdef RTW_HALMAC
  6966. if (rtw_efuse_bt_access(padapter, _FALSE, 0, mapLen, rawdata) == _FAIL) {
  6967. RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
  6968. err = -EFAULT;
  6969. goto exit;
  6970. }
  6971. #else
  6972. rtw_write8(padapter, 0x35, 0x1);
  6973. if (rtw_efuse_access(padapter, _FALSE, addr, mapLen, rawdata) == _FAIL) {
  6974. RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
  6975. err = -EFAULT;
  6976. goto exit;
  6977. }
  6978. #endif
  6979. _rtw_memset(extra, '\0', strlen(extra));
  6980. shift = blksz * bt_raw_order;
  6981. rawdata += shift;
  6982. cnt = mapLen - shift;
  6983. if (cnt > blksz) {
  6984. cnt = blksz;
  6985. bt_raw_order++;
  6986. } else
  6987. bt_raw_order = 0;
  6988. sprintf(extra, "\n");
  6989. for (i = 0; i < cnt; i += 16) {
  6990. pextra = extra + strlen(extra);
  6991. pextra += sprintf(pextra, "0x%02x\t", shift + i);
  6992. for (j = 0; j < 8; j++)
  6993. pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
  6994. pextra += sprintf(pextra, "\t");
  6995. for (; j < 16; j++)
  6996. pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
  6997. pextra += sprintf(pextra, "\n");
  6998. }
  6999. if ((shift + cnt) < mapLen)
  7000. pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
  7001. } else if (strcmp(tmp[0], "mac") == 0) {
  7002. if (hal_efuse_macaddr_offset(padapter) == -1) {
  7003. err = -EFAULT;
  7004. goto exit;
  7005. }
  7006. addr = hal_efuse_macaddr_offset(padapter);
  7007. cnts = 6;
  7008. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7009. if ((addr + cnts) > max_available_len) {
  7010. RTW_INFO("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7011. err = -EFAULT;
  7012. goto exit;
  7013. }
  7014. if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
  7015. RTW_INFO("%s: rtw_efuse_mask_map_read error!\n", __func__);
  7016. err = -EFAULT;
  7017. goto exit;
  7018. }
  7019. /* RTW_INFO("%s: MAC address={", __FUNCTION__); */
  7020. *extra = 0;
  7021. pextra = extra;
  7022. for (i = 0; i < cnts; i++) {
  7023. /* RTW_INFO("%02X", data[i]); */
  7024. pextra += sprintf(pextra, "%02X", data[i]);
  7025. if (i != (cnts - 1)) {
  7026. /* RTW_INFO(":"); */
  7027. pextra += sprintf(pextra, ":");
  7028. }
  7029. }
  7030. /* RTW_INFO("}\n"); */
  7031. } else if (strcmp(tmp[0], "vidpid") == 0) {
  7032. #ifdef CONFIG_RTL8188E
  7033. #ifdef CONFIG_USB_HCI
  7034. addr = EEPROM_VID_88EU;
  7035. #endif
  7036. #ifdef CONFIG_PCI_HCI
  7037. addr = EEPROM_VID_88EE;
  7038. #endif
  7039. #endif /* CONFIG_RTL8188E */
  7040. #ifdef CONFIG_RTL8192E
  7041. #ifdef CONFIG_USB_HCI
  7042. addr = EEPROM_VID_8192EU;
  7043. #endif
  7044. #ifdef CONFIG_PCI_HCI
  7045. addr = EEPROM_VID_8192EE;
  7046. #endif
  7047. #endif /* CONFIG_RTL8192E */
  7048. #ifdef CONFIG_RTL8723B
  7049. addr = EEPROM_VID_8723BU;
  7050. #endif /* CONFIG_RTL8192E */
  7051. #ifdef CONFIG_RTL8188F
  7052. addr = EEPROM_VID_8188FU;
  7053. #endif /* CONFIG_RTL8188F */
  7054. #ifdef CONFIG_RTL8188GTV
  7055. addr = EEPROM_VID_8188GTVU;
  7056. #endif
  7057. #ifdef CONFIG_RTL8703B
  7058. #ifdef CONFIG_USB_HCI
  7059. addr = EEPROM_VID_8703BU;
  7060. #endif
  7061. #endif /* CONFIG_RTL8703B */
  7062. #ifdef CONFIG_RTL8723D
  7063. #ifdef CONFIG_USB_HCI
  7064. addr = EEPROM_VID_8723DU;
  7065. #endif /* CONFIG_USB_HCI */
  7066. #endif /* CONFIG_RTL8723D */
  7067. cnts = 4;
  7068. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7069. if ((addr + cnts) > max_available_len) {
  7070. RTW_INFO("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7071. err = -EFAULT;
  7072. goto exit;
  7073. }
  7074. if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
  7075. RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7076. err = -EFAULT;
  7077. goto exit;
  7078. }
  7079. /* RTW_INFO("%s: {VID,PID}={", __FUNCTION__); */
  7080. *extra = 0;
  7081. pextra = extra;
  7082. for (i = 0; i < cnts; i++) {
  7083. /* RTW_INFO("0x%02x", data[i]); */
  7084. pextra += sprintf(pextra, "0x%02X", data[i]);
  7085. if (i != (cnts - 1)) {
  7086. /* RTW_INFO(","); */
  7087. pextra += sprintf(pextra, ",");
  7088. }
  7089. }
  7090. /* RTW_INFO("}\n"); */
  7091. } else if (strcmp(tmp[0], "ableraw") == 0) {
  7092. #ifdef RTW_HALMAC
  7093. raw_maxsize = efuse_GetavailableSize(padapter);
  7094. #else
  7095. efuse_GetCurrentSize(padapter, &raw_cursize);
  7096. raw_maxsize = efuse_GetMaxSize(padapter);
  7097. #endif
  7098. sprintf(extra, "[available raw size]= %d bytes\n", raw_maxsize - raw_cursize);
  7099. } else if (strcmp(tmp[0], "btableraw") == 0) {
  7100. efuse_bt_GetCurrentSize(padapter, &raw_cursize);
  7101. raw_maxsize = efuse_bt_GetMaxSize(padapter);
  7102. sprintf(extra, "[available raw size]= %d bytes\n", raw_maxsize - raw_cursize);
  7103. } else if (strcmp(tmp[0], "btfmap") == 0) {
  7104. BTEfuse_PowerSwitch(padapter, 1, _TRUE);
  7105. mapLen = EFUSE_BT_MAX_MAP_LEN;
  7106. if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
  7107. RTW_INFO("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
  7108. err = -EFAULT;
  7109. goto exit;
  7110. }
  7111. /* RTW_INFO("OFFSET\tVALUE(hex)\n"); */
  7112. sprintf(extra, "\n");
  7113. for (i = 0; i < 512; i += 16) { /* set 512 because the iwpriv's extra size have limit 0x7FF */
  7114. /* RTW_INFO("0x%03x\t", i); */
  7115. pextra = extra + strlen(extra);
  7116. pextra += sprintf(pextra, "0x%03x\t", i);
  7117. for (j = 0; j < 8; j++) {
  7118. /* RTW_INFO("%02X ", pEfuseHal->BTEfuseInitMap[i+j]); */
  7119. pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7120. }
  7121. /* RTW_INFO("\t"); */
  7122. pextra += sprintf(pextra, "\t");
  7123. for (; j < 16; j++) {
  7124. /* RTW_INFO("%02X ", pEfuseHal->BTEfuseInitMap[i+j]); */
  7125. pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7126. }
  7127. /* RTW_INFO("\n"); */
  7128. pextra += sprintf(pextra, "\n");
  7129. }
  7130. /* RTW_INFO("\n"); */
  7131. } else if (strcmp(tmp[0], "btbmap") == 0) {
  7132. BTEfuse_PowerSwitch(padapter, 1, _TRUE);
  7133. mapLen = EFUSE_BT_MAX_MAP_LEN;
  7134. if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
  7135. RTW_INFO("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
  7136. err = -EFAULT;
  7137. goto exit;
  7138. }
  7139. /* RTW_INFO("OFFSET\tVALUE(hex)\n"); */
  7140. sprintf(extra, "\n");
  7141. for (i = 512; i < 1024 ; i += 16) {
  7142. /* RTW_INFO("0x%03x\t", i); */
  7143. pextra = extra + strlen(extra);
  7144. pextra += sprintf(pextra, "0x%03x\t", i);
  7145. for (j = 0; j < 8; j++) {
  7146. /* RTW_INFO("%02X ", data[i+j]); */
  7147. pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7148. }
  7149. /* RTW_INFO("\t"); */
  7150. pextra += sprintf(pextra, "\t");
  7151. for (; j < 16; j++) {
  7152. /* RTW_INFO("%02X ", data[i+j]); */
  7153. pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7154. }
  7155. /* RTW_INFO("\n"); */
  7156. pextra += sprintf(pextra, "\n");
  7157. }
  7158. /* RTW_INFO("\n"); */
  7159. } else if (strcmp(tmp[0], "btrmap") == 0) {
  7160. u8 BTStatus;
  7161. rtw_write8(padapter, 0xa3, 0x05); /* For 8723AB ,8821S ? */
  7162. BTStatus = rtw_read8(padapter, 0xa0);
  7163. RTW_INFO("%s: Check 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
  7164. if (BTStatus != 0x04) {
  7165. sprintf(extra, "BT Status not Active ,can't to read BT eFuse\n");
  7166. goto exit;
  7167. }
  7168. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7169. err = -EINVAL;
  7170. goto exit;
  7171. }
  7172. BTEfuse_PowerSwitch(padapter, 1, _TRUE);
  7173. /* rmap addr cnts */
  7174. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7175. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7176. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  7177. if (cnts == 0) {
  7178. RTW_INFO("%s: btrmap Fail!! cnts error!\n", __FUNCTION__);
  7179. err = -EINVAL;
  7180. goto exit;
  7181. }
  7182. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7183. #ifndef RTW_HALMAC
  7184. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7185. if ((addr + cnts) > max_available_len) {
  7186. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7187. err = -EFAULT;
  7188. goto exit;
  7189. }
  7190. #endif
  7191. if (rtw_BT_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
  7192. RTW_INFO("%s: rtw_BT_efuse_map_read error!!\n", __FUNCTION__);
  7193. err = -EFAULT;
  7194. goto exit;
  7195. }
  7196. *extra = 0;
  7197. pextra = extra;
  7198. /* RTW_INFO("%s: bt efuse data={", __FUNCTION__); */
  7199. for (i = 0; i < cnts; i++) {
  7200. /* RTW_INFO("0x%02x ", data[i]); */
  7201. pextra += sprintf(pextra, " 0x%02X ", data[i]);
  7202. }
  7203. /* RTW_INFO("}\n"); */
  7204. RTW_INFO(FUNC_ADPT_FMT ": BT MAC=[%s]\n", FUNC_ADPT_ARG(padapter), extra);
  7205. } else if (strcmp(tmp[0], "btffake") == 0) {
  7206. /* RTW_INFO("OFFSET\tVALUE(hex)\n"); */
  7207. sprintf(extra, "\n");
  7208. for (i = 0; i < 512; i += 16) {
  7209. /* RTW_INFO("0x%03x\t", i); */
  7210. pextra = extra + strlen(extra);
  7211. pextra += sprintf(pextra, "0x%03x\t", i);
  7212. for (j = 0; j < 8; j++) {
  7213. /* RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
  7214. pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7215. }
  7216. /* RTW_INFO("\t"); */
  7217. pextra += sprintf(pextra, "\t");
  7218. for (; j < 16; j++) {
  7219. /* RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
  7220. pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7221. }
  7222. /* RTW_INFO("\n"); */
  7223. pextra += sprintf(pextra, "\n");
  7224. }
  7225. /* RTW_INFO("\n"); */
  7226. } else if (strcmp(tmp[0], "btbfake") == 0) {
  7227. /* RTW_INFO("OFFSET\tVALUE(hex)\n"); */
  7228. sprintf(extra, "\n");
  7229. for (i = 512; i < 1024; i += 16) {
  7230. /* RTW_INFO("0x%03x\t", i); */
  7231. pextra = extra + strlen(extra);
  7232. pextra += sprintf(pextra, "0x%03x\t", i);
  7233. for (j = 0; j < 8; j++) {
  7234. /* RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
  7235. pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7236. }
  7237. /* RTW_INFO("\t"); */
  7238. pextra += sprintf(pextra, "\t");
  7239. for (; j < 16; j++) {
  7240. /* RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
  7241. pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7242. }
  7243. /* RTW_INFO("\n"); */
  7244. pextra += sprintf(pextra, "\n");
  7245. }
  7246. /* RTW_INFO("\n"); */
  7247. } else if (strcmp(tmp[0], "wlrfkmap") == 0) {
  7248. static u8 fk_order = 0;
  7249. u8 *efuse;
  7250. u32 shift, cnt;
  7251. u32 blksz = 0x200; /* The size of one time show, default 512 */
  7252. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&mapLen, _FALSE);
  7253. efuse = pEfuseHal->fakeEfuseModifiedMap;
  7254. shift = blksz * fk_order;
  7255. efuse += shift;
  7256. cnt = mapLen - shift;
  7257. if (cnt > blksz) {
  7258. cnt = blksz;
  7259. fk_order++;
  7260. } else
  7261. fk_order = 0;
  7262. sprintf(extra, "\n");
  7263. for (i = 0; i < cnt; i += 16) {
  7264. pextra = extra + strlen(extra);
  7265. pextra += sprintf(pextra, "0x%02x\t", shift + i);
  7266. for (j = 0; j < 8; j++)
  7267. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  7268. pextra += sprintf(pextra, "\t");
  7269. for (; j < 16; j++)
  7270. pextra += sprintf(pextra, "%02X ", efuse[i + j]);
  7271. pextra += sprintf(pextra, "\n");
  7272. }
  7273. if ((shift + cnt) < mapLen)
  7274. pextra += sprintf(pextra, "\t...more\n");
  7275. } else if (strcmp(tmp[0], "wlrfkrmap") == 0) {
  7276. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7277. RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
  7278. err = -EINVAL;
  7279. goto exit;
  7280. }
  7281. /* rmap addr cnts */
  7282. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7283. RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
  7284. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  7285. if (cnts == 0) {
  7286. RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
  7287. err = -EINVAL;
  7288. goto exit;
  7289. }
  7290. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7291. /* RTW_INFO("%s: data={", __FUNCTION__); */
  7292. *extra = 0;
  7293. pextra = extra;
  7294. for (i = 0; i < cnts; i++) {
  7295. RTW_INFO("wlrfkrmap = 0x%02x\n", pEfuseHal->fakeEfuseModifiedMap[addr + i]);
  7296. pextra += sprintf(pextra, "0x%02X ", pEfuseHal->fakeEfuseModifiedMap[addr+i]);
  7297. }
  7298. } else if (strcmp(tmp[0], "btrfkrmap") == 0) {
  7299. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7300. RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
  7301. err = -EINVAL;
  7302. goto exit;
  7303. }
  7304. /* rmap addr cnts */
  7305. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7306. RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
  7307. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  7308. if (cnts == 0) {
  7309. RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
  7310. err = -EINVAL;
  7311. goto exit;
  7312. }
  7313. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7314. /* RTW_INFO("%s: data={", __FUNCTION__); */
  7315. *extra = 0;
  7316. pextra = extra;
  7317. for (i = 0; i < cnts; i++) {
  7318. RTW_INFO("wlrfkrmap = 0x%02x\n", pEfuseHal->fakeBTEfuseModifiedMap[addr + i]);
  7319. pextra += sprintf(pextra, "0x%02X ", pEfuseHal->fakeBTEfuseModifiedMap[addr+i]);
  7320. }
  7321. } else if (strcmp(tmp[0], "mask") == 0) {
  7322. *extra = 0;
  7323. mask_len = sizeof(u8) * rtw_get_efuse_mask_arraylen(padapter);
  7324. rtw_efuse_mask_array(padapter, mask_buf);
  7325. if (padapter->registrypriv.bFileMaskEfuse == _TRUE)
  7326. _rtw_memcpy(mask_buf, maskfileBuffer, mask_len);
  7327. sprintf(extra, "\n");
  7328. pextra = extra + strlen(extra);
  7329. for (i = 0; i < mask_len; i++)
  7330. pextra += sprintf(pextra, "0x%02X\n", mask_buf[i]);
  7331. } else
  7332. sprintf(extra, "Command not found!");
  7333. exit:
  7334. if (data)
  7335. rtw_mfree(data, EFUSE_BT_MAX_MAP_LEN);
  7336. if (rawdata)
  7337. rtw_mfree(rawdata, EFUSE_BT_MAX_MAP_LEN);
  7338. if (!err)
  7339. wrqu->length = strlen(extra);
  7340. if (padapter->registrypriv.mp_mode == 0) {
  7341. #ifdef CONFIG_IPS
  7342. rtw_pm_set_ips(padapter, ips_mode);
  7343. #endif /* CONFIG_IPS */
  7344. #ifdef CONFIG_LPS
  7345. rtw_pm_set_lps(padapter, lps_mode);
  7346. #endif /* CONFIG_LPS */
  7347. }
  7348. #ifdef CONFIG_IOL
  7349. padapter->registrypriv.fw_iol = org_fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
  7350. #endif
  7351. return err;
  7352. }
  7353. #ifdef CONFIG_MP_INCLUDED
  7354. static int rtw_mp_efuse_set(struct net_device *dev,
  7355. struct iw_request_info *info,
  7356. union iwreq_data *wdata, char *extra)
  7357. {
  7358. struct iw_point *wrqu;
  7359. PADAPTER padapter;
  7360. struct pwrctrl_priv *pwrctrlpriv ;
  7361. PHAL_DATA_TYPE pHalData;
  7362. PEFUSE_HAL pEfuseHal;
  7363. struct hal_ops *pHalFunc;
  7364. struct mp_priv *pmp_priv;
  7365. u8 ips_mode = IPS_NUM; /* init invalid value */
  7366. u8 lps_mode = PS_MODE_NUM; /* init invalid value */
  7367. u32 i = 0, j = 0, jj, kk;
  7368. u8 *setdata = NULL;
  7369. u8 *ShadowMapBT = NULL;
  7370. u8 *ShadowMapWiFi = NULL;
  7371. u8 *setrawdata = NULL;
  7372. char *pch, *ptmp, *token, *tmp[3] = {0x00, 0x00, 0x00};
  7373. u16 addr = 0xFF, cnts = 0, BTStatus = 0 , max_available_len = 0;
  7374. u16 wifimaplen;
  7375. int err;
  7376. boolean bcmpchk = _TRUE;
  7377. wrqu = (struct iw_point *)wdata;
  7378. padapter = rtw_netdev_priv(dev);
  7379. pwrctrlpriv = adapter_to_pwrctl(padapter);
  7380. pHalData = GET_HAL_DATA(padapter);
  7381. pEfuseHal = &pHalData->EfuseHal;
  7382. pHalFunc = &padapter->hal_func;
  7383. pmp_priv = &padapter->mppriv;
  7384. err = 0;
  7385. if (copy_from_user(extra, wrqu->pointer, wrqu->length))
  7386. return -EFAULT;
  7387. *(extra + wrqu->length) = '\0';
  7388. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&wifimaplen, _FALSE);
  7389. setdata = rtw_zmalloc(1024);
  7390. if (setdata == NULL) {
  7391. err = -ENOMEM;
  7392. goto exit;
  7393. }
  7394. ShadowMapBT = rtw_malloc(EFUSE_BT_MAX_MAP_LEN);
  7395. if (ShadowMapBT == NULL) {
  7396. err = -ENOMEM;
  7397. goto exit;
  7398. }
  7399. ShadowMapWiFi = rtw_malloc(wifimaplen);
  7400. if (ShadowMapWiFi == NULL) {
  7401. err = -ENOMEM;
  7402. goto exit;
  7403. }
  7404. setrawdata = rtw_malloc(EFUSE_MAX_SIZE);
  7405. if (setrawdata == NULL) {
  7406. err = -ENOMEM;
  7407. goto exit;
  7408. }
  7409. #ifdef CONFIG_LPS
  7410. lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
  7411. rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
  7412. #endif
  7413. #ifdef CONFIG_IPS
  7414. ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
  7415. rtw_pm_set_ips(padapter, IPS_NONE);
  7416. #endif
  7417. pch = extra;
  7418. RTW_INFO("%s: in=%s\n", __FUNCTION__, extra);
  7419. i = 0;
  7420. while ((token = strsep(&pch, ",")) != NULL) {
  7421. if (i > 2)
  7422. break;
  7423. tmp[i] = token;
  7424. i++;
  7425. }
  7426. /* tmp[0],[1],[2] */
  7427. /* wmap,addr,00e04c871200 */
  7428. if (strcmp(tmp[0], "wmap") == 0) {
  7429. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7430. err = -EINVAL;
  7431. goto exit;
  7432. }
  7433. #ifndef RTW_HALMAC
  7434. /* unknown bug workaround, need to fix later */
  7435. addr = 0x1ff;
  7436. rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
  7437. rtw_msleep_os(10);
  7438. rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
  7439. rtw_msleep_os(10);
  7440. rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
  7441. rtw_msleep_os(10);
  7442. rtw_read8(padapter, EFUSE_CTRL);
  7443. #endif /* RTW_HALMAC */
  7444. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7445. addr &= 0xFFF;
  7446. cnts = strlen(tmp[2]);
  7447. if (cnts % 2) {
  7448. err = -EINVAL;
  7449. goto exit;
  7450. }
  7451. cnts /= 2;
  7452. if (cnts == 0) {
  7453. err = -EINVAL;
  7454. goto exit;
  7455. }
  7456. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7457. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7458. RTW_INFO("%s: map data=%s\n", __FUNCTION__, tmp[2]);
  7459. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7460. setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7461. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7462. if ((addr + cnts) > max_available_len) {
  7463. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7464. err = -EFAULT;
  7465. goto exit;
  7466. }
  7467. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
  7468. RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7469. err = -EFAULT;
  7470. goto exit;
  7471. }
  7472. *extra = 0;
  7473. RTW_INFO("%s: after rtw_efuse_map_write to _rtw_memcmp\n", __func__);
  7474. if (rtw_efuse_mask_map_read(padapter, addr, cnts, ShadowMapWiFi) == _SUCCESS) {
  7475. if (_rtw_memcmp((void *)ShadowMapWiFi , (void *)setdata, cnts)) {
  7476. RTW_INFO("%s: WiFi write map afterf compare success\n", __FUNCTION__);
  7477. sprintf(extra, "WiFi write map compare OK\n");
  7478. err = 0;
  7479. goto exit;
  7480. } else {
  7481. sprintf(extra, "WiFi write map compare FAIL\n");
  7482. RTW_INFO("%s: WiFi write map compare Fail\n", __FUNCTION__);
  7483. err = 0;
  7484. goto exit;
  7485. }
  7486. }
  7487. } else if (strcmp(tmp[0], "wraw") == 0) {
  7488. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7489. err = -EINVAL;
  7490. goto exit;
  7491. }
  7492. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7493. addr &= 0xFFF;
  7494. cnts = strlen(tmp[2]);
  7495. if (cnts % 2) {
  7496. err = -EINVAL;
  7497. goto exit;
  7498. }
  7499. cnts /= 2;
  7500. if (cnts == 0) {
  7501. err = -EINVAL;
  7502. goto exit;
  7503. }
  7504. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7505. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7506. RTW_INFO("%s: raw data=%s\n", __FUNCTION__, tmp[2]);
  7507. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7508. setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7509. if (rtw_efuse_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
  7510. RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7511. err = -EFAULT;
  7512. goto exit;
  7513. }
  7514. } else if (strcmp(tmp[0], "btwraw") == 0) {
  7515. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7516. err = -EINVAL;
  7517. goto exit;
  7518. }
  7519. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7520. addr &= 0xFFF;
  7521. cnts = strlen(tmp[2]);
  7522. if (cnts % 2) {
  7523. err = -EINVAL;
  7524. goto exit;
  7525. }
  7526. cnts /= 2;
  7527. if (cnts == 0) {
  7528. err = -EINVAL;
  7529. goto exit;
  7530. }
  7531. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7532. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7533. RTW_INFO("%s: raw data=%s\n", __FUNCTION__, tmp[2]);
  7534. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7535. setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7536. #ifdef RTW_HALMAC
  7537. if (rtw_efuse_bt_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
  7538. RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7539. err = -EFAULT;
  7540. goto exit;
  7541. }
  7542. #else
  7543. rtw_write8(padapter, 0x35, 1); /* switch bank 1 (BT)*/
  7544. if (rtw_efuse_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
  7545. RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7546. rtw_write8(padapter, 0x35, 0); /* switch bank 0 (WiFi)*/
  7547. err = -EFAULT;
  7548. goto exit;
  7549. }
  7550. rtw_write8(padapter, 0x35, 0); /* switch bank 0 (WiFi)*/
  7551. #endif
  7552. } else if (strcmp(tmp[0], "mac") == 0) {
  7553. if (tmp[1] == NULL) {
  7554. err = -EINVAL;
  7555. goto exit;
  7556. }
  7557. /* mac,00e04c871200 */
  7558. if (hal_efuse_macaddr_offset(padapter) == -1) {
  7559. err = -EFAULT;
  7560. goto exit;
  7561. }
  7562. addr = hal_efuse_macaddr_offset(padapter);
  7563. cnts = strlen(tmp[1]);
  7564. if (cnts % 2) {
  7565. err = -EINVAL;
  7566. goto exit;
  7567. }
  7568. cnts /= 2;
  7569. if (cnts == 0) {
  7570. err = -EINVAL;
  7571. goto exit;
  7572. }
  7573. if (cnts > 6) {
  7574. RTW_INFO("%s: error data for mac addr=\"%s\"\n", __FUNCTION__, tmp[1]);
  7575. err = -EFAULT;
  7576. goto exit;
  7577. }
  7578. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7579. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7580. RTW_INFO("%s: MAC address=%s\n", __FUNCTION__, tmp[1]);
  7581. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7582. setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
  7583. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7584. if ((addr + cnts) > max_available_len) {
  7585. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7586. err = -EFAULT;
  7587. goto exit;
  7588. }
  7589. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
  7590. RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7591. err = -EFAULT;
  7592. goto exit;
  7593. }
  7594. } else if (strcmp(tmp[0], "vidpid") == 0) {
  7595. if (tmp[1] == NULL) {
  7596. err = -EINVAL;
  7597. goto exit;
  7598. }
  7599. /* pidvid,da0b7881 */
  7600. #ifdef CONFIG_RTL8188E
  7601. #ifdef CONFIG_USB_HCI
  7602. addr = EEPROM_VID_88EU;
  7603. #endif
  7604. #ifdef CONFIG_PCI_HCI
  7605. addr = EEPROM_VID_88EE;
  7606. #endif
  7607. #endif /* CONFIG_RTL8188E */
  7608. #ifdef CONFIG_RTL8192E
  7609. #ifdef CONFIG_USB_HCI
  7610. addr = EEPROM_VID_8192EU;
  7611. #endif
  7612. #ifdef CONFIG_PCI_HCI
  7613. addr = EEPROM_VID_8192EE;
  7614. #endif
  7615. #endif /* CONFIG_RTL8188E */
  7616. #ifdef CONFIG_RTL8723B
  7617. addr = EEPROM_VID_8723BU;
  7618. #endif
  7619. #ifdef CONFIG_RTL8188F
  7620. addr = EEPROM_VID_8188FU;
  7621. #endif
  7622. #ifdef CONFIG_RTL8188GTV
  7623. addr = EEPROM_VID_8188GTVU;
  7624. #endif
  7625. #ifdef CONFIG_RTL8703B
  7626. #ifdef CONFIG_USB_HCI
  7627. addr = EEPROM_VID_8703BU;
  7628. #endif /* CONFIG_USB_HCI */
  7629. #endif /* CONFIG_RTL8703B */
  7630. #ifdef CONFIG_RTL8723D
  7631. #ifdef CONFIG_USB_HCI
  7632. addr = EEPROM_VID_8723DU;
  7633. #endif /* CONFIG_USB_HCI */
  7634. #endif /* CONFIG_RTL8723D */
  7635. cnts = strlen(tmp[1]);
  7636. if (cnts % 2) {
  7637. err = -EINVAL;
  7638. goto exit;
  7639. }
  7640. cnts /= 2;
  7641. if (cnts == 0) {
  7642. err = -EINVAL;
  7643. goto exit;
  7644. }
  7645. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7646. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7647. RTW_INFO("%s: VID/PID=%s\n", __FUNCTION__, tmp[1]);
  7648. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7649. setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
  7650. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7651. if ((addr + cnts) > max_available_len) {
  7652. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7653. err = -EFAULT;
  7654. goto exit;
  7655. }
  7656. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
  7657. RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7658. err = -EFAULT;
  7659. goto exit;
  7660. }
  7661. } else if (strcmp(tmp[0], "wldumpfake") == 0) {
  7662. if (wifimaplen > EFUSE_MAX_MAP_LEN)
  7663. cnts = EFUSE_MAX_MAP_LEN;
  7664. else
  7665. cnts = wifimaplen;
  7666. if (rtw_efuse_mask_map_read(padapter, 0, cnts, pEfuseHal->fakeEfuseModifiedMap) == _SUCCESS)
  7667. RTW_INFO("%s: WiFi hw efuse dump to Fake map success\n", __func__);
  7668. else {
  7669. RTW_INFO("%s: WiFi hw efuse dump to Fake map Fail\n", __func__);
  7670. err = -EFAULT;
  7671. }
  7672. } else if (strcmp(tmp[0], "btwmap") == 0) {
  7673. rtw_write8(padapter, 0xa3, 0x05); /* For 8723AB ,8821S ? */
  7674. BTStatus = rtw_read8(padapter, 0xa0);
  7675. RTW_INFO("%s: btwmap before read 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
  7676. if (BTStatus != 0x04) {
  7677. sprintf(extra, "BT Status not Active ,can't do Write\n");
  7678. goto exit;
  7679. }
  7680. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7681. err = -EINVAL;
  7682. goto exit;
  7683. }
  7684. #ifndef RTW_HALMAC
  7685. BTEfuse_PowerSwitch(padapter, 1, _TRUE);
  7686. addr = 0x1ff;
  7687. rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
  7688. rtw_msleep_os(10);
  7689. rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
  7690. rtw_msleep_os(10);
  7691. rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
  7692. rtw_msleep_os(10);
  7693. rtw_read8(padapter, EFUSE_CTRL);
  7694. BTEfuse_PowerSwitch(padapter, 1, _FALSE);
  7695. #endif /* RTW_HALMAC */
  7696. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7697. addr &= 0xFFF;
  7698. cnts = strlen(tmp[2]);
  7699. if (cnts % 2) {
  7700. err = -EINVAL;
  7701. goto exit;
  7702. }
  7703. cnts /= 2;
  7704. if (cnts == 0) {
  7705. err = -EINVAL;
  7706. goto exit;
  7707. }
  7708. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7709. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7710. RTW_INFO("%s: BT data=%s\n", __FUNCTION__, tmp[2]);
  7711. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7712. setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7713. #ifndef RTW_HALMAC
  7714. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_len, _FALSE);
  7715. if ((addr + cnts) > max_available_len) {
  7716. RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7717. err = -EFAULT;
  7718. goto exit;
  7719. }
  7720. #endif
  7721. if (rtw_BT_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
  7722. RTW_INFO("%s: rtw_BT_efuse_map_write error!!\n", __FUNCTION__);
  7723. err = -EFAULT;
  7724. goto exit;
  7725. }
  7726. *extra = 0;
  7727. RTW_INFO("%s: after rtw_BT_efuse_map_write to _rtw_memcmp\n", __FUNCTION__);
  7728. if ((rtw_BT_efuse_map_read(padapter, addr, cnts, ShadowMapBT) == _SUCCESS)) {
  7729. if (_rtw_memcmp((void *)ShadowMapBT , (void *)setdata, cnts)) {
  7730. RTW_INFO("%s: BT write map compare OK BTStatus=0x%x\n", __FUNCTION__, BTStatus);
  7731. sprintf(extra, "BT write map compare OK");
  7732. err = 0;
  7733. goto exit;
  7734. } else {
  7735. sprintf(extra, "BT write map compare FAIL");
  7736. RTW_INFO("%s: BT write map compare FAIL BTStatus=0x%x\n", __FUNCTION__, BTStatus);
  7737. err = 0;
  7738. goto exit;
  7739. }
  7740. }
  7741. } else if (strcmp(tmp[0], "btwfake") == 0) {
  7742. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7743. err = -EINVAL;
  7744. goto exit;
  7745. }
  7746. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7747. addr &= 0xFFF;
  7748. cnts = strlen(tmp[2]);
  7749. if (cnts % 2) {
  7750. err = -EINVAL;
  7751. goto exit;
  7752. }
  7753. cnts /= 2;
  7754. if (cnts == 0) {
  7755. err = -EINVAL;
  7756. goto exit;
  7757. }
  7758. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7759. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7760. RTW_INFO("%s: BT tmp data=%s\n", __FUNCTION__, tmp[2]);
  7761. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7762. pEfuseHal->fakeBTEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7763. } else if (strcmp(tmp[0], "btdumpfake") == 0) {
  7764. if (rtw_BT_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _SUCCESS)
  7765. RTW_INFO("%s: BT read all map success\n", __FUNCTION__);
  7766. else {
  7767. RTW_INFO("%s: BT read all map Fail!\n", __FUNCTION__);
  7768. err = -EFAULT;
  7769. }
  7770. } else if (strcmp(tmp[0], "btfk2map") == 0) {
  7771. rtw_write8(padapter, 0xa3, 0x05);
  7772. BTStatus = rtw_read8(padapter, 0xa0);
  7773. RTW_INFO("%s: btwmap before read 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
  7774. if (BTStatus != 0x04) {
  7775. sprintf(extra, "BT Status not Active Write FAIL\n");
  7776. goto exit;
  7777. }
  7778. #ifndef RTW_HALMAC
  7779. BTEfuse_PowerSwitch(padapter, 1, _TRUE);
  7780. addr = 0x1ff;
  7781. rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
  7782. rtw_msleep_os(10);
  7783. rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
  7784. rtw_msleep_os(10);
  7785. rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
  7786. rtw_msleep_os(10);
  7787. rtw_read8(padapter, EFUSE_CTRL);
  7788. BTEfuse_PowerSwitch(padapter, 1, _FALSE);
  7789. #endif /* RTW_HALMAC */
  7790. _rtw_memcpy(pEfuseHal->BTEfuseModifiedMap, pEfuseHal->fakeBTEfuseModifiedMap, EFUSE_BT_MAX_MAP_LEN);
  7791. if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL) {
  7792. RTW_INFO("%s: rtw_BT_efuse_map_write error!\n", __FUNCTION__);
  7793. err = -EFAULT;
  7794. goto exit;
  7795. }
  7796. RTW_INFO("pEfuseHal->fakeBTEfuseModifiedMap OFFSET\tVALUE(hex)\n");
  7797. for (i = 0; i < EFUSE_BT_MAX_MAP_LEN; i += 16) {
  7798. printk("0x%02x\t", i);
  7799. for (j = 0; j < 8; j++)
  7800. printk("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
  7801. printk("\t");
  7802. for (; j < 16; j++)
  7803. printk("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
  7804. printk("\n");
  7805. }
  7806. printk("\n");
  7807. #if 1
  7808. err = -EFAULT;
  7809. RTW_INFO("%s: rtw_BT_efuse_map_read _rtw_memcmp\n", __FUNCTION__);
  7810. if ((rtw_BT_efuse_map_read(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseInitMap) == _SUCCESS)) {
  7811. if (_rtw_memcmp((void *)pEfuseHal->fakeBTEfuseModifiedMap, (void *)pEfuseHal->fakeBTEfuseInitMap, EFUSE_BT_MAX_MAP_LEN)) {
  7812. sprintf(extra, "BT write map compare OK");
  7813. RTW_INFO("%s: BT write map afterf compare success BTStatus=0x%x\n", __FUNCTION__, BTStatus);
  7814. err = 0;
  7815. goto exit;
  7816. } else {
  7817. sprintf(extra, "BT write map compare FAIL");
  7818. if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL)
  7819. RTW_INFO("%s: rtw_BT_efuse_map_write compare error,retry = %d!\n", __FUNCTION__, i);
  7820. if (rtw_BT_efuse_map_read(padapter, EFUSE_BT, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseInitMap) == _SUCCESS) {
  7821. RTW_INFO("pEfuseHal->fakeBTEfuseInitMap OFFSET\tVALUE(hex)\n");
  7822. for (i = 0; i < EFUSE_BT_MAX_MAP_LEN; i += 16) {
  7823. printk("0x%02x\t", i);
  7824. for (j = 0; j < 8; j++)
  7825. printk("%02X ", pEfuseHal->fakeBTEfuseInitMap[i + j]);
  7826. printk("\t");
  7827. for (; j < 16; j++)
  7828. printk("%02X ", pEfuseHal->fakeBTEfuseInitMap[i + j]);
  7829. printk("\n");
  7830. }
  7831. printk("\n");
  7832. }
  7833. RTW_INFO("%s: BT write map afterf compare not match to write efuse try write Map again , BTStatus=0x%x\n", __FUNCTION__, BTStatus);
  7834. goto exit;
  7835. }
  7836. }
  7837. #endif
  7838. } else if (strcmp(tmp[0], "wlfk2map") == 0) {
  7839. *extra = 0;
  7840. if (padapter->registrypriv.bFileMaskEfuse != _TRUE && pmp_priv->bloadefusemap == _TRUE) {
  7841. RTW_INFO("%s: File eFuse mask file not to be loaded\n", __FUNCTION__);
  7842. sprintf(extra, "Not load eFuse mask file yet, Please use the efuse_mask CMD, now remove the interface !!!!\n");
  7843. rtw_set_surprise_removed(padapter);
  7844. err = 0;
  7845. goto exit;
  7846. }
  7847. if (wifimaplen > EFUSE_MAX_MAP_LEN)
  7848. cnts = EFUSE_MAX_MAP_LEN;
  7849. else
  7850. cnts = wifimaplen;
  7851. if (rtw_efuse_map_write(padapter, 0x00, cnts, pEfuseHal->fakeEfuseModifiedMap) == _FAIL) {
  7852. RTW_INFO("%s: rtw_efuse_map_write fakeEfuseModifiedMap error!\n", __FUNCTION__);
  7853. err = -EFAULT;
  7854. goto exit;
  7855. }
  7856. if (rtw_efuse_mask_map_read(padapter, 0x00, wifimaplen, ShadowMapWiFi) == _SUCCESS) {
  7857. addr = 0x00;
  7858. err = _TRUE;
  7859. for (i = 0; i < cnts; i++) {
  7860. if (padapter->registrypriv.boffefusemask == 0) {
  7861. if (padapter->registrypriv.bFileMaskEfuse == _TRUE) {
  7862. if (rtw_file_efuse_IsMasked(padapter, addr + i) == _TRUE) /*use file efuse mask. */
  7863. bcmpchk = _FALSE;
  7864. } else {
  7865. if (efuse_IsMasked(padapter, addr + i) == _TRUE)
  7866. bcmpchk = _FALSE;
  7867. }
  7868. }
  7869. if (bcmpchk == _TRUE) {
  7870. RTW_INFO("compare readMapWiFi[0x%02x] = %x, ModifiedMap = %x\n", addr + i, ShadowMapWiFi[ addr + i], pEfuseHal->fakeEfuseModifiedMap[addr + i]);
  7871. if (_rtw_memcmp((void *) &ShadowMapWiFi[addr + i], (void *)&pEfuseHal->fakeEfuseModifiedMap[addr + i], 1) == _FALSE){
  7872. err = _FALSE;
  7873. break;
  7874. }
  7875. }
  7876. bcmpchk = _TRUE;
  7877. }
  7878. }
  7879. if (err) {
  7880. RTW_INFO("%s: WiFi write map afterf compare OK\n", __FUNCTION__);
  7881. sprintf(extra, "WiFi write map compare OK\n");
  7882. err = 0;
  7883. goto exit;
  7884. } else {
  7885. sprintf(extra, "WiFi write map compare FAIL\n");
  7886. RTW_INFO("%s: WiFi write map compare Fail\n", __FUNCTION__);
  7887. err = 0;
  7888. goto exit;
  7889. }
  7890. } else if (strcmp(tmp[0], "wlwfake") == 0) {
  7891. if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
  7892. err = -EINVAL;
  7893. goto exit;
  7894. }
  7895. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7896. addr &= 0xFFF;
  7897. cnts = strlen(tmp[2]);
  7898. if (cnts % 2) {
  7899. err = -EINVAL;
  7900. goto exit;
  7901. }
  7902. cnts /= 2;
  7903. if (cnts == 0) {
  7904. err = -EINVAL;
  7905. goto exit;
  7906. }
  7907. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7908. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7909. RTW_INFO("%s: map tmp data=%s\n", __FUNCTION__, tmp[2]);
  7910. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7911. pEfuseHal->fakeEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
  7912. _rtw_memset(extra, '\0', strlen(extra));
  7913. sprintf(extra, "wlwfake OK\n");
  7914. }
  7915. else if (strcmp(tmp[0], "wfakemac") == 0) {
  7916. if (tmp[1] == NULL) {
  7917. err = -EINVAL;
  7918. goto exit;
  7919. }
  7920. /* wfakemac,00e04c871200 */
  7921. if (hal_efuse_macaddr_offset(padapter) == -1) {
  7922. err = -EFAULT;
  7923. goto exit;
  7924. }
  7925. addr = hal_efuse_macaddr_offset(padapter);
  7926. cnts = strlen(tmp[1]);
  7927. if (cnts % 2) {
  7928. err = -EINVAL;
  7929. goto exit;
  7930. }
  7931. cnts /= 2;
  7932. if (cnts == 0) {
  7933. err = -EINVAL;
  7934. goto exit;
  7935. }
  7936. if (cnts > 6) {
  7937. RTW_INFO("%s: error data for mac addr=\"%s\"\n", __FUNCTION__, tmp[1]);
  7938. err = -EFAULT;
  7939. goto exit;
  7940. }
  7941. RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
  7942. RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
  7943. RTW_INFO("%s: MAC address=%s\n", __FUNCTION__, tmp[1]);
  7944. for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
  7945. pEfuseHal->fakeEfuseModifiedMap[addr + jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
  7946. _rtw_memset(extra, '\0', strlen(extra));
  7947. sprintf(extra, "write mac addr to fake map OK\n");
  7948. } else if(strcmp(tmp[0], "update") == 0) {
  7949. RTW_INFO("To Use new eFuse map\n");
  7950. /*step read efuse/eeprom data and get mac_addr*/
  7951. rtw_hal_read_chip_info(padapter);
  7952. /* set mac addr*/
  7953. rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));
  7954. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 17, 0)
  7955. _rtw_memcpy(padapter->pnetdev->dev_addr, get_hal_mac_addr(padapter), ETH_ALEN); /* set mac addr to net_device */
  7956. #else
  7957. eth_hw_addr_set(padapter->pnetdev, get_hal_mac_addr(padapter));
  7958. #endif
  7959. #ifdef CONFIG_P2P
  7960. rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
  7961. #endif
  7962. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  7963. rtw_hal_change_macaddr_mbid(padapter, adapter_mac_addr(padapter));
  7964. #else
  7965. rtw_hal_set_hwreg(padapter, HW_VAR_MAC_ADDR, adapter_mac_addr(padapter)); /* set mac addr to mac register */
  7966. #endif
  7967. /*pHalFunc->hal_deinit(padapter);*/
  7968. if (pHalFunc->hal_init(padapter) == _FAIL) {
  7969. err = -EINVAL;
  7970. goto exit;
  7971. }
  7972. _rtw_memset(extra, '\0', strlen(extra));
  7973. sprintf(extra, "eFuse Update OK\n");
  7974. } else if (strcmp(tmp[0], "analyze") == 0) {
  7975. rtw_efuse_analyze(padapter, EFUSE_WIFI, 0);
  7976. _rtw_memset(extra, '\0', strlen(extra));
  7977. sprintf(extra, "eFuse Analyze OK,please to check kernel log\n");
  7978. }
  7979. exit:
  7980. if (setdata)
  7981. rtw_mfree(setdata, 1024);
  7982. if (ShadowMapBT)
  7983. rtw_mfree(ShadowMapBT, EFUSE_BT_MAX_MAP_LEN);
  7984. if (ShadowMapWiFi)
  7985. rtw_mfree(ShadowMapWiFi, wifimaplen);
  7986. if (setrawdata)
  7987. rtw_mfree(setrawdata, EFUSE_MAX_SIZE);
  7988. wrqu->length = strlen(extra);
  7989. if (padapter->registrypriv.mp_mode == 0) {
  7990. #ifdef CONFIG_IPS
  7991. rtw_pm_set_ips(padapter, ips_mode);
  7992. #endif /* CONFIG_IPS */
  7993. #ifdef CONFIG_LPS
  7994. rtw_pm_set_lps(padapter, lps_mode);
  7995. #endif /* CONFIG_LPS */
  7996. }
  7997. return err;
  7998. }
  7999. #ifdef CONFIG_RTW_CUSTOMER_STR
  8000. static int rtw_mp_customer_str(
  8001. struct net_device *dev,
  8002. struct iw_request_info *info,
  8003. union iwreq_data *wrqu, char *extra)
  8004. {
  8005. _adapter *adapter = rtw_netdev_priv(dev);
  8006. u32 len;
  8007. u8 *pbuf = NULL, *pch;
  8008. char *ptmp;
  8009. u8 param[RTW_CUSTOMER_STR_LEN];
  8010. u8 count = 0;
  8011. u8 tmp;
  8012. u8 i;
  8013. u32 pos;
  8014. u8 ret;
  8015. u8 read = 0;
  8016. if (adapter->registrypriv.mp_mode != 1
  8017. || !adapter->registrypriv.mp_customer_str)
  8018. return -EFAULT;
  8019. len = wrqu->data.length + 1;
  8020. pbuf = (u8 *)rtw_zmalloc(len);
  8021. if (pbuf == NULL) {
  8022. RTW_WARN("%s: no memory!\n", __func__);
  8023. return -ENOMEM;
  8024. }
  8025. if (copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length)) {
  8026. rtw_mfree(pbuf, len);
  8027. RTW_WARN("%s: copy from user fail!\n", __func__);
  8028. return -EFAULT;
  8029. }
  8030. RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
  8031. ptmp = (char *)pbuf;
  8032. pch = strsep(&ptmp, ",");
  8033. if ((pch == NULL) || (strlen(pch) == 0)) {
  8034. rtw_mfree(pbuf, len);
  8035. RTW_INFO("%s: parameter error(no cmd)!\n", __func__);
  8036. return -EFAULT;
  8037. }
  8038. _rtw_memset(param, 0xFF, RTW_CUSTOMER_STR_LEN);
  8039. if (strcmp(pch, "read") == 0) {
  8040. read = 1;
  8041. ret = rtw_hal_customer_str_read(adapter, param);
  8042. } else if (strcmp(pch, "write") == 0) {
  8043. do {
  8044. pch = strsep(&ptmp, ":");
  8045. if ((pch == NULL) || (strlen(pch) == 0))
  8046. break;
  8047. if (strlen(pch) != 2
  8048. || IsHexDigit(*pch) == _FALSE
  8049. || IsHexDigit(*(pch + 1)) == _FALSE
  8050. || sscanf(pch, "%hhx", &tmp) != 1
  8051. ) {
  8052. RTW_WARN("%s: invalid 8-bit hex!\n", __func__);
  8053. rtw_mfree(pbuf, len);
  8054. return -EFAULT;
  8055. }
  8056. param[count++] = tmp;
  8057. } while (count < RTW_CUSTOMER_STR_LEN);
  8058. if (count == 0) {
  8059. rtw_mfree(pbuf, len);
  8060. RTW_WARN("%s: no input!\n", __func__);
  8061. return -EFAULT;
  8062. }
  8063. ret = rtw_hal_customer_str_write(adapter, param);
  8064. } else {
  8065. rtw_mfree(pbuf, len);
  8066. RTW_INFO("%s: parameter error(unknown cmd)!\n", __func__);
  8067. return -EFAULT;
  8068. }
  8069. pos = sprintf(extra, "%s: ", read ? "read" : "write");
  8070. if (read == 0 || ret == _SUCCESS) {
  8071. for (i = 0; i < RTW_CUSTOMER_STR_LEN; i++)
  8072. pos += sprintf(extra + pos, "%02x:", param[i]);
  8073. extra[pos] = 0;
  8074. pos--;
  8075. }
  8076. pos += sprintf(extra + pos, " %s", ret == _SUCCESS ? "OK" : "FAIL");
  8077. wrqu->data.length = strlen(extra) + 1;
  8078. free_buf:
  8079. rtw_mfree(pbuf, len);
  8080. return 0;
  8081. }
  8082. #endif /* CONFIG_RTW_CUSTOMER_STR */
  8083. static int rtw_priv_mp_set(struct net_device *dev,
  8084. struct iw_request_info *info,
  8085. union iwreq_data *wdata, char *extra)
  8086. {
  8087. struct iw_point *wrqu = (struct iw_point *)wdata;
  8088. u32 subcmd = wrqu->flags;
  8089. #ifdef CONFIG_CONCURRENT_MODE
  8090. PADAPTER padapter = rtw_netdev_priv(dev);
  8091. #endif
  8092. if (!is_primary_adapter(padapter)) {
  8093. RTW_INFO("MP mode only primary Adapter support\n");
  8094. return -EIO;
  8095. }
  8096. switch (subcmd) {
  8097. case CTA_TEST:
  8098. RTW_INFO("set CTA_TEST\n");
  8099. rtw_cta_test_start(dev, info, wdata, extra);
  8100. break;
  8101. case MP_DISABLE_BT_COEXIST:
  8102. RTW_INFO("set case MP_DISABLE_BT_COEXIST\n");
  8103. rtw_mp_disable_bt_coexist(dev, info, wdata, extra);
  8104. break;
  8105. case MP_IQK:
  8106. RTW_INFO("set MP_IQK\n");
  8107. rtw_mp_iqk(dev, info, wrqu, extra);
  8108. break;
  8109. case MP_LCK:
  8110. RTW_INFO("set MP_LCK\n");
  8111. rtw_mp_lck(dev, info, wrqu, extra);
  8112. break;
  8113. default:
  8114. return -EIO;
  8115. }
  8116. return 0;
  8117. }
  8118. static int rtw_priv_mp_get(struct net_device *dev,
  8119. struct iw_request_info *info,
  8120. union iwreq_data *wdata, char *extra)
  8121. {
  8122. struct iw_point *wrqu = (struct iw_point *)wdata;
  8123. u32 subcmd = wrqu->flags;
  8124. #ifdef CONFIG_CONCURRENT_MODE
  8125. PADAPTER padapter = rtw_netdev_priv(dev);
  8126. #endif
  8127. if (!is_primary_adapter(padapter)) {
  8128. RTW_INFO("MP mode only primary Adapter support\n");
  8129. return -EIO;
  8130. }
  8131. switch (subcmd) {
  8132. case MP_START:
  8133. RTW_INFO("set case mp_start\n");
  8134. rtw_mp_start(dev, info, wrqu, extra);
  8135. break;
  8136. case MP_STOP:
  8137. RTW_INFO("set case mp_stop\n");
  8138. rtw_mp_stop(dev, info, wrqu, extra);
  8139. break;
  8140. case MP_BANDWIDTH:
  8141. RTW_INFO("set case mp_bandwidth\n");
  8142. rtw_mp_bandwidth(dev, info, wrqu, extra);
  8143. break;
  8144. case MP_RESET_STATS:
  8145. RTW_INFO("set case MP_RESET_STATS\n");
  8146. rtw_mp_reset_stats(dev, info, wrqu, extra);
  8147. break;
  8148. case MP_SetRFPathSwh:
  8149. RTW_INFO("set MP_SetRFPathSwitch\n");
  8150. rtw_mp_SetRFPath(dev, info, wrqu, extra);
  8151. break;
  8152. case WRITE_REG:
  8153. rtw_mp_write_reg(dev, info, wrqu, extra);
  8154. break;
  8155. case WRITE_RF:
  8156. rtw_mp_write_rf(dev, info, wrqu, extra);
  8157. break;
  8158. case MP_PHYPARA:
  8159. RTW_INFO("mp_get MP_PHYPARA\n");
  8160. rtw_mp_phypara(dev, info, wrqu, extra);
  8161. break;
  8162. case MP_CHANNEL:
  8163. RTW_INFO("set case mp_channel\n");
  8164. rtw_mp_channel(dev , info, wrqu, extra);
  8165. break;
  8166. case MP_CHL_OFFSET:
  8167. RTW_INFO("set case mp_ch_offset\n");
  8168. rtw_mp_ch_offset(dev , info, wrqu, extra);
  8169. break;
  8170. case READ_REG:
  8171. RTW_INFO("mp_get READ_REG\n");
  8172. rtw_mp_read_reg(dev, info, wrqu, extra);
  8173. break;
  8174. case READ_RF:
  8175. RTW_INFO("mp_get READ_RF\n");
  8176. rtw_mp_read_rf(dev, info, wrqu, extra);
  8177. break;
  8178. case MP_RATE:
  8179. RTW_INFO("set case mp_rate\n");
  8180. rtw_mp_rate(dev, info, wrqu, extra);
  8181. break;
  8182. case MP_TXPOWER:
  8183. RTW_INFO("set case MP_TXPOWER\n");
  8184. rtw_mp_txpower(dev, info, wrqu, extra);
  8185. break;
  8186. case MP_ANT_TX:
  8187. RTW_INFO("set case MP_ANT_TX\n");
  8188. rtw_mp_ant_tx(dev, info, wrqu, extra);
  8189. break;
  8190. case MP_ANT_RX:
  8191. RTW_INFO("set case MP_ANT_RX\n");
  8192. rtw_mp_ant_rx(dev, info, wrqu, extra);
  8193. break;
  8194. case MP_QUERY:
  8195. rtw_mp_trx_query(dev, info, wrqu, extra);
  8196. break;
  8197. case MP_CTX:
  8198. RTW_INFO("set case MP_CTX\n");
  8199. rtw_mp_ctx(dev, info, wrqu, extra);
  8200. break;
  8201. case MP_ARX:
  8202. RTW_INFO("set case MP_ARX\n");
  8203. rtw_mp_arx(dev, info, wrqu, extra);
  8204. break;
  8205. case MP_DUMP:
  8206. RTW_INFO("set case MP_DUMP\n");
  8207. rtw_mp_dump(dev, info, wrqu, extra);
  8208. break;
  8209. case MP_PSD:
  8210. RTW_INFO("set case MP_PSD\n");
  8211. rtw_mp_psd(dev, info, wrqu, extra);
  8212. break;
  8213. case MP_THER:
  8214. RTW_INFO("set case MP_THER\n");
  8215. rtw_mp_thermal(dev, info, wrqu, extra);
  8216. break;
  8217. case MP_PwrCtlDM:
  8218. RTW_INFO("set MP_PwrCtlDM\n");
  8219. rtw_mp_PwrCtlDM(dev, info, wrqu, extra);
  8220. break;
  8221. case MP_QueryDrvStats:
  8222. RTW_INFO("mp_get MP_QueryDrvStats\n");
  8223. rtw_mp_QueryDrv(dev, info, wdata, extra);
  8224. break;
  8225. case MP_PWRTRK:
  8226. RTW_INFO("set case MP_PWRTRK\n");
  8227. rtw_mp_pwrtrk(dev, info, wrqu, extra);
  8228. break;
  8229. #ifdef CONFIG_MP_INCLUDED
  8230. case EFUSE_SET:
  8231. RTW_INFO("set case efuse set\n");
  8232. rtw_mp_efuse_set(dev, info, wdata, extra);
  8233. break;
  8234. #endif
  8235. case EFUSE_GET:
  8236. RTW_INFO("efuse get EFUSE_GET\n");
  8237. rtw_mp_efuse_get(dev, info, wdata, extra);
  8238. break;
  8239. case MP_GET_TXPOWER_INX:
  8240. RTW_INFO("mp_get MP_GET_TXPOWER_INX\n");
  8241. rtw_mp_txpower_index(dev, info, wrqu, extra);
  8242. break;
  8243. case MP_GETVER:
  8244. RTW_INFO("mp_get MP_GETVER\n");
  8245. rtw_mp_getver(dev, info, wdata, extra);
  8246. break;
  8247. case MP_MON:
  8248. RTW_INFO("mp_get MP_MON\n");
  8249. rtw_mp_mon(dev, info, wdata, extra);
  8250. break;
  8251. case EFUSE_MASK:
  8252. RTW_INFO("mp_get EFUSE_MASK\n");
  8253. rtw_efuse_mask_file(dev, info, wdata, extra);
  8254. break;
  8255. case EFUSE_FILE:
  8256. RTW_INFO("mp_get EFUSE_FILE\n");
  8257. rtw_efuse_file_map(dev, info, wdata, extra);
  8258. break;
  8259. case MP_TX:
  8260. RTW_INFO("mp_get MP_TX\n");
  8261. rtw_mp_tx(dev, info, wdata, extra);
  8262. break;
  8263. case MP_RX:
  8264. RTW_INFO("mp_get MP_RX\n");
  8265. rtw_mp_rx(dev, info, wdata, extra);
  8266. break;
  8267. case MP_HW_TX_MODE:
  8268. RTW_INFO("mp_get MP_HW_TX_MODE\n");
  8269. rtw_mp_hwtx(dev, info, wdata, extra);
  8270. break;
  8271. #ifdef CONFIG_RTW_CUSTOMER_STR
  8272. case MP_CUSTOMER_STR:
  8273. RTW_INFO("customer str\n");
  8274. rtw_mp_customer_str(dev, info, wdata, extra);
  8275. break;
  8276. #endif
  8277. case MP_PWRLMT:
  8278. RTW_INFO("mp_get MP_SETPWRLMT\n");
  8279. rtw_mp_pwrlmt(dev, info, wdata, extra);
  8280. break;
  8281. case MP_PWRBYRATE:
  8282. RTW_INFO("mp_get MP_SETPWRBYRATE\n");
  8283. rtw_mp_pwrbyrate(dev, info, wdata, extra);
  8284. break;
  8285. case BT_EFUSE_FILE:
  8286. RTW_INFO("mp_get BT EFUSE_FILE\n");
  8287. rtw_bt_efuse_file_map(dev, info, wdata, extra);
  8288. break;
  8289. case MP_SWRFPath:
  8290. RTW_INFO("mp_get MP_SWRFPath\n");
  8291. rtw_mp_switch_rf_path(dev, info, wrqu, extra);
  8292. break;
  8293. default:
  8294. return -EIO;
  8295. }
  8296. return 0;
  8297. }
  8298. #endif /*#if defined(CONFIG_MP_INCLUDED)*/
  8299. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  8300. #define DBG_MP_SDIO_INDIRECT_ACCESS 1
  8301. static int rtw_mp_sd_iread(struct net_device *dev
  8302. , struct iw_request_info *info
  8303. , struct iw_point *wrqu
  8304. , char *extra)
  8305. {
  8306. char input[16];
  8307. u8 width;
  8308. unsigned long addr;
  8309. u32 ret = 0;
  8310. PADAPTER padapter = rtw_netdev_priv(dev);
  8311. if (wrqu->length > 16) {
  8312. RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
  8313. ret = -EINVAL;
  8314. goto exit;
  8315. }
  8316. if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
  8317. RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
  8318. ret = -EFAULT;
  8319. goto exit;
  8320. }
  8321. _rtw_memset(extra, 0, wrqu->length);
  8322. if (sscanf(input, "%hhu,%lx", &width, &addr) != 2) {
  8323. RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
  8324. ret = -EINVAL;
  8325. goto exit;
  8326. }
  8327. if (addr > 0x3FFF) {
  8328. RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
  8329. ret = -EINVAL;
  8330. goto exit;
  8331. }
  8332. if (DBG_MP_SDIO_INDIRECT_ACCESS)
  8333. RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr);
  8334. switch (width) {
  8335. case 1:
  8336. sprintf(extra, "0x%02x", rtw_sd_iread8(padapter, addr));
  8337. wrqu->length = strlen(extra);
  8338. break;
  8339. case 2:
  8340. sprintf(extra, "0x%04x", rtw_sd_iread16(padapter, addr));
  8341. wrqu->length = strlen(extra);
  8342. break;
  8343. case 4:
  8344. sprintf(extra, "0x%08x", rtw_sd_iread32(padapter, addr));
  8345. wrqu->length = strlen(extra);
  8346. break;
  8347. default:
  8348. wrqu->length = 0;
  8349. ret = -EINVAL;
  8350. break;
  8351. }
  8352. exit:
  8353. return ret;
  8354. }
  8355. static int rtw_mp_sd_iwrite(struct net_device *dev
  8356. , struct iw_request_info *info
  8357. , struct iw_point *wrqu
  8358. , char *extra)
  8359. {
  8360. char width;
  8361. unsigned long addr, data;
  8362. int ret = 0;
  8363. PADAPTER padapter = rtw_netdev_priv(dev);
  8364. char input[32];
  8365. if (wrqu->length > 32) {
  8366. RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
  8367. ret = -EINVAL;
  8368. goto exit;
  8369. }
  8370. if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
  8371. RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
  8372. ret = -EFAULT;
  8373. goto exit;
  8374. }
  8375. _rtw_memset(extra, 0, wrqu->length);
  8376. if (sscanf(input, "%hhu,%lx,%lx", &width, &addr, &data) != 3) {
  8377. RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
  8378. ret = -EINVAL;
  8379. goto exit;
  8380. }
  8381. if (addr > 0x3FFF) {
  8382. RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
  8383. ret = -EINVAL;
  8384. goto exit;
  8385. }
  8386. if (DBG_MP_SDIO_INDIRECT_ACCESS)
  8387. RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx, data:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr, data);
  8388. switch (width) {
  8389. case 1:
  8390. if (data > 0xFF) {
  8391. ret = -EINVAL;
  8392. break;
  8393. }
  8394. rtw_sd_iwrite8(padapter, addr, data);
  8395. break;
  8396. case 2:
  8397. if (data > 0xFFFF) {
  8398. ret = -EINVAL;
  8399. break;
  8400. }
  8401. rtw_sd_iwrite16(padapter, addr, data);
  8402. break;
  8403. case 4:
  8404. rtw_sd_iwrite32(padapter, addr, data);
  8405. break;
  8406. default:
  8407. wrqu->length = 0;
  8408. ret = -EINVAL;
  8409. break;
  8410. }
  8411. exit:
  8412. return ret;
  8413. }
  8414. #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
  8415. static int rtw_priv_set(struct net_device *dev,
  8416. struct iw_request_info *info,
  8417. union iwreq_data *wdata, char *extra)
  8418. {
  8419. struct iw_point *wrqu = (struct iw_point *)wdata;
  8420. u32 subcmd = wrqu->flags;
  8421. PADAPTER padapter = rtw_netdev_priv(dev);
  8422. if (padapter == NULL)
  8423. return -ENETDOWN;
  8424. if (padapter->bup == _FALSE) {
  8425. RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
  8426. return -ENETDOWN;
  8427. }
  8428. if (RTW_CANNOT_RUN(padapter)) {
  8429. RTW_INFO("%s fail =>(bSurpriseRemoved == _TRUE) || ( bDriverStopped == _TRUE)\n", __func__);
  8430. return -ENETDOWN;
  8431. }
  8432. if (extra == NULL) {
  8433. wrqu->length = 0;
  8434. return -EIO;
  8435. }
  8436. if (subcmd < MP_NULL) {
  8437. #ifdef CONFIG_MP_INCLUDED
  8438. rtw_priv_mp_set(dev, info, wdata, extra);
  8439. #endif
  8440. return 0;
  8441. }
  8442. switch (subcmd) {
  8443. #ifdef CONFIG_WOWLAN
  8444. case MP_WOW_ENABLE:
  8445. RTW_INFO("set case MP_WOW_ENABLE: %s\n", extra);
  8446. rtw_wowlan_ctrl(dev, info, wdata, extra);
  8447. break;
  8448. case MP_WOW_SET_PATTERN:
  8449. RTW_INFO("set case MP_WOW_SET_PATTERN: %s\n", extra);
  8450. rtw_wowlan_set_pattern(dev, info, wdata, extra);
  8451. break;
  8452. #endif
  8453. #ifdef CONFIG_AP_WOWLAN
  8454. case MP_AP_WOW_ENABLE:
  8455. RTW_INFO("set case MP_AP_WOW_ENABLE: %s\n", extra);
  8456. rtw_ap_wowlan_ctrl(dev, info, wdata, extra);
  8457. break;
  8458. #endif
  8459. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  8460. case VENDOR_IE_SET:
  8461. RTW_INFO("set case VENDOR_IE_SET\n");
  8462. rtw_vendor_ie_set(dev , info , wdata , extra);
  8463. break;
  8464. #endif
  8465. default:
  8466. return -EIO;
  8467. }
  8468. return 0;
  8469. }
  8470. static int rtw_priv_get(struct net_device *dev,
  8471. struct iw_request_info *info,
  8472. union iwreq_data *wdata, char *extra)
  8473. {
  8474. struct iw_point *wrqu = (struct iw_point *)wdata;
  8475. u32 subcmd = wrqu->flags;
  8476. PADAPTER padapter = rtw_netdev_priv(dev);
  8477. if (padapter == NULL)
  8478. return -ENETDOWN;
  8479. if (padapter->bup == _FALSE) {
  8480. RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
  8481. return -ENETDOWN;
  8482. }
  8483. if (RTW_CANNOT_RUN(padapter)) {
  8484. RTW_INFO("%s fail =>(padapter->bSurpriseRemoved == _TRUE) || ( padapter->bDriverStopped == _TRUE)\n", __func__);
  8485. return -ENETDOWN;
  8486. }
  8487. if (extra == NULL) {
  8488. wrqu->length = 0;
  8489. return -EIO;
  8490. }
  8491. if (subcmd < MP_NULL) {
  8492. #ifdef CONFIG_MP_INCLUDED
  8493. rtw_priv_mp_get(dev, info, wdata, extra);
  8494. #endif
  8495. return 0;
  8496. }
  8497. switch (subcmd) {
  8498. #if defined(CONFIG_RTL8723B)
  8499. case MP_SetBT:
  8500. RTW_INFO("set MP_SetBT\n");
  8501. rtw_mp_SetBT(dev, info, wdata, extra);
  8502. break;
  8503. #endif
  8504. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  8505. case MP_SD_IREAD:
  8506. rtw_mp_sd_iread(dev, info, wrqu, extra);
  8507. break;
  8508. case MP_SD_IWRITE:
  8509. rtw_mp_sd_iwrite(dev, info, wrqu, extra);
  8510. break;
  8511. #endif
  8512. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  8513. case VENDOR_IE_GET:
  8514. RTW_INFO("get case VENDOR_IE_GET\n");
  8515. rtw_vendor_ie_get(dev , info , wdata , extra);
  8516. break;
  8517. #endif
  8518. default:
  8519. return -EIO;
  8520. }
  8521. rtw_msleep_os(10); /* delay 5ms for sending pkt before exit adb shell operation */
  8522. return 0;
  8523. }
  8524. static int rtw_wx_tdls_wfd_enable(struct net_device *dev,
  8525. struct iw_request_info *info,
  8526. union iwreq_data *wrqu, char *extra)
  8527. {
  8528. int ret = 0;
  8529. #ifdef CONFIG_TDLS
  8530. #ifdef CONFIG_WFD
  8531. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8532. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8533. if (extra[0] == '0')
  8534. rtw_tdls_wfd_enable(padapter, 0);
  8535. else
  8536. rtw_tdls_wfd_enable(padapter, 1);
  8537. #endif /* CONFIG_WFD */
  8538. #endif /* CONFIG_TDLS */
  8539. return ret;
  8540. }
  8541. static int rtw_tdls_weaksec(struct net_device *dev,
  8542. struct iw_request_info *info,
  8543. union iwreq_data *wrqu, char *extra)
  8544. {
  8545. int ret = 0;
  8546. #ifdef CONFIG_TDLS
  8547. u8 i, j;
  8548. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8549. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8550. if (extra[0] == '0')
  8551. padapter->wdinfo.wfd_tdls_weaksec = 0;
  8552. else
  8553. padapter->wdinfo.wfd_tdls_weaksec = 1;
  8554. #endif /* CONFIG_TDLS */
  8555. return ret;
  8556. }
  8557. static int rtw_tdls_enable(struct net_device *dev,
  8558. struct iw_request_info *info,
  8559. union iwreq_data *wrqu, char *extra)
  8560. {
  8561. int ret = 0;
  8562. #ifdef CONFIG_TDLS
  8563. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8564. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8565. if (extra[0] == '0')
  8566. rtw_disable_tdls_func(padapter, _TRUE);
  8567. else if (extra[0] == '1')
  8568. rtw_enable_tdls_func(padapter);
  8569. #endif /* CONFIG_TDLS */
  8570. return ret;
  8571. }
  8572. static int rtw_tdls_setup(struct net_device *dev,
  8573. struct iw_request_info *info,
  8574. union iwreq_data *wrqu, char *extra)
  8575. {
  8576. int ret = 0;
  8577. #ifdef CONFIG_TDLS
  8578. u8 i, j;
  8579. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8580. struct tdls_txmgmt txmgmt;
  8581. #ifdef CONFIG_WFD
  8582. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  8583. #endif /* CONFIG_WFD */
  8584. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8585. if (wrqu->data.length - 1 != 17) {
  8586. RTW_INFO("[%s] length:%d != 17\n", __FUNCTION__, (wrqu->data.length - 1));
  8587. return ret;
  8588. }
  8589. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8590. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8591. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8592. #ifdef CONFIG_WFD
  8593. if (_AES_ != padapter->securitypriv.dot11PrivacyAlgrthm) {
  8594. /* Weak Security situation with AP. */
  8595. if (0 == pwdinfo->wfd_tdls_weaksec) {
  8596. /* Can't send the tdls setup request out!! */
  8597. RTW_INFO("[%s] Current link is not AES, "
  8598. "SKIP sending the tdls setup request!!\n", __FUNCTION__);
  8599. } else
  8600. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  8601. } else
  8602. #endif /* CONFIG_WFD */
  8603. {
  8604. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  8605. }
  8606. #endif /* CONFIG_TDLS */
  8607. return ret;
  8608. }
  8609. static int rtw_tdls_teardown(struct net_device *dev,
  8610. struct iw_request_info *info,
  8611. union iwreq_data *wrqu, char *extra)
  8612. {
  8613. int ret = 0;
  8614. #ifdef CONFIG_TDLS
  8615. u8 i, j;
  8616. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8617. struct sta_info *ptdls_sta = NULL;
  8618. struct tdls_txmgmt txmgmt;
  8619. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8620. if (wrqu->data.length - 1 != 17 && wrqu->data.length - 1 != 19) {
  8621. RTW_INFO("[%s] length:%d != 17 or 19\n",
  8622. __FUNCTION__, (wrqu->data.length - 1));
  8623. return ret;
  8624. }
  8625. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8626. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8627. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8628. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), txmgmt.peer);
  8629. if (ptdls_sta != NULL) {
  8630. txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
  8631. if (wrqu->data.length - 1 == 19)
  8632. issue_tdls_teardown(padapter, &txmgmt, _FALSE);
  8633. else
  8634. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  8635. } else
  8636. RTW_INFO("TDLS peer not found\n");
  8637. #endif /* CONFIG_TDLS */
  8638. return ret;
  8639. }
  8640. static int rtw_tdls_discovery(struct net_device *dev,
  8641. struct iw_request_info *info,
  8642. union iwreq_data *wrqu, char *extra)
  8643. {
  8644. int ret = 0;
  8645. #ifdef CONFIG_TDLS
  8646. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8647. struct tdls_txmgmt txmgmt;
  8648. int i = 0, j = 0;
  8649. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8650. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8651. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8652. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8653. issue_tdls_dis_req(padapter, &txmgmt);
  8654. #endif /* CONFIG_TDLS */
  8655. return ret;
  8656. }
  8657. static int rtw_tdls_ch_switch(struct net_device *dev,
  8658. struct iw_request_info *info,
  8659. union iwreq_data *wrqu, char *extra)
  8660. {
  8661. int ret = 0;
  8662. #ifdef CONFIG_TDLS
  8663. #ifdef CONFIG_TDLS_CH_SW
  8664. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8665. struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
  8666. u8 i, j;
  8667. struct sta_info *ptdls_sta = NULL;
  8668. u8 take_care_iqk;
  8669. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8670. if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
  8671. RTW_INFO("TDLS channel switch is not allowed\n");
  8672. return ret;
  8673. }
  8674. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8675. pchsw_info->addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8676. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, pchsw_info->addr);
  8677. if (ptdls_sta == NULL)
  8678. return ret;
  8679. pchsw_info->ch_sw_state |= TDLS_CH_SW_INITIATOR_STATE;
  8680. if (ptdls_sta != NULL) {
  8681. if (pchsw_info->off_ch_num == 0)
  8682. pchsw_info->off_ch_num = 11;
  8683. } else
  8684. RTW_INFO("TDLS peer not found\n");
  8685. rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
  8686. rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
  8687. if (take_care_iqk == _TRUE) {
  8688. u8 central_chnl;
  8689. u8 bw_mode;
  8690. bw_mode = (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20;
  8691. central_chnl = rtw_get_center_ch(pchsw_info->off_ch_num, bw_mode, pchsw_info->ch_offset);
  8692. if (rtw_hal_ch_sw_iqk_info_search(padapter, central_chnl, bw_mode) >= 0)
  8693. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
  8694. else
  8695. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_PREPARE);
  8696. } else
  8697. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
  8698. /* issue_tdls_ch_switch_req(padapter, ptdls_sta); */
  8699. /* RTW_INFO("issue tdls ch switch req\n"); */
  8700. #endif /* CONFIG_TDLS_CH_SW */
  8701. #endif /* CONFIG_TDLS */
  8702. return ret;
  8703. }
  8704. static int rtw_tdls_ch_switch_off(struct net_device *dev,
  8705. struct iw_request_info *info,
  8706. union iwreq_data *wrqu, char *extra)
  8707. {
  8708. int ret = 0;
  8709. #ifdef CONFIG_TDLS
  8710. #ifdef CONFIG_TDLS_CH_SW
  8711. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8712. struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
  8713. u8 i, j, mac_addr[ETH_ALEN];
  8714. struct sta_info *ptdls_sta = NULL;
  8715. struct tdls_txmgmt txmgmt;
  8716. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8717. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8718. if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
  8719. RTW_INFO("TDLS channel switch is not allowed\n");
  8720. return ret;
  8721. }
  8722. if (wrqu->data.length >= 17) {
  8723. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8724. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8725. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8726. }
  8727. if (ptdls_sta == NULL)
  8728. return ret;
  8729. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END_TO_BASE_CHNL);
  8730. pchsw_info->ch_sw_state &= ~(TDLS_CH_SW_INITIATOR_STATE |
  8731. TDLS_CH_SWITCH_ON_STATE |
  8732. TDLS_PEER_AT_OFF_STATE);
  8733. _rtw_memset(pchsw_info->addr, 0x00, ETH_ALEN);
  8734. ptdls_sta->ch_switch_time = 0;
  8735. ptdls_sta->ch_switch_timeout = 0;
  8736. _cancel_timer_ex(&ptdls_sta->ch_sw_timer);
  8737. _cancel_timer_ex(&ptdls_sta->delay_timer);
  8738. _cancel_timer_ex(&ptdls_sta->stay_on_base_chnl_timer);
  8739. _cancel_timer_ex(&ptdls_sta->ch_sw_monitor_timer);
  8740. rtw_pm_set_lps(padapter, PS_MODE_MAX);
  8741. #endif /* CONFIG_TDLS_CH_SW */
  8742. #endif /* CONFIG_TDLS */
  8743. return ret;
  8744. }
  8745. static int rtw_tdls_dump_ch(struct net_device *dev,
  8746. struct iw_request_info *info,
  8747. union iwreq_data *wrqu, char *extra)
  8748. {
  8749. int ret = 0;
  8750. #ifdef CONFIG_TDLS
  8751. #ifdef CONFIG_TDLS_CH_SW
  8752. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8753. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8754. RTW_INFO("[%s] dump_stack:%s\n", __FUNCTION__, extra);
  8755. extra[wrqu->data.length] = 0x00;
  8756. ptdlsinfo->chsw_info.dump_stack = rtw_atoi(extra);
  8757. return ret;
  8758. #endif
  8759. #endif /* CONFIG_TDLS */
  8760. return ret;
  8761. }
  8762. static int rtw_tdls_off_ch_num(struct net_device *dev,
  8763. struct iw_request_info *info,
  8764. union iwreq_data *wrqu, char *extra)
  8765. {
  8766. int ret = 0;
  8767. #ifdef CONFIG_TDLS
  8768. #ifdef CONFIG_TDLS_CH_SW
  8769. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8770. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8771. RTW_INFO("[%s] off_ch_num:%s\n", __FUNCTION__, extra);
  8772. extra[wrqu->data.length] = 0x00;
  8773. ptdlsinfo->chsw_info.off_ch_num = rtw_atoi(extra);
  8774. return ret;
  8775. #endif
  8776. #endif /* CONFIG_TDLS */
  8777. return ret;
  8778. }
  8779. static int rtw_tdls_ch_offset(struct net_device *dev,
  8780. struct iw_request_info *info,
  8781. union iwreq_data *wrqu, char *extra)
  8782. {
  8783. int ret = 0;
  8784. #ifdef CONFIG_TDLS
  8785. #ifdef CONFIG_TDLS_CH_SW
  8786. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8787. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8788. RTW_INFO("[%s] ch_offset:%s\n", __FUNCTION__, extra);
  8789. extra[wrqu->data.length] = 0x00;
  8790. switch (rtw_atoi(extra)) {
  8791. case SCA:
  8792. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  8793. break;
  8794. case SCB:
  8795. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  8796. break;
  8797. default:
  8798. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  8799. break;
  8800. }
  8801. return ret;
  8802. #endif
  8803. #endif /* CONFIG_TDLS */
  8804. return ret;
  8805. }
  8806. static int rtw_tdls_pson(struct net_device *dev,
  8807. struct iw_request_info *info,
  8808. union iwreq_data *wrqu, char *extra)
  8809. {
  8810. int ret = 0;
  8811. #ifdef CONFIG_TDLS
  8812. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8813. u8 i, j, mac_addr[ETH_ALEN];
  8814. struct sta_info *ptdls_sta = NULL;
  8815. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8816. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8817. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8818. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8819. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 1, 3, 500);
  8820. #endif /* CONFIG_TDLS */
  8821. return ret;
  8822. }
  8823. static int rtw_tdls_psoff(struct net_device *dev,
  8824. struct iw_request_info *info,
  8825. union iwreq_data *wrqu, char *extra)
  8826. {
  8827. int ret = 0;
  8828. #ifdef CONFIG_TDLS
  8829. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8830. u8 i, j, mac_addr[ETH_ALEN];
  8831. struct sta_info *ptdls_sta = NULL;
  8832. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8833. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8834. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8835. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8836. if (ptdls_sta)
  8837. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 0, 3, 500);
  8838. #endif /* CONFIG_TDLS */
  8839. return ret;
  8840. }
  8841. static int rtw_tdls_setip(struct net_device *dev,
  8842. struct iw_request_info *info,
  8843. union iwreq_data *wrqu, char *extra)
  8844. {
  8845. int ret = 0;
  8846. #ifdef CONFIG_TDLS
  8847. #ifdef CONFIG_WFD
  8848. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8849. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8850. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8851. u8 i = 0, j = 0, k = 0, tag = 0;
  8852. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8853. while (i < 4) {
  8854. for (j = 0; j < 4; j++) {
  8855. if (*(extra + j + tag) == '.' || *(extra + j + tag) == '\0') {
  8856. if (j == 1)
  8857. pwfd_info->ip_address[i] = convert_ip_addr('0', '0', *(extra + (j - 1) + tag));
  8858. if (j == 2)
  8859. pwfd_info->ip_address[i] = convert_ip_addr('0', *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
  8860. if (j == 3)
  8861. pwfd_info->ip_address[i] = convert_ip_addr(*(extra + (j - 3) + tag), *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
  8862. tag += j + 1;
  8863. break;
  8864. }
  8865. }
  8866. i++;
  8867. }
  8868. RTW_INFO("[%s] Set IP = %u.%u.%u.%u\n", __FUNCTION__,
  8869. ptdlsinfo->wfd_info->ip_address[0],
  8870. ptdlsinfo->wfd_info->ip_address[1],
  8871. ptdlsinfo->wfd_info->ip_address[2],
  8872. ptdlsinfo->wfd_info->ip_address[3]);
  8873. #endif /* CONFIG_WFD */
  8874. #endif /* CONFIG_TDLS */
  8875. return ret;
  8876. }
  8877. static int rtw_tdls_getip(struct net_device *dev,
  8878. struct iw_request_info *info,
  8879. union iwreq_data *wrqu, char *extra)
  8880. {
  8881. int ret = 0;
  8882. #ifdef CONFIG_TDLS
  8883. #ifdef CONFIG_WFD
  8884. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8885. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8886. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8887. RTW_INFO("[%s]\n", __FUNCTION__);
  8888. sprintf(extra, "\n\n%u.%u.%u.%u\n",
  8889. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  8890. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
  8891. RTW_INFO("[%s] IP=%u.%u.%u.%u\n", __FUNCTION__,
  8892. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  8893. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
  8894. wrqu->data.length = strlen(extra);
  8895. #endif /* CONFIG_WFD */
  8896. #endif /* CONFIG_TDLS */
  8897. return ret;
  8898. }
  8899. static int rtw_tdls_getport(struct net_device *dev,
  8900. struct iw_request_info *info,
  8901. union iwreq_data *wrqu, char *extra)
  8902. {
  8903. int ret = 0;
  8904. #ifdef CONFIG_TDLS
  8905. #ifdef CONFIG_WFD
  8906. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8907. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8908. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8909. RTW_INFO("[%s]\n", __FUNCTION__);
  8910. sprintf(extra, "\n\n%d\n", pwfd_info->peer_rtsp_ctrlport);
  8911. RTW_INFO("[%s] remote port = %d\n",
  8912. __FUNCTION__, pwfd_info->peer_rtsp_ctrlport);
  8913. wrqu->data.length = strlen(extra);
  8914. #endif /* CONFIG_WFD */
  8915. #endif /* CONFIG_TDLS */
  8916. return ret;
  8917. }
  8918. /* WFDTDLS, for sigma test */
  8919. static int rtw_tdls_dis_result(struct net_device *dev,
  8920. struct iw_request_info *info,
  8921. union iwreq_data *wrqu, char *extra)
  8922. {
  8923. int ret = 0;
  8924. #ifdef CONFIG_TDLS
  8925. #ifdef CONFIG_WFD
  8926. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8927. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8928. RTW_INFO("[%s]\n", __FUNCTION__);
  8929. if (ptdlsinfo->dev_discovered == _TRUE) {
  8930. sprintf(extra, "\n\nDis=1\n");
  8931. ptdlsinfo->dev_discovered = _FALSE;
  8932. }
  8933. wrqu->data.length = strlen(extra);
  8934. #endif /* CONFIG_WFD */
  8935. #endif /* CONFIG_TDLS */
  8936. return ret;
  8937. }
  8938. /* WFDTDLS, for sigma test */
  8939. static int rtw_wfd_tdls_status(struct net_device *dev,
  8940. struct iw_request_info *info,
  8941. union iwreq_data *wrqu, char *extra)
  8942. {
  8943. int ret = 0;
  8944. #ifdef CONFIG_TDLS
  8945. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8946. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8947. RTW_INFO("[%s]\n", __FUNCTION__);
  8948. sprintf(extra, "\nlink_established:%d\n"
  8949. "sta_cnt:%d\n"
  8950. "sta_maximum:%d\n"
  8951. "cur_channel:%d\n"
  8952. "tdls_enable:%d"
  8953. #ifdef CONFIG_TDLS_CH_SW
  8954. "ch_sw_state:%08x\n"
  8955. "chsw_on:%d\n"
  8956. "off_ch_num:%d\n"
  8957. "cur_time:%d\n"
  8958. "ch_offset:%d\n"
  8959. "delay_swtich_back:%d"
  8960. #endif
  8961. ,
  8962. ptdlsinfo->link_established, ptdlsinfo->sta_cnt,
  8963. ptdlsinfo->sta_maximum, ptdlsinfo->cur_channel,
  8964. rtw_is_tdls_enabled(padapter)
  8965. #ifdef CONFIG_TDLS_CH_SW
  8966. ,
  8967. ptdlsinfo->chsw_info.ch_sw_state,
  8968. ATOMIC_READ(&padapter->tdlsinfo.chsw_info.chsw_on),
  8969. ptdlsinfo->chsw_info.off_ch_num,
  8970. ptdlsinfo->chsw_info.cur_time,
  8971. ptdlsinfo->chsw_info.ch_offset,
  8972. ptdlsinfo->chsw_info.delay_switch_back
  8973. #endif
  8974. );
  8975. wrqu->data.length = strlen(extra);
  8976. #endif /* CONFIG_TDLS */
  8977. return ret;
  8978. }
  8979. static int rtw_tdls_getsta(struct net_device *dev,
  8980. struct iw_request_info *info,
  8981. union iwreq_data *wrqu, char *extra)
  8982. {
  8983. int ret = 0;
  8984. #ifdef CONFIG_TDLS
  8985. u8 i, j;
  8986. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8987. u8 addr[ETH_ALEN] = {0};
  8988. char charmac[17];
  8989. struct sta_info *ptdls_sta = NULL;
  8990. RTW_INFO("[%s] %s %d\n", __FUNCTION__,
  8991. (char *)wrqu->data.pointer, wrqu->data.length - 1);
  8992. if (copy_from_user(charmac, wrqu->data.pointer + 9, 17)) {
  8993. ret = -EFAULT;
  8994. goto exit;
  8995. }
  8996. RTW_INFO("[%s] %d, charmac:%s\n", __FUNCTION__, __LINE__, charmac);
  8997. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8998. addr[i] = key_2char2num(*(charmac + j), *(charmac + j + 1));
  8999. RTW_INFO("[%s] %d, charmac:%s, addr:"MAC_FMT"\n",
  9000. __FUNCTION__, __LINE__, charmac, MAC_ARG(addr));
  9001. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, addr);
  9002. if (ptdls_sta) {
  9003. sprintf(extra, "\n\ntdls_sta_state=0x%08x\n", ptdls_sta->tdls_sta_state);
  9004. RTW_INFO("\n\ntdls_sta_state=%d\n", ptdls_sta->tdls_sta_state);
  9005. } else {
  9006. sprintf(extra, "\n\nNot found this sta\n");
  9007. RTW_INFO("\n\nNot found this sta\n");
  9008. }
  9009. wrqu->data.length = strlen(extra);
  9010. #endif /* CONFIG_TDLS */
  9011. exit:
  9012. return ret;
  9013. }
  9014. static int rtw_tdls_get_best_ch(struct net_device *dev,
  9015. struct iw_request_info *info,
  9016. union iwreq_data *wrqu, char *extra)
  9017. {
  9018. #ifdef CONFIG_FIND_BEST_CHANNEL
  9019. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9020. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  9021. u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0;
  9022. for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
  9023. if (rfctl->channel_set[i].ChannelNum == 1)
  9024. index_24G = i;
  9025. if (rfctl->channel_set[i].ChannelNum == 36)
  9026. index_5G = i;
  9027. }
  9028. for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
  9029. /* 2.4G */
  9030. if (rfctl->channel_set[i].ChannelNum == 6 || rfctl->channel_set[i].ChannelNum == 11) {
  9031. if (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_24G].rx_count) {
  9032. index_24G = i;
  9033. best_channel_24G = rfctl->channel_set[i].ChannelNum;
  9034. }
  9035. }
  9036. /* 5G */
  9037. if (rfctl->channel_set[i].ChannelNum >= 36
  9038. && rfctl->channel_set[i].ChannelNum < 140) {
  9039. /* Find primary channel */
  9040. if (((rfctl->channel_set[i].ChannelNum - 36) % 8 == 0)
  9041. && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
  9042. index_5G = i;
  9043. best_channel_5G = rfctl->channel_set[i].ChannelNum;
  9044. }
  9045. }
  9046. if (rfctl->channel_set[i].ChannelNum >= 149
  9047. && rfctl->channel_set[i].ChannelNum < 165) {
  9048. /* Find primary channel */
  9049. if (((rfctl->channel_set[i].ChannelNum - 149) % 8 == 0)
  9050. && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
  9051. index_5G = i;
  9052. best_channel_5G = rfctl->channel_set[i].ChannelNum;
  9053. }
  9054. }
  9055. #if 1 /* debug */
  9056. RTW_INFO("The rx cnt of channel %3d = %d\n",
  9057. rfctl->channel_set[i].ChannelNum,
  9058. rfctl->channel_set[i].rx_count);
  9059. #endif
  9060. }
  9061. sprintf(extra, "\nbest_channel_24G = %d\n", best_channel_24G);
  9062. RTW_INFO("best_channel_24G = %d\n", best_channel_24G);
  9063. if (index_5G != 0) {
  9064. sprintf(extra, "best_channel_5G = %d\n", best_channel_5G);
  9065. RTW_INFO("best_channel_5G = %d\n", best_channel_5G);
  9066. }
  9067. wrqu->data.length = strlen(extra);
  9068. #endif
  9069. return 0;
  9070. }
  9071. static int rtw_tdls(struct net_device *dev,
  9072. struct iw_request_info *info,
  9073. union iwreq_data *wrqu, char *extra)
  9074. {
  9075. int ret = 0;
  9076. #ifdef CONFIG_TDLS
  9077. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9078. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
  9079. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  9080. RTW_INFO("Discard tdls oper since hal doesn't support tdls\n");
  9081. return 0;
  9082. }
  9083. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  9084. RTW_INFO("TDLS is not enabled\n");
  9085. return 0;
  9086. }
  9087. /* WFD Sigma will use the tdls enable command to let the driver know we want to test the tdls now! */
  9088. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  9089. if (_rtw_memcmp(extra, "wfdenable=", 10)) {
  9090. wrqu->data.length -= 10;
  9091. rtw_wx_tdls_wfd_enable(dev, info, wrqu, &extra[10]);
  9092. return ret;
  9093. }
  9094. }
  9095. if (_rtw_memcmp(extra, "weaksec=", 8)) {
  9096. wrqu->data.length -= 8;
  9097. rtw_tdls_weaksec(dev, info, wrqu, &extra[8]);
  9098. return ret;
  9099. } else if (_rtw_memcmp(extra, "tdlsenable=", 11)) {
  9100. wrqu->data.length -= 11;
  9101. rtw_tdls_enable(dev, info, wrqu, &extra[11]);
  9102. return ret;
  9103. }
  9104. if (_rtw_memcmp(extra, "setup=", 6)) {
  9105. wrqu->data.length -= 6;
  9106. rtw_tdls_setup(dev, info, wrqu, &extra[6]);
  9107. } else if (_rtw_memcmp(extra, "tear=", 5)) {
  9108. wrqu->data.length -= 5;
  9109. rtw_tdls_teardown(dev, info, wrqu, &extra[5]);
  9110. } else if (_rtw_memcmp(extra, "dis=", 4)) {
  9111. wrqu->data.length -= 4;
  9112. rtw_tdls_discovery(dev, info, wrqu, &extra[4]);
  9113. } else if (_rtw_memcmp(extra, "swoff=", 6)) {
  9114. wrqu->data.length -= 6;
  9115. rtw_tdls_ch_switch_off(dev, info, wrqu, &extra[6]);
  9116. } else if (_rtw_memcmp(extra, "sw=", 3)) {
  9117. wrqu->data.length -= 3;
  9118. rtw_tdls_ch_switch(dev, info, wrqu, &extra[3]);
  9119. } else if (_rtw_memcmp(extra, "dumpstack=", 10)) {
  9120. wrqu->data.length -= 10;
  9121. rtw_tdls_dump_ch(dev, info, wrqu, &extra[10]);
  9122. } else if (_rtw_memcmp(extra, "offchnum=", 9)) {
  9123. wrqu->data.length -= 9;
  9124. rtw_tdls_off_ch_num(dev, info, wrqu, &extra[9]);
  9125. } else if (_rtw_memcmp(extra, "choffset=", 9)) {
  9126. wrqu->data.length -= 9;
  9127. rtw_tdls_ch_offset(dev, info, wrqu, &extra[9]);
  9128. } else if (_rtw_memcmp(extra, "pson=", 5)) {
  9129. wrqu->data.length -= 5;
  9130. rtw_tdls_pson(dev, info, wrqu, &extra[5]);
  9131. } else if (_rtw_memcmp(extra, "psoff=", 6)) {
  9132. wrqu->data.length -= 6;
  9133. rtw_tdls_psoff(dev, info, wrqu, &extra[6]);
  9134. }
  9135. #ifdef CONFIG_WFD
  9136. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  9137. if (_rtw_memcmp(extra, "setip=", 6)) {
  9138. wrqu->data.length -= 6;
  9139. rtw_tdls_setip(dev, info, wrqu, &extra[6]);
  9140. } else if (_rtw_memcmp(extra, "tprobe=", 6))
  9141. issue_tunneled_probe_req((_adapter *)rtw_netdev_priv(dev));
  9142. }
  9143. #endif /* CONFIG_WFD */
  9144. #endif /* CONFIG_TDLS */
  9145. return ret;
  9146. }
  9147. static int rtw_tdls_get(struct net_device *dev,
  9148. struct iw_request_info *info,
  9149. union iwreq_data *wrqu, char *extra)
  9150. {
  9151. int ret = 0;
  9152. #ifdef CONFIG_TDLS
  9153. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, (char *) wrqu->data.pointer);
  9154. if (_rtw_memcmp(wrqu->data.pointer, "ip", 2))
  9155. rtw_tdls_getip(dev, info, wrqu, extra);
  9156. else if (_rtw_memcmp(wrqu->data.pointer, "port", 4))
  9157. rtw_tdls_getport(dev, info, wrqu, extra);
  9158. /* WFDTDLS, for sigma test */
  9159. else if (_rtw_memcmp(wrqu->data.pointer, "dis", 3))
  9160. rtw_tdls_dis_result(dev, info, wrqu, extra);
  9161. else if (_rtw_memcmp(wrqu->data.pointer, "status", 6))
  9162. rtw_wfd_tdls_status(dev, info, wrqu, extra);
  9163. else if (_rtw_memcmp(wrqu->data.pointer, "tdls_sta=", 9))
  9164. rtw_tdls_getsta(dev, info, wrqu, extra);
  9165. else if (_rtw_memcmp(wrqu->data.pointer, "best_ch", 7))
  9166. rtw_tdls_get_best_ch(dev, info, wrqu, extra);
  9167. #endif /* CONFIG_TDLS */
  9168. return ret;
  9169. }
  9170. #ifdef CONFIG_INTEL_WIDI
  9171. static int rtw_widi_set(struct net_device *dev,
  9172. struct iw_request_info *info,
  9173. union iwreq_data *wrqu, char *extra)
  9174. {
  9175. int ret = 0;
  9176. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9177. process_intel_widi_cmd(padapter, extra);
  9178. return ret;
  9179. }
  9180. static int rtw_widi_set_probe_request(struct net_device *dev,
  9181. struct iw_request_info *info,
  9182. union iwreq_data *wrqu, char *extra)
  9183. {
  9184. int ret = 0;
  9185. u8 *pbuf = NULL;
  9186. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9187. pbuf = rtw_malloc(sizeof(l2_msg_t));
  9188. if (pbuf) {
  9189. if (copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length))
  9190. ret = -EFAULT;
  9191. /* _rtw_memcpy(pbuf, wrqu->data.pointer, wrqu->data.length); */
  9192. if (wrqu->data.flags == 0)
  9193. intel_widi_wk_cmd(padapter, INTEL_WIDI_ISSUE_PROB_WK, pbuf, sizeof(l2_msg_t));
  9194. else if (wrqu->data.flags == 1)
  9195. rtw_set_wfd_rds_sink_info(padapter, (l2_msg_t *)pbuf);
  9196. }
  9197. return ret;
  9198. }
  9199. #endif /* CONFIG_INTEL_WIDI */
  9200. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  9201. #if defined(CONFIG_RTL8188E)
  9202. #include <rtl8188e_hal.h>
  9203. extern void rtl8188e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9204. #define cal_txdesc_chksum rtl8188e_cal_txdesc_chksum
  9205. #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
  9206. extern void rtl8188es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9207. #define fill_default_txdesc rtl8188es_fill_default_txdesc
  9208. #endif /* CONFIG_SDIO_HCI */
  9209. #endif /* CONFIG_RTL8188E */
  9210. #if defined(CONFIG_RTL8723B)
  9211. extern void rtl8723b_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9212. #define cal_txdesc_chksum rtl8723b_cal_txdesc_chksum
  9213. extern void rtl8723b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9214. #define fill_default_txdesc rtl8723b_fill_default_txdesc
  9215. #endif /* CONFIG_RTL8723B */
  9216. #if defined(CONFIG_RTL8703B)
  9217. /* extern void rtl8703b_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9218. #define cal_txdesc_chksum rtl8703b_cal_txdesc_chksum
  9219. /* extern void rtl8703b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9220. #define fill_default_txdesc rtl8703b_fill_default_txdesc
  9221. #endif /* CONFIG_RTL8703B */
  9222. #if defined(CONFIG_RTL8723D)
  9223. /* extern void rtl8723d_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9224. #define cal_txdesc_chksum rtl8723d_cal_txdesc_chksum
  9225. /* extern void rtl8723d_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9226. #define fill_default_txdesc rtl8723d_fill_default_txdesc
  9227. #endif /* CONFIG_RTL8723D */
  9228. #if defined(CONFIG_RTL8710B)
  9229. #define cal_txdesc_chksum rtl8710b_cal_txdesc_chksum
  9230. #define fill_default_txdesc rtl8710b_fill_default_txdesc
  9231. #endif /* CONFIG_RTL8710B */
  9232. #if defined(CONFIG_RTL8192E)
  9233. extern void rtl8192e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9234. #define cal_txdesc_chksum rtl8192e_cal_txdesc_chksum
  9235. #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
  9236. extern void rtl8192es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9237. #define fill_default_txdesc rtl8192es_fill_default_txdesc
  9238. #endif /* CONFIG_SDIO_HCI */
  9239. #endif /* CONFIG_RTL8192E */
  9240. #if defined(CONFIG_RTL8192F)
  9241. /* extern void rtl8192f_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9242. #define cal_txdesc_chksum rtl8192f_cal_txdesc_chksum
  9243. /* extern void rtl8192f_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9244. #define fill_default_txdesc rtl8192f_fill_default_txdesc
  9245. #endif /* CONFIG_RTL8192F */
  9246. static s32 initLoopback(PADAPTER padapter)
  9247. {
  9248. PLOOPBACKDATA ploopback;
  9249. if (padapter->ploopback == NULL) {
  9250. ploopback = (PLOOPBACKDATA)rtw_zmalloc(sizeof(LOOPBACKDATA));
  9251. if (ploopback == NULL)
  9252. return -ENOMEM;
  9253. _rtw_init_sema(&ploopback->sema, 0);
  9254. ploopback->bstop = _TRUE;
  9255. ploopback->cnt = 0;
  9256. ploopback->size = 300;
  9257. _rtw_memset(ploopback->msg, 0, sizeof(ploopback->msg));
  9258. padapter->ploopback = ploopback;
  9259. }
  9260. return 0;
  9261. }
  9262. static void freeLoopback(PADAPTER padapter)
  9263. {
  9264. PLOOPBACKDATA ploopback;
  9265. ploopback = padapter->ploopback;
  9266. if (ploopback) {
  9267. rtw_mfree((u8 *)ploopback, sizeof(LOOPBACKDATA));
  9268. padapter->ploopback = NULL;
  9269. }
  9270. }
  9271. static s32 initpseudoadhoc(PADAPTER padapter)
  9272. {
  9273. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  9274. s32 err;
  9275. networkType = Ndis802_11IBSS;
  9276. err = rtw_set_802_11_infrastructure_mode(padapter, networkType);
  9277. if (err == _FALSE)
  9278. return _FAIL;
  9279. err = rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
  9280. if (err == _FAIL)
  9281. return _FAIL;
  9282. return _SUCCESS;
  9283. }
  9284. static s32 createpseudoadhoc(PADAPTER padapter)
  9285. {
  9286. NDIS_802_11_AUTHENTICATION_MODE authmode;
  9287. struct mlme_priv *pmlmepriv;
  9288. NDIS_802_11_SSID *passoc_ssid;
  9289. WLAN_BSSID_EX *pdev_network;
  9290. u8 *pibss;
  9291. u8 ssid[] = "pseduo_ad-hoc";
  9292. s32 err;
  9293. _irqL irqL;
  9294. pmlmepriv = &padapter->mlmepriv;
  9295. authmode = Ndis802_11AuthModeOpen;
  9296. err = rtw_set_802_11_authentication_mode(padapter, authmode);
  9297. if (err == _FALSE)
  9298. return _FAIL;
  9299. passoc_ssid = &pmlmepriv->assoc_ssid;
  9300. _rtw_memset(passoc_ssid, 0, sizeof(NDIS_802_11_SSID));
  9301. passoc_ssid->SsidLength = sizeof(ssid) - 1;
  9302. _rtw_memcpy(passoc_ssid->Ssid, ssid, passoc_ssid->SsidLength);
  9303. pdev_network = &padapter->registrypriv.dev_network;
  9304. pibss = padapter->registrypriv.dev_network.MacAddress;
  9305. _rtw_memcpy(&pdev_network->Ssid, passoc_ssid, sizeof(NDIS_802_11_SSID));
  9306. rtw_update_registrypriv_dev_network(padapter);
  9307. rtw_generate_random_ibss(pibss);
  9308. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  9309. /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
  9310. init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  9311. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  9312. #if 0
  9313. err = rtw_create_ibss_cmd(padapter, 0);
  9314. if (err == _FAIL)
  9315. return _FAIL;
  9316. #else
  9317. {
  9318. struct wlan_network *pcur_network;
  9319. struct sta_info *psta;
  9320. /* 3 create a new psta */
  9321. pcur_network = &pmlmepriv->cur_network;
  9322. /* clear psta in the cur_network, if any */
  9323. psta = rtw_get_stainfo(&padapter->stapriv, pcur_network->network.MacAddress);
  9324. if (psta)
  9325. rtw_free_stainfo(padapter, psta);
  9326. psta = rtw_alloc_stainfo(&padapter->stapriv, pibss);
  9327. if (psta == NULL)
  9328. return _FAIL;
  9329. /* 3 join psudo AdHoc */
  9330. pcur_network->join_res = 1;
  9331. pcur_network->aid = psta->cmn.aid = 1;
  9332. _rtw_memcpy(&pcur_network->network, pdev_network, get_WLAN_BSSID_EX_sz(pdev_network));
  9333. /* set msr to WIFI_FW_ADHOC_STATE */
  9334. padapter->hw_port = HW_PORT0;
  9335. Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
  9336. }
  9337. #endif
  9338. return _SUCCESS;
  9339. }
  9340. static struct xmit_frame *createloopbackpkt(PADAPTER padapter, u32 size)
  9341. {
  9342. struct xmit_priv *pxmitpriv;
  9343. struct xmit_frame *pframe;
  9344. struct xmit_buf *pxmitbuf;
  9345. struct pkt_attrib *pattrib;
  9346. struct tx_desc *desc;
  9347. u8 *pkt_start, *pkt_end, *ptr;
  9348. struct rtw_ieee80211_hdr *hdr;
  9349. s32 bmcast;
  9350. _irqL irqL;
  9351. if ((TXDESC_SIZE + WLANHDR_OFFSET + size) > MAX_XMITBUF_SZ)
  9352. return NULL;
  9353. pxmitpriv = &padapter->xmitpriv;
  9354. pframe = NULL;
  9355. /* 2 1. allocate xmit frame */
  9356. pframe = rtw_alloc_xmitframe(pxmitpriv);
  9357. if (pframe == NULL)
  9358. return NULL;
  9359. pframe->padapter = padapter;
  9360. /* 2 2. allocate xmit buffer */
  9361. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  9362. pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
  9363. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  9364. if (pxmitbuf == NULL) {
  9365. rtw_free_xmitframe(pxmitpriv, pframe);
  9366. return NULL;
  9367. }
  9368. pframe->pxmitbuf = pxmitbuf;
  9369. pframe->buf_addr = pxmitbuf->pbuf;
  9370. pxmitbuf->priv_data = pframe;
  9371. /* 2 3. update_attrib() */
  9372. pattrib = &pframe->attrib;
  9373. /* init xmitframe attribute */
  9374. _rtw_memset(pattrib, 0, sizeof(struct pkt_attrib));
  9375. pattrib->ether_type = 0x8723;
  9376. _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
  9377. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  9378. _rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
  9379. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  9380. /* pattrib->dhcp_pkt = 0;
  9381. * pattrib->pktlen = 0; */
  9382. pattrib->ack_policy = 0;
  9383. /* pattrib->pkt_hdrlen = ETH_HLEN; */
  9384. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  9385. pattrib->subtype = WIFI_DATA;
  9386. pattrib->priority = 0;
  9387. pattrib->qsel = pattrib->priority;
  9388. /* do_queue_select(padapter, pattrib); */
  9389. pattrib->nr_frags = 1;
  9390. pattrib->encrypt = 0;
  9391. pattrib->bswenc = _FALSE;
  9392. pattrib->qos_en = _FALSE;
  9393. bmcast = IS_MCAST(pattrib->ra);
  9394. if (bmcast)
  9395. pattrib->psta = rtw_get_bcmc_stainfo(padapter);
  9396. else
  9397. pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
  9398. pattrib->mac_id = pattrib->psta->cmn.mac_id;
  9399. pattrib->pktlen = size;
  9400. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
  9401. /* 2 4. fill TX descriptor */
  9402. desc = (struct tx_desc *)pframe->buf_addr;
  9403. _rtw_memset(desc, 0, TXDESC_SIZE);
  9404. fill_default_txdesc(pframe, (u8 *)desc);
  9405. /* Hw set sequence number */
  9406. ((PTXDESC)desc)->hwseq_en = 0; /* HWSEQ_EN, 0:disable, 1:enable
  9407. * ((PTXDESC)desc)->hwseq_sel = 0; */ /* HWSEQ_SEL */
  9408. ((PTXDESC)desc)->disdatafb = 1;
  9409. /* convert to little endian */
  9410. desc->txdw0 = cpu_to_le32(desc->txdw0);
  9411. desc->txdw1 = cpu_to_le32(desc->txdw1);
  9412. desc->txdw2 = cpu_to_le32(desc->txdw2);
  9413. desc->txdw3 = cpu_to_le32(desc->txdw3);
  9414. desc->txdw4 = cpu_to_le32(desc->txdw4);
  9415. desc->txdw5 = cpu_to_le32(desc->txdw5);
  9416. desc->txdw6 = cpu_to_le32(desc->txdw6);
  9417. desc->txdw7 = cpu_to_le32(desc->txdw7);
  9418. #ifdef CONFIG_PCI_HCI
  9419. desc->txdw8 = cpu_to_le32(desc->txdw8);
  9420. desc->txdw9 = cpu_to_le32(desc->txdw9);
  9421. desc->txdw10 = cpu_to_le32(desc->txdw10);
  9422. desc->txdw11 = cpu_to_le32(desc->txdw11);
  9423. desc->txdw12 = cpu_to_le32(desc->txdw12);
  9424. desc->txdw13 = cpu_to_le32(desc->txdw13);
  9425. desc->txdw14 = cpu_to_le32(desc->txdw14);
  9426. desc->txdw15 = cpu_to_le32(desc->txdw15);
  9427. #endif
  9428. cal_txdesc_chksum(desc);
  9429. /* 2 5. coalesce */
  9430. pkt_start = pframe->buf_addr + TXDESC_SIZE;
  9431. pkt_end = pkt_start + pattrib->last_txcmdsz;
  9432. /* 3 5.1. make wlan header, make_wlanhdr() */
  9433. hdr = (struct rtw_ieee80211_hdr *)pkt_start;
  9434. set_frame_sub_type(&hdr->frame_ctl, pattrib->subtype);
  9435. _rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); /* DA */
  9436. _rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); /* SA */
  9437. _rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); /* RA, BSSID */
  9438. /* 3 5.2. make payload */
  9439. ptr = pkt_start + pattrib->hdrlen;
  9440. get_random_bytes(ptr, pkt_end - ptr);
  9441. pxmitbuf->len = TXDESC_SIZE + pattrib->last_txcmdsz;
  9442. pxmitbuf->ptail += pxmitbuf->len;
  9443. return pframe;
  9444. }
  9445. static void freeloopbackpkt(PADAPTER padapter, struct xmit_frame *pframe)
  9446. {
  9447. struct xmit_priv *pxmitpriv;
  9448. struct xmit_buf *pxmitbuf;
  9449. pxmitpriv = &padapter->xmitpriv;
  9450. pxmitbuf = pframe->pxmitbuf;
  9451. rtw_free_xmitframe(pxmitpriv, pframe);
  9452. rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
  9453. }
  9454. static void printdata(u8 *pbuf, u32 len)
  9455. {
  9456. u32 i, val;
  9457. for (i = 0; (i + 4) <= len; i += 4) {
  9458. printk("%08X", *(u32 *)(pbuf + i));
  9459. if ((i + 4) & 0x1F)
  9460. printk(" ");
  9461. else
  9462. printk("\n");
  9463. }
  9464. if (i < len) {
  9465. #ifdef CONFIG_BIG_ENDIAN
  9466. for (; i < len, i++)
  9467. printk("%02X", pbuf + i);
  9468. #else /* CONFIG_LITTLE_ENDIAN */
  9469. #if 0
  9470. val = 0;
  9471. _rtw_memcpy(&val, pbuf + i, len - i);
  9472. printk("%8X", val);
  9473. #else
  9474. u8 str[9];
  9475. u8 n;
  9476. val = 0;
  9477. n = len - i;
  9478. _rtw_memcpy(&val, pbuf + i, n);
  9479. sprintf(str, "%08X", val);
  9480. n = (4 - n) * 2;
  9481. printk("%8s", str + n);
  9482. #endif
  9483. #endif /* CONFIG_LITTLE_ENDIAN */
  9484. }
  9485. printk("\n");
  9486. }
  9487. static u8 pktcmp(PADAPTER padapter, u8 *txbuf, u32 txsz, u8 *rxbuf, u32 rxsz)
  9488. {
  9489. PHAL_DATA_TYPE phal;
  9490. struct recv_stat *prxstat;
  9491. struct recv_stat report;
  9492. PRXREPORT prxreport;
  9493. u32 drvinfosize;
  9494. u32 rxpktsize;
  9495. u8 fcssize;
  9496. u8 ret = _FALSE;
  9497. prxstat = (struct recv_stat *)rxbuf;
  9498. report.rxdw0 = le32_to_cpu(prxstat->rxdw0);
  9499. report.rxdw1 = le32_to_cpu(prxstat->rxdw1);
  9500. report.rxdw2 = le32_to_cpu(prxstat->rxdw2);
  9501. report.rxdw3 = le32_to_cpu(prxstat->rxdw3);
  9502. report.rxdw4 = le32_to_cpu(prxstat->rxdw4);
  9503. report.rxdw5 = le32_to_cpu(prxstat->rxdw5);
  9504. prxreport = (PRXREPORT)&report;
  9505. drvinfosize = prxreport->drvinfosize << 3;
  9506. rxpktsize = prxreport->pktlen;
  9507. phal = GET_HAL_DATA(padapter);
  9508. if (rtw_hal_rcr_check(padapter, RCR_APPFCS))
  9509. fcssize = IEEE80211_FCS_LEN;
  9510. else
  9511. fcssize = 0;
  9512. if ((txsz - TXDESC_SIZE) != (rxpktsize - fcssize)) {
  9513. RTW_INFO("%s: ERROR! size not match tx/rx=%d/%d !\n",
  9514. __func__, txsz - TXDESC_SIZE, rxpktsize - fcssize);
  9515. ret = _FALSE;
  9516. } else {
  9517. ret = _rtw_memcmp(txbuf + TXDESC_SIZE, \
  9518. rxbuf + RXDESC_SIZE + drvinfosize, \
  9519. txsz - TXDESC_SIZE);
  9520. if (ret == _FALSE)
  9521. RTW_INFO("%s: ERROR! pkt content mismatch!\n", __func__);
  9522. }
  9523. if (ret == _FALSE) {
  9524. RTW_INFO("\n%s: TX PKT total=%d, desc=%d, content=%d\n",
  9525. __func__, txsz, TXDESC_SIZE, txsz - TXDESC_SIZE);
  9526. RTW_INFO("%s: TX DESC size=%d\n", __func__, TXDESC_SIZE);
  9527. printdata(txbuf, TXDESC_SIZE);
  9528. RTW_INFO("%s: TX content size=%d\n", __func__, txsz - TXDESC_SIZE);
  9529. printdata(txbuf + TXDESC_SIZE, txsz - TXDESC_SIZE);
  9530. RTW_INFO("\n%s: RX PKT read=%d offset=%d(%d,%d) content=%d\n",
  9531. __func__, rxsz, RXDESC_SIZE + drvinfosize, RXDESC_SIZE, drvinfosize, rxpktsize);
  9532. if (rxpktsize != 0) {
  9533. RTW_INFO("%s: RX DESC size=%d\n", __func__, RXDESC_SIZE);
  9534. printdata(rxbuf, RXDESC_SIZE);
  9535. RTW_INFO("%s: RX drvinfo size=%d\n", __func__, drvinfosize);
  9536. printdata(rxbuf + RXDESC_SIZE, drvinfosize);
  9537. RTW_INFO("%s: RX content size=%d\n", __func__, rxpktsize);
  9538. printdata(rxbuf + RXDESC_SIZE + drvinfosize, rxpktsize);
  9539. } else {
  9540. RTW_INFO("%s: RX data size=%d\n", __func__, rxsz);
  9541. printdata(rxbuf, rxsz);
  9542. }
  9543. }
  9544. return ret;
  9545. }
  9546. thread_return lbk_thread(thread_context context)
  9547. {
  9548. s32 err;
  9549. PADAPTER padapter;
  9550. PLOOPBACKDATA ploopback;
  9551. struct xmit_frame *pxmitframe;
  9552. u32 cnt, ok, fail, headerlen;
  9553. u32 pktsize;
  9554. u32 ff_hwaddr;
  9555. padapter = (PADAPTER)context;
  9556. ploopback = padapter->ploopback;
  9557. if (ploopback == NULL)
  9558. return -1;
  9559. cnt = 0;
  9560. ok = 0;
  9561. fail = 0;
  9562. daemonize("%s", "RTW_LBK_THREAD");
  9563. allow_signal(SIGTERM);
  9564. do {
  9565. if (ploopback->size == 0) {
  9566. get_random_bytes(&pktsize, 4);
  9567. pktsize = (pktsize % 1535) + 1; /* 1~1535 */
  9568. } else
  9569. pktsize = ploopback->size;
  9570. pxmitframe = createloopbackpkt(padapter, pktsize);
  9571. if (pxmitframe == NULL) {
  9572. sprintf(ploopback->msg, "loopback FAIL! 3. create Packet FAIL!");
  9573. break;
  9574. }
  9575. ploopback->txsize = TXDESC_SIZE + pxmitframe->attrib.last_txcmdsz;
  9576. _rtw_memcpy(ploopback->txbuf, pxmitframe->buf_addr, ploopback->txsize);
  9577. ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
  9578. cnt++;
  9579. RTW_INFO("%s: wirte port cnt=%d size=%d\n", __func__, cnt, ploopback->txsize);
  9580. pxmitframe->pxmitbuf->pdata = ploopback->txbuf;
  9581. rtw_write_port(padapter, ff_hwaddr, ploopback->txsize, (u8 *)pxmitframe->pxmitbuf);
  9582. /* wait for rx pkt */
  9583. _rtw_down_sema(&ploopback->sema);
  9584. err = pktcmp(padapter, ploopback->txbuf, ploopback->txsize, ploopback->rxbuf, ploopback->rxsize);
  9585. if (err == _TRUE)
  9586. ok++;
  9587. else
  9588. fail++;
  9589. ploopback->txsize = 0;
  9590. _rtw_memset(ploopback->txbuf, 0, 0x8000);
  9591. ploopback->rxsize = 0;
  9592. _rtw_memset(ploopback->rxbuf, 0, 0x8000);
  9593. freeloopbackpkt(padapter, pxmitframe);
  9594. pxmitframe = NULL;
  9595. flush_signals_thread();
  9596. if ((ploopback->bstop == _TRUE) ||
  9597. ((ploopback->cnt != 0) && (ploopback->cnt == cnt))) {
  9598. u32 ok_rate, fail_rate, all;
  9599. all = cnt;
  9600. ok_rate = (ok * 100) / all;
  9601. fail_rate = (fail * 100) / all;
  9602. sprintf(ploopback->msg, \
  9603. "loopback result: ok=%d%%(%d/%d),error=%d%%(%d/%d)", \
  9604. ok_rate, ok, all, fail_rate, fail, all);
  9605. break;
  9606. }
  9607. } while (1);
  9608. ploopback->bstop = _TRUE;
  9609. thread_exit(NULL);
  9610. return 0;
  9611. }
  9612. static void loopbackTest(PADAPTER padapter, u32 cnt, u32 size, u8 *pmsg)
  9613. {
  9614. PLOOPBACKDATA ploopback;
  9615. u32 len;
  9616. s32 err;
  9617. ploopback = padapter->ploopback;
  9618. if (ploopback) {
  9619. if (ploopback->bstop == _FALSE) {
  9620. ploopback->bstop = _TRUE;
  9621. _rtw_up_sema(&ploopback->sema);
  9622. }
  9623. len = 0;
  9624. do {
  9625. len = strlen(ploopback->msg);
  9626. if (len)
  9627. break;
  9628. rtw_msleep_os(1);
  9629. } while (1);
  9630. _rtw_memcpy(pmsg, ploopback->msg, len + 1);
  9631. freeLoopback(padapter);
  9632. return;
  9633. }
  9634. /* disable dynamic algorithm */
  9635. rtw_phydm_ability_backup(padapter);
  9636. rtw_phydm_func_disable_all(padapter);
  9637. /* create pseudo ad-hoc connection */
  9638. err = initpseudoadhoc(padapter);
  9639. if (err == _FAIL) {
  9640. sprintf(pmsg, "loopback FAIL! 1.1 init ad-hoc FAIL!");
  9641. return;
  9642. }
  9643. err = createpseudoadhoc(padapter);
  9644. if (err == _FAIL) {
  9645. sprintf(pmsg, "loopback FAIL! 1.2 create ad-hoc master FAIL!");
  9646. return;
  9647. }
  9648. err = initLoopback(padapter);
  9649. if (err) {
  9650. sprintf(pmsg, "loopback FAIL! 2. init FAIL! error code=%d", err);
  9651. return;
  9652. }
  9653. ploopback = padapter->ploopback;
  9654. ploopback->bstop = _FALSE;
  9655. ploopback->cnt = cnt;
  9656. ploopback->size = size;
  9657. ploopback->lbkthread = kthread_run(lbk_thread, padapter, "RTW_LBK_THREAD");
  9658. if (IS_ERR(padapter->lbkthread)) {
  9659. freeLoopback(padapter);
  9660. ploopback->lbkthread = NULL;
  9661. sprintf(pmsg, "loopback start FAIL! cnt=%d", cnt);
  9662. return;
  9663. }
  9664. sprintf(pmsg, "loopback start! cnt=%d", cnt);
  9665. }
  9666. #endif /* CONFIG_MAC_LOOPBACK_DRIVER */
  9667. static int rtw_test(
  9668. struct net_device *dev,
  9669. struct iw_request_info *info,
  9670. union iwreq_data *wrqu, char *extra)
  9671. {
  9672. u32 len;
  9673. u8 *pbuf, *pch;
  9674. char *ptmp;
  9675. u8 *delim = ",";
  9676. PADAPTER padapter = rtw_netdev_priv(dev);
  9677. RTW_INFO("+%s\n", __func__);
  9678. len = wrqu->data.length;
  9679. pbuf = (u8 *)rtw_zmalloc(len + 1);
  9680. if (pbuf == NULL) {
  9681. RTW_INFO("%s: no memory!\n", __func__);
  9682. return -ENOMEM;
  9683. }
  9684. if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
  9685. rtw_mfree(pbuf, len + 1);
  9686. RTW_INFO("%s: copy from user fail!\n", __func__);
  9687. return -EFAULT;
  9688. }
  9689. pbuf[len] = '\0';
  9690. RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
  9691. ptmp = (char *)pbuf;
  9692. pch = strsep(&ptmp, delim);
  9693. if ((pch == NULL) || (strlen(pch) == 0)) {
  9694. rtw_mfree(pbuf, len);
  9695. RTW_INFO("%s: parameter error(level 1)!\n", __func__);
  9696. return -EFAULT;
  9697. }
  9698. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  9699. if (strcmp(pch, "loopback") == 0) {
  9700. s32 cnt = 0;
  9701. u32 size = 64;
  9702. pch = strsep(&ptmp, delim);
  9703. if ((pch == NULL) || (strlen(pch) == 0)) {
  9704. rtw_mfree(pbuf, len);
  9705. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9706. return -EFAULT;
  9707. }
  9708. sscanf(pch, "%d", &cnt);
  9709. RTW_INFO("%s: loopback cnt=%d\n", __func__, cnt);
  9710. pch = strsep(&ptmp, delim);
  9711. if ((pch == NULL) || (strlen(pch) == 0)) {
  9712. rtw_mfree(pbuf, len);
  9713. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9714. return -EFAULT;
  9715. }
  9716. sscanf(pch, "%d", &size);
  9717. RTW_INFO("%s: loopback size=%d\n", __func__, size);
  9718. loopbackTest(padapter, cnt, size, extra);
  9719. wrqu->data.length = strlen(extra) + 1;
  9720. goto free_buf;
  9721. }
  9722. #endif
  9723. #ifdef CONFIG_BT_COEXIST
  9724. if (strcmp(pch, "bton") == 0) {
  9725. rtw_btcoex_SetManualControl(padapter, _FALSE);
  9726. goto free_buf;
  9727. } else if (strcmp(pch, "btoff") == 0) {
  9728. rtw_btcoex_SetManualControl(padapter, _TRUE);
  9729. goto free_buf;
  9730. }
  9731. #endif
  9732. if (strcmp(pch, "h2c") == 0) {
  9733. u8 param[8];
  9734. u8 count = 0;
  9735. u32 tmp;
  9736. u8 i;
  9737. u32 pos;
  9738. u8 ret;
  9739. do {
  9740. pch = strsep(&ptmp, delim);
  9741. if ((pch == NULL) || (strlen(pch) == 0))
  9742. break;
  9743. sscanf(pch, "%x", &tmp);
  9744. param[count++] = (u8)tmp;
  9745. } while (count < 8);
  9746. if (count == 0) {
  9747. rtw_mfree(pbuf, len);
  9748. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9749. return -EFAULT;
  9750. }
  9751. ret = rtw_test_h2c_cmd(padapter, param, count);
  9752. pos = sprintf(extra, "H2C ID=0x%02x content=", param[0]);
  9753. for (i = 1; i < count; i++)
  9754. pos += sprintf(extra + pos, "%02x,", param[i]);
  9755. extra[pos] = 0;
  9756. pos--;
  9757. pos += sprintf(extra + pos, " %s", ret == _FAIL ? "FAIL" : "OK");
  9758. wrqu->data.length = strlen(extra) + 1;
  9759. goto free_buf;
  9760. }
  9761. free_buf:
  9762. rtw_mfree(pbuf, len);
  9763. return 0;
  9764. }
  9765. static iw_handler rtw_handlers[] = {
  9766. NULL, /* SIOCSIWCOMMIT */
  9767. rtw_wx_get_name, /* SIOCGIWNAME */
  9768. dummy, /* SIOCSIWNWID */
  9769. dummy, /* SIOCGIWNWID */
  9770. rtw_wx_set_freq, /* SIOCSIWFREQ */
  9771. rtw_wx_get_freq, /* SIOCGIWFREQ */
  9772. rtw_wx_set_mode, /* SIOCSIWMODE */
  9773. rtw_wx_get_mode, /* SIOCGIWMODE */
  9774. dummy, /* SIOCSIWSENS */
  9775. rtw_wx_get_sens, /* SIOCGIWSENS */
  9776. NULL, /* SIOCSIWRANGE */
  9777. rtw_wx_get_range, /* SIOCGIWRANGE */
  9778. rtw_wx_set_priv, /* SIOCSIWPRIV */
  9779. NULL, /* SIOCGIWPRIV */
  9780. NULL, /* SIOCSIWSTATS */
  9781. NULL, /* SIOCGIWSTATS */
  9782. dummy, /* SIOCSIWSPY */
  9783. dummy, /* SIOCGIWSPY */
  9784. NULL, /* SIOCGIWTHRSPY */
  9785. NULL, /* SIOCWIWTHRSPY */
  9786. rtw_wx_set_wap, /* SIOCSIWAP */
  9787. rtw_wx_get_wap, /* SIOCGIWAP */
  9788. rtw_wx_set_mlme, /* request MLME operation; uses struct iw_mlme */
  9789. dummy, /* SIOCGIWAPLIST -- depricated */
  9790. rtw_wx_set_scan, /* SIOCSIWSCAN */
  9791. rtw_wx_get_scan, /* SIOCGIWSCAN */
  9792. rtw_wx_set_essid, /* SIOCSIWESSID */
  9793. rtw_wx_get_essid, /* SIOCGIWESSID */
  9794. dummy, /* SIOCSIWNICKN */
  9795. rtw_wx_get_nick, /* SIOCGIWNICKN */
  9796. NULL, /* -- hole -- */
  9797. NULL, /* -- hole -- */
  9798. rtw_wx_set_rate, /* SIOCSIWRATE */
  9799. rtw_wx_get_rate, /* SIOCGIWRATE */
  9800. rtw_wx_set_rts, /* SIOCSIWRTS */
  9801. rtw_wx_get_rts, /* SIOCGIWRTS */
  9802. rtw_wx_set_frag, /* SIOCSIWFRAG */
  9803. rtw_wx_get_frag, /* SIOCGIWFRAG */
  9804. dummy, /* SIOCSIWTXPOW */
  9805. dummy, /* SIOCGIWTXPOW */
  9806. dummy, /* SIOCSIWRETRY */
  9807. rtw_wx_get_retry, /* SIOCGIWRETRY */
  9808. rtw_wx_set_enc, /* SIOCSIWENCODE */
  9809. rtw_wx_get_enc, /* SIOCGIWENCODE */
  9810. dummy, /* SIOCSIWPOWER */
  9811. rtw_wx_get_power, /* SIOCGIWPOWER */
  9812. NULL, /*---hole---*/
  9813. NULL, /*---hole---*/
  9814. rtw_wx_set_gen_ie, /* SIOCSIWGENIE */
  9815. NULL, /* SIOCGWGENIE */
  9816. rtw_wx_set_auth, /* SIOCSIWAUTH */
  9817. NULL, /* SIOCGIWAUTH */
  9818. rtw_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
  9819. NULL, /* SIOCGIWENCODEEXT */
  9820. rtw_wx_set_pmkid, /* SIOCSIWPMKSA */
  9821. NULL, /*---hole---*/
  9822. };
  9823. static const struct iw_priv_args rtw_private_args[] = {
  9824. {
  9825. SIOCIWFIRSTPRIV + 0x0,
  9826. IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
  9827. },
  9828. {
  9829. SIOCIWFIRSTPRIV + 0x1,
  9830. IW_PRIV_TYPE_CHAR | 0x7FF,
  9831. IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
  9832. },
  9833. {
  9834. SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
  9835. },
  9836. {
  9837. SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
  9838. },
  9839. {
  9840. SIOCIWFIRSTPRIV + 0x4,
  9841. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
  9842. },
  9843. {
  9844. SIOCIWFIRSTPRIV + 0x5,
  9845. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
  9846. },
  9847. {
  9848. SIOCIWFIRSTPRIV + 0x6,
  9849. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
  9850. },
  9851. /* for PLATFORM_MT53XX */
  9852. {
  9853. SIOCIWFIRSTPRIV + 0x7,
  9854. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "get_sensitivity"
  9855. },
  9856. {
  9857. SIOCIWFIRSTPRIV + 0x8,
  9858. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_prob_req_ie"
  9859. },
  9860. {
  9861. SIOCIWFIRSTPRIV + 0x9,
  9862. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_assoc_req_ie"
  9863. },
  9864. /* for RTK_DMP_PLATFORM */
  9865. {
  9866. SIOCIWFIRSTPRIV + 0xA,
  9867. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
  9868. },
  9869. {
  9870. SIOCIWFIRSTPRIV + 0xB,
  9871. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
  9872. },
  9873. {
  9874. SIOCIWFIRSTPRIV + 0xC,
  9875. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
  9876. },
  9877. {
  9878. SIOCIWFIRSTPRIV + 0xD,
  9879. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
  9880. },
  9881. #if 0
  9882. {
  9883. SIOCIWFIRSTPRIV + 0xE, 0, 0, "wowlan_ctrl"
  9884. },
  9885. #endif
  9886. {
  9887. SIOCIWFIRSTPRIV + 0x10,
  9888. IW_PRIV_TYPE_CHAR | 1024, 0, "p2p_set"
  9889. },
  9890. {
  9891. SIOCIWFIRSTPRIV + 0x11,
  9892. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "p2p_get"
  9893. },
  9894. {
  9895. SIOCIWFIRSTPRIV + 0x12, 0, 0, "NULL"
  9896. },
  9897. {
  9898. SIOCIWFIRSTPRIV + 0x13,
  9899. IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64 , "p2p_get2"
  9900. },
  9901. {
  9902. SIOCIWFIRSTPRIV + 0x14,
  9903. IW_PRIV_TYPE_CHAR | 64, 0, "tdls"
  9904. },
  9905. {
  9906. SIOCIWFIRSTPRIV + 0x15,
  9907. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "tdls_get"
  9908. },
  9909. {
  9910. SIOCIWFIRSTPRIV + 0x16,
  9911. IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
  9912. },
  9913. #ifdef CONFIG_RTW_80211K
  9914. {
  9915. SIOCIWFIRSTPRIV + 0x17,
  9916. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "rrm"
  9917. },
  9918. #endif
  9919. {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ , 0 , "rereg_nd_name"},
  9920. #ifdef CONFIG_MP_INCLUDED
  9921. {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "NULL"},
  9922. {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "NULL"},
  9923. #else
  9924. {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "NULL"},
  9925. {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
  9926. #endif
  9927. {
  9928. SIOCIWFIRSTPRIV + 0x1D,
  9929. IW_PRIV_TYPE_CHAR | 40, IW_PRIV_TYPE_CHAR | 0x7FF, "test"
  9930. },
  9931. #ifdef CONFIG_INTEL_WIDI
  9932. {
  9933. SIOCIWFIRSTPRIV + 0x1E,
  9934. IW_PRIV_TYPE_CHAR | 1024, 0, "widi_set"
  9935. },
  9936. {
  9937. SIOCIWFIRSTPRIV + 0x1F,
  9938. IW_PRIV_TYPE_CHAR | 128, 0, "widi_prob_req"
  9939. },
  9940. #endif /* CONFIG_INTEL_WIDI */
  9941. { SIOCIWFIRSTPRIV + 0x0E, IW_PRIV_TYPE_CHAR | 1024, 0 , ""}, /* set */
  9942. { SIOCIWFIRSTPRIV + 0x0F, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , ""},/* get
  9943. * --- sub-ioctls definitions --- */
  9944. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  9945. { VENDOR_IE_SET, IW_PRIV_TYPE_CHAR | 1024 , 0 , "vendor_ie_set" },
  9946. { VENDOR_IE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "vendor_ie_get" },
  9947. #endif
  9948. #if defined(CONFIG_RTL8723B)
  9949. { MP_SetBT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setbt" },
  9950. { MP_DISABLE_BT_COEXIST, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_disa_btcoex"},
  9951. #endif
  9952. #ifdef CONFIG_WOWLAN
  9953. { MP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_mode" },
  9954. { MP_WOW_SET_PATTERN , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_set_pattern" },
  9955. #endif
  9956. #ifdef CONFIG_AP_WOWLAN
  9957. { MP_AP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "ap_wow_mode" }, /* set */
  9958. #endif
  9959. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  9960. { MP_SD_IREAD, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iread" },
  9961. { MP_SD_IWRITE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iwrite" },
  9962. #endif
  9963. };
  9964. static const struct iw_priv_args rtw_mp_private_args[] = {
  9965. /* --- sub-ioctls definitions --- */
  9966. #ifdef CONFIG_MP_INCLUDED
  9967. { MP_START , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_start" },
  9968. { MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara" },
  9969. { MP_STOP , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_stop" },
  9970. { MP_CHANNEL , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel" },
  9971. { MP_CHL_OFFSET , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ch_offset" },
  9972. { MP_BANDWIDTH , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_bandwidth"},
  9973. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  9974. { MP_RESET_STATS , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_reset_stats"},
  9975. { MP_QUERY , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "mp_query"},
  9976. { READ_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg" },
  9977. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  9978. { READ_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf" },
  9979. { MP_PSD , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
  9980. { MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump" },
  9981. { MP_TXPOWER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
  9982. { MP_ANT_TX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
  9983. { MP_ANT_RX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
  9984. { WRITE_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_reg" },
  9985. { WRITE_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_rf" },
  9986. { MP_CTX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
  9987. { MP_ARX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
  9988. { MP_THER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
  9989. { EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_set" },
  9990. { EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get" },
  9991. { MP_PWRTRK , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrtrk"},
  9992. { MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery" },
  9993. { MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"},
  9994. { MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setrfpath" },
  9995. { MP_PwrCtlDM, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrctldm" },
  9996. { MP_GET_TXPOWER_INX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_get_txpower" },
  9997. { MP_GETVER, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_priv_ver" },
  9998. { MP_MON, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_mon" },
  9999. { EFUSE_MASK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_mask" },
  10000. { EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_file" },
  10001. { MP_TX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_tx" },
  10002. { MP_RX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rx" },
  10003. { MP_HW_TX_MODE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_hxtx" },
  10004. { MP_PWRLMT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrlmt" },
  10005. { MP_PWRBYRATE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrbyrate" },
  10006. { CTA_TEST, IW_PRIV_TYPE_CHAR | 1024, 0, "cta_test"},
  10007. { MP_IQK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_iqk"},
  10008. { MP_LCK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_lck"},
  10009. { BT_EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bt_efuse_file" },
  10010. { MP_SWRFPath, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_swrfpath" },
  10011. #ifdef CONFIG_RTW_CUSTOMER_STR
  10012. { MP_CUSTOMER_STR, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "customer_str" },
  10013. #endif
  10014. #endif /* CONFIG_MP_INCLUDED */
  10015. };
  10016. static iw_handler rtw_private_handler[] = {
  10017. rtw_wx_write32, /* 0x00 */
  10018. rtw_wx_read32, /* 0x01 */
  10019. NULL, /* 0x02 */
  10020. #ifdef MP_IOCTL_HDL
  10021. rtw_mp_ioctl_hdl, /* 0x03 */
  10022. #else
  10023. rtw_wx_priv_null,
  10024. #endif
  10025. /* for MM DTV platform */
  10026. rtw_get_ap_info, /* 0x04 */
  10027. rtw_set_pid, /* 0x05 */
  10028. rtw_wps_start, /* 0x06 */
  10029. /* for PLATFORM_MT53XX */
  10030. rtw_wx_get_sensitivity, /* 0x07 */
  10031. rtw_wx_set_mtk_wps_probe_ie, /* 0x08 */
  10032. rtw_wx_set_mtk_wps_ie, /* 0x09 */
  10033. /* for RTK_DMP_PLATFORM
  10034. * Set Channel depend on the country code */
  10035. rtw_wx_set_channel_plan, /* 0x0A */
  10036. rtw_dbg_port, /* 0x0B */
  10037. rtw_wx_write_rf, /* 0x0C */
  10038. rtw_wx_read_rf, /* 0x0D */
  10039. rtw_priv_set, /*0x0E*/
  10040. rtw_priv_get, /*0x0F*/
  10041. rtw_p2p_set, /* 0x10 */
  10042. rtw_p2p_get, /* 0x11 */
  10043. NULL, /* 0x12 */
  10044. rtw_p2p_get2, /* 0x13 */
  10045. rtw_tdls, /* 0x14 */
  10046. rtw_tdls_get, /* 0x15 */
  10047. rtw_pm_set, /* 0x16 */
  10048. #ifdef CONFIG_RTW_80211K
  10049. rtw_wx_priv_rrm, /* 0x17 */
  10050. #else
  10051. rtw_wx_priv_null, /* 0x17 */
  10052. #endif
  10053. rtw_rereg_nd_name, /* 0x18 */
  10054. rtw_wx_priv_null, /* 0x19 */
  10055. #ifdef CONFIG_MP_INCLUDED
  10056. rtw_wx_priv_null, /* 0x1A */
  10057. rtw_wx_priv_null, /* 0x1B */
  10058. #else
  10059. rtw_wx_priv_null, /* 0x1A */
  10060. rtw_mp_efuse_get, /* 0x1B */
  10061. #endif
  10062. NULL, /* 0x1C is reserved for hostapd */
  10063. rtw_test, /* 0x1D */
  10064. #ifdef CONFIG_INTEL_WIDI
  10065. rtw_widi_set, /* 0x1E */
  10066. rtw_widi_set_probe_request, /* 0x1F */
  10067. #endif /* CONFIG_INTEL_WIDI */
  10068. };
  10069. #if WIRELESS_EXT >= 17
  10070. static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
  10071. {
  10072. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  10073. struct iw_statistics *piwstats = &padapter->iwstats;
  10074. int tmp_level = 0;
  10075. int tmp_qual = 0;
  10076. int tmp_noise = 0;
  10077. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) != _TRUE) {
  10078. piwstats->qual.qual = 0;
  10079. piwstats->qual.level = 0;
  10080. piwstats->qual.noise = 0;
  10081. /* RTW_INFO("No link level:%d, qual:%d, noise:%d\n", tmp_level, tmp_qual, tmp_noise); */
  10082. } else {
  10083. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10084. tmp_level = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  10085. #else
  10086. tmp_level = padapter->recvpriv.signal_strength;
  10087. #endif
  10088. tmp_qual = padapter->recvpriv.signal_qual;
  10089. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  10090. if (IS_NM_ENABLE(padapter)) {
  10091. tmp_noise = rtw_noise_measure_curchan(padapter);
  10092. #ifndef CONFIG_SIGNAL_DISPLAY_DBM
  10093. tmp_noise = translate_dbm_to_percentage(tmp_noise);/*percentage*/
  10094. #endif
  10095. }
  10096. #endif
  10097. /* RTW_INFO("level:%d, qual:%d, noise:%d, rssi (%d)\n", tmp_level, tmp_qual, tmp_noise,padapter->recvpriv.rssi); */
  10098. piwstats->qual.level = tmp_level;
  10099. piwstats->qual.qual = tmp_qual;
  10100. piwstats->qual.noise = tmp_noise;
  10101. }
  10102. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14))
  10103. piwstats->qual.updated = IW_QUAL_ALL_UPDATED ;/* |IW_QUAL_DBM; */
  10104. #else
  10105. #ifdef RTK_DMP_PLATFORM
  10106. /* IW_QUAL_DBM= 0x8, if driver use this flag, wireless extension will show value of dbm. */
  10107. /* remove this flag for show percentage 0~100 */
  10108. piwstats->qual.updated = 0x07;
  10109. #else
  10110. piwstats->qual.updated = 0x0f;
  10111. #endif
  10112. #endif
  10113. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10114. piwstats->qual.updated = piwstats->qual.updated | IW_QUAL_DBM;
  10115. #endif
  10116. return &padapter->iwstats;
  10117. }
  10118. #endif
  10119. #ifdef CONFIG_WIRELESS_EXT
  10120. struct iw_handler_def rtw_handlers_def = {
  10121. .standard = rtw_handlers,
  10122. .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
  10123. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) || defined(CONFIG_WEXT_PRIV)
  10124. .private = rtw_private_handler,
  10125. .private_args = (struct iw_priv_args *)rtw_private_args,
  10126. .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler),
  10127. .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args),
  10128. #endif
  10129. #if WIRELESS_EXT >= 17
  10130. .get_wireless_stats = rtw_get_wireless_stats,
  10131. #endif
  10132. };
  10133. #endif
  10134. /* copy from net/wireless/wext.c start
  10135. * ----------------------------------------------------------------
  10136. *
  10137. * Calculate size of private arguments
  10138. */
  10139. static const char iw_priv_type_size[] = {
  10140. 0, /* IW_PRIV_TYPE_NONE */
  10141. 1, /* IW_PRIV_TYPE_BYTE */
  10142. 1, /* IW_PRIV_TYPE_CHAR */
  10143. 0, /* Not defined */
  10144. sizeof(__u32), /* IW_PRIV_TYPE_INT */
  10145. sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
  10146. sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
  10147. 0, /* Not defined */
  10148. };
  10149. static int get_priv_size(__u16 args)
  10150. {
  10151. int num = args & IW_PRIV_SIZE_MASK;
  10152. int type = (args & IW_PRIV_TYPE_MASK) >> 12;
  10153. return num * iw_priv_type_size[type];
  10154. }
  10155. /* copy from net/wireless/wext.c end */
  10156. static int _rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_data)
  10157. {
  10158. int err = 0;
  10159. u8 *input = NULL;
  10160. u32 input_len = 0;
  10161. const char delim[] = " ";
  10162. u8 *output = NULL;
  10163. u32 output_len = 0;
  10164. u32 count = 0;
  10165. u8 *buffer = NULL;
  10166. u32 buffer_len = 0;
  10167. char *ptr = NULL;
  10168. u8 cmdname[17] = {0}; /* IFNAMSIZ+1 */
  10169. u32 cmdlen;
  10170. s32 len;
  10171. u8 *extra = NULL;
  10172. u32 extra_size = 0;
  10173. s32 k;
  10174. const iw_handler *priv; /* Private ioctl */
  10175. const struct iw_priv_args *priv_args; /* Private ioctl description */
  10176. const struct iw_priv_args *mp_priv_args; /*MP Private ioctl description */
  10177. const struct iw_priv_args *sel_priv_args; /*Selected Private ioctl description */
  10178. u32 num_priv; /* Number of ioctl */
  10179. u32 num_priv_args; /* Number of descriptions */
  10180. u32 num_mp_priv_args; /*Number of MP descriptions */
  10181. u32 num_sel_priv_args; /*Number of Selected descriptions */
  10182. iw_handler handler;
  10183. int temp;
  10184. int subcmd = 0; /* sub-ioctl index */
  10185. int offset = 0; /* Space for sub-ioctl index */
  10186. union iwreq_data wdata;
  10187. _rtw_memcpy(&wdata, wrq_data, sizeof(wdata));
  10188. input_len = wdata.data.length;
  10189. if (!input_len)
  10190. return -EINVAL;
  10191. input = rtw_zmalloc(input_len);
  10192. if (NULL == input)
  10193. return -ENOMEM;
  10194. if (copy_from_user(input, wdata.data.pointer, input_len)) {
  10195. err = -EFAULT;
  10196. goto exit;
  10197. }
  10198. input[input_len - 1] = '\0';
  10199. ptr = input;
  10200. len = input_len;
  10201. if (ptr == NULL) {
  10202. err = -EOPNOTSUPP;
  10203. goto exit;
  10204. }
  10205. sscanf(ptr, "%16s", cmdname);
  10206. cmdlen = strlen(cmdname);
  10207. RTW_INFO("%s: cmd=%s\n", __func__, cmdname);
  10208. /* skip command string */
  10209. if (cmdlen > 0)
  10210. cmdlen += 1; /* skip one space */
  10211. ptr += cmdlen;
  10212. len -= cmdlen;
  10213. RTW_INFO("%s: parameters=%s\n", __func__, ptr);
  10214. priv = rtw_private_handler;
  10215. priv_args = rtw_private_args;
  10216. mp_priv_args = rtw_mp_private_args;
  10217. num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler);
  10218. num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args);
  10219. num_mp_priv_args = sizeof(rtw_mp_private_args) / sizeof(struct iw_priv_args);
  10220. if (num_priv_args == 0) {
  10221. err = -EOPNOTSUPP;
  10222. goto exit;
  10223. }
  10224. /* Search the correct ioctl */
  10225. k = -1;
  10226. sel_priv_args = priv_args;
  10227. num_sel_priv_args = num_priv_args;
  10228. while
  10229. ((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
  10230. ;
  10231. /* If not found... */
  10232. if (k == num_sel_priv_args) {
  10233. k = -1;
  10234. sel_priv_args = mp_priv_args;
  10235. num_sel_priv_args = num_mp_priv_args;
  10236. while
  10237. ((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
  10238. ;
  10239. if (k == num_sel_priv_args) {
  10240. err = -EOPNOTSUPP;
  10241. goto exit;
  10242. }
  10243. }
  10244. /* Watch out for sub-ioctls ! */
  10245. if (sel_priv_args[k].cmd < SIOCDEVPRIVATE) {
  10246. int j = -1;
  10247. /* Find the matching *real* ioctl */
  10248. while ((++j < num_priv_args) && ((priv_args[j].name[0] != '\0') ||
  10249. (priv_args[j].set_args != sel_priv_args[k].set_args) ||
  10250. (priv_args[j].get_args != sel_priv_args[k].get_args)))
  10251. ;
  10252. /* If not found... */
  10253. if (j == num_priv_args) {
  10254. err = -EINVAL;
  10255. goto exit;
  10256. }
  10257. /* Save sub-ioctl number */
  10258. subcmd = sel_priv_args[k].cmd;
  10259. /* Reserve one int (simplify alignment issues) */
  10260. offset = sizeof(__u32);
  10261. /* Use real ioctl definition from now on */
  10262. k = j;
  10263. }
  10264. buffer = rtw_zmalloc(4096);
  10265. if (NULL == buffer) {
  10266. err = -ENOMEM;
  10267. goto exit;
  10268. }
  10269. if (k >= num_priv_args) {
  10270. err = -EINVAL;
  10271. goto exit;
  10272. }
  10273. /* If we have to set some data */
  10274. if ((priv_args[k].set_args & IW_PRIV_TYPE_MASK) &&
  10275. (priv_args[k].set_args & IW_PRIV_SIZE_MASK)) {
  10276. u8 *str;
  10277. switch (priv_args[k].set_args & IW_PRIV_TYPE_MASK) {
  10278. case IW_PRIV_TYPE_BYTE:
  10279. /* Fetch args */
  10280. count = 0;
  10281. do {
  10282. str = strsep(&ptr, delim);
  10283. if (NULL == str)
  10284. break;
  10285. sscanf(str, "%i", &temp);
  10286. buffer[count++] = (u8)temp;
  10287. } while (1);
  10288. buffer_len = count;
  10289. /* Number of args to fetch */
  10290. wdata.data.length = count;
  10291. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10292. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10293. break;
  10294. case IW_PRIV_TYPE_INT:
  10295. /* Fetch args */
  10296. count = 0;
  10297. do {
  10298. str = strsep(&ptr, delim);
  10299. if (NULL == str)
  10300. break;
  10301. sscanf(str, "%i", &temp);
  10302. ((s32 *)buffer)[count++] = (s32)temp;
  10303. } while (1);
  10304. buffer_len = count * sizeof(s32);
  10305. /* Number of args to fetch */
  10306. wdata.data.length = count;
  10307. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10308. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10309. break;
  10310. case IW_PRIV_TYPE_CHAR:
  10311. if (len > 0) {
  10312. /* Size of the string to fetch */
  10313. wdata.data.length = len;
  10314. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10315. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10316. /* Fetch string */
  10317. _rtw_memcpy(buffer, ptr, wdata.data.length);
  10318. } else {
  10319. wdata.data.length = 1;
  10320. buffer[0] = '\0';
  10321. }
  10322. buffer_len = wdata.data.length;
  10323. break;
  10324. default:
  10325. RTW_INFO("%s: Not yet implemented...\n", __func__);
  10326. err = -1;
  10327. goto exit;
  10328. }
  10329. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10330. (wdata.data.length != (priv_args[k].set_args & IW_PRIV_SIZE_MASK))) {
  10331. RTW_INFO("%s: The command %s needs exactly %d argument(s)...\n",
  10332. __func__, cmdname, priv_args[k].set_args & IW_PRIV_SIZE_MASK);
  10333. err = -EINVAL;
  10334. goto exit;
  10335. }
  10336. } /* if args to set */
  10337. else
  10338. wdata.data.length = 0L;
  10339. /* Those two tests are important. They define how the driver
  10340. * will have to handle the data */
  10341. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10342. ((get_priv_size(priv_args[k].set_args) + offset) <= IFNAMSIZ)) {
  10343. /* First case : all SET args fit within wrq */
  10344. if (offset)
  10345. wdata.mode = subcmd;
  10346. _rtw_memcpy(wdata.name + offset, buffer, IFNAMSIZ - offset);
  10347. } else {
  10348. if ((priv_args[k].set_args == 0) &&
  10349. (priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10350. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ)) {
  10351. /* Second case : no SET args, GET args fit within wrq */
  10352. if (offset)
  10353. wdata.mode = subcmd;
  10354. } else {
  10355. /* Third case : args won't fit in wrq, or variable number of args */
  10356. if (copy_to_user(wdata.data.pointer, buffer, buffer_len)) {
  10357. err = -EFAULT;
  10358. goto exit;
  10359. }
  10360. wdata.data.flags = subcmd;
  10361. }
  10362. }
  10363. rtw_mfree(input, input_len);
  10364. input = NULL;
  10365. extra_size = 0;
  10366. if (IW_IS_SET(priv_args[k].cmd)) {
  10367. /* Size of set arguments */
  10368. extra_size = get_priv_size(priv_args[k].set_args);
  10369. /* Does it fits in iwr ? */
  10370. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10371. ((extra_size + offset) <= IFNAMSIZ))
  10372. extra_size = 0;
  10373. } else {
  10374. /* Size of get arguments */
  10375. extra_size = get_priv_size(priv_args[k].get_args);
  10376. /* Does it fits in iwr ? */
  10377. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10378. (extra_size <= IFNAMSIZ))
  10379. extra_size = 0;
  10380. }
  10381. if (extra_size == 0) {
  10382. extra = (u8 *)&wdata;
  10383. rtw_mfree(buffer, 4096);
  10384. buffer = NULL;
  10385. } else
  10386. extra = buffer;
  10387. handler = priv[priv_args[k].cmd - SIOCIWFIRSTPRIV];
  10388. err = handler(dev, NULL, &wdata, extra);
  10389. /* If we have to get some data */
  10390. if ((priv_args[k].get_args & IW_PRIV_TYPE_MASK) &&
  10391. (priv_args[k].get_args & IW_PRIV_SIZE_MASK)) {
  10392. int j;
  10393. int n = 0; /* number of args */
  10394. u8 str[20] = {0};
  10395. /* Check where is the returned data */
  10396. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10397. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ))
  10398. n = priv_args[k].get_args & IW_PRIV_SIZE_MASK;
  10399. else
  10400. n = wdata.data.length;
  10401. output = rtw_zmalloc(4096);
  10402. if (NULL == output) {
  10403. err = -ENOMEM;
  10404. goto exit;
  10405. }
  10406. switch (priv_args[k].get_args & IW_PRIV_TYPE_MASK) {
  10407. case IW_PRIV_TYPE_BYTE:
  10408. /* Display args */
  10409. for (j = 0; j < n; j++) {
  10410. sprintf(str, "%d ", extra[j]);
  10411. len = strlen(str);
  10412. output_len = strlen(output);
  10413. if ((output_len + len + 1) > 4096) {
  10414. err = -E2BIG;
  10415. goto exit;
  10416. }
  10417. _rtw_memcpy(output + output_len, str, len);
  10418. }
  10419. break;
  10420. case IW_PRIV_TYPE_INT:
  10421. /* Display args */
  10422. for (j = 0; j < n; j++) {
  10423. sprintf(str, "%d ", ((__s32 *)extra)[j]);
  10424. len = strlen(str);
  10425. output_len = strlen(output);
  10426. if ((output_len + len + 1) > 4096) {
  10427. err = -E2BIG;
  10428. goto exit;
  10429. }
  10430. _rtw_memcpy(output + output_len, str, len);
  10431. }
  10432. break;
  10433. case IW_PRIV_TYPE_CHAR:
  10434. /* Display args */
  10435. _rtw_memcpy(output, extra, n);
  10436. break;
  10437. default:
  10438. RTW_INFO("%s: Not yet implemented...\n", __func__);
  10439. err = -1;
  10440. goto exit;
  10441. }
  10442. output_len = strlen(output) + 1;
  10443. wrq_data->data.length = output_len;
  10444. if (copy_to_user(wrq_data->data.pointer, output, output_len)) {
  10445. err = -EFAULT;
  10446. goto exit;
  10447. }
  10448. } /* if args to set */
  10449. else
  10450. wrq_data->data.length = 0;
  10451. exit:
  10452. if (input)
  10453. rtw_mfree(input, input_len);
  10454. if (buffer)
  10455. rtw_mfree(buffer, 4096);
  10456. if (output)
  10457. rtw_mfree(output, 4096);
  10458. return err;
  10459. }
  10460. #ifdef CONFIG_COMPAT
  10461. static int rtw_ioctl_compat_wext_private(struct net_device *dev, struct ifreq *rq)
  10462. {
  10463. struct compat_iw_point iwp_compat;
  10464. union iwreq_data wrq_data;
  10465. int err = 0;
  10466. RTW_INFO("%s:...\n", __func__);
  10467. if (copy_from_user(&iwp_compat, rq->ifr_ifru.ifru_data, sizeof(struct compat_iw_point)))
  10468. return -EFAULT;
  10469. wrq_data.data.pointer = compat_ptr(iwp_compat.pointer);
  10470. wrq_data.data.length = iwp_compat.length;
  10471. wrq_data.data.flags = iwp_compat.flags;
  10472. err = _rtw_ioctl_wext_private(dev, &wrq_data);
  10473. iwp_compat.pointer = ptr_to_compat(wrq_data.data.pointer);
  10474. iwp_compat.length = wrq_data.data.length;
  10475. iwp_compat.flags = wrq_data.data.flags;
  10476. if (copy_to_user(rq->ifr_ifru.ifru_data, &iwp_compat, sizeof(struct compat_iw_point)))
  10477. return -EFAULT;
  10478. return err;
  10479. }
  10480. #endif /* CONFIG_COMPAT */
  10481. static int rtw_ioctl_standard_wext_private(struct net_device *dev, struct ifreq *rq)
  10482. {
  10483. struct iw_point *iwp;
  10484. union iwreq_data wrq_data;
  10485. int err = 0;
  10486. iwp = &wrq_data.data;
  10487. RTW_INFO("%s:...\n", __func__);
  10488. if (copy_from_user(iwp, rq->ifr_ifru.ifru_data, sizeof(struct iw_point)))
  10489. return -EFAULT;
  10490. err = _rtw_ioctl_wext_private(dev, &wrq_data);
  10491. if (copy_to_user(rq->ifr_ifru.ifru_data, iwp, sizeof(struct iw_point)))
  10492. return -EFAULT;
  10493. return err;
  10494. }
  10495. static int rtw_ioctl_wext_private(struct net_device *dev, struct ifreq *rq)
  10496. {
  10497. #ifdef CONFIG_COMPAT
  10498. #if (KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE)
  10499. if (is_compat_task())
  10500. #else
  10501. if (in_compat_syscall())
  10502. #endif
  10503. return rtw_ioctl_compat_wext_private(dev, rq);
  10504. else
  10505. #endif /* CONFIG_COMPAT */
  10506. return rtw_ioctl_standard_wext_private(dev, rq);
  10507. }
  10508. int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  10509. {
  10510. struct iwreq *wrq = (struct iwreq *)rq;
  10511. int ret = 0;
  10512. switch (cmd) {
  10513. case RTL_IOCTL_WPA_SUPPLICANT:
  10514. ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
  10515. break;
  10516. #ifdef CONFIG_AP_MODE
  10517. case RTL_IOCTL_HOSTAPD:
  10518. ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
  10519. break;
  10520. #ifdef CONFIG_WIRELESS_EXT
  10521. case SIOCSIWMODE:
  10522. ret = rtw_wx_set_mode(dev, NULL, &wrq->u, NULL);
  10523. break;
  10524. #endif
  10525. #endif /* CONFIG_AP_MODE */
  10526. case SIOCDEVPRIVATE:
  10527. ret = rtw_ioctl_wext_private(dev, rq);
  10528. break;
  10529. case (SIOCDEVPRIVATE+1):
  10530. ret = rtw_android_priv_cmd(dev, rq, cmd);
  10531. break;
  10532. default:
  10533. ret = -EOPNOTSUPP;
  10534. break;
  10535. }
  10536. return ret;
  10537. }