ioctl_linux.c 359 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868
  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. _rtw_memcpy(padapter->pnetdev->dev_addr, get_hal_mac_addr(padapter), ETH_ALEN); /* set mac addr to net_device */
  7955. #ifdef CONFIG_P2P
  7956. rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
  7957. #endif
  7958. #ifdef CONFIG_MI_WITH_MBSSID_CAM
  7959. rtw_hal_change_macaddr_mbid(padapter, adapter_mac_addr(padapter));
  7960. #else
  7961. rtw_hal_set_hwreg(padapter, HW_VAR_MAC_ADDR, adapter_mac_addr(padapter)); /* set mac addr to mac register */
  7962. #endif
  7963. /*pHalFunc->hal_deinit(padapter);*/
  7964. if (pHalFunc->hal_init(padapter) == _FAIL) {
  7965. err = -EINVAL;
  7966. goto exit;
  7967. }
  7968. _rtw_memset(extra, '\0', strlen(extra));
  7969. sprintf(extra, "eFuse Update OK\n");
  7970. } else if (strcmp(tmp[0], "analyze") == 0) {
  7971. rtw_efuse_analyze(padapter, EFUSE_WIFI, 0);
  7972. _rtw_memset(extra, '\0', strlen(extra));
  7973. sprintf(extra, "eFuse Analyze OK,please to check kernel log\n");
  7974. }
  7975. exit:
  7976. if (setdata)
  7977. rtw_mfree(setdata, 1024);
  7978. if (ShadowMapBT)
  7979. rtw_mfree(ShadowMapBT, EFUSE_BT_MAX_MAP_LEN);
  7980. if (ShadowMapWiFi)
  7981. rtw_mfree(ShadowMapWiFi, wifimaplen);
  7982. if (setrawdata)
  7983. rtw_mfree(setrawdata, EFUSE_MAX_SIZE);
  7984. wrqu->length = strlen(extra);
  7985. if (padapter->registrypriv.mp_mode == 0) {
  7986. #ifdef CONFIG_IPS
  7987. rtw_pm_set_ips(padapter, ips_mode);
  7988. #endif /* CONFIG_IPS */
  7989. #ifdef CONFIG_LPS
  7990. rtw_pm_set_lps(padapter, lps_mode);
  7991. #endif /* CONFIG_LPS */
  7992. }
  7993. return err;
  7994. }
  7995. #ifdef CONFIG_RTW_CUSTOMER_STR
  7996. static int rtw_mp_customer_str(
  7997. struct net_device *dev,
  7998. struct iw_request_info *info,
  7999. union iwreq_data *wrqu, char *extra)
  8000. {
  8001. _adapter *adapter = rtw_netdev_priv(dev);
  8002. u32 len;
  8003. u8 *pbuf = NULL, *pch;
  8004. char *ptmp;
  8005. u8 param[RTW_CUSTOMER_STR_LEN];
  8006. u8 count = 0;
  8007. u8 tmp;
  8008. u8 i;
  8009. u32 pos;
  8010. u8 ret;
  8011. u8 read = 0;
  8012. if (adapter->registrypriv.mp_mode != 1
  8013. || !adapter->registrypriv.mp_customer_str)
  8014. return -EFAULT;
  8015. len = wrqu->data.length + 1;
  8016. pbuf = (u8 *)rtw_zmalloc(len);
  8017. if (pbuf == NULL) {
  8018. RTW_WARN("%s: no memory!\n", __func__);
  8019. return -ENOMEM;
  8020. }
  8021. if (copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length)) {
  8022. rtw_mfree(pbuf, len);
  8023. RTW_WARN("%s: copy from user fail!\n", __func__);
  8024. return -EFAULT;
  8025. }
  8026. RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
  8027. ptmp = (char *)pbuf;
  8028. pch = strsep(&ptmp, ",");
  8029. if ((pch == NULL) || (strlen(pch) == 0)) {
  8030. rtw_mfree(pbuf, len);
  8031. RTW_INFO("%s: parameter error(no cmd)!\n", __func__);
  8032. return -EFAULT;
  8033. }
  8034. _rtw_memset(param, 0xFF, RTW_CUSTOMER_STR_LEN);
  8035. if (strcmp(pch, "read") == 0) {
  8036. read = 1;
  8037. ret = rtw_hal_customer_str_read(adapter, param);
  8038. } else if (strcmp(pch, "write") == 0) {
  8039. do {
  8040. pch = strsep(&ptmp, ":");
  8041. if ((pch == NULL) || (strlen(pch) == 0))
  8042. break;
  8043. if (strlen(pch) != 2
  8044. || IsHexDigit(*pch) == _FALSE
  8045. || IsHexDigit(*(pch + 1)) == _FALSE
  8046. || sscanf(pch, "%hhx", &tmp) != 1
  8047. ) {
  8048. RTW_WARN("%s: invalid 8-bit hex!\n", __func__);
  8049. rtw_mfree(pbuf, len);
  8050. return -EFAULT;
  8051. }
  8052. param[count++] = tmp;
  8053. } while (count < RTW_CUSTOMER_STR_LEN);
  8054. if (count == 0) {
  8055. rtw_mfree(pbuf, len);
  8056. RTW_WARN("%s: no input!\n", __func__);
  8057. return -EFAULT;
  8058. }
  8059. ret = rtw_hal_customer_str_write(adapter, param);
  8060. } else {
  8061. rtw_mfree(pbuf, len);
  8062. RTW_INFO("%s: parameter error(unknown cmd)!\n", __func__);
  8063. return -EFAULT;
  8064. }
  8065. pos = sprintf(extra, "%s: ", read ? "read" : "write");
  8066. if (read == 0 || ret == _SUCCESS) {
  8067. for (i = 0; i < RTW_CUSTOMER_STR_LEN; i++)
  8068. pos += sprintf(extra + pos, "%02x:", param[i]);
  8069. extra[pos] = 0;
  8070. pos--;
  8071. }
  8072. pos += sprintf(extra + pos, " %s", ret == _SUCCESS ? "OK" : "FAIL");
  8073. wrqu->data.length = strlen(extra) + 1;
  8074. free_buf:
  8075. rtw_mfree(pbuf, len);
  8076. return 0;
  8077. }
  8078. #endif /* CONFIG_RTW_CUSTOMER_STR */
  8079. static int rtw_priv_mp_set(struct net_device *dev,
  8080. struct iw_request_info *info,
  8081. union iwreq_data *wdata, char *extra)
  8082. {
  8083. struct iw_point *wrqu = (struct iw_point *)wdata;
  8084. u32 subcmd = wrqu->flags;
  8085. #ifdef CONFIG_CONCURRENT_MODE
  8086. PADAPTER padapter = rtw_netdev_priv(dev);
  8087. #endif
  8088. if (!is_primary_adapter(padapter)) {
  8089. RTW_INFO("MP mode only primary Adapter support\n");
  8090. return -EIO;
  8091. }
  8092. switch (subcmd) {
  8093. case CTA_TEST:
  8094. RTW_INFO("set CTA_TEST\n");
  8095. rtw_cta_test_start(dev, info, wdata, extra);
  8096. break;
  8097. case MP_DISABLE_BT_COEXIST:
  8098. RTW_INFO("set case MP_DISABLE_BT_COEXIST\n");
  8099. rtw_mp_disable_bt_coexist(dev, info, wdata, extra);
  8100. break;
  8101. case MP_IQK:
  8102. RTW_INFO("set MP_IQK\n");
  8103. rtw_mp_iqk(dev, info, wrqu, extra);
  8104. break;
  8105. case MP_LCK:
  8106. RTW_INFO("set MP_LCK\n");
  8107. rtw_mp_lck(dev, info, wrqu, extra);
  8108. break;
  8109. default:
  8110. return -EIO;
  8111. }
  8112. return 0;
  8113. }
  8114. static int rtw_priv_mp_get(struct net_device *dev,
  8115. struct iw_request_info *info,
  8116. union iwreq_data *wdata, char *extra)
  8117. {
  8118. struct iw_point *wrqu = (struct iw_point *)wdata;
  8119. u32 subcmd = wrqu->flags;
  8120. #ifdef CONFIG_CONCURRENT_MODE
  8121. PADAPTER padapter = rtw_netdev_priv(dev);
  8122. #endif
  8123. if (!is_primary_adapter(padapter)) {
  8124. RTW_INFO("MP mode only primary Adapter support\n");
  8125. return -EIO;
  8126. }
  8127. switch (subcmd) {
  8128. case MP_START:
  8129. RTW_INFO("set case mp_start\n");
  8130. rtw_mp_start(dev, info, wrqu, extra);
  8131. break;
  8132. case MP_STOP:
  8133. RTW_INFO("set case mp_stop\n");
  8134. rtw_mp_stop(dev, info, wrqu, extra);
  8135. break;
  8136. case MP_BANDWIDTH:
  8137. RTW_INFO("set case mp_bandwidth\n");
  8138. rtw_mp_bandwidth(dev, info, wrqu, extra);
  8139. break;
  8140. case MP_RESET_STATS:
  8141. RTW_INFO("set case MP_RESET_STATS\n");
  8142. rtw_mp_reset_stats(dev, info, wrqu, extra);
  8143. break;
  8144. case MP_SetRFPathSwh:
  8145. RTW_INFO("set MP_SetRFPathSwitch\n");
  8146. rtw_mp_SetRFPath(dev, info, wrqu, extra);
  8147. break;
  8148. case WRITE_REG:
  8149. rtw_mp_write_reg(dev, info, wrqu, extra);
  8150. break;
  8151. case WRITE_RF:
  8152. rtw_mp_write_rf(dev, info, wrqu, extra);
  8153. break;
  8154. case MP_PHYPARA:
  8155. RTW_INFO("mp_get MP_PHYPARA\n");
  8156. rtw_mp_phypara(dev, info, wrqu, extra);
  8157. break;
  8158. case MP_CHANNEL:
  8159. RTW_INFO("set case mp_channel\n");
  8160. rtw_mp_channel(dev , info, wrqu, extra);
  8161. break;
  8162. case MP_CHL_OFFSET:
  8163. RTW_INFO("set case mp_ch_offset\n");
  8164. rtw_mp_ch_offset(dev , info, wrqu, extra);
  8165. break;
  8166. case READ_REG:
  8167. RTW_INFO("mp_get READ_REG\n");
  8168. rtw_mp_read_reg(dev, info, wrqu, extra);
  8169. break;
  8170. case READ_RF:
  8171. RTW_INFO("mp_get READ_RF\n");
  8172. rtw_mp_read_rf(dev, info, wrqu, extra);
  8173. break;
  8174. case MP_RATE:
  8175. RTW_INFO("set case mp_rate\n");
  8176. rtw_mp_rate(dev, info, wrqu, extra);
  8177. break;
  8178. case MP_TXPOWER:
  8179. RTW_INFO("set case MP_TXPOWER\n");
  8180. rtw_mp_txpower(dev, info, wrqu, extra);
  8181. break;
  8182. case MP_ANT_TX:
  8183. RTW_INFO("set case MP_ANT_TX\n");
  8184. rtw_mp_ant_tx(dev, info, wrqu, extra);
  8185. break;
  8186. case MP_ANT_RX:
  8187. RTW_INFO("set case MP_ANT_RX\n");
  8188. rtw_mp_ant_rx(dev, info, wrqu, extra);
  8189. break;
  8190. case MP_QUERY:
  8191. rtw_mp_trx_query(dev, info, wrqu, extra);
  8192. break;
  8193. case MP_CTX:
  8194. RTW_INFO("set case MP_CTX\n");
  8195. rtw_mp_ctx(dev, info, wrqu, extra);
  8196. break;
  8197. case MP_ARX:
  8198. RTW_INFO("set case MP_ARX\n");
  8199. rtw_mp_arx(dev, info, wrqu, extra);
  8200. break;
  8201. case MP_DUMP:
  8202. RTW_INFO("set case MP_DUMP\n");
  8203. rtw_mp_dump(dev, info, wrqu, extra);
  8204. break;
  8205. case MP_PSD:
  8206. RTW_INFO("set case MP_PSD\n");
  8207. rtw_mp_psd(dev, info, wrqu, extra);
  8208. break;
  8209. case MP_THER:
  8210. RTW_INFO("set case MP_THER\n");
  8211. rtw_mp_thermal(dev, info, wrqu, extra);
  8212. break;
  8213. case MP_PwrCtlDM:
  8214. RTW_INFO("set MP_PwrCtlDM\n");
  8215. rtw_mp_PwrCtlDM(dev, info, wrqu, extra);
  8216. break;
  8217. case MP_QueryDrvStats:
  8218. RTW_INFO("mp_get MP_QueryDrvStats\n");
  8219. rtw_mp_QueryDrv(dev, info, wdata, extra);
  8220. break;
  8221. case MP_PWRTRK:
  8222. RTW_INFO("set case MP_PWRTRK\n");
  8223. rtw_mp_pwrtrk(dev, info, wrqu, extra);
  8224. break;
  8225. #ifdef CONFIG_MP_INCLUDED
  8226. case EFUSE_SET:
  8227. RTW_INFO("set case efuse set\n");
  8228. rtw_mp_efuse_set(dev, info, wdata, extra);
  8229. break;
  8230. #endif
  8231. case EFUSE_GET:
  8232. RTW_INFO("efuse get EFUSE_GET\n");
  8233. rtw_mp_efuse_get(dev, info, wdata, extra);
  8234. break;
  8235. case MP_GET_TXPOWER_INX:
  8236. RTW_INFO("mp_get MP_GET_TXPOWER_INX\n");
  8237. rtw_mp_txpower_index(dev, info, wrqu, extra);
  8238. break;
  8239. case MP_GETVER:
  8240. RTW_INFO("mp_get MP_GETVER\n");
  8241. rtw_mp_getver(dev, info, wdata, extra);
  8242. break;
  8243. case MP_MON:
  8244. RTW_INFO("mp_get MP_MON\n");
  8245. rtw_mp_mon(dev, info, wdata, extra);
  8246. break;
  8247. case EFUSE_MASK:
  8248. RTW_INFO("mp_get EFUSE_MASK\n");
  8249. rtw_efuse_mask_file(dev, info, wdata, extra);
  8250. break;
  8251. case EFUSE_FILE:
  8252. RTW_INFO("mp_get EFUSE_FILE\n");
  8253. rtw_efuse_file_map(dev, info, wdata, extra);
  8254. break;
  8255. case MP_TX:
  8256. RTW_INFO("mp_get MP_TX\n");
  8257. rtw_mp_tx(dev, info, wdata, extra);
  8258. break;
  8259. case MP_RX:
  8260. RTW_INFO("mp_get MP_RX\n");
  8261. rtw_mp_rx(dev, info, wdata, extra);
  8262. break;
  8263. case MP_HW_TX_MODE:
  8264. RTW_INFO("mp_get MP_HW_TX_MODE\n");
  8265. rtw_mp_hwtx(dev, info, wdata, extra);
  8266. break;
  8267. #ifdef CONFIG_RTW_CUSTOMER_STR
  8268. case MP_CUSTOMER_STR:
  8269. RTW_INFO("customer str\n");
  8270. rtw_mp_customer_str(dev, info, wdata, extra);
  8271. break;
  8272. #endif
  8273. case MP_PWRLMT:
  8274. RTW_INFO("mp_get MP_SETPWRLMT\n");
  8275. rtw_mp_pwrlmt(dev, info, wdata, extra);
  8276. break;
  8277. case MP_PWRBYRATE:
  8278. RTW_INFO("mp_get MP_SETPWRBYRATE\n");
  8279. rtw_mp_pwrbyrate(dev, info, wdata, extra);
  8280. break;
  8281. case BT_EFUSE_FILE:
  8282. RTW_INFO("mp_get BT EFUSE_FILE\n");
  8283. rtw_bt_efuse_file_map(dev, info, wdata, extra);
  8284. break;
  8285. case MP_SWRFPath:
  8286. RTW_INFO("mp_get MP_SWRFPath\n");
  8287. rtw_mp_switch_rf_path(dev, info, wrqu, extra);
  8288. break;
  8289. default:
  8290. return -EIO;
  8291. }
  8292. return 0;
  8293. }
  8294. #endif /*#if defined(CONFIG_MP_INCLUDED)*/
  8295. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  8296. #define DBG_MP_SDIO_INDIRECT_ACCESS 1
  8297. static int rtw_mp_sd_iread(struct net_device *dev
  8298. , struct iw_request_info *info
  8299. , struct iw_point *wrqu
  8300. , char *extra)
  8301. {
  8302. char input[16];
  8303. u8 width;
  8304. unsigned long addr;
  8305. u32 ret = 0;
  8306. PADAPTER padapter = rtw_netdev_priv(dev);
  8307. if (wrqu->length > 16) {
  8308. RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
  8309. ret = -EINVAL;
  8310. goto exit;
  8311. }
  8312. if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
  8313. RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
  8314. ret = -EFAULT;
  8315. goto exit;
  8316. }
  8317. _rtw_memset(extra, 0, wrqu->length);
  8318. if (sscanf(input, "%hhu,%lx", &width, &addr) != 2) {
  8319. RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
  8320. ret = -EINVAL;
  8321. goto exit;
  8322. }
  8323. if (addr > 0x3FFF) {
  8324. RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
  8325. ret = -EINVAL;
  8326. goto exit;
  8327. }
  8328. if (DBG_MP_SDIO_INDIRECT_ACCESS)
  8329. RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr);
  8330. switch (width) {
  8331. case 1:
  8332. sprintf(extra, "0x%02x", rtw_sd_iread8(padapter, addr));
  8333. wrqu->length = strlen(extra);
  8334. break;
  8335. case 2:
  8336. sprintf(extra, "0x%04x", rtw_sd_iread16(padapter, addr));
  8337. wrqu->length = strlen(extra);
  8338. break;
  8339. case 4:
  8340. sprintf(extra, "0x%08x", rtw_sd_iread32(padapter, addr));
  8341. wrqu->length = strlen(extra);
  8342. break;
  8343. default:
  8344. wrqu->length = 0;
  8345. ret = -EINVAL;
  8346. break;
  8347. }
  8348. exit:
  8349. return ret;
  8350. }
  8351. static int rtw_mp_sd_iwrite(struct net_device *dev
  8352. , struct iw_request_info *info
  8353. , struct iw_point *wrqu
  8354. , char *extra)
  8355. {
  8356. char width;
  8357. unsigned long addr, data;
  8358. int ret = 0;
  8359. PADAPTER padapter = rtw_netdev_priv(dev);
  8360. char input[32];
  8361. if (wrqu->length > 32) {
  8362. RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
  8363. ret = -EINVAL;
  8364. goto exit;
  8365. }
  8366. if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
  8367. RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
  8368. ret = -EFAULT;
  8369. goto exit;
  8370. }
  8371. _rtw_memset(extra, 0, wrqu->length);
  8372. if (sscanf(input, "%hhu,%lx,%lx", &width, &addr, &data) != 3) {
  8373. RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
  8374. ret = -EINVAL;
  8375. goto exit;
  8376. }
  8377. if (addr > 0x3FFF) {
  8378. RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
  8379. ret = -EINVAL;
  8380. goto exit;
  8381. }
  8382. if (DBG_MP_SDIO_INDIRECT_ACCESS)
  8383. RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx, data:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr, data);
  8384. switch (width) {
  8385. case 1:
  8386. if (data > 0xFF) {
  8387. ret = -EINVAL;
  8388. break;
  8389. }
  8390. rtw_sd_iwrite8(padapter, addr, data);
  8391. break;
  8392. case 2:
  8393. if (data > 0xFFFF) {
  8394. ret = -EINVAL;
  8395. break;
  8396. }
  8397. rtw_sd_iwrite16(padapter, addr, data);
  8398. break;
  8399. case 4:
  8400. rtw_sd_iwrite32(padapter, addr, data);
  8401. break;
  8402. default:
  8403. wrqu->length = 0;
  8404. ret = -EINVAL;
  8405. break;
  8406. }
  8407. exit:
  8408. return ret;
  8409. }
  8410. #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
  8411. static int rtw_priv_set(struct net_device *dev,
  8412. struct iw_request_info *info,
  8413. union iwreq_data *wdata, char *extra)
  8414. {
  8415. struct iw_point *wrqu = (struct iw_point *)wdata;
  8416. u32 subcmd = wrqu->flags;
  8417. PADAPTER padapter = rtw_netdev_priv(dev);
  8418. if (padapter == NULL)
  8419. return -ENETDOWN;
  8420. if (padapter->bup == _FALSE) {
  8421. RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
  8422. return -ENETDOWN;
  8423. }
  8424. if (RTW_CANNOT_RUN(padapter)) {
  8425. RTW_INFO("%s fail =>(bSurpriseRemoved == _TRUE) || ( bDriverStopped == _TRUE)\n", __func__);
  8426. return -ENETDOWN;
  8427. }
  8428. if (extra == NULL) {
  8429. wrqu->length = 0;
  8430. return -EIO;
  8431. }
  8432. if (subcmd < MP_NULL) {
  8433. #ifdef CONFIG_MP_INCLUDED
  8434. rtw_priv_mp_set(dev, info, wdata, extra);
  8435. #endif
  8436. return 0;
  8437. }
  8438. switch (subcmd) {
  8439. #ifdef CONFIG_WOWLAN
  8440. case MP_WOW_ENABLE:
  8441. RTW_INFO("set case MP_WOW_ENABLE: %s\n", extra);
  8442. rtw_wowlan_ctrl(dev, info, wdata, extra);
  8443. break;
  8444. case MP_WOW_SET_PATTERN:
  8445. RTW_INFO("set case MP_WOW_SET_PATTERN: %s\n", extra);
  8446. rtw_wowlan_set_pattern(dev, info, wdata, extra);
  8447. break;
  8448. #endif
  8449. #ifdef CONFIG_AP_WOWLAN
  8450. case MP_AP_WOW_ENABLE:
  8451. RTW_INFO("set case MP_AP_WOW_ENABLE: %s\n", extra);
  8452. rtw_ap_wowlan_ctrl(dev, info, wdata, extra);
  8453. break;
  8454. #endif
  8455. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  8456. case VENDOR_IE_SET:
  8457. RTW_INFO("set case VENDOR_IE_SET\n");
  8458. rtw_vendor_ie_set(dev , info , wdata , extra);
  8459. break;
  8460. #endif
  8461. default:
  8462. return -EIO;
  8463. }
  8464. return 0;
  8465. }
  8466. static int rtw_priv_get(struct net_device *dev,
  8467. struct iw_request_info *info,
  8468. union iwreq_data *wdata, char *extra)
  8469. {
  8470. struct iw_point *wrqu = (struct iw_point *)wdata;
  8471. u32 subcmd = wrqu->flags;
  8472. PADAPTER padapter = rtw_netdev_priv(dev);
  8473. if (padapter == NULL)
  8474. return -ENETDOWN;
  8475. if (padapter->bup == _FALSE) {
  8476. RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
  8477. return -ENETDOWN;
  8478. }
  8479. if (RTW_CANNOT_RUN(padapter)) {
  8480. RTW_INFO("%s fail =>(padapter->bSurpriseRemoved == _TRUE) || ( padapter->bDriverStopped == _TRUE)\n", __func__);
  8481. return -ENETDOWN;
  8482. }
  8483. if (extra == NULL) {
  8484. wrqu->length = 0;
  8485. return -EIO;
  8486. }
  8487. if (subcmd < MP_NULL) {
  8488. #ifdef CONFIG_MP_INCLUDED
  8489. rtw_priv_mp_get(dev, info, wdata, extra);
  8490. #endif
  8491. return 0;
  8492. }
  8493. switch (subcmd) {
  8494. #if defined(CONFIG_RTL8723B)
  8495. case MP_SetBT:
  8496. RTW_INFO("set MP_SetBT\n");
  8497. rtw_mp_SetBT(dev, info, wdata, extra);
  8498. break;
  8499. #endif
  8500. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  8501. case MP_SD_IREAD:
  8502. rtw_mp_sd_iread(dev, info, wrqu, extra);
  8503. break;
  8504. case MP_SD_IWRITE:
  8505. rtw_mp_sd_iwrite(dev, info, wrqu, extra);
  8506. break;
  8507. #endif
  8508. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  8509. case VENDOR_IE_GET:
  8510. RTW_INFO("get case VENDOR_IE_GET\n");
  8511. rtw_vendor_ie_get(dev , info , wdata , extra);
  8512. break;
  8513. #endif
  8514. default:
  8515. return -EIO;
  8516. }
  8517. rtw_msleep_os(10); /* delay 5ms for sending pkt before exit adb shell operation */
  8518. return 0;
  8519. }
  8520. static int rtw_wx_tdls_wfd_enable(struct net_device *dev,
  8521. struct iw_request_info *info,
  8522. union iwreq_data *wrqu, char *extra)
  8523. {
  8524. int ret = 0;
  8525. #ifdef CONFIG_TDLS
  8526. #ifdef CONFIG_WFD
  8527. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8528. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8529. if (extra[0] == '0')
  8530. rtw_tdls_wfd_enable(padapter, 0);
  8531. else
  8532. rtw_tdls_wfd_enable(padapter, 1);
  8533. #endif /* CONFIG_WFD */
  8534. #endif /* CONFIG_TDLS */
  8535. return ret;
  8536. }
  8537. static int rtw_tdls_weaksec(struct net_device *dev,
  8538. struct iw_request_info *info,
  8539. union iwreq_data *wrqu, char *extra)
  8540. {
  8541. int ret = 0;
  8542. #ifdef CONFIG_TDLS
  8543. u8 i, j;
  8544. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8545. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8546. if (extra[0] == '0')
  8547. padapter->wdinfo.wfd_tdls_weaksec = 0;
  8548. else
  8549. padapter->wdinfo.wfd_tdls_weaksec = 1;
  8550. #endif /* CONFIG_TDLS */
  8551. return ret;
  8552. }
  8553. static int rtw_tdls_enable(struct net_device *dev,
  8554. struct iw_request_info *info,
  8555. union iwreq_data *wrqu, char *extra)
  8556. {
  8557. int ret = 0;
  8558. #ifdef CONFIG_TDLS
  8559. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8560. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8561. if (extra[0] == '0')
  8562. rtw_disable_tdls_func(padapter, _TRUE);
  8563. else if (extra[0] == '1')
  8564. rtw_enable_tdls_func(padapter);
  8565. #endif /* CONFIG_TDLS */
  8566. return ret;
  8567. }
  8568. static int rtw_tdls_setup(struct net_device *dev,
  8569. struct iw_request_info *info,
  8570. union iwreq_data *wrqu, char *extra)
  8571. {
  8572. int ret = 0;
  8573. #ifdef CONFIG_TDLS
  8574. u8 i, j;
  8575. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8576. struct tdls_txmgmt txmgmt;
  8577. #ifdef CONFIG_WFD
  8578. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  8579. #endif /* CONFIG_WFD */
  8580. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8581. if (wrqu->data.length - 1 != 17) {
  8582. RTW_INFO("[%s] length:%d != 17\n", __FUNCTION__, (wrqu->data.length - 1));
  8583. return ret;
  8584. }
  8585. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8586. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8587. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8588. #ifdef CONFIG_WFD
  8589. if (_AES_ != padapter->securitypriv.dot11PrivacyAlgrthm) {
  8590. /* Weak Security situation with AP. */
  8591. if (0 == pwdinfo->wfd_tdls_weaksec) {
  8592. /* Can't send the tdls setup request out!! */
  8593. RTW_INFO("[%s] Current link is not AES, "
  8594. "SKIP sending the tdls setup request!!\n", __FUNCTION__);
  8595. } else
  8596. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  8597. } else
  8598. #endif /* CONFIG_WFD */
  8599. {
  8600. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  8601. }
  8602. #endif /* CONFIG_TDLS */
  8603. return ret;
  8604. }
  8605. static int rtw_tdls_teardown(struct net_device *dev,
  8606. struct iw_request_info *info,
  8607. union iwreq_data *wrqu, char *extra)
  8608. {
  8609. int ret = 0;
  8610. #ifdef CONFIG_TDLS
  8611. u8 i, j;
  8612. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8613. struct sta_info *ptdls_sta = NULL;
  8614. struct tdls_txmgmt txmgmt;
  8615. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8616. if (wrqu->data.length - 1 != 17 && wrqu->data.length - 1 != 19) {
  8617. RTW_INFO("[%s] length:%d != 17 or 19\n",
  8618. __FUNCTION__, (wrqu->data.length - 1));
  8619. return ret;
  8620. }
  8621. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8622. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8623. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8624. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), txmgmt.peer);
  8625. if (ptdls_sta != NULL) {
  8626. txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
  8627. if (wrqu->data.length - 1 == 19)
  8628. issue_tdls_teardown(padapter, &txmgmt, _FALSE);
  8629. else
  8630. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  8631. } else
  8632. RTW_INFO("TDLS peer not found\n");
  8633. #endif /* CONFIG_TDLS */
  8634. return ret;
  8635. }
  8636. static int rtw_tdls_discovery(struct net_device *dev,
  8637. struct iw_request_info *info,
  8638. union iwreq_data *wrqu, char *extra)
  8639. {
  8640. int ret = 0;
  8641. #ifdef CONFIG_TDLS
  8642. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8643. struct tdls_txmgmt txmgmt;
  8644. int i = 0, j = 0;
  8645. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8646. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8647. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8648. txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8649. issue_tdls_dis_req(padapter, &txmgmt);
  8650. #endif /* CONFIG_TDLS */
  8651. return ret;
  8652. }
  8653. static int rtw_tdls_ch_switch(struct net_device *dev,
  8654. struct iw_request_info *info,
  8655. union iwreq_data *wrqu, char *extra)
  8656. {
  8657. int ret = 0;
  8658. #ifdef CONFIG_TDLS
  8659. #ifdef CONFIG_TDLS_CH_SW
  8660. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8661. struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
  8662. u8 i, j;
  8663. struct sta_info *ptdls_sta = NULL;
  8664. u8 take_care_iqk;
  8665. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8666. if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
  8667. RTW_INFO("TDLS channel switch is not allowed\n");
  8668. return ret;
  8669. }
  8670. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8671. pchsw_info->addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8672. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, pchsw_info->addr);
  8673. if (ptdls_sta == NULL)
  8674. return ret;
  8675. pchsw_info->ch_sw_state |= TDLS_CH_SW_INITIATOR_STATE;
  8676. if (ptdls_sta != NULL) {
  8677. if (pchsw_info->off_ch_num == 0)
  8678. pchsw_info->off_ch_num = 11;
  8679. } else
  8680. RTW_INFO("TDLS peer not found\n");
  8681. rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
  8682. rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
  8683. if (take_care_iqk == _TRUE) {
  8684. u8 central_chnl;
  8685. u8 bw_mode;
  8686. bw_mode = (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20;
  8687. central_chnl = rtw_get_center_ch(pchsw_info->off_ch_num, bw_mode, pchsw_info->ch_offset);
  8688. if (rtw_hal_ch_sw_iqk_info_search(padapter, central_chnl, bw_mode) >= 0)
  8689. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
  8690. else
  8691. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_PREPARE);
  8692. } else
  8693. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
  8694. /* issue_tdls_ch_switch_req(padapter, ptdls_sta); */
  8695. /* RTW_INFO("issue tdls ch switch req\n"); */
  8696. #endif /* CONFIG_TDLS_CH_SW */
  8697. #endif /* CONFIG_TDLS */
  8698. return ret;
  8699. }
  8700. static int rtw_tdls_ch_switch_off(struct net_device *dev,
  8701. struct iw_request_info *info,
  8702. union iwreq_data *wrqu, char *extra)
  8703. {
  8704. int ret = 0;
  8705. #ifdef CONFIG_TDLS
  8706. #ifdef CONFIG_TDLS_CH_SW
  8707. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8708. struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
  8709. u8 i, j, mac_addr[ETH_ALEN];
  8710. struct sta_info *ptdls_sta = NULL;
  8711. struct tdls_txmgmt txmgmt;
  8712. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  8713. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8714. if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
  8715. RTW_INFO("TDLS channel switch is not allowed\n");
  8716. return ret;
  8717. }
  8718. if (wrqu->data.length >= 17) {
  8719. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8720. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8721. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8722. }
  8723. if (ptdls_sta == NULL)
  8724. return ret;
  8725. rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END_TO_BASE_CHNL);
  8726. pchsw_info->ch_sw_state &= ~(TDLS_CH_SW_INITIATOR_STATE |
  8727. TDLS_CH_SWITCH_ON_STATE |
  8728. TDLS_PEER_AT_OFF_STATE);
  8729. _rtw_memset(pchsw_info->addr, 0x00, ETH_ALEN);
  8730. ptdls_sta->ch_switch_time = 0;
  8731. ptdls_sta->ch_switch_timeout = 0;
  8732. _cancel_timer_ex(&ptdls_sta->ch_sw_timer);
  8733. _cancel_timer_ex(&ptdls_sta->delay_timer);
  8734. _cancel_timer_ex(&ptdls_sta->stay_on_base_chnl_timer);
  8735. _cancel_timer_ex(&ptdls_sta->ch_sw_monitor_timer);
  8736. rtw_pm_set_lps(padapter, PS_MODE_MAX);
  8737. #endif /* CONFIG_TDLS_CH_SW */
  8738. #endif /* CONFIG_TDLS */
  8739. return ret;
  8740. }
  8741. static int rtw_tdls_dump_ch(struct net_device *dev,
  8742. struct iw_request_info *info,
  8743. union iwreq_data *wrqu, char *extra)
  8744. {
  8745. int ret = 0;
  8746. #ifdef CONFIG_TDLS
  8747. #ifdef CONFIG_TDLS_CH_SW
  8748. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8749. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8750. RTW_INFO("[%s] dump_stack:%s\n", __FUNCTION__, extra);
  8751. extra[wrqu->data.length] = 0x00;
  8752. ptdlsinfo->chsw_info.dump_stack = rtw_atoi(extra);
  8753. return ret;
  8754. #endif
  8755. #endif /* CONFIG_TDLS */
  8756. return ret;
  8757. }
  8758. static int rtw_tdls_off_ch_num(struct net_device *dev,
  8759. struct iw_request_info *info,
  8760. union iwreq_data *wrqu, char *extra)
  8761. {
  8762. int ret = 0;
  8763. #ifdef CONFIG_TDLS
  8764. #ifdef CONFIG_TDLS_CH_SW
  8765. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8766. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8767. RTW_INFO("[%s] off_ch_num:%s\n", __FUNCTION__, extra);
  8768. extra[wrqu->data.length] = 0x00;
  8769. ptdlsinfo->chsw_info.off_ch_num = rtw_atoi(extra);
  8770. return ret;
  8771. #endif
  8772. #endif /* CONFIG_TDLS */
  8773. return ret;
  8774. }
  8775. static int rtw_tdls_ch_offset(struct net_device *dev,
  8776. struct iw_request_info *info,
  8777. union iwreq_data *wrqu, char *extra)
  8778. {
  8779. int ret = 0;
  8780. #ifdef CONFIG_TDLS
  8781. #ifdef CONFIG_TDLS_CH_SW
  8782. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8783. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8784. RTW_INFO("[%s] ch_offset:%s\n", __FUNCTION__, extra);
  8785. extra[wrqu->data.length] = 0x00;
  8786. switch (rtw_atoi(extra)) {
  8787. case SCA:
  8788. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  8789. break;
  8790. case SCB:
  8791. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  8792. break;
  8793. default:
  8794. ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  8795. break;
  8796. }
  8797. return ret;
  8798. #endif
  8799. #endif /* CONFIG_TDLS */
  8800. return ret;
  8801. }
  8802. static int rtw_tdls_pson(struct net_device *dev,
  8803. struct iw_request_info *info,
  8804. union iwreq_data *wrqu, char *extra)
  8805. {
  8806. int ret = 0;
  8807. #ifdef CONFIG_TDLS
  8808. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8809. u8 i, j, mac_addr[ETH_ALEN];
  8810. struct sta_info *ptdls_sta = NULL;
  8811. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8812. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8813. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8814. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8815. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 1, 3, 500);
  8816. #endif /* CONFIG_TDLS */
  8817. return ret;
  8818. }
  8819. static int rtw_tdls_psoff(struct net_device *dev,
  8820. struct iw_request_info *info,
  8821. union iwreq_data *wrqu, char *extra)
  8822. {
  8823. int ret = 0;
  8824. #ifdef CONFIG_TDLS
  8825. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8826. u8 i, j, mac_addr[ETH_ALEN];
  8827. struct sta_info *ptdls_sta = NULL;
  8828. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8829. for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
  8830. mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
  8831. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  8832. if (ptdls_sta)
  8833. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 0, 3, 500);
  8834. #endif /* CONFIG_TDLS */
  8835. return ret;
  8836. }
  8837. static int rtw_tdls_setip(struct net_device *dev,
  8838. struct iw_request_info *info,
  8839. union iwreq_data *wrqu, char *extra)
  8840. {
  8841. int ret = 0;
  8842. #ifdef CONFIG_TDLS
  8843. #ifdef CONFIG_WFD
  8844. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8845. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8846. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8847. u8 i = 0, j = 0, k = 0, tag = 0;
  8848. RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
  8849. while (i < 4) {
  8850. for (j = 0; j < 4; j++) {
  8851. if (*(extra + j + tag) == '.' || *(extra + j + tag) == '\0') {
  8852. if (j == 1)
  8853. pwfd_info->ip_address[i] = convert_ip_addr('0', '0', *(extra + (j - 1) + tag));
  8854. if (j == 2)
  8855. pwfd_info->ip_address[i] = convert_ip_addr('0', *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
  8856. if (j == 3)
  8857. pwfd_info->ip_address[i] = convert_ip_addr(*(extra + (j - 3) + tag), *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
  8858. tag += j + 1;
  8859. break;
  8860. }
  8861. }
  8862. i++;
  8863. }
  8864. RTW_INFO("[%s] Set IP = %u.%u.%u.%u\n", __FUNCTION__,
  8865. ptdlsinfo->wfd_info->ip_address[0],
  8866. ptdlsinfo->wfd_info->ip_address[1],
  8867. ptdlsinfo->wfd_info->ip_address[2],
  8868. ptdlsinfo->wfd_info->ip_address[3]);
  8869. #endif /* CONFIG_WFD */
  8870. #endif /* CONFIG_TDLS */
  8871. return ret;
  8872. }
  8873. static int rtw_tdls_getip(struct net_device *dev,
  8874. struct iw_request_info *info,
  8875. union iwreq_data *wrqu, char *extra)
  8876. {
  8877. int ret = 0;
  8878. #ifdef CONFIG_TDLS
  8879. #ifdef CONFIG_WFD
  8880. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8881. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8882. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8883. RTW_INFO("[%s]\n", __FUNCTION__);
  8884. sprintf(extra, "\n\n%u.%u.%u.%u\n",
  8885. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  8886. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
  8887. RTW_INFO("[%s] IP=%u.%u.%u.%u\n", __FUNCTION__,
  8888. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  8889. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
  8890. wrqu->data.length = strlen(extra);
  8891. #endif /* CONFIG_WFD */
  8892. #endif /* CONFIG_TDLS */
  8893. return ret;
  8894. }
  8895. static int rtw_tdls_getport(struct net_device *dev,
  8896. struct iw_request_info *info,
  8897. union iwreq_data *wrqu, char *extra)
  8898. {
  8899. int ret = 0;
  8900. #ifdef CONFIG_TDLS
  8901. #ifdef CONFIG_WFD
  8902. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8903. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8904. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  8905. RTW_INFO("[%s]\n", __FUNCTION__);
  8906. sprintf(extra, "\n\n%d\n", pwfd_info->peer_rtsp_ctrlport);
  8907. RTW_INFO("[%s] remote port = %d\n",
  8908. __FUNCTION__, pwfd_info->peer_rtsp_ctrlport);
  8909. wrqu->data.length = strlen(extra);
  8910. #endif /* CONFIG_WFD */
  8911. #endif /* CONFIG_TDLS */
  8912. return ret;
  8913. }
  8914. /* WFDTDLS, for sigma test */
  8915. static int rtw_tdls_dis_result(struct net_device *dev,
  8916. struct iw_request_info *info,
  8917. union iwreq_data *wrqu, char *extra)
  8918. {
  8919. int ret = 0;
  8920. #ifdef CONFIG_TDLS
  8921. #ifdef CONFIG_WFD
  8922. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8923. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8924. RTW_INFO("[%s]\n", __FUNCTION__);
  8925. if (ptdlsinfo->dev_discovered == _TRUE) {
  8926. sprintf(extra, "\n\nDis=1\n");
  8927. ptdlsinfo->dev_discovered = _FALSE;
  8928. }
  8929. wrqu->data.length = strlen(extra);
  8930. #endif /* CONFIG_WFD */
  8931. #endif /* CONFIG_TDLS */
  8932. return ret;
  8933. }
  8934. /* WFDTDLS, for sigma test */
  8935. static int rtw_wfd_tdls_status(struct net_device *dev,
  8936. struct iw_request_info *info,
  8937. union iwreq_data *wrqu, char *extra)
  8938. {
  8939. int ret = 0;
  8940. #ifdef CONFIG_TDLS
  8941. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8942. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  8943. RTW_INFO("[%s]\n", __FUNCTION__);
  8944. sprintf(extra, "\nlink_established:%d\n"
  8945. "sta_cnt:%d\n"
  8946. "sta_maximum:%d\n"
  8947. "cur_channel:%d\n"
  8948. "tdls_enable:%d"
  8949. #ifdef CONFIG_TDLS_CH_SW
  8950. "ch_sw_state:%08x\n"
  8951. "chsw_on:%d\n"
  8952. "off_ch_num:%d\n"
  8953. "cur_time:%d\n"
  8954. "ch_offset:%d\n"
  8955. "delay_swtich_back:%d"
  8956. #endif
  8957. ,
  8958. ptdlsinfo->link_established, ptdlsinfo->sta_cnt,
  8959. ptdlsinfo->sta_maximum, ptdlsinfo->cur_channel,
  8960. rtw_is_tdls_enabled(padapter)
  8961. #ifdef CONFIG_TDLS_CH_SW
  8962. ,
  8963. ptdlsinfo->chsw_info.ch_sw_state,
  8964. ATOMIC_READ(&padapter->tdlsinfo.chsw_info.chsw_on),
  8965. ptdlsinfo->chsw_info.off_ch_num,
  8966. ptdlsinfo->chsw_info.cur_time,
  8967. ptdlsinfo->chsw_info.ch_offset,
  8968. ptdlsinfo->chsw_info.delay_switch_back
  8969. #endif
  8970. );
  8971. wrqu->data.length = strlen(extra);
  8972. #endif /* CONFIG_TDLS */
  8973. return ret;
  8974. }
  8975. static int rtw_tdls_getsta(struct net_device *dev,
  8976. struct iw_request_info *info,
  8977. union iwreq_data *wrqu, char *extra)
  8978. {
  8979. int ret = 0;
  8980. #ifdef CONFIG_TDLS
  8981. u8 i, j;
  8982. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  8983. u8 addr[ETH_ALEN] = {0};
  8984. char charmac[17];
  8985. struct sta_info *ptdls_sta = NULL;
  8986. RTW_INFO("[%s] %s %d\n", __FUNCTION__,
  8987. (char *)wrqu->data.pointer, wrqu->data.length - 1);
  8988. if (copy_from_user(charmac, wrqu->data.pointer + 9, 17)) {
  8989. ret = -EFAULT;
  8990. goto exit;
  8991. }
  8992. RTW_INFO("[%s] %d, charmac:%s\n", __FUNCTION__, __LINE__, charmac);
  8993. for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
  8994. addr[i] = key_2char2num(*(charmac + j), *(charmac + j + 1));
  8995. RTW_INFO("[%s] %d, charmac:%s, addr:"MAC_FMT"\n",
  8996. __FUNCTION__, __LINE__, charmac, MAC_ARG(addr));
  8997. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, addr);
  8998. if (ptdls_sta) {
  8999. sprintf(extra, "\n\ntdls_sta_state=0x%08x\n", ptdls_sta->tdls_sta_state);
  9000. RTW_INFO("\n\ntdls_sta_state=%d\n", ptdls_sta->tdls_sta_state);
  9001. } else {
  9002. sprintf(extra, "\n\nNot found this sta\n");
  9003. RTW_INFO("\n\nNot found this sta\n");
  9004. }
  9005. wrqu->data.length = strlen(extra);
  9006. #endif /* CONFIG_TDLS */
  9007. exit:
  9008. return ret;
  9009. }
  9010. static int rtw_tdls_get_best_ch(struct net_device *dev,
  9011. struct iw_request_info *info,
  9012. union iwreq_data *wrqu, char *extra)
  9013. {
  9014. #ifdef CONFIG_FIND_BEST_CHANNEL
  9015. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9016. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  9017. u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0;
  9018. for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
  9019. if (rfctl->channel_set[i].ChannelNum == 1)
  9020. index_24G = i;
  9021. if (rfctl->channel_set[i].ChannelNum == 36)
  9022. index_5G = i;
  9023. }
  9024. for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
  9025. /* 2.4G */
  9026. if (rfctl->channel_set[i].ChannelNum == 6 || rfctl->channel_set[i].ChannelNum == 11) {
  9027. if (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_24G].rx_count) {
  9028. index_24G = i;
  9029. best_channel_24G = rfctl->channel_set[i].ChannelNum;
  9030. }
  9031. }
  9032. /* 5G */
  9033. if (rfctl->channel_set[i].ChannelNum >= 36
  9034. && rfctl->channel_set[i].ChannelNum < 140) {
  9035. /* Find primary channel */
  9036. if (((rfctl->channel_set[i].ChannelNum - 36) % 8 == 0)
  9037. && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
  9038. index_5G = i;
  9039. best_channel_5G = rfctl->channel_set[i].ChannelNum;
  9040. }
  9041. }
  9042. if (rfctl->channel_set[i].ChannelNum >= 149
  9043. && rfctl->channel_set[i].ChannelNum < 165) {
  9044. /* Find primary channel */
  9045. if (((rfctl->channel_set[i].ChannelNum - 149) % 8 == 0)
  9046. && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
  9047. index_5G = i;
  9048. best_channel_5G = rfctl->channel_set[i].ChannelNum;
  9049. }
  9050. }
  9051. #if 1 /* debug */
  9052. RTW_INFO("The rx cnt of channel %3d = %d\n",
  9053. rfctl->channel_set[i].ChannelNum,
  9054. rfctl->channel_set[i].rx_count);
  9055. #endif
  9056. }
  9057. sprintf(extra, "\nbest_channel_24G = %d\n", best_channel_24G);
  9058. RTW_INFO("best_channel_24G = %d\n", best_channel_24G);
  9059. if (index_5G != 0) {
  9060. sprintf(extra, "best_channel_5G = %d\n", best_channel_5G);
  9061. RTW_INFO("best_channel_5G = %d\n", best_channel_5G);
  9062. }
  9063. wrqu->data.length = strlen(extra);
  9064. #endif
  9065. return 0;
  9066. }
  9067. static int rtw_tdls(struct net_device *dev,
  9068. struct iw_request_info *info,
  9069. union iwreq_data *wrqu, char *extra)
  9070. {
  9071. int ret = 0;
  9072. #ifdef CONFIG_TDLS
  9073. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9074. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
  9075. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  9076. RTW_INFO("Discard tdls oper since hal doesn't support tdls\n");
  9077. return 0;
  9078. }
  9079. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  9080. RTW_INFO("TDLS is not enabled\n");
  9081. return 0;
  9082. }
  9083. /* WFD Sigma will use the tdls enable command to let the driver know we want to test the tdls now! */
  9084. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  9085. if (_rtw_memcmp(extra, "wfdenable=", 10)) {
  9086. wrqu->data.length -= 10;
  9087. rtw_wx_tdls_wfd_enable(dev, info, wrqu, &extra[10]);
  9088. return ret;
  9089. }
  9090. }
  9091. if (_rtw_memcmp(extra, "weaksec=", 8)) {
  9092. wrqu->data.length -= 8;
  9093. rtw_tdls_weaksec(dev, info, wrqu, &extra[8]);
  9094. return ret;
  9095. } else if (_rtw_memcmp(extra, "tdlsenable=", 11)) {
  9096. wrqu->data.length -= 11;
  9097. rtw_tdls_enable(dev, info, wrqu, &extra[11]);
  9098. return ret;
  9099. }
  9100. if (_rtw_memcmp(extra, "setup=", 6)) {
  9101. wrqu->data.length -= 6;
  9102. rtw_tdls_setup(dev, info, wrqu, &extra[6]);
  9103. } else if (_rtw_memcmp(extra, "tear=", 5)) {
  9104. wrqu->data.length -= 5;
  9105. rtw_tdls_teardown(dev, info, wrqu, &extra[5]);
  9106. } else if (_rtw_memcmp(extra, "dis=", 4)) {
  9107. wrqu->data.length -= 4;
  9108. rtw_tdls_discovery(dev, info, wrqu, &extra[4]);
  9109. } else if (_rtw_memcmp(extra, "swoff=", 6)) {
  9110. wrqu->data.length -= 6;
  9111. rtw_tdls_ch_switch_off(dev, info, wrqu, &extra[6]);
  9112. } else if (_rtw_memcmp(extra, "sw=", 3)) {
  9113. wrqu->data.length -= 3;
  9114. rtw_tdls_ch_switch(dev, info, wrqu, &extra[3]);
  9115. } else if (_rtw_memcmp(extra, "dumpstack=", 10)) {
  9116. wrqu->data.length -= 10;
  9117. rtw_tdls_dump_ch(dev, info, wrqu, &extra[10]);
  9118. } else if (_rtw_memcmp(extra, "offchnum=", 9)) {
  9119. wrqu->data.length -= 9;
  9120. rtw_tdls_off_ch_num(dev, info, wrqu, &extra[9]);
  9121. } else if (_rtw_memcmp(extra, "choffset=", 9)) {
  9122. wrqu->data.length -= 9;
  9123. rtw_tdls_ch_offset(dev, info, wrqu, &extra[9]);
  9124. } else if (_rtw_memcmp(extra, "pson=", 5)) {
  9125. wrqu->data.length -= 5;
  9126. rtw_tdls_pson(dev, info, wrqu, &extra[5]);
  9127. } else if (_rtw_memcmp(extra, "psoff=", 6)) {
  9128. wrqu->data.length -= 6;
  9129. rtw_tdls_psoff(dev, info, wrqu, &extra[6]);
  9130. }
  9131. #ifdef CONFIG_WFD
  9132. if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  9133. if (_rtw_memcmp(extra, "setip=", 6)) {
  9134. wrqu->data.length -= 6;
  9135. rtw_tdls_setip(dev, info, wrqu, &extra[6]);
  9136. } else if (_rtw_memcmp(extra, "tprobe=", 6))
  9137. issue_tunneled_probe_req((_adapter *)rtw_netdev_priv(dev));
  9138. }
  9139. #endif /* CONFIG_WFD */
  9140. #endif /* CONFIG_TDLS */
  9141. return ret;
  9142. }
  9143. static int rtw_tdls_get(struct net_device *dev,
  9144. struct iw_request_info *info,
  9145. union iwreq_data *wrqu, char *extra)
  9146. {
  9147. int ret = 0;
  9148. #ifdef CONFIG_TDLS
  9149. RTW_INFO("[%s] extra = %s\n", __FUNCTION__, (char *) wrqu->data.pointer);
  9150. if (_rtw_memcmp(wrqu->data.pointer, "ip", 2))
  9151. rtw_tdls_getip(dev, info, wrqu, extra);
  9152. else if (_rtw_memcmp(wrqu->data.pointer, "port", 4))
  9153. rtw_tdls_getport(dev, info, wrqu, extra);
  9154. /* WFDTDLS, for sigma test */
  9155. else if (_rtw_memcmp(wrqu->data.pointer, "dis", 3))
  9156. rtw_tdls_dis_result(dev, info, wrqu, extra);
  9157. else if (_rtw_memcmp(wrqu->data.pointer, "status", 6))
  9158. rtw_wfd_tdls_status(dev, info, wrqu, extra);
  9159. else if (_rtw_memcmp(wrqu->data.pointer, "tdls_sta=", 9))
  9160. rtw_tdls_getsta(dev, info, wrqu, extra);
  9161. else if (_rtw_memcmp(wrqu->data.pointer, "best_ch", 7))
  9162. rtw_tdls_get_best_ch(dev, info, wrqu, extra);
  9163. #endif /* CONFIG_TDLS */
  9164. return ret;
  9165. }
  9166. #ifdef CONFIG_INTEL_WIDI
  9167. static int rtw_widi_set(struct net_device *dev,
  9168. struct iw_request_info *info,
  9169. union iwreq_data *wrqu, char *extra)
  9170. {
  9171. int ret = 0;
  9172. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9173. process_intel_widi_cmd(padapter, extra);
  9174. return ret;
  9175. }
  9176. static int rtw_widi_set_probe_request(struct net_device *dev,
  9177. struct iw_request_info *info,
  9178. union iwreq_data *wrqu, char *extra)
  9179. {
  9180. int ret = 0;
  9181. u8 *pbuf = NULL;
  9182. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9183. pbuf = rtw_malloc(sizeof(l2_msg_t));
  9184. if (pbuf) {
  9185. if (copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length))
  9186. ret = -EFAULT;
  9187. /* _rtw_memcpy(pbuf, wrqu->data.pointer, wrqu->data.length); */
  9188. if (wrqu->data.flags == 0)
  9189. intel_widi_wk_cmd(padapter, INTEL_WIDI_ISSUE_PROB_WK, pbuf, sizeof(l2_msg_t));
  9190. else if (wrqu->data.flags == 1)
  9191. rtw_set_wfd_rds_sink_info(padapter, (l2_msg_t *)pbuf);
  9192. }
  9193. return ret;
  9194. }
  9195. #endif /* CONFIG_INTEL_WIDI */
  9196. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  9197. #if defined(CONFIG_RTL8188E)
  9198. #include <rtl8188e_hal.h>
  9199. extern void rtl8188e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9200. #define cal_txdesc_chksum rtl8188e_cal_txdesc_chksum
  9201. #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
  9202. extern void rtl8188es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9203. #define fill_default_txdesc rtl8188es_fill_default_txdesc
  9204. #endif /* CONFIG_SDIO_HCI */
  9205. #endif /* CONFIG_RTL8188E */
  9206. #if defined(CONFIG_RTL8723B)
  9207. extern void rtl8723b_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9208. #define cal_txdesc_chksum rtl8723b_cal_txdesc_chksum
  9209. extern void rtl8723b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9210. #define fill_default_txdesc rtl8723b_fill_default_txdesc
  9211. #endif /* CONFIG_RTL8723B */
  9212. #if defined(CONFIG_RTL8703B)
  9213. /* extern void rtl8703b_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9214. #define cal_txdesc_chksum rtl8703b_cal_txdesc_chksum
  9215. /* extern void rtl8703b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9216. #define fill_default_txdesc rtl8703b_fill_default_txdesc
  9217. #endif /* CONFIG_RTL8703B */
  9218. #if defined(CONFIG_RTL8723D)
  9219. /* extern void rtl8723d_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9220. #define cal_txdesc_chksum rtl8723d_cal_txdesc_chksum
  9221. /* extern void rtl8723d_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9222. #define fill_default_txdesc rtl8723d_fill_default_txdesc
  9223. #endif /* CONFIG_RTL8723D */
  9224. #if defined(CONFIG_RTL8710B)
  9225. #define cal_txdesc_chksum rtl8710b_cal_txdesc_chksum
  9226. #define fill_default_txdesc rtl8710b_fill_default_txdesc
  9227. #endif /* CONFIG_RTL8710B */
  9228. #if defined(CONFIG_RTL8192E)
  9229. extern void rtl8192e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9230. #define cal_txdesc_chksum rtl8192e_cal_txdesc_chksum
  9231. #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
  9232. extern void rtl8192es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9233. #define fill_default_txdesc rtl8192es_fill_default_txdesc
  9234. #endif /* CONFIG_SDIO_HCI */
  9235. #endif /* CONFIG_RTL8192E */
  9236. #if defined(CONFIG_RTL8192F)
  9237. /* extern void rtl8192f_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
  9238. #define cal_txdesc_chksum rtl8192f_cal_txdesc_chksum
  9239. /* extern void rtl8192f_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
  9240. #define fill_default_txdesc rtl8192f_fill_default_txdesc
  9241. #endif /* CONFIG_RTL8192F */
  9242. static s32 initLoopback(PADAPTER padapter)
  9243. {
  9244. PLOOPBACKDATA ploopback;
  9245. if (padapter->ploopback == NULL) {
  9246. ploopback = (PLOOPBACKDATA)rtw_zmalloc(sizeof(LOOPBACKDATA));
  9247. if (ploopback == NULL)
  9248. return -ENOMEM;
  9249. _rtw_init_sema(&ploopback->sema, 0);
  9250. ploopback->bstop = _TRUE;
  9251. ploopback->cnt = 0;
  9252. ploopback->size = 300;
  9253. _rtw_memset(ploopback->msg, 0, sizeof(ploopback->msg));
  9254. padapter->ploopback = ploopback;
  9255. }
  9256. return 0;
  9257. }
  9258. static void freeLoopback(PADAPTER padapter)
  9259. {
  9260. PLOOPBACKDATA ploopback;
  9261. ploopback = padapter->ploopback;
  9262. if (ploopback) {
  9263. rtw_mfree((u8 *)ploopback, sizeof(LOOPBACKDATA));
  9264. padapter->ploopback = NULL;
  9265. }
  9266. }
  9267. static s32 initpseudoadhoc(PADAPTER padapter)
  9268. {
  9269. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  9270. s32 err;
  9271. networkType = Ndis802_11IBSS;
  9272. err = rtw_set_802_11_infrastructure_mode(padapter, networkType);
  9273. if (err == _FALSE)
  9274. return _FAIL;
  9275. err = rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
  9276. if (err == _FAIL)
  9277. return _FAIL;
  9278. return _SUCCESS;
  9279. }
  9280. static s32 createpseudoadhoc(PADAPTER padapter)
  9281. {
  9282. NDIS_802_11_AUTHENTICATION_MODE authmode;
  9283. struct mlme_priv *pmlmepriv;
  9284. NDIS_802_11_SSID *passoc_ssid;
  9285. WLAN_BSSID_EX *pdev_network;
  9286. u8 *pibss;
  9287. u8 ssid[] = "pseduo_ad-hoc";
  9288. s32 err;
  9289. _irqL irqL;
  9290. pmlmepriv = &padapter->mlmepriv;
  9291. authmode = Ndis802_11AuthModeOpen;
  9292. err = rtw_set_802_11_authentication_mode(padapter, authmode);
  9293. if (err == _FALSE)
  9294. return _FAIL;
  9295. passoc_ssid = &pmlmepriv->assoc_ssid;
  9296. _rtw_memset(passoc_ssid, 0, sizeof(NDIS_802_11_SSID));
  9297. passoc_ssid->SsidLength = sizeof(ssid) - 1;
  9298. _rtw_memcpy(passoc_ssid->Ssid, ssid, passoc_ssid->SsidLength);
  9299. pdev_network = &padapter->registrypriv.dev_network;
  9300. pibss = padapter->registrypriv.dev_network.MacAddress;
  9301. _rtw_memcpy(&pdev_network->Ssid, passoc_ssid, sizeof(NDIS_802_11_SSID));
  9302. rtw_update_registrypriv_dev_network(padapter);
  9303. rtw_generate_random_ibss(pibss);
  9304. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  9305. /*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
  9306. init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
  9307. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  9308. #if 0
  9309. err = rtw_create_ibss_cmd(padapter, 0);
  9310. if (err == _FAIL)
  9311. return _FAIL;
  9312. #else
  9313. {
  9314. struct wlan_network *pcur_network;
  9315. struct sta_info *psta;
  9316. /* 3 create a new psta */
  9317. pcur_network = &pmlmepriv->cur_network;
  9318. /* clear psta in the cur_network, if any */
  9319. psta = rtw_get_stainfo(&padapter->stapriv, pcur_network->network.MacAddress);
  9320. if (psta)
  9321. rtw_free_stainfo(padapter, psta);
  9322. psta = rtw_alloc_stainfo(&padapter->stapriv, pibss);
  9323. if (psta == NULL)
  9324. return _FAIL;
  9325. /* 3 join psudo AdHoc */
  9326. pcur_network->join_res = 1;
  9327. pcur_network->aid = psta->cmn.aid = 1;
  9328. _rtw_memcpy(&pcur_network->network, pdev_network, get_WLAN_BSSID_EX_sz(pdev_network));
  9329. /* set msr to WIFI_FW_ADHOC_STATE */
  9330. padapter->hw_port = HW_PORT0;
  9331. Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
  9332. }
  9333. #endif
  9334. return _SUCCESS;
  9335. }
  9336. static struct xmit_frame *createloopbackpkt(PADAPTER padapter, u32 size)
  9337. {
  9338. struct xmit_priv *pxmitpriv;
  9339. struct xmit_frame *pframe;
  9340. struct xmit_buf *pxmitbuf;
  9341. struct pkt_attrib *pattrib;
  9342. struct tx_desc *desc;
  9343. u8 *pkt_start, *pkt_end, *ptr;
  9344. struct rtw_ieee80211_hdr *hdr;
  9345. s32 bmcast;
  9346. _irqL irqL;
  9347. if ((TXDESC_SIZE + WLANHDR_OFFSET + size) > MAX_XMITBUF_SZ)
  9348. return NULL;
  9349. pxmitpriv = &padapter->xmitpriv;
  9350. pframe = NULL;
  9351. /* 2 1. allocate xmit frame */
  9352. pframe = rtw_alloc_xmitframe(pxmitpriv);
  9353. if (pframe == NULL)
  9354. return NULL;
  9355. pframe->padapter = padapter;
  9356. /* 2 2. allocate xmit buffer */
  9357. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  9358. pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
  9359. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  9360. if (pxmitbuf == NULL) {
  9361. rtw_free_xmitframe(pxmitpriv, pframe);
  9362. return NULL;
  9363. }
  9364. pframe->pxmitbuf = pxmitbuf;
  9365. pframe->buf_addr = pxmitbuf->pbuf;
  9366. pxmitbuf->priv_data = pframe;
  9367. /* 2 3. update_attrib() */
  9368. pattrib = &pframe->attrib;
  9369. /* init xmitframe attribute */
  9370. _rtw_memset(pattrib, 0, sizeof(struct pkt_attrib));
  9371. pattrib->ether_type = 0x8723;
  9372. _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
  9373. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  9374. _rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
  9375. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  9376. /* pattrib->dhcp_pkt = 0;
  9377. * pattrib->pktlen = 0; */
  9378. pattrib->ack_policy = 0;
  9379. /* pattrib->pkt_hdrlen = ETH_HLEN; */
  9380. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  9381. pattrib->subtype = WIFI_DATA;
  9382. pattrib->priority = 0;
  9383. pattrib->qsel = pattrib->priority;
  9384. /* do_queue_select(padapter, pattrib); */
  9385. pattrib->nr_frags = 1;
  9386. pattrib->encrypt = 0;
  9387. pattrib->bswenc = _FALSE;
  9388. pattrib->qos_en = _FALSE;
  9389. bmcast = IS_MCAST(pattrib->ra);
  9390. if (bmcast)
  9391. pattrib->psta = rtw_get_bcmc_stainfo(padapter);
  9392. else
  9393. pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
  9394. pattrib->mac_id = pattrib->psta->cmn.mac_id;
  9395. pattrib->pktlen = size;
  9396. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
  9397. /* 2 4. fill TX descriptor */
  9398. desc = (struct tx_desc *)pframe->buf_addr;
  9399. _rtw_memset(desc, 0, TXDESC_SIZE);
  9400. fill_default_txdesc(pframe, (u8 *)desc);
  9401. /* Hw set sequence number */
  9402. ((PTXDESC)desc)->hwseq_en = 0; /* HWSEQ_EN, 0:disable, 1:enable
  9403. * ((PTXDESC)desc)->hwseq_sel = 0; */ /* HWSEQ_SEL */
  9404. ((PTXDESC)desc)->disdatafb = 1;
  9405. /* convert to little endian */
  9406. desc->txdw0 = cpu_to_le32(desc->txdw0);
  9407. desc->txdw1 = cpu_to_le32(desc->txdw1);
  9408. desc->txdw2 = cpu_to_le32(desc->txdw2);
  9409. desc->txdw3 = cpu_to_le32(desc->txdw3);
  9410. desc->txdw4 = cpu_to_le32(desc->txdw4);
  9411. desc->txdw5 = cpu_to_le32(desc->txdw5);
  9412. desc->txdw6 = cpu_to_le32(desc->txdw6);
  9413. desc->txdw7 = cpu_to_le32(desc->txdw7);
  9414. #ifdef CONFIG_PCI_HCI
  9415. desc->txdw8 = cpu_to_le32(desc->txdw8);
  9416. desc->txdw9 = cpu_to_le32(desc->txdw9);
  9417. desc->txdw10 = cpu_to_le32(desc->txdw10);
  9418. desc->txdw11 = cpu_to_le32(desc->txdw11);
  9419. desc->txdw12 = cpu_to_le32(desc->txdw12);
  9420. desc->txdw13 = cpu_to_le32(desc->txdw13);
  9421. desc->txdw14 = cpu_to_le32(desc->txdw14);
  9422. desc->txdw15 = cpu_to_le32(desc->txdw15);
  9423. #endif
  9424. cal_txdesc_chksum(desc);
  9425. /* 2 5. coalesce */
  9426. pkt_start = pframe->buf_addr + TXDESC_SIZE;
  9427. pkt_end = pkt_start + pattrib->last_txcmdsz;
  9428. /* 3 5.1. make wlan header, make_wlanhdr() */
  9429. hdr = (struct rtw_ieee80211_hdr *)pkt_start;
  9430. set_frame_sub_type(&hdr->frame_ctl, pattrib->subtype);
  9431. _rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); /* DA */
  9432. _rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); /* SA */
  9433. _rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); /* RA, BSSID */
  9434. /* 3 5.2. make payload */
  9435. ptr = pkt_start + pattrib->hdrlen;
  9436. get_random_bytes(ptr, pkt_end - ptr);
  9437. pxmitbuf->len = TXDESC_SIZE + pattrib->last_txcmdsz;
  9438. pxmitbuf->ptail += pxmitbuf->len;
  9439. return pframe;
  9440. }
  9441. static void freeloopbackpkt(PADAPTER padapter, struct xmit_frame *pframe)
  9442. {
  9443. struct xmit_priv *pxmitpriv;
  9444. struct xmit_buf *pxmitbuf;
  9445. pxmitpriv = &padapter->xmitpriv;
  9446. pxmitbuf = pframe->pxmitbuf;
  9447. rtw_free_xmitframe(pxmitpriv, pframe);
  9448. rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
  9449. }
  9450. static void printdata(u8 *pbuf, u32 len)
  9451. {
  9452. u32 i, val;
  9453. for (i = 0; (i + 4) <= len; i += 4) {
  9454. printk("%08X", *(u32 *)(pbuf + i));
  9455. if ((i + 4) & 0x1F)
  9456. printk(" ");
  9457. else
  9458. printk("\n");
  9459. }
  9460. if (i < len) {
  9461. #ifdef CONFIG_BIG_ENDIAN
  9462. for (; i < len, i++)
  9463. printk("%02X", pbuf + i);
  9464. #else /* CONFIG_LITTLE_ENDIAN */
  9465. #if 0
  9466. val = 0;
  9467. _rtw_memcpy(&val, pbuf + i, len - i);
  9468. printk("%8X", val);
  9469. #else
  9470. u8 str[9];
  9471. u8 n;
  9472. val = 0;
  9473. n = len - i;
  9474. _rtw_memcpy(&val, pbuf + i, n);
  9475. sprintf(str, "%08X", val);
  9476. n = (4 - n) * 2;
  9477. printk("%8s", str + n);
  9478. #endif
  9479. #endif /* CONFIG_LITTLE_ENDIAN */
  9480. }
  9481. printk("\n");
  9482. }
  9483. static u8 pktcmp(PADAPTER padapter, u8 *txbuf, u32 txsz, u8 *rxbuf, u32 rxsz)
  9484. {
  9485. PHAL_DATA_TYPE phal;
  9486. struct recv_stat *prxstat;
  9487. struct recv_stat report;
  9488. PRXREPORT prxreport;
  9489. u32 drvinfosize;
  9490. u32 rxpktsize;
  9491. u8 fcssize;
  9492. u8 ret = _FALSE;
  9493. prxstat = (struct recv_stat *)rxbuf;
  9494. report.rxdw0 = le32_to_cpu(prxstat->rxdw0);
  9495. report.rxdw1 = le32_to_cpu(prxstat->rxdw1);
  9496. report.rxdw2 = le32_to_cpu(prxstat->rxdw2);
  9497. report.rxdw3 = le32_to_cpu(prxstat->rxdw3);
  9498. report.rxdw4 = le32_to_cpu(prxstat->rxdw4);
  9499. report.rxdw5 = le32_to_cpu(prxstat->rxdw5);
  9500. prxreport = (PRXREPORT)&report;
  9501. drvinfosize = prxreport->drvinfosize << 3;
  9502. rxpktsize = prxreport->pktlen;
  9503. phal = GET_HAL_DATA(padapter);
  9504. if (rtw_hal_rcr_check(padapter, RCR_APPFCS))
  9505. fcssize = IEEE80211_FCS_LEN;
  9506. else
  9507. fcssize = 0;
  9508. if ((txsz - TXDESC_SIZE) != (rxpktsize - fcssize)) {
  9509. RTW_INFO("%s: ERROR! size not match tx/rx=%d/%d !\n",
  9510. __func__, txsz - TXDESC_SIZE, rxpktsize - fcssize);
  9511. ret = _FALSE;
  9512. } else {
  9513. ret = _rtw_memcmp(txbuf + TXDESC_SIZE, \
  9514. rxbuf + RXDESC_SIZE + drvinfosize, \
  9515. txsz - TXDESC_SIZE);
  9516. if (ret == _FALSE)
  9517. RTW_INFO("%s: ERROR! pkt content mismatch!\n", __func__);
  9518. }
  9519. if (ret == _FALSE) {
  9520. RTW_INFO("\n%s: TX PKT total=%d, desc=%d, content=%d\n",
  9521. __func__, txsz, TXDESC_SIZE, txsz - TXDESC_SIZE);
  9522. RTW_INFO("%s: TX DESC size=%d\n", __func__, TXDESC_SIZE);
  9523. printdata(txbuf, TXDESC_SIZE);
  9524. RTW_INFO("%s: TX content size=%d\n", __func__, txsz - TXDESC_SIZE);
  9525. printdata(txbuf + TXDESC_SIZE, txsz - TXDESC_SIZE);
  9526. RTW_INFO("\n%s: RX PKT read=%d offset=%d(%d,%d) content=%d\n",
  9527. __func__, rxsz, RXDESC_SIZE + drvinfosize, RXDESC_SIZE, drvinfosize, rxpktsize);
  9528. if (rxpktsize != 0) {
  9529. RTW_INFO("%s: RX DESC size=%d\n", __func__, RXDESC_SIZE);
  9530. printdata(rxbuf, RXDESC_SIZE);
  9531. RTW_INFO("%s: RX drvinfo size=%d\n", __func__, drvinfosize);
  9532. printdata(rxbuf + RXDESC_SIZE, drvinfosize);
  9533. RTW_INFO("%s: RX content size=%d\n", __func__, rxpktsize);
  9534. printdata(rxbuf + RXDESC_SIZE + drvinfosize, rxpktsize);
  9535. } else {
  9536. RTW_INFO("%s: RX data size=%d\n", __func__, rxsz);
  9537. printdata(rxbuf, rxsz);
  9538. }
  9539. }
  9540. return ret;
  9541. }
  9542. thread_return lbk_thread(thread_context context)
  9543. {
  9544. s32 err;
  9545. PADAPTER padapter;
  9546. PLOOPBACKDATA ploopback;
  9547. struct xmit_frame *pxmitframe;
  9548. u32 cnt, ok, fail, headerlen;
  9549. u32 pktsize;
  9550. u32 ff_hwaddr;
  9551. padapter = (PADAPTER)context;
  9552. ploopback = padapter->ploopback;
  9553. if (ploopback == NULL)
  9554. return -1;
  9555. cnt = 0;
  9556. ok = 0;
  9557. fail = 0;
  9558. daemonize("%s", "RTW_LBK_THREAD");
  9559. allow_signal(SIGTERM);
  9560. do {
  9561. if (ploopback->size == 0) {
  9562. get_random_bytes(&pktsize, 4);
  9563. pktsize = (pktsize % 1535) + 1; /* 1~1535 */
  9564. } else
  9565. pktsize = ploopback->size;
  9566. pxmitframe = createloopbackpkt(padapter, pktsize);
  9567. if (pxmitframe == NULL) {
  9568. sprintf(ploopback->msg, "loopback FAIL! 3. create Packet FAIL!");
  9569. break;
  9570. }
  9571. ploopback->txsize = TXDESC_SIZE + pxmitframe->attrib.last_txcmdsz;
  9572. _rtw_memcpy(ploopback->txbuf, pxmitframe->buf_addr, ploopback->txsize);
  9573. ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
  9574. cnt++;
  9575. RTW_INFO("%s: wirte port cnt=%d size=%d\n", __func__, cnt, ploopback->txsize);
  9576. pxmitframe->pxmitbuf->pdata = ploopback->txbuf;
  9577. rtw_write_port(padapter, ff_hwaddr, ploopback->txsize, (u8 *)pxmitframe->pxmitbuf);
  9578. /* wait for rx pkt */
  9579. _rtw_down_sema(&ploopback->sema);
  9580. err = pktcmp(padapter, ploopback->txbuf, ploopback->txsize, ploopback->rxbuf, ploopback->rxsize);
  9581. if (err == _TRUE)
  9582. ok++;
  9583. else
  9584. fail++;
  9585. ploopback->txsize = 0;
  9586. _rtw_memset(ploopback->txbuf, 0, 0x8000);
  9587. ploopback->rxsize = 0;
  9588. _rtw_memset(ploopback->rxbuf, 0, 0x8000);
  9589. freeloopbackpkt(padapter, pxmitframe);
  9590. pxmitframe = NULL;
  9591. flush_signals_thread();
  9592. if ((ploopback->bstop == _TRUE) ||
  9593. ((ploopback->cnt != 0) && (ploopback->cnt == cnt))) {
  9594. u32 ok_rate, fail_rate, all;
  9595. all = cnt;
  9596. ok_rate = (ok * 100) / all;
  9597. fail_rate = (fail * 100) / all;
  9598. sprintf(ploopback->msg, \
  9599. "loopback result: ok=%d%%(%d/%d),error=%d%%(%d/%d)", \
  9600. ok_rate, ok, all, fail_rate, fail, all);
  9601. break;
  9602. }
  9603. } while (1);
  9604. ploopback->bstop = _TRUE;
  9605. thread_exit(NULL);
  9606. return 0;
  9607. }
  9608. static void loopbackTest(PADAPTER padapter, u32 cnt, u32 size, u8 *pmsg)
  9609. {
  9610. PLOOPBACKDATA ploopback;
  9611. u32 len;
  9612. s32 err;
  9613. ploopback = padapter->ploopback;
  9614. if (ploopback) {
  9615. if (ploopback->bstop == _FALSE) {
  9616. ploopback->bstop = _TRUE;
  9617. _rtw_up_sema(&ploopback->sema);
  9618. }
  9619. len = 0;
  9620. do {
  9621. len = strlen(ploopback->msg);
  9622. if (len)
  9623. break;
  9624. rtw_msleep_os(1);
  9625. } while (1);
  9626. _rtw_memcpy(pmsg, ploopback->msg, len + 1);
  9627. freeLoopback(padapter);
  9628. return;
  9629. }
  9630. /* disable dynamic algorithm */
  9631. rtw_phydm_ability_backup(padapter);
  9632. rtw_phydm_func_disable_all(padapter);
  9633. /* create pseudo ad-hoc connection */
  9634. err = initpseudoadhoc(padapter);
  9635. if (err == _FAIL) {
  9636. sprintf(pmsg, "loopback FAIL! 1.1 init ad-hoc FAIL!");
  9637. return;
  9638. }
  9639. err = createpseudoadhoc(padapter);
  9640. if (err == _FAIL) {
  9641. sprintf(pmsg, "loopback FAIL! 1.2 create ad-hoc master FAIL!");
  9642. return;
  9643. }
  9644. err = initLoopback(padapter);
  9645. if (err) {
  9646. sprintf(pmsg, "loopback FAIL! 2. init FAIL! error code=%d", err);
  9647. return;
  9648. }
  9649. ploopback = padapter->ploopback;
  9650. ploopback->bstop = _FALSE;
  9651. ploopback->cnt = cnt;
  9652. ploopback->size = size;
  9653. ploopback->lbkthread = kthread_run(lbk_thread, padapter, "RTW_LBK_THREAD");
  9654. if (IS_ERR(padapter->lbkthread)) {
  9655. freeLoopback(padapter);
  9656. ploopback->lbkthread = NULL;
  9657. sprintf(pmsg, "loopback start FAIL! cnt=%d", cnt);
  9658. return;
  9659. }
  9660. sprintf(pmsg, "loopback start! cnt=%d", cnt);
  9661. }
  9662. #endif /* CONFIG_MAC_LOOPBACK_DRIVER */
  9663. static int rtw_test(
  9664. struct net_device *dev,
  9665. struct iw_request_info *info,
  9666. union iwreq_data *wrqu, char *extra)
  9667. {
  9668. u32 len;
  9669. u8 *pbuf, *pch;
  9670. char *ptmp;
  9671. u8 *delim = ",";
  9672. PADAPTER padapter = rtw_netdev_priv(dev);
  9673. RTW_INFO("+%s\n", __func__);
  9674. len = wrqu->data.length;
  9675. pbuf = (u8 *)rtw_zmalloc(len + 1);
  9676. if (pbuf == NULL) {
  9677. RTW_INFO("%s: no memory!\n", __func__);
  9678. return -ENOMEM;
  9679. }
  9680. if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
  9681. rtw_mfree(pbuf, len + 1);
  9682. RTW_INFO("%s: copy from user fail!\n", __func__);
  9683. return -EFAULT;
  9684. }
  9685. pbuf[len] = '\0';
  9686. RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
  9687. ptmp = (char *)pbuf;
  9688. pch = strsep(&ptmp, delim);
  9689. if ((pch == NULL) || (strlen(pch) == 0)) {
  9690. rtw_mfree(pbuf, len);
  9691. RTW_INFO("%s: parameter error(level 1)!\n", __func__);
  9692. return -EFAULT;
  9693. }
  9694. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  9695. if (strcmp(pch, "loopback") == 0) {
  9696. s32 cnt = 0;
  9697. u32 size = 64;
  9698. pch = strsep(&ptmp, delim);
  9699. if ((pch == NULL) || (strlen(pch) == 0)) {
  9700. rtw_mfree(pbuf, len);
  9701. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9702. return -EFAULT;
  9703. }
  9704. sscanf(pch, "%d", &cnt);
  9705. RTW_INFO("%s: loopback cnt=%d\n", __func__, cnt);
  9706. pch = strsep(&ptmp, delim);
  9707. if ((pch == NULL) || (strlen(pch) == 0)) {
  9708. rtw_mfree(pbuf, len);
  9709. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9710. return -EFAULT;
  9711. }
  9712. sscanf(pch, "%d", &size);
  9713. RTW_INFO("%s: loopback size=%d\n", __func__, size);
  9714. loopbackTest(padapter, cnt, size, extra);
  9715. wrqu->data.length = strlen(extra) + 1;
  9716. goto free_buf;
  9717. }
  9718. #endif
  9719. #ifdef CONFIG_BT_COEXIST
  9720. if (strcmp(pch, "bton") == 0) {
  9721. rtw_btcoex_SetManualControl(padapter, _FALSE);
  9722. goto free_buf;
  9723. } else if (strcmp(pch, "btoff") == 0) {
  9724. rtw_btcoex_SetManualControl(padapter, _TRUE);
  9725. goto free_buf;
  9726. }
  9727. #endif
  9728. if (strcmp(pch, "h2c") == 0) {
  9729. u8 param[8];
  9730. u8 count = 0;
  9731. u32 tmp;
  9732. u8 i;
  9733. u32 pos;
  9734. u8 ret;
  9735. do {
  9736. pch = strsep(&ptmp, delim);
  9737. if ((pch == NULL) || (strlen(pch) == 0))
  9738. break;
  9739. sscanf(pch, "%x", &tmp);
  9740. param[count++] = (u8)tmp;
  9741. } while (count < 8);
  9742. if (count == 0) {
  9743. rtw_mfree(pbuf, len);
  9744. RTW_INFO("%s: parameter error(level 2)!\n", __func__);
  9745. return -EFAULT;
  9746. }
  9747. ret = rtw_test_h2c_cmd(padapter, param, count);
  9748. pos = sprintf(extra, "H2C ID=0x%02x content=", param[0]);
  9749. for (i = 1; i < count; i++)
  9750. pos += sprintf(extra + pos, "%02x,", param[i]);
  9751. extra[pos] = 0;
  9752. pos--;
  9753. pos += sprintf(extra + pos, " %s", ret == _FAIL ? "FAIL" : "OK");
  9754. wrqu->data.length = strlen(extra) + 1;
  9755. goto free_buf;
  9756. }
  9757. free_buf:
  9758. rtw_mfree(pbuf, len);
  9759. return 0;
  9760. }
  9761. static iw_handler rtw_handlers[] = {
  9762. NULL, /* SIOCSIWCOMMIT */
  9763. rtw_wx_get_name, /* SIOCGIWNAME */
  9764. dummy, /* SIOCSIWNWID */
  9765. dummy, /* SIOCGIWNWID */
  9766. rtw_wx_set_freq, /* SIOCSIWFREQ */
  9767. rtw_wx_get_freq, /* SIOCGIWFREQ */
  9768. rtw_wx_set_mode, /* SIOCSIWMODE */
  9769. rtw_wx_get_mode, /* SIOCGIWMODE */
  9770. dummy, /* SIOCSIWSENS */
  9771. rtw_wx_get_sens, /* SIOCGIWSENS */
  9772. NULL, /* SIOCSIWRANGE */
  9773. rtw_wx_get_range, /* SIOCGIWRANGE */
  9774. rtw_wx_set_priv, /* SIOCSIWPRIV */
  9775. NULL, /* SIOCGIWPRIV */
  9776. NULL, /* SIOCSIWSTATS */
  9777. NULL, /* SIOCGIWSTATS */
  9778. dummy, /* SIOCSIWSPY */
  9779. dummy, /* SIOCGIWSPY */
  9780. NULL, /* SIOCGIWTHRSPY */
  9781. NULL, /* SIOCWIWTHRSPY */
  9782. rtw_wx_set_wap, /* SIOCSIWAP */
  9783. rtw_wx_get_wap, /* SIOCGIWAP */
  9784. rtw_wx_set_mlme, /* request MLME operation; uses struct iw_mlme */
  9785. dummy, /* SIOCGIWAPLIST -- depricated */
  9786. rtw_wx_set_scan, /* SIOCSIWSCAN */
  9787. rtw_wx_get_scan, /* SIOCGIWSCAN */
  9788. rtw_wx_set_essid, /* SIOCSIWESSID */
  9789. rtw_wx_get_essid, /* SIOCGIWESSID */
  9790. dummy, /* SIOCSIWNICKN */
  9791. rtw_wx_get_nick, /* SIOCGIWNICKN */
  9792. NULL, /* -- hole -- */
  9793. NULL, /* -- hole -- */
  9794. rtw_wx_set_rate, /* SIOCSIWRATE */
  9795. rtw_wx_get_rate, /* SIOCGIWRATE */
  9796. rtw_wx_set_rts, /* SIOCSIWRTS */
  9797. rtw_wx_get_rts, /* SIOCGIWRTS */
  9798. rtw_wx_set_frag, /* SIOCSIWFRAG */
  9799. rtw_wx_get_frag, /* SIOCGIWFRAG */
  9800. dummy, /* SIOCSIWTXPOW */
  9801. dummy, /* SIOCGIWTXPOW */
  9802. dummy, /* SIOCSIWRETRY */
  9803. rtw_wx_get_retry, /* SIOCGIWRETRY */
  9804. rtw_wx_set_enc, /* SIOCSIWENCODE */
  9805. rtw_wx_get_enc, /* SIOCGIWENCODE */
  9806. dummy, /* SIOCSIWPOWER */
  9807. rtw_wx_get_power, /* SIOCGIWPOWER */
  9808. NULL, /*---hole---*/
  9809. NULL, /*---hole---*/
  9810. rtw_wx_set_gen_ie, /* SIOCSIWGENIE */
  9811. NULL, /* SIOCGWGENIE */
  9812. rtw_wx_set_auth, /* SIOCSIWAUTH */
  9813. NULL, /* SIOCGIWAUTH */
  9814. rtw_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
  9815. NULL, /* SIOCGIWENCODEEXT */
  9816. rtw_wx_set_pmkid, /* SIOCSIWPMKSA */
  9817. NULL, /*---hole---*/
  9818. };
  9819. static const struct iw_priv_args rtw_private_args[] = {
  9820. {
  9821. SIOCIWFIRSTPRIV + 0x0,
  9822. IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
  9823. },
  9824. {
  9825. SIOCIWFIRSTPRIV + 0x1,
  9826. IW_PRIV_TYPE_CHAR | 0x7FF,
  9827. IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
  9828. },
  9829. {
  9830. SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
  9831. },
  9832. {
  9833. SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
  9834. },
  9835. {
  9836. SIOCIWFIRSTPRIV + 0x4,
  9837. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
  9838. },
  9839. {
  9840. SIOCIWFIRSTPRIV + 0x5,
  9841. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
  9842. },
  9843. {
  9844. SIOCIWFIRSTPRIV + 0x6,
  9845. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
  9846. },
  9847. /* for PLATFORM_MT53XX */
  9848. {
  9849. SIOCIWFIRSTPRIV + 0x7,
  9850. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "get_sensitivity"
  9851. },
  9852. {
  9853. SIOCIWFIRSTPRIV + 0x8,
  9854. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_prob_req_ie"
  9855. },
  9856. {
  9857. SIOCIWFIRSTPRIV + 0x9,
  9858. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_assoc_req_ie"
  9859. },
  9860. /* for RTK_DMP_PLATFORM */
  9861. {
  9862. SIOCIWFIRSTPRIV + 0xA,
  9863. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
  9864. },
  9865. {
  9866. SIOCIWFIRSTPRIV + 0xB,
  9867. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
  9868. },
  9869. {
  9870. SIOCIWFIRSTPRIV + 0xC,
  9871. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
  9872. },
  9873. {
  9874. SIOCIWFIRSTPRIV + 0xD,
  9875. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
  9876. },
  9877. #if 0
  9878. {
  9879. SIOCIWFIRSTPRIV + 0xE, 0, 0, "wowlan_ctrl"
  9880. },
  9881. #endif
  9882. {
  9883. SIOCIWFIRSTPRIV + 0x10,
  9884. IW_PRIV_TYPE_CHAR | 1024, 0, "p2p_set"
  9885. },
  9886. {
  9887. SIOCIWFIRSTPRIV + 0x11,
  9888. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "p2p_get"
  9889. },
  9890. {
  9891. SIOCIWFIRSTPRIV + 0x12, 0, 0, "NULL"
  9892. },
  9893. {
  9894. SIOCIWFIRSTPRIV + 0x13,
  9895. IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64 , "p2p_get2"
  9896. },
  9897. {
  9898. SIOCIWFIRSTPRIV + 0x14,
  9899. IW_PRIV_TYPE_CHAR | 64, 0, "tdls"
  9900. },
  9901. {
  9902. SIOCIWFIRSTPRIV + 0x15,
  9903. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "tdls_get"
  9904. },
  9905. {
  9906. SIOCIWFIRSTPRIV + 0x16,
  9907. IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
  9908. },
  9909. #ifdef CONFIG_RTW_80211K
  9910. {
  9911. SIOCIWFIRSTPRIV + 0x17,
  9912. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "rrm"
  9913. },
  9914. #endif
  9915. {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ , 0 , "rereg_nd_name"},
  9916. #ifdef CONFIG_MP_INCLUDED
  9917. {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "NULL"},
  9918. {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "NULL"},
  9919. #else
  9920. {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "NULL"},
  9921. {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
  9922. #endif
  9923. {
  9924. SIOCIWFIRSTPRIV + 0x1D,
  9925. IW_PRIV_TYPE_CHAR | 40, IW_PRIV_TYPE_CHAR | 0x7FF, "test"
  9926. },
  9927. #ifdef CONFIG_INTEL_WIDI
  9928. {
  9929. SIOCIWFIRSTPRIV + 0x1E,
  9930. IW_PRIV_TYPE_CHAR | 1024, 0, "widi_set"
  9931. },
  9932. {
  9933. SIOCIWFIRSTPRIV + 0x1F,
  9934. IW_PRIV_TYPE_CHAR | 128, 0, "widi_prob_req"
  9935. },
  9936. #endif /* CONFIG_INTEL_WIDI */
  9937. { SIOCIWFIRSTPRIV + 0x0E, IW_PRIV_TYPE_CHAR | 1024, 0 , ""}, /* set */
  9938. { SIOCIWFIRSTPRIV + 0x0F, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , ""},/* get
  9939. * --- sub-ioctls definitions --- */
  9940. #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
  9941. { VENDOR_IE_SET, IW_PRIV_TYPE_CHAR | 1024 , 0 , "vendor_ie_set" },
  9942. { VENDOR_IE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "vendor_ie_get" },
  9943. #endif
  9944. #if defined(CONFIG_RTL8723B)
  9945. { MP_SetBT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setbt" },
  9946. { MP_DISABLE_BT_COEXIST, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_disa_btcoex"},
  9947. #endif
  9948. #ifdef CONFIG_WOWLAN
  9949. { MP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_mode" },
  9950. { MP_WOW_SET_PATTERN , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_set_pattern" },
  9951. #endif
  9952. #ifdef CONFIG_AP_WOWLAN
  9953. { MP_AP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "ap_wow_mode" }, /* set */
  9954. #endif
  9955. #ifdef CONFIG_SDIO_INDIRECT_ACCESS
  9956. { MP_SD_IREAD, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iread" },
  9957. { MP_SD_IWRITE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iwrite" },
  9958. #endif
  9959. };
  9960. static const struct iw_priv_args rtw_mp_private_args[] = {
  9961. /* --- sub-ioctls definitions --- */
  9962. #ifdef CONFIG_MP_INCLUDED
  9963. { MP_START , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_start" },
  9964. { MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara" },
  9965. { MP_STOP , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_stop" },
  9966. { MP_CHANNEL , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel" },
  9967. { MP_CHL_OFFSET , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ch_offset" },
  9968. { MP_BANDWIDTH , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_bandwidth"},
  9969. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  9970. { MP_RESET_STATS , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_reset_stats"},
  9971. { MP_QUERY , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "mp_query"},
  9972. { READ_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg" },
  9973. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  9974. { READ_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf" },
  9975. { MP_PSD , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
  9976. { MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump" },
  9977. { MP_TXPOWER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
  9978. { MP_ANT_TX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
  9979. { MP_ANT_RX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
  9980. { WRITE_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_reg" },
  9981. { WRITE_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_rf" },
  9982. { MP_CTX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
  9983. { MP_ARX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
  9984. { MP_THER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
  9985. { EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_set" },
  9986. { EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get" },
  9987. { MP_PWRTRK , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrtrk"},
  9988. { MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery" },
  9989. { MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"},
  9990. { MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setrfpath" },
  9991. { MP_PwrCtlDM, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrctldm" },
  9992. { MP_GET_TXPOWER_INX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_get_txpower" },
  9993. { MP_GETVER, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_priv_ver" },
  9994. { MP_MON, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_mon" },
  9995. { EFUSE_MASK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_mask" },
  9996. { EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_file" },
  9997. { MP_TX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_tx" },
  9998. { MP_RX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rx" },
  9999. { MP_HW_TX_MODE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_hxtx" },
  10000. { MP_PWRLMT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrlmt" },
  10001. { MP_PWRBYRATE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrbyrate" },
  10002. { CTA_TEST, IW_PRIV_TYPE_CHAR | 1024, 0, "cta_test"},
  10003. { MP_IQK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_iqk"},
  10004. { MP_LCK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_lck"},
  10005. { BT_EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bt_efuse_file" },
  10006. { MP_SWRFPath, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_swrfpath" },
  10007. #ifdef CONFIG_RTW_CUSTOMER_STR
  10008. { MP_CUSTOMER_STR, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "customer_str" },
  10009. #endif
  10010. #endif /* CONFIG_MP_INCLUDED */
  10011. };
  10012. static iw_handler rtw_private_handler[] = {
  10013. rtw_wx_write32, /* 0x00 */
  10014. rtw_wx_read32, /* 0x01 */
  10015. NULL, /* 0x02 */
  10016. #ifdef MP_IOCTL_HDL
  10017. rtw_mp_ioctl_hdl, /* 0x03 */
  10018. #else
  10019. rtw_wx_priv_null,
  10020. #endif
  10021. /* for MM DTV platform */
  10022. rtw_get_ap_info, /* 0x04 */
  10023. rtw_set_pid, /* 0x05 */
  10024. rtw_wps_start, /* 0x06 */
  10025. /* for PLATFORM_MT53XX */
  10026. rtw_wx_get_sensitivity, /* 0x07 */
  10027. rtw_wx_set_mtk_wps_probe_ie, /* 0x08 */
  10028. rtw_wx_set_mtk_wps_ie, /* 0x09 */
  10029. /* for RTK_DMP_PLATFORM
  10030. * Set Channel depend on the country code */
  10031. rtw_wx_set_channel_plan, /* 0x0A */
  10032. rtw_dbg_port, /* 0x0B */
  10033. rtw_wx_write_rf, /* 0x0C */
  10034. rtw_wx_read_rf, /* 0x0D */
  10035. rtw_priv_set, /*0x0E*/
  10036. rtw_priv_get, /*0x0F*/
  10037. rtw_p2p_set, /* 0x10 */
  10038. rtw_p2p_get, /* 0x11 */
  10039. NULL, /* 0x12 */
  10040. rtw_p2p_get2, /* 0x13 */
  10041. rtw_tdls, /* 0x14 */
  10042. rtw_tdls_get, /* 0x15 */
  10043. rtw_pm_set, /* 0x16 */
  10044. #ifdef CONFIG_RTW_80211K
  10045. rtw_wx_priv_rrm, /* 0x17 */
  10046. #else
  10047. rtw_wx_priv_null, /* 0x17 */
  10048. #endif
  10049. rtw_rereg_nd_name, /* 0x18 */
  10050. rtw_wx_priv_null, /* 0x19 */
  10051. #ifdef CONFIG_MP_INCLUDED
  10052. rtw_wx_priv_null, /* 0x1A */
  10053. rtw_wx_priv_null, /* 0x1B */
  10054. #else
  10055. rtw_wx_priv_null, /* 0x1A */
  10056. rtw_mp_efuse_get, /* 0x1B */
  10057. #endif
  10058. NULL, /* 0x1C is reserved for hostapd */
  10059. rtw_test, /* 0x1D */
  10060. #ifdef CONFIG_INTEL_WIDI
  10061. rtw_widi_set, /* 0x1E */
  10062. rtw_widi_set_probe_request, /* 0x1F */
  10063. #endif /* CONFIG_INTEL_WIDI */
  10064. };
  10065. #if WIRELESS_EXT >= 17
  10066. static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
  10067. {
  10068. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  10069. struct iw_statistics *piwstats = &padapter->iwstats;
  10070. int tmp_level = 0;
  10071. int tmp_qual = 0;
  10072. int tmp_noise = 0;
  10073. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) != _TRUE) {
  10074. piwstats->qual.qual = 0;
  10075. piwstats->qual.level = 0;
  10076. piwstats->qual.noise = 0;
  10077. /* RTW_INFO("No link level:%d, qual:%d, noise:%d\n", tmp_level, tmp_qual, tmp_noise); */
  10078. } else {
  10079. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10080. tmp_level = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  10081. #else
  10082. tmp_level = padapter->recvpriv.signal_strength;
  10083. #endif
  10084. tmp_qual = padapter->recvpriv.signal_qual;
  10085. #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
  10086. if (IS_NM_ENABLE(padapter)) {
  10087. tmp_noise = rtw_noise_measure_curchan(padapter);
  10088. #ifndef CONFIG_SIGNAL_DISPLAY_DBM
  10089. tmp_noise = translate_dbm_to_percentage(tmp_noise);/*percentage*/
  10090. #endif
  10091. }
  10092. #endif
  10093. /* RTW_INFO("level:%d, qual:%d, noise:%d, rssi (%d)\n", tmp_level, tmp_qual, tmp_noise,padapter->recvpriv.rssi); */
  10094. piwstats->qual.level = tmp_level;
  10095. piwstats->qual.qual = tmp_qual;
  10096. piwstats->qual.noise = tmp_noise;
  10097. }
  10098. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14))
  10099. piwstats->qual.updated = IW_QUAL_ALL_UPDATED ;/* |IW_QUAL_DBM; */
  10100. #else
  10101. #ifdef RTK_DMP_PLATFORM
  10102. /* IW_QUAL_DBM= 0x8, if driver use this flag, wireless extension will show value of dbm. */
  10103. /* remove this flag for show percentage 0~100 */
  10104. piwstats->qual.updated = 0x07;
  10105. #else
  10106. piwstats->qual.updated = 0x0f;
  10107. #endif
  10108. #endif
  10109. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10110. piwstats->qual.updated = piwstats->qual.updated | IW_QUAL_DBM;
  10111. #endif
  10112. return &padapter->iwstats;
  10113. }
  10114. #endif
  10115. #ifdef CONFIG_WIRELESS_EXT
  10116. struct iw_handler_def rtw_handlers_def = {
  10117. .standard = rtw_handlers,
  10118. .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
  10119. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) || defined(CONFIG_WEXT_PRIV)
  10120. .private = rtw_private_handler,
  10121. .private_args = (struct iw_priv_args *)rtw_private_args,
  10122. .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler),
  10123. .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args),
  10124. #endif
  10125. #if WIRELESS_EXT >= 17
  10126. .get_wireless_stats = rtw_get_wireless_stats,
  10127. #endif
  10128. };
  10129. #endif
  10130. /* copy from net/wireless/wext.c start
  10131. * ----------------------------------------------------------------
  10132. *
  10133. * Calculate size of private arguments
  10134. */
  10135. static const char iw_priv_type_size[] = {
  10136. 0, /* IW_PRIV_TYPE_NONE */
  10137. 1, /* IW_PRIV_TYPE_BYTE */
  10138. 1, /* IW_PRIV_TYPE_CHAR */
  10139. 0, /* Not defined */
  10140. sizeof(__u32), /* IW_PRIV_TYPE_INT */
  10141. sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
  10142. sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
  10143. 0, /* Not defined */
  10144. };
  10145. static int get_priv_size(__u16 args)
  10146. {
  10147. int num = args & IW_PRIV_SIZE_MASK;
  10148. int type = (args & IW_PRIV_TYPE_MASK) >> 12;
  10149. return num * iw_priv_type_size[type];
  10150. }
  10151. /* copy from net/wireless/wext.c end */
  10152. static int _rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_data)
  10153. {
  10154. int err = 0;
  10155. u8 *input = NULL;
  10156. u32 input_len = 0;
  10157. const char delim[] = " ";
  10158. u8 *output = NULL;
  10159. u32 output_len = 0;
  10160. u32 count = 0;
  10161. u8 *buffer = NULL;
  10162. u32 buffer_len = 0;
  10163. char *ptr = NULL;
  10164. u8 cmdname[17] = {0}; /* IFNAMSIZ+1 */
  10165. u32 cmdlen;
  10166. s32 len;
  10167. u8 *extra = NULL;
  10168. u32 extra_size = 0;
  10169. s32 k;
  10170. const iw_handler *priv; /* Private ioctl */
  10171. const struct iw_priv_args *priv_args; /* Private ioctl description */
  10172. const struct iw_priv_args *mp_priv_args; /*MP Private ioctl description */
  10173. const struct iw_priv_args *sel_priv_args; /*Selected Private ioctl description */
  10174. u32 num_priv; /* Number of ioctl */
  10175. u32 num_priv_args; /* Number of descriptions */
  10176. u32 num_mp_priv_args; /*Number of MP descriptions */
  10177. u32 num_sel_priv_args; /*Number of Selected descriptions */
  10178. iw_handler handler;
  10179. int temp;
  10180. int subcmd = 0; /* sub-ioctl index */
  10181. int offset = 0; /* Space for sub-ioctl index */
  10182. union iwreq_data wdata;
  10183. _rtw_memcpy(&wdata, wrq_data, sizeof(wdata));
  10184. input_len = wdata.data.length;
  10185. if (!input_len)
  10186. return -EINVAL;
  10187. input = rtw_zmalloc(input_len);
  10188. if (NULL == input)
  10189. return -ENOMEM;
  10190. if (copy_from_user(input, wdata.data.pointer, input_len)) {
  10191. err = -EFAULT;
  10192. goto exit;
  10193. }
  10194. input[input_len - 1] = '\0';
  10195. ptr = input;
  10196. len = input_len;
  10197. if (ptr == NULL) {
  10198. err = -EOPNOTSUPP;
  10199. goto exit;
  10200. }
  10201. sscanf(ptr, "%16s", cmdname);
  10202. cmdlen = strlen(cmdname);
  10203. RTW_INFO("%s: cmd=%s\n", __func__, cmdname);
  10204. /* skip command string */
  10205. if (cmdlen > 0)
  10206. cmdlen += 1; /* skip one space */
  10207. ptr += cmdlen;
  10208. len -= cmdlen;
  10209. RTW_INFO("%s: parameters=%s\n", __func__, ptr);
  10210. priv = rtw_private_handler;
  10211. priv_args = rtw_private_args;
  10212. mp_priv_args = rtw_mp_private_args;
  10213. num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler);
  10214. num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args);
  10215. num_mp_priv_args = sizeof(rtw_mp_private_args) / sizeof(struct iw_priv_args);
  10216. if (num_priv_args == 0) {
  10217. err = -EOPNOTSUPP;
  10218. goto exit;
  10219. }
  10220. /* Search the correct ioctl */
  10221. k = -1;
  10222. sel_priv_args = priv_args;
  10223. num_sel_priv_args = num_priv_args;
  10224. while
  10225. ((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
  10226. ;
  10227. /* If not found... */
  10228. if (k == num_sel_priv_args) {
  10229. k = -1;
  10230. sel_priv_args = mp_priv_args;
  10231. num_sel_priv_args = num_mp_priv_args;
  10232. while
  10233. ((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
  10234. ;
  10235. if (k == num_sel_priv_args) {
  10236. err = -EOPNOTSUPP;
  10237. goto exit;
  10238. }
  10239. }
  10240. /* Watch out for sub-ioctls ! */
  10241. if (sel_priv_args[k].cmd < SIOCDEVPRIVATE) {
  10242. int j = -1;
  10243. /* Find the matching *real* ioctl */
  10244. while ((++j < num_priv_args) && ((priv_args[j].name[0] != '\0') ||
  10245. (priv_args[j].set_args != sel_priv_args[k].set_args) ||
  10246. (priv_args[j].get_args != sel_priv_args[k].get_args)))
  10247. ;
  10248. /* If not found... */
  10249. if (j == num_priv_args) {
  10250. err = -EINVAL;
  10251. goto exit;
  10252. }
  10253. /* Save sub-ioctl number */
  10254. subcmd = sel_priv_args[k].cmd;
  10255. /* Reserve one int (simplify alignment issues) */
  10256. offset = sizeof(__u32);
  10257. /* Use real ioctl definition from now on */
  10258. k = j;
  10259. }
  10260. buffer = rtw_zmalloc(4096);
  10261. if (NULL == buffer) {
  10262. err = -ENOMEM;
  10263. goto exit;
  10264. }
  10265. if (k >= num_priv_args) {
  10266. err = -EINVAL;
  10267. goto exit;
  10268. }
  10269. /* If we have to set some data */
  10270. if ((priv_args[k].set_args & IW_PRIV_TYPE_MASK) &&
  10271. (priv_args[k].set_args & IW_PRIV_SIZE_MASK)) {
  10272. u8 *str;
  10273. switch (priv_args[k].set_args & IW_PRIV_TYPE_MASK) {
  10274. case IW_PRIV_TYPE_BYTE:
  10275. /* Fetch args */
  10276. count = 0;
  10277. do {
  10278. str = strsep(&ptr, delim);
  10279. if (NULL == str)
  10280. break;
  10281. sscanf(str, "%i", &temp);
  10282. buffer[count++] = (u8)temp;
  10283. } while (1);
  10284. buffer_len = count;
  10285. /* Number of args to fetch */
  10286. wdata.data.length = count;
  10287. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10288. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10289. break;
  10290. case IW_PRIV_TYPE_INT:
  10291. /* Fetch args */
  10292. count = 0;
  10293. do {
  10294. str = strsep(&ptr, delim);
  10295. if (NULL == str)
  10296. break;
  10297. sscanf(str, "%i", &temp);
  10298. ((s32 *)buffer)[count++] = (s32)temp;
  10299. } while (1);
  10300. buffer_len = count * sizeof(s32);
  10301. /* Number of args to fetch */
  10302. wdata.data.length = count;
  10303. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10304. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10305. break;
  10306. case IW_PRIV_TYPE_CHAR:
  10307. if (len > 0) {
  10308. /* Size of the string to fetch */
  10309. wdata.data.length = len;
  10310. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  10311. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  10312. /* Fetch string */
  10313. _rtw_memcpy(buffer, ptr, wdata.data.length);
  10314. } else {
  10315. wdata.data.length = 1;
  10316. buffer[0] = '\0';
  10317. }
  10318. buffer_len = wdata.data.length;
  10319. break;
  10320. default:
  10321. RTW_INFO("%s: Not yet implemented...\n", __func__);
  10322. err = -1;
  10323. goto exit;
  10324. }
  10325. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10326. (wdata.data.length != (priv_args[k].set_args & IW_PRIV_SIZE_MASK))) {
  10327. RTW_INFO("%s: The command %s needs exactly %d argument(s)...\n",
  10328. __func__, cmdname, priv_args[k].set_args & IW_PRIV_SIZE_MASK);
  10329. err = -EINVAL;
  10330. goto exit;
  10331. }
  10332. } /* if args to set */
  10333. else
  10334. wdata.data.length = 0L;
  10335. /* Those two tests are important. They define how the driver
  10336. * will have to handle the data */
  10337. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10338. ((get_priv_size(priv_args[k].set_args) + offset) <= IFNAMSIZ)) {
  10339. /* First case : all SET args fit within wrq */
  10340. if (offset)
  10341. wdata.mode = subcmd;
  10342. _rtw_memcpy(wdata.name + offset, buffer, IFNAMSIZ - offset);
  10343. } else {
  10344. if ((priv_args[k].set_args == 0) &&
  10345. (priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10346. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ)) {
  10347. /* Second case : no SET args, GET args fit within wrq */
  10348. if (offset)
  10349. wdata.mode = subcmd;
  10350. } else {
  10351. /* Third case : args won't fit in wrq, or variable number of args */
  10352. if (copy_to_user(wdata.data.pointer, buffer, buffer_len)) {
  10353. err = -EFAULT;
  10354. goto exit;
  10355. }
  10356. wdata.data.flags = subcmd;
  10357. }
  10358. }
  10359. rtw_mfree(input, input_len);
  10360. input = NULL;
  10361. extra_size = 0;
  10362. if (IW_IS_SET(priv_args[k].cmd)) {
  10363. /* Size of set arguments */
  10364. extra_size = get_priv_size(priv_args[k].set_args);
  10365. /* Does it fits in iwr ? */
  10366. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  10367. ((extra_size + offset) <= IFNAMSIZ))
  10368. extra_size = 0;
  10369. } else {
  10370. /* Size of get arguments */
  10371. extra_size = get_priv_size(priv_args[k].get_args);
  10372. /* Does it fits in iwr ? */
  10373. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10374. (extra_size <= IFNAMSIZ))
  10375. extra_size = 0;
  10376. }
  10377. if (extra_size == 0) {
  10378. extra = (u8 *)&wdata;
  10379. rtw_mfree(buffer, 4096);
  10380. buffer = NULL;
  10381. } else
  10382. extra = buffer;
  10383. handler = priv[priv_args[k].cmd - SIOCIWFIRSTPRIV];
  10384. err = handler(dev, NULL, &wdata, extra);
  10385. /* If we have to get some data */
  10386. if ((priv_args[k].get_args & IW_PRIV_TYPE_MASK) &&
  10387. (priv_args[k].get_args & IW_PRIV_SIZE_MASK)) {
  10388. int j;
  10389. int n = 0; /* number of args */
  10390. u8 str[20] = {0};
  10391. /* Check where is the returned data */
  10392. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  10393. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ))
  10394. n = priv_args[k].get_args & IW_PRIV_SIZE_MASK;
  10395. else
  10396. n = wdata.data.length;
  10397. output = rtw_zmalloc(4096);
  10398. if (NULL == output) {
  10399. err = -ENOMEM;
  10400. goto exit;
  10401. }
  10402. switch (priv_args[k].get_args & IW_PRIV_TYPE_MASK) {
  10403. case IW_PRIV_TYPE_BYTE:
  10404. /* Display args */
  10405. for (j = 0; j < n; j++) {
  10406. sprintf(str, "%d ", extra[j]);
  10407. len = strlen(str);
  10408. output_len = strlen(output);
  10409. if ((output_len + len + 1) > 4096) {
  10410. err = -E2BIG;
  10411. goto exit;
  10412. }
  10413. _rtw_memcpy(output + output_len, str, len);
  10414. }
  10415. break;
  10416. case IW_PRIV_TYPE_INT:
  10417. /* Display args */
  10418. for (j = 0; j < n; j++) {
  10419. sprintf(str, "%d ", ((__s32 *)extra)[j]);
  10420. len = strlen(str);
  10421. output_len = strlen(output);
  10422. if ((output_len + len + 1) > 4096) {
  10423. err = -E2BIG;
  10424. goto exit;
  10425. }
  10426. _rtw_memcpy(output + output_len, str, len);
  10427. }
  10428. break;
  10429. case IW_PRIV_TYPE_CHAR:
  10430. /* Display args */
  10431. _rtw_memcpy(output, extra, n);
  10432. break;
  10433. default:
  10434. RTW_INFO("%s: Not yet implemented...\n", __func__);
  10435. err = -1;
  10436. goto exit;
  10437. }
  10438. output_len = strlen(output) + 1;
  10439. wrq_data->data.length = output_len;
  10440. if (copy_to_user(wrq_data->data.pointer, output, output_len)) {
  10441. err = -EFAULT;
  10442. goto exit;
  10443. }
  10444. } /* if args to set */
  10445. else
  10446. wrq_data->data.length = 0;
  10447. exit:
  10448. if (input)
  10449. rtw_mfree(input, input_len);
  10450. if (buffer)
  10451. rtw_mfree(buffer, 4096);
  10452. if (output)
  10453. rtw_mfree(output, 4096);
  10454. return err;
  10455. }
  10456. #ifdef CONFIG_COMPAT
  10457. static int rtw_ioctl_compat_wext_private(struct net_device *dev, struct ifreq *rq)
  10458. {
  10459. struct compat_iw_point iwp_compat;
  10460. union iwreq_data wrq_data;
  10461. int err = 0;
  10462. RTW_INFO("%s:...\n", __func__);
  10463. if (copy_from_user(&iwp_compat, rq->ifr_ifru.ifru_data, sizeof(struct compat_iw_point)))
  10464. return -EFAULT;
  10465. wrq_data.data.pointer = compat_ptr(iwp_compat.pointer);
  10466. wrq_data.data.length = iwp_compat.length;
  10467. wrq_data.data.flags = iwp_compat.flags;
  10468. err = _rtw_ioctl_wext_private(dev, &wrq_data);
  10469. iwp_compat.pointer = ptr_to_compat(wrq_data.data.pointer);
  10470. iwp_compat.length = wrq_data.data.length;
  10471. iwp_compat.flags = wrq_data.data.flags;
  10472. if (copy_to_user(rq->ifr_ifru.ifru_data, &iwp_compat, sizeof(struct compat_iw_point)))
  10473. return -EFAULT;
  10474. return err;
  10475. }
  10476. #endif /* CONFIG_COMPAT */
  10477. static int rtw_ioctl_standard_wext_private(struct net_device *dev, struct ifreq *rq)
  10478. {
  10479. struct iw_point *iwp;
  10480. union iwreq_data wrq_data;
  10481. int err = 0;
  10482. iwp = &wrq_data.data;
  10483. RTW_INFO("%s:...\n", __func__);
  10484. if (copy_from_user(iwp, rq->ifr_ifru.ifru_data, sizeof(struct iw_point)))
  10485. return -EFAULT;
  10486. err = _rtw_ioctl_wext_private(dev, &wrq_data);
  10487. if (copy_to_user(rq->ifr_ifru.ifru_data, iwp, sizeof(struct iw_point)))
  10488. return -EFAULT;
  10489. return err;
  10490. }
  10491. static int rtw_ioctl_wext_private(struct net_device *dev, struct ifreq *rq)
  10492. {
  10493. #ifdef CONFIG_COMPAT
  10494. #if (KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE)
  10495. if (is_compat_task())
  10496. #else
  10497. if (in_compat_syscall())
  10498. #endif
  10499. return rtw_ioctl_compat_wext_private(dev, rq);
  10500. else
  10501. #endif /* CONFIG_COMPAT */
  10502. return rtw_ioctl_standard_wext_private(dev, rq);
  10503. }
  10504. int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  10505. {
  10506. struct iwreq *wrq = (struct iwreq *)rq;
  10507. int ret = 0;
  10508. switch (cmd) {
  10509. case RTL_IOCTL_WPA_SUPPLICANT:
  10510. ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
  10511. break;
  10512. #ifdef CONFIG_AP_MODE
  10513. case RTL_IOCTL_HOSTAPD:
  10514. ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
  10515. break;
  10516. #ifdef CONFIG_WIRELESS_EXT
  10517. case SIOCSIWMODE:
  10518. ret = rtw_wx_set_mode(dev, NULL, &wrq->u, NULL);
  10519. break;
  10520. #endif
  10521. #endif /* CONFIG_AP_MODE */
  10522. case SIOCDEVPRIVATE:
  10523. ret = rtw_ioctl_wext_private(dev, rq);
  10524. break;
  10525. case (SIOCDEVPRIVATE+1):
  10526. ret = rtw_android_priv_cmd(dev, rq, cmd);
  10527. break;
  10528. default:
  10529. ret = -EOPNOTSUPP;
  10530. break;
  10531. }
  10532. return ret;
  10533. }