ioctl_linux.c 352 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #define _IOCTL_LINUX_C_
  21. #include <drv_types.h>
  22. //#ifdef CONFIG_MP_INCLUDED
  23. #include <rtw_mp_ioctl.h>
  24. #include "../../hal/OUTSRC/odm_precomp.h"
  25. //#endif
  26. #if defined(CONFIG_RTL8723A)
  27. #include "rtl8723a_hal.h"
  28. #include <rtw_bt_mp.h>
  29. #endif
  30. #if defined(CONFIG_RTL8723B)
  31. #include <rtw_bt_mp.h>
  32. #endif
  33. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27))
  34. #define iwe_stream_add_event(a, b, c, d, e) iwe_stream_add_event(b, c, d, e)
  35. #define iwe_stream_add_point(a, b, c, d, e) iwe_stream_add_point(b, c, d, e)
  36. #endif
  37. #define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
  38. #define SCAN_ITEM_SIZE 768
  39. #define MAX_CUSTOM_LEN 64
  40. #define RATE_COUNT 4
  41. #ifdef CONFIG_GLOBAL_UI_PID
  42. extern int ui_pid[3];
  43. #endif
  44. // combo scan
  45. #define WEXT_CSCAN_AMOUNT 9
  46. #define WEXT_CSCAN_BUF_LEN 360
  47. #define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
  48. #define WEXT_CSCAN_HEADER_SIZE 12
  49. #define WEXT_CSCAN_SSID_SECTION 'S'
  50. #define WEXT_CSCAN_CHANNEL_SECTION 'C'
  51. #define WEXT_CSCAN_NPROBE_SECTION 'N'
  52. #define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
  53. #define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
  54. #define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
  55. #define WEXT_CSCAN_TYPE_SECTION 'T'
  56. extern u8 key_2char2num(u8 hch, u8 lch);
  57. extern u8 str_2char2num(u8 hch, u8 lch);
  58. extern u8 convert_ip_addr(u8 hch, u8 mch, u8 lch);
  59. u32 rtw_rates[] = {1000000,2000000,5500000,11000000,
  60. 6000000,9000000,12000000,18000000,24000000,36000000,48000000,54000000};
  61. static const char * const iw_operation_mode[] =
  62. {
  63. "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", "Secondary", "Monitor"
  64. };
  65. static int hex2num_i(char c)
  66. {
  67. if (c >= '0' && c <= '9')
  68. return c - '0';
  69. if (c >= 'a' && c <= 'f')
  70. return c - 'a' + 10;
  71. if (c >= 'A' && c <= 'F')
  72. return c - 'A' + 10;
  73. return -1;
  74. }
  75. static int hex2byte_i(const char *hex)
  76. {
  77. int a, b;
  78. a = hex2num_i(*hex++);
  79. if (a < 0)
  80. return -1;
  81. b = hex2num_i(*hex++);
  82. if (b < 0)
  83. return -1;
  84. return (a << 4) | b;
  85. }
  86. /**
  87. * hwaddr_aton - Convert ASCII string to MAC address
  88. * @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
  89. * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
  90. * Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
  91. */
  92. static int hwaddr_aton_i(const char *txt, u8 *addr)
  93. {
  94. int i;
  95. for (i = 0; i < 6; i++) {
  96. int a, b;
  97. a = hex2num_i(*txt++);
  98. if (a < 0)
  99. return -1;
  100. b = hex2num_i(*txt++);
  101. if (b < 0)
  102. return -1;
  103. *addr++ = (a << 4) | b;
  104. if (i < 5 && *txt++ != ':')
  105. return -1;
  106. }
  107. return 0;
  108. }
  109. static void indicate_wx_custom_event(_adapter *padapter, char *msg)
  110. {
  111. u8 *buff, *p;
  112. union iwreq_data wrqu;
  113. if (strlen(msg) > IW_CUSTOM_MAX) {
  114. DBG_871X("%s strlen(msg):%zu > IW_CUSTOM_MAX:%u\n", __FUNCTION__ , strlen(msg), IW_CUSTOM_MAX);
  115. return;
  116. }
  117. buff = rtw_zmalloc(IW_CUSTOM_MAX+1);
  118. if(!buff)
  119. return;
  120. _rtw_memcpy(buff, msg, strlen(msg));
  121. _rtw_memset(&wrqu,0,sizeof(wrqu));
  122. wrqu.data.length = strlen(msg);
  123. DBG_871X("%s %s\n", __FUNCTION__, buff);
  124. #ifndef CONFIG_IOCTL_CFG80211
  125. wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
  126. #endif
  127. rtw_mfree(buff, IW_CUSTOM_MAX+1);
  128. }
  129. static void request_wps_pbc_event(_adapter *padapter)
  130. {
  131. u8 *buff, *p;
  132. union iwreq_data wrqu;
  133. buff = rtw_malloc(IW_CUSTOM_MAX);
  134. if(!buff)
  135. return;
  136. _rtw_memset(buff, 0, IW_CUSTOM_MAX);
  137. p=buff;
  138. p+=sprintf(p, "WPS_PBC_START.request=TRUE");
  139. _rtw_memset(&wrqu,0,sizeof(wrqu));
  140. wrqu.data.length = p-buff;
  141. wrqu.data.length = (wrqu.data.length<IW_CUSTOM_MAX) ? wrqu.data.length:IW_CUSTOM_MAX;
  142. DBG_871X("%s\n", __FUNCTION__);
  143. #ifndef CONFIG_IOCTL_CFG80211
  144. wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
  145. #endif
  146. if(buff)
  147. {
  148. rtw_mfree(buff, IW_CUSTOM_MAX);
  149. }
  150. }
  151. void rtw_request_wps_pbc_event(_adapter *padapter)
  152. {
  153. #ifdef RTK_DMP_PLATFORM
  154. #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12))
  155. kobject_uevent(&padapter->pnetdev->dev.kobj, KOBJ_NET_PBC);
  156. #else
  157. kobject_hotplug(&padapter->pnetdev->class_dev.kobj, KOBJ_NET_PBC);
  158. #endif
  159. #else
  160. if ( padapter->pid[0] == 0 )
  161. { // 0 is the default value and it means the application monitors the HW PBC doesn't privde its pid to driver.
  162. return;
  163. }
  164. rtw_signal_process(padapter->pid[0], SIGUSR1);
  165. #endif
  166. rtw_led_control(padapter, LED_CTL_START_WPS_BOTTON);
  167. }
  168. void indicate_wx_scan_complete_event(_adapter *padapter)
  169. {
  170. union iwreq_data wrqu;
  171. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  172. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  173. //DBG_871X("+rtw_indicate_wx_scan_complete_event\n");
  174. #ifndef CONFIG_IOCTL_CFG80211
  175. wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
  176. #endif
  177. }
  178. void rtw_indicate_wx_assoc_event(_adapter *padapter)
  179. {
  180. union iwreq_data wrqu;
  181. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  182. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  183. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  184. _rtw_memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
  185. DBG_871X("BSSID:" MAC_FMT "\n", MAC_ARG(pmlmepriv->cur_network.network.MacAddress));
  186. DBG_871X_LEVEL(_drv_always_, "assoc success\n");
  187. #ifndef CONFIG_IOCTL_CFG80211
  188. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  189. #endif
  190. }
  191. void rtw_indicate_wx_disassoc_event(_adapter *padapter)
  192. {
  193. union iwreq_data wrqu;
  194. _rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
  195. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  196. _rtw_memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  197. #ifndef CONFIG_IOCTL_CFG80211
  198. DBG_871X_LEVEL(_drv_always_, "indicate disassoc\n");
  199. wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
  200. #endif
  201. }
  202. /*
  203. uint rtw_is_cckrates_included(u8 *rate)
  204. {
  205. u32 i = 0;
  206. while(rate[i]!=0)
  207. {
  208. if ( (((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
  209. (((rate[i]) & 0x7f) == 11) || (((rate[i]) & 0x7f) == 22) )
  210. return _TRUE;
  211. i++;
  212. }
  213. return _FALSE;
  214. }
  215. uint rtw_is_cckratesonly_included(u8 *rate)
  216. {
  217. u32 i = 0;
  218. while(rate[i]!=0)
  219. {
  220. if ( (((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
  221. (((rate[i]) & 0x7f) != 11) && (((rate[i]) & 0x7f) != 22) )
  222. return _FALSE;
  223. i++;
  224. }
  225. return _TRUE;
  226. }
  227. */
  228. static char *translate_scan(_adapter *padapter,
  229. struct iw_request_info* info, struct wlan_network *pnetwork,
  230. char *start, char *stop)
  231. {
  232. struct iw_event iwe;
  233. u16 cap;
  234. u32 ht_ielen = 0, vht_ielen = 0;
  235. char custom[MAX_CUSTOM_LEN];
  236. char *p;
  237. u16 max_rate=0, rate, ht_cap=_FALSE, vht_cap = _FALSE;
  238. u32 i = 0;
  239. char *current_val;
  240. long rssi;
  241. u8 bw_40MHz=0, short_GI=0, bw_160MHz=0, vht_highest_rate = 0;
  242. u16 mcs_rate=0, vht_data_rate=0;
  243. struct registry_priv *pregpriv = &padapter->registrypriv;
  244. #ifdef CONFIG_P2P
  245. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  246. #endif //CONFIG_P2P
  247. #ifdef CONFIG_P2P
  248. #ifdef CONFIG_WFD
  249. if ( SCAN_RESULT_ALL == pwdinfo->wfd_info->scan_result_type )
  250. {
  251. }
  252. else if ( ( SCAN_RESULT_P2P_ONLY == pwdinfo->wfd_info->scan_result_type ) ||
  253. ( SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type ) )
  254. #endif // CONFIG_WFD
  255. {
  256. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  257. {
  258. u32 blnGotP2PIE = _FALSE;
  259. // User is doing the P2P device discovery
  260. // The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE.
  261. // If not, the driver should ignore this AP and go to the next AP.
  262. // Verifying the SSID
  263. if ( _rtw_memcmp( pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN ) )
  264. {
  265. u32 p2pielen = 0;
  266. // Verifying the P2P IE
  267. if ( rtw_get_p2p_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen) )
  268. {
  269. blnGotP2PIE = _TRUE;
  270. }
  271. }
  272. if ( blnGotP2PIE == _FALSE )
  273. {
  274. return start;
  275. }
  276. }
  277. }
  278. #ifdef CONFIG_WFD
  279. if ( SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type )
  280. {
  281. u32 blnGotWFD = _FALSE;
  282. u8 wfd_ie[ 128 ] = { 0x00 };
  283. uint wfd_ielen = 0;
  284. if ( rtw_get_wfd_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, wfd_ie, &wfd_ielen ) )
  285. {
  286. u8 wfd_devinfo[ 6 ] = { 0x00 };
  287. uint wfd_devlen = 6;
  288. if ( rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, wfd_devinfo, &wfd_devlen) )
  289. {
  290. if ( pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_PSINK )
  291. {
  292. // the first two bits will indicate the WFD device type
  293. if ( ( wfd_devinfo[ 1 ] & 0x03 ) == WFD_DEVINFO_SOURCE )
  294. {
  295. // If this device is Miracast PSink device, the scan reuslt should just provide the Miracast source.
  296. blnGotWFD = _TRUE;
  297. }
  298. }
  299. else if ( pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_SOURCE )
  300. {
  301. // the first two bits will indicate the WFD device type
  302. if ( ( wfd_devinfo[ 1 ] & 0x03 ) == WFD_DEVINFO_PSINK )
  303. {
  304. // If this device is Miracast source device, the scan reuslt should just provide the Miracast PSink.
  305. // Todo: How about the SSink?!
  306. blnGotWFD = _TRUE;
  307. }
  308. }
  309. }
  310. }
  311. if ( blnGotWFD == _FALSE )
  312. {
  313. return start;
  314. }
  315. }
  316. #endif // CONFIG_WFD
  317. #endif //CONFIG_P2P
  318. /* AP MAC address */
  319. iwe.cmd = SIOCGIWAP;
  320. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  321. _rtw_memcpy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
  322. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
  323. /* Add the ESSID */
  324. iwe.cmd = SIOCGIWESSID;
  325. iwe.u.data.flags = 1;
  326. iwe.u.data.length = min((u16)pnetwork->network.Ssid.SsidLength, (u16)32);
  327. start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
  328. //parsing HT_CAP_IE
  329. p = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength-12);
  330. if(p && ht_ielen>0)
  331. {
  332. struct rtw_ieee80211_ht_cap *pht_capie;
  333. ht_cap = _TRUE;
  334. pht_capie = (struct rtw_ieee80211_ht_cap *)(p+2);
  335. _rtw_memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
  336. bw_40MHz = (pht_capie->cap_info&IEEE80211_HT_CAP_SUP_WIDTH) ? 1:0;
  337. short_GI = (pht_capie->cap_info&(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40)) ? 1:0;
  338. }
  339. #ifdef CONFIG_80211AC_VHT
  340. //parsing VHT_CAP_IE
  341. p = rtw_get_ie(&pnetwork->network.IEs[12], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength-12);
  342. if(p && vht_ielen>0)
  343. {
  344. u8 mcs_map[2];
  345. vht_cap = _TRUE;
  346. bw_160MHz = GET_VHT_CAPABILITY_ELE_CHL_WIDTH(p+2);
  347. if(bw_160MHz)
  348. short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI160M(p+2);
  349. else
  350. short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI80M(p+2);
  351. _rtw_memcpy(mcs_map, GET_VHT_CAPABILITY_ELE_TX_MCS(p+2), 2);
  352. vht_highest_rate = rtw_get_vht_highest_rate(padapter, mcs_map);
  353. vht_data_rate = rtw_vht_data_rate(CHANNEL_WIDTH_80, short_GI, vht_highest_rate);
  354. }
  355. #endif
  356. /* Add the protocol name */
  357. iwe.cmd = SIOCGIWNAME;
  358. if ((rtw_is_cckratesonly_included((u8*)&pnetwork->network.SupportedRates)) == _TRUE)
  359. {
  360. if(ht_cap == _TRUE)
  361. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
  362. else
  363. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
  364. }
  365. else if ((rtw_is_cckrates_included((u8*)&pnetwork->network.SupportedRates)) == _TRUE)
  366. {
  367. if(ht_cap == _TRUE)
  368. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
  369. else
  370. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
  371. }
  372. else
  373. {
  374. if(pnetwork->network.Configuration.DSConfig > 14)
  375. {
  376. if(vht_cap == _TRUE)
  377. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11AC");
  378. else if(ht_cap == _TRUE)
  379. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11an");
  380. else
  381. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11a");
  382. }
  383. else
  384. {
  385. if(ht_cap == _TRUE)
  386. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
  387. else
  388. snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
  389. }
  390. }
  391. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
  392. /* Add mode */
  393. iwe.cmd = SIOCGIWMODE;
  394. _rtw_memcpy((u8 *)&cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
  395. cap = le16_to_cpu(cap);
  396. if(cap & (WLAN_CAPABILITY_IBSS |WLAN_CAPABILITY_BSS)){
  397. if (cap & WLAN_CAPABILITY_BSS)
  398. iwe.u.mode = IW_MODE_MASTER;
  399. else
  400. iwe.u.mode = IW_MODE_ADHOC;
  401. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
  402. }
  403. if(pnetwork->network.Configuration.DSConfig<1 /*|| pnetwork->network.Configuration.DSConfig>14*/)
  404. pnetwork->network.Configuration.DSConfig = 1;
  405. /* Add frequency/channel */
  406. iwe.cmd = SIOCGIWFREQ;
  407. iwe.u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
  408. iwe.u.freq.e = 1;
  409. iwe.u.freq.i = pnetwork->network.Configuration.DSConfig;
  410. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
  411. /* Add encryption capability */
  412. iwe.cmd = SIOCGIWENCODE;
  413. if (cap & WLAN_CAPABILITY_PRIVACY)
  414. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  415. else
  416. iwe.u.data.flags = IW_ENCODE_DISABLED;
  417. iwe.u.data.length = 0;
  418. start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
  419. /*Add basic and extended rates */
  420. max_rate = 0;
  421. p = custom;
  422. p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
  423. while(pnetwork->network.SupportedRates[i]!=0)
  424. {
  425. rate = pnetwork->network.SupportedRates[i]&0x7F;
  426. if (rate > max_rate)
  427. max_rate = rate;
  428. p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
  429. "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
  430. i++;
  431. }
  432. if(vht_cap == _TRUE) {
  433. max_rate = vht_data_rate;
  434. }
  435. else if(ht_cap == _TRUE)
  436. {
  437. if(mcs_rate&0x8000)//MCS15
  438. {
  439. max_rate = (bw_40MHz) ? ((short_GI)?300:270):((short_GI)?144:130);
  440. }
  441. else if(mcs_rate&0x0080)//MCS7
  442. {
  443. max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
  444. }
  445. else//default MCS7
  446. {
  447. //DBG_871X("wx_get_scan, mcs_rate_bitmap=0x%x\n", mcs_rate);
  448. max_rate = (bw_40MHz) ? ((short_GI)?150:135):((short_GI)?72:65);
  449. }
  450. max_rate = max_rate*2;//Mbps/2;
  451. }
  452. iwe.cmd = SIOCGIWRATE;
  453. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  454. iwe.u.bitrate.value = max_rate * 500000;
  455. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN);
  456. //parsing WPA/WPA2 IE
  457. {
  458. u8 buf[MAX_WPA_IE_LEN];
  459. u8 wpa_ie[255],rsn_ie[255];
  460. u16 wpa_len=0,rsn_len=0;
  461. u8 *p;
  462. sint out_len=0;
  463. out_len=rtw_get_sec_ie(pnetwork->network.IEs ,pnetwork->network.IELength,rsn_ie,&rsn_len,wpa_ie,&wpa_len);
  464. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: ssid=%s\n",pnetwork->network.Ssid.Ssid));
  465. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: wpa_len=%d rsn_len=%d\n",wpa_len,rsn_len));
  466. if (wpa_len > 0)
  467. {
  468. p=buf;
  469. _rtw_memset(buf, 0, MAX_WPA_IE_LEN);
  470. p += sprintf(p, "wpa_ie=");
  471. for (i = 0; i < wpa_len; i++) {
  472. p += sprintf(p, "%02x", wpa_ie[i]);
  473. }
  474. _rtw_memset(&iwe, 0, sizeof(iwe));
  475. iwe.cmd = IWEVCUSTOM;
  476. iwe.u.data.length = strlen(buf);
  477. start = iwe_stream_add_point(info, start, stop, &iwe,buf);
  478. _rtw_memset(&iwe, 0, sizeof(iwe));
  479. iwe.cmd =IWEVGENIE;
  480. iwe.u.data.length = wpa_len;
  481. start = iwe_stream_add_point(info, start, stop, &iwe, wpa_ie);
  482. }
  483. if (rsn_len > 0)
  484. {
  485. p = buf;
  486. _rtw_memset(buf, 0, MAX_WPA_IE_LEN);
  487. p += sprintf(p, "rsn_ie=");
  488. for (i = 0; i < rsn_len; i++) {
  489. p += sprintf(p, "%02x", rsn_ie[i]);
  490. }
  491. _rtw_memset(&iwe, 0, sizeof(iwe));
  492. iwe.cmd = IWEVCUSTOM;
  493. iwe.u.data.length = strlen(buf);
  494. start = iwe_stream_add_point(info, start, stop, &iwe,buf);
  495. _rtw_memset(&iwe, 0, sizeof(iwe));
  496. iwe.cmd =IWEVGENIE;
  497. iwe.u.data.length = rsn_len;
  498. start = iwe_stream_add_point(info, start, stop, &iwe, rsn_ie);
  499. }
  500. }
  501. { //parsing WPS IE
  502. uint cnt = 0,total_ielen;
  503. u8 *wpsie_ptr=NULL;
  504. uint wps_ielen = 0;
  505. u8 *ie_ptr = pnetwork->network.IEs +_FIXED_IE_LENGTH_;
  506. total_ielen= pnetwork->network.IELength - _FIXED_IE_LENGTH_;
  507. while(cnt < total_ielen)
  508. {
  509. if(rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen>2))
  510. {
  511. wpsie_ptr = &ie_ptr[cnt];
  512. iwe.cmd =IWEVGENIE;
  513. iwe.u.data.length = (u16)wps_ielen;
  514. start = iwe_stream_add_point(info, start, stop, &iwe, wpsie_ptr);
  515. }
  516. cnt+=ie_ptr[cnt+1]+2; //goto next
  517. }
  518. }
  519. #ifdef CONFIG_WAPI_SUPPORT
  520. {
  521. sint out_len_wapi=0;
  522. /* here use static for stack size */
  523. static u8 buf_wapi[MAX_WAPI_IE_LEN];
  524. static u8 wapi_ie[MAX_WAPI_IE_LEN];
  525. u16 wapi_len=0;
  526. u16 i;
  527. _rtw_memset(buf_wapi, 0, MAX_WAPI_IE_LEN);
  528. _rtw_memset(wapi_ie, 0, MAX_WAPI_IE_LEN);
  529. out_len_wapi=rtw_get_wapi_ie(pnetwork->network.IEs ,pnetwork->network.IELength,wapi_ie,&wapi_len);
  530. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: ssid=%s\n",pnetwork->network.Ssid.Ssid));
  531. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan: wapi_len=%d \n",wapi_len));
  532. DBG_871X("rtw_wx_get_scan: %s ",pnetwork->network.Ssid.Ssid);
  533. DBG_871X("rtw_wx_get_scan: ssid = %d ",wapi_len);
  534. if (wapi_len > 0)
  535. {
  536. p=buf_wapi;
  537. _rtw_memset(buf_wapi, 0, MAX_WAPI_IE_LEN);
  538. p += sprintf(p, "wapi_ie=");
  539. for (i = 0; i < wapi_len; i++) {
  540. p += sprintf(p, "%02x", wapi_ie[i]);
  541. }
  542. _rtw_memset(&iwe, 0, sizeof(iwe));
  543. iwe.cmd = IWEVCUSTOM;
  544. iwe.u.data.length = strlen(buf_wapi);
  545. start = iwe_stream_add_point(info, start, stop, &iwe,buf_wapi);
  546. _rtw_memset(&iwe, 0, sizeof(iwe));
  547. iwe.cmd =IWEVGENIE;
  548. iwe.u.data.length = wapi_len;
  549. start = iwe_stream_add_point(info, start, stop, &iwe, wapi_ie);
  550. }
  551. }
  552. #endif
  553. {
  554. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  555. u8 ss, sq;
  556. /* Add quality statistics */
  557. iwe.cmd = IWEVQUAL;
  558. iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID
  559. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  560. | IW_QUAL_DBM
  561. #endif
  562. ;
  563. if ( check_fwstate(pmlmepriv, _FW_LINKED)== _TRUE &&
  564. is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) {
  565. ss = padapter->recvpriv.signal_strength;
  566. sq = padapter->recvpriv.signal_qual;
  567. } else {
  568. ss = pnetwork->network.PhyInfo.SignalStrength;
  569. sq = pnetwork->network.PhyInfo.SignalQuality;
  570. }
  571. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  572. iwe.u.qual.level = (u8) translate_percentage_to_dbm(ss);//dbm
  573. #else
  574. iwe.u.qual.level = (u8)ss;//%
  575. #ifdef CONFIG_BT_COEXIST
  576. BT_SignalCompensation(padapter, &iwe.u.qual.level, NULL);
  577. #endif // CONFIG_BT_COEXIST
  578. #endif
  579. iwe.u.qual.qual = (u8)sq; // signal quality
  580. #ifdef CONFIG_PLATFORM_ROCKCHIPS
  581. iwe.u.qual.noise = -100; // noise level suggest by zhf@rockchips
  582. #else
  583. iwe.u.qual.noise = 0; // noise level
  584. #endif //CONFIG_PLATFORM_ROCKCHIPS
  585. //DBG_871X("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);
  586. start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
  587. }
  588. return start;
  589. }
  590. static int wpa_set_auth_algs(struct net_device *dev, u32 value)
  591. {
  592. _adapter *padapter = (_adapter *) rtw_netdev_priv(dev);
  593. int ret = 0;
  594. if ((value & AUTH_ALG_SHARED_KEY)&&(value & AUTH_ALG_OPEN_SYSTEM))
  595. {
  596. DBG_871X("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n",value);
  597. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  598. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  599. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  600. }
  601. else if (value & AUTH_ALG_SHARED_KEY)
  602. {
  603. DBG_871X("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY [value:0x%x]\n",value);
  604. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  605. #ifdef CONFIG_PLATFORM_MT53XX
  606. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  607. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  608. #else
  609. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
  610. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  611. #endif
  612. }
  613. else if(value & AUTH_ALG_OPEN_SYSTEM)
  614. {
  615. DBG_871X("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n");
  616. //padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  617. if(padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK)
  618. {
  619. #ifdef CONFIG_PLATFORM_MT53XX
  620. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
  621. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  622. #else
  623. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
  624. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  625. #endif
  626. }
  627. }
  628. else if(value & AUTH_ALG_LEAP)
  629. {
  630. DBG_871X("wpa_set_auth_algs, AUTH_ALG_LEAP\n");
  631. }
  632. else
  633. {
  634. DBG_871X("wpa_set_auth_algs, error!\n");
  635. ret = -EINVAL;
  636. }
  637. return ret;
  638. }
  639. static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  640. {
  641. int ret = 0;
  642. u32 wep_key_idx, wep_key_len,wep_total_len;
  643. NDIS_802_11_WEP *pwep = NULL;
  644. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  645. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  646. struct security_priv *psecuritypriv = &padapter->securitypriv;
  647. #ifdef CONFIG_P2P
  648. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  649. #endif //CONFIG_P2P
  650. _func_enter_;
  651. param->u.crypt.err = 0;
  652. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  653. if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len)
  654. {
  655. ret = -EINVAL;
  656. goto exit;
  657. }
  658. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  659. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  660. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  661. {
  662. if (param->u.crypt.idx >= WEP_KEYS)
  663. {
  664. ret = -EINVAL;
  665. goto exit;
  666. }
  667. } else {
  668. #ifdef CONFIG_WAPI_SUPPORT
  669. if (strcmp(param->u.crypt.alg, "SMS4"))
  670. #endif
  671. {
  672. ret = -EINVAL;
  673. goto exit;
  674. }
  675. }
  676. if (strcmp(param->u.crypt.alg, "WEP") == 0)
  677. {
  678. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("wpa_set_encryption, crypt.alg = WEP\n"));
  679. DBG_871X("wpa_set_encryption, crypt.alg = WEP\n");
  680. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  681. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  682. padapter->securitypriv.dot118021XGrpPrivacy=_WEP40_;
  683. wep_key_idx = param->u.crypt.idx;
  684. wep_key_len = param->u.crypt.key_len;
  685. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("(1)wep_key_idx=%d\n", wep_key_idx));
  686. DBG_871X("(1)wep_key_idx=%d\n", wep_key_idx);
  687. if (wep_key_idx > WEP_KEYS)
  688. return -EINVAL;
  689. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("(2)wep_key_idx=%d\n", wep_key_idx));
  690. if (wep_key_len > 0)
  691. {
  692. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  693. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  694. pwep =(NDIS_802_11_WEP *) rtw_malloc(wep_total_len);
  695. if(pwep == NULL){
  696. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,(" wpa_set_encryption: pwep allocate fail !!!\n"));
  697. goto exit;
  698. }
  699. _rtw_memset(pwep, 0, wep_total_len);
  700. pwep->KeyLength = wep_key_len;
  701. pwep->Length = wep_total_len;
  702. if(wep_key_len==13)
  703. {
  704. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  705. padapter->securitypriv.dot118021XGrpPrivacy=_WEP104_;
  706. }
  707. }
  708. else {
  709. ret = -EINVAL;
  710. goto exit;
  711. }
  712. pwep->KeyIndex = wep_key_idx;
  713. pwep->KeyIndex |= 0x80000000;
  714. _rtw_memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
  715. if(param->u.crypt.set_tx)
  716. {
  717. DBG_871X("wep, set_tx=1\n");
  718. if(rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
  719. {
  720. ret = -EOPNOTSUPP ;
  721. }
  722. }
  723. else
  724. {
  725. DBG_871X("wep, set_tx=0\n");
  726. //don't update "psecuritypriv->dot11PrivacyAlgrthm" and
  727. //"psecuritypriv->dot11PrivacyKeyIndex=keyid", but can rtw_set_key to fw/cam
  728. if (wep_key_idx >= WEP_KEYS) {
  729. ret = -EOPNOTSUPP ;
  730. goto exit;
  731. }
  732. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
  733. psecuritypriv->dot11DefKeylen[wep_key_idx]=pwep->KeyLength;
  734. rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0);
  735. }
  736. goto exit;
  737. }
  738. if(padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) // 802_1x
  739. {
  740. struct sta_info * psta,*pbcmc_sta;
  741. struct sta_priv * pstapriv = &padapter->stapriv;
  742. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) //sta mode
  743. {
  744. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  745. if (psta == NULL) {
  746. //DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail \n"));
  747. }
  748. else
  749. {
  750. //Jeff: don't disable ieee8021x_blocked while clearing key
  751. if (strcmp(param->u.crypt.alg, "none") != 0)
  752. psta->ieee8021x_blocked = _FALSE;
  753. if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
  754. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  755. {
  756. psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  757. }
  758. if(param->u.crypt.set_tx ==1)//pairwise key
  759. {
  760. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  761. if(strcmp(param->u.crypt.alg, "TKIP") == 0)//set mic key
  762. {
  763. //DEBUG_ERR(("\nset key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
  764. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  765. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  766. padapter->securitypriv.busetkipkey=_FALSE;
  767. //_set_timer(&padapter->securitypriv.tkip_timer, 50);
  768. }
  769. //DEBUG_ERR((" param->u.crypt.key_len=%d\n",param->u.crypt.key_len));
  770. DBG_871X(" ~~~~set sta key:unicastkey\n");
  771. rtw_setstakey_cmd(padapter, (unsigned char *)psta, _TRUE);
  772. }
  773. else//group key
  774. {
  775. _rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key,(param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  776. _rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]),8);
  777. _rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]),8);
  778. padapter->securitypriv.binstallGrpkey = _TRUE;
  779. //DEBUG_ERR((" param->u.crypt.key_len=%d\n", param->u.crypt.key_len));
  780. DBG_871X(" ~~~~set sta key:groupkey\n");
  781. padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
  782. rtw_set_key(padapter,&padapter->securitypriv,param->u.crypt.idx, 1);
  783. #ifdef CONFIG_P2P
  784. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  785. {
  786. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
  787. }
  788. #endif //CONFIG_P2P
  789. }
  790. }
  791. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  792. if(pbcmc_sta==NULL)
  793. {
  794. //DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null \n"));
  795. }
  796. else
  797. {
  798. //Jeff: don't disable ieee8021x_blocked while clearing key
  799. if (strcmp(param->u.crypt.alg, "none") != 0)
  800. pbcmc_sta->ieee8021x_blocked = _FALSE;
  801. if((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)||
  802. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  803. {
  804. pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  805. }
  806. }
  807. }
  808. else if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) //adhoc mode
  809. {
  810. }
  811. }
  812. #ifdef CONFIG_WAPI_SUPPORT
  813. if (strcmp(param->u.crypt.alg, "SMS4") == 0)
  814. {
  815. PRT_WAPI_T pWapiInfo = &padapter->wapiInfo;
  816. PRT_WAPI_STA_INFO pWapiSta;
  817. u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  818. u8 WapiAEPNInitialValueSrc[16] = {0x37,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  819. u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ;
  820. if(param->u.crypt.set_tx == 1)
  821. {
  822. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  823. if(_rtw_memcmp(pWapiSta->PeerMacAddr,param->sta_addr,6))
  824. {
  825. _rtw_memcpy(pWapiSta->lastTxUnicastPN,WapiASUEPNInitialValueSrc,16);
  826. pWapiSta->wapiUsk.bSet = true;
  827. _rtw_memcpy(pWapiSta->wapiUsk.dataKey,param->u.crypt.key,16);
  828. _rtw_memcpy(pWapiSta->wapiUsk.micKey,param->u.crypt.key+16,16);
  829. pWapiSta->wapiUsk.keyId = param->u.crypt.idx ;
  830. pWapiSta->wapiUsk.bTxEnable = true;
  831. _rtw_memcpy(pWapiSta->lastRxUnicastPNBEQueue,WapiAEPNInitialValueSrc,16);
  832. _rtw_memcpy(pWapiSta->lastRxUnicastPNBKQueue,WapiAEPNInitialValueSrc,16);
  833. _rtw_memcpy(pWapiSta->lastRxUnicastPNVIQueue,WapiAEPNInitialValueSrc,16);
  834. _rtw_memcpy(pWapiSta->lastRxUnicastPNVOQueue,WapiAEPNInitialValueSrc,16);
  835. _rtw_memcpy(pWapiSta->lastRxUnicastPN,WapiAEPNInitialValueSrc,16);
  836. pWapiSta->wapiUskUpdate.bTxEnable = false;
  837. pWapiSta->wapiUskUpdate.bSet = false;
  838. if (psecuritypriv->sw_encrypt== false || psecuritypriv->sw_decrypt == false)
  839. {
  840. //set unicast key for ASUE
  841. rtw_wapi_set_key(padapter, &pWapiSta->wapiUsk, pWapiSta, false, false);
  842. }
  843. }
  844. }
  845. }
  846. else
  847. {
  848. list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) {
  849. if(_rtw_memcmp(pWapiSta->PeerMacAddr,get_bssid(pmlmepriv),6))
  850. {
  851. pWapiSta->wapiMsk.bSet = true;
  852. _rtw_memcpy(pWapiSta->wapiMsk.dataKey,param->u.crypt.key,16);
  853. _rtw_memcpy(pWapiSta->wapiMsk.micKey,param->u.crypt.key+16,16);
  854. pWapiSta->wapiMsk.keyId = param->u.crypt.idx ;
  855. pWapiSta->wapiMsk.bTxEnable = false;
  856. if(!pWapiSta->bSetkeyOk)
  857. pWapiSta->bSetkeyOk = true;
  858. pWapiSta->bAuthenticateInProgress = false;
  859. _rtw_memcpy(pWapiSta->lastRxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16);
  860. if (psecuritypriv->sw_decrypt == false)
  861. {
  862. //set rx broadcast key for ASUE
  863. rtw_wapi_set_key(padapter, &pWapiSta->wapiMsk, pWapiSta, true, false);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. #endif
  870. exit:
  871. if (pwep) {
  872. rtw_mfree((u8 *)pwep, wep_total_len);
  873. }
  874. _func_exit_;
  875. return ret;
  876. }
  877. static int rtw_set_wpa_ie(_adapter *padapter, char *pie, unsigned short ielen)
  878. {
  879. u8 *buf=NULL, *pos=NULL;
  880. u32 left;
  881. int group_cipher = 0, pairwise_cipher = 0;
  882. int ret = 0;
  883. u8 null_addr[]= {0,0,0,0,0,0};
  884. #ifdef CONFIG_P2P
  885. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  886. #endif //CONFIG_P2P
  887. if((ielen > MAX_WPA_IE_LEN) || (pie == NULL)){
  888. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  889. if(pie == NULL)
  890. return ret;
  891. else
  892. return -EINVAL;
  893. }
  894. if(ielen)
  895. {
  896. buf = rtw_zmalloc(ielen);
  897. if (buf == NULL){
  898. ret = -ENOMEM;
  899. goto exit;
  900. }
  901. _rtw_memcpy(buf, pie , ielen);
  902. //dump
  903. {
  904. int i;
  905. DBG_871X("\n wpa_ie(length:%d):\n", ielen);
  906. for(i=0;i<ielen;i=i+8)
  907. DBG_871X("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]);
  908. }
  909. pos = buf;
  910. if(ielen < RSN_HEADER_LEN){
  911. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("Ie len too short %d\n", ielen));
  912. ret = -1;
  913. goto exit;
  914. }
  915. #if 0
  916. pos += RSN_HEADER_LEN;
  917. left = ielen - RSN_HEADER_LEN;
  918. if (left >= RSN_SELECTOR_LEN){
  919. pos += RSN_SELECTOR_LEN;
  920. left -= RSN_SELECTOR_LEN;
  921. }
  922. else if (left > 0){
  923. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("Ie length mismatch, %u too much \n", left));
  924. ret =-1;
  925. goto exit;
  926. }
  927. #endif
  928. if(rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  929. {
  930. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  931. padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPAPSK;
  932. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
  933. }
  934. if(rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS)
  935. {
  936. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X;
  937. padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeWPA2PSK;
  938. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
  939. }
  940. if (group_cipher == 0)
  941. {
  942. group_cipher = WPA_CIPHER_NONE;
  943. }
  944. if (pairwise_cipher == 0)
  945. {
  946. pairwise_cipher = WPA_CIPHER_NONE;
  947. }
  948. switch(group_cipher)
  949. {
  950. case WPA_CIPHER_NONE:
  951. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  952. padapter->securitypriv.ndisencryptstatus=Ndis802_11EncryptionDisabled;
  953. break;
  954. case WPA_CIPHER_WEP40:
  955. padapter->securitypriv.dot118021XGrpPrivacy=_WEP40_;
  956. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  957. break;
  958. case WPA_CIPHER_TKIP:
  959. padapter->securitypriv.dot118021XGrpPrivacy=_TKIP_;
  960. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  961. break;
  962. case WPA_CIPHER_CCMP:
  963. padapter->securitypriv.dot118021XGrpPrivacy=_AES_;
  964. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  965. break;
  966. case WPA_CIPHER_WEP104:
  967. padapter->securitypriv.dot118021XGrpPrivacy=_WEP104_;
  968. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  969. break;
  970. }
  971. switch(pairwise_cipher)
  972. {
  973. case WPA_CIPHER_NONE:
  974. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  975. padapter->securitypriv.ndisencryptstatus=Ndis802_11EncryptionDisabled;
  976. break;
  977. case WPA_CIPHER_WEP40:
  978. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  979. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  980. break;
  981. case WPA_CIPHER_TKIP:
  982. padapter->securitypriv.dot11PrivacyAlgrthm=_TKIP_;
  983. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  984. break;
  985. case WPA_CIPHER_CCMP:
  986. padapter->securitypriv.dot11PrivacyAlgrthm=_AES_;
  987. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  988. break;
  989. case WPA_CIPHER_WEP104:
  990. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  991. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  992. break;
  993. }
  994. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  995. {//set wps_ie
  996. u16 cnt = 0;
  997. u8 eid, wps_oui[4]={0x0,0x50,0xf2,0x04};
  998. while( cnt < ielen )
  999. {
  1000. eid = buf[cnt];
  1001. if((eid==_VENDOR_SPECIFIC_IE_)&&(_rtw_memcmp(&buf[cnt+2], wps_oui, 4)==_TRUE))
  1002. {
  1003. DBG_871X("SET WPS_IE\n");
  1004. padapter->securitypriv.wps_ie_len = ( (buf[cnt+1]+2) < (MAX_WPA_IE_LEN<<2)) ? (buf[cnt+1]+2):(MAX_WPA_IE_LEN<<2);
  1005. _rtw_memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
  1006. set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
  1007. #ifdef CONFIG_P2P
  1008. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK))
  1009. {
  1010. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_ING);
  1011. }
  1012. #endif //CONFIG_P2P
  1013. cnt += buf[cnt+1]+2;
  1014. break;
  1015. } else {
  1016. cnt += buf[cnt+1]+2; //goto next
  1017. }
  1018. }
  1019. }
  1020. }
  1021. //TKIP and AES disallow multicast packets until installing group key
  1022. if(padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
  1023. || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
  1024. || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
  1025. //WPS open need to enable multicast
  1026. //|| check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE)
  1027. rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
  1028. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  1029. ("rtw_set_wpa_ie: pairwise_cipher=0x%08x padapter->securitypriv.ndisencryptstatus=%d padapter->securitypriv.ndisauthtype=%d\n",
  1030. pairwise_cipher, padapter->securitypriv.ndisencryptstatus, padapter->securitypriv.ndisauthtype));
  1031. exit:
  1032. if (buf) rtw_mfree(buf, ielen);
  1033. return ret;
  1034. }
  1035. static int rtw_wx_get_name(struct net_device *dev,
  1036. struct iw_request_info *info,
  1037. union iwreq_data *wrqu, char *extra)
  1038. {
  1039. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1040. u16 cap;
  1041. u32 ht_ielen = 0;
  1042. char *p;
  1043. u8 ht_cap=_FALSE, vht_cap=_FALSE;
  1044. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1045. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1046. NDIS_802_11_RATES_EX* prates = NULL;
  1047. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("cmd_code=%x\n", info->cmd));
  1048. _func_enter_;
  1049. if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == _TRUE)
  1050. {
  1051. //parsing HT_CAP_IE
  1052. p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength-12);
  1053. if(p && ht_ielen>0)
  1054. {
  1055. ht_cap = _TRUE;
  1056. }
  1057. #ifdef CONFIG_80211AC_VHT
  1058. if(pmlmepriv->vhtpriv.vht_option == _TRUE)
  1059. vht_cap = _TRUE;
  1060. #endif
  1061. prates = &pcur_bss->SupportedRates;
  1062. if (rtw_is_cckratesonly_included((u8*)prates) == _TRUE)
  1063. {
  1064. if(ht_cap == _TRUE)
  1065. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
  1066. else
  1067. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
  1068. }
  1069. else if ((rtw_is_cckrates_included((u8*)prates)) == _TRUE)
  1070. {
  1071. if(ht_cap == _TRUE)
  1072. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
  1073. else
  1074. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg");
  1075. }
  1076. else
  1077. {
  1078. if(pcur_bss->Configuration.DSConfig > 14)
  1079. {
  1080. if(vht_cap == _TRUE)
  1081. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11AC");
  1082. else if(ht_cap == _TRUE)
  1083. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11an");
  1084. else
  1085. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11a");
  1086. }
  1087. else
  1088. {
  1089. if(ht_cap == _TRUE)
  1090. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn");
  1091. else
  1092. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
  1093. }
  1094. }
  1095. }
  1096. else
  1097. {
  1098. //prates = &padapter->registrypriv.dev_network.SupportedRates;
  1099. //snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
  1100. snprintf(wrqu->name, IFNAMSIZ, "unassociated");
  1101. }
  1102. _func_exit_;
  1103. return 0;
  1104. }
  1105. static int rtw_wx_set_freq(struct net_device *dev,
  1106. struct iw_request_info *info,
  1107. union iwreq_data *wrqu, char *extra)
  1108. {
  1109. _func_enter_;
  1110. RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+rtw_wx_set_freq\n"));
  1111. _func_exit_;
  1112. return 0;
  1113. }
  1114. static int rtw_wx_get_freq(struct net_device *dev,
  1115. struct iw_request_info *info,
  1116. union iwreq_data *wrqu, char *extra)
  1117. {
  1118. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1119. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1120. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1121. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE)
  1122. {
  1123. //wrqu->freq.m = ieee80211_wlan_frequencies[pcur_bss->Configuration.DSConfig-1] * 100000;
  1124. wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000;
  1125. wrqu->freq.e = 1;
  1126. wrqu->freq.i = pcur_bss->Configuration.DSConfig;
  1127. }
  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. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType ;
  1140. int ret = 0;
  1141. _func_enter_;
  1142. if(_FAIL == rtw_pwr_wakeup(padapter)) {
  1143. ret= -EPERM;
  1144. goto exit;
  1145. }
  1146. if (padapter->hw_init_completed==_FALSE){
  1147. ret = -EPERM;
  1148. goto exit;
  1149. }
  1150. switch(wrqu->mode)
  1151. {
  1152. case IW_MODE_AUTO:
  1153. networkType = Ndis802_11AutoUnknown;
  1154. DBG_871X("set_mode = IW_MODE_AUTO\n");
  1155. break;
  1156. case IW_MODE_ADHOC:
  1157. networkType = Ndis802_11IBSS;
  1158. DBG_871X("set_mode = IW_MODE_ADHOC\n");
  1159. break;
  1160. case IW_MODE_MASTER:
  1161. networkType = Ndis802_11APMode;
  1162. DBG_871X("set_mode = IW_MODE_MASTER\n");
  1163. //rtw_setopmode_cmd(padapter, networkType);
  1164. break;
  1165. case IW_MODE_INFRA:
  1166. networkType = Ndis802_11Infrastructure;
  1167. DBG_871X("set_mode = IW_MODE_INFRA\n");
  1168. break;
  1169. default :
  1170. ret = -EINVAL;;
  1171. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("\n Mode: %s is not supported \n", iw_operation_mode[wrqu->mode]));
  1172. goto exit;
  1173. }
  1174. /*
  1175. if(Ndis802_11APMode == networkType)
  1176. {
  1177. rtw_setopmode_cmd(padapter, networkType);
  1178. }
  1179. else
  1180. {
  1181. rtw_setopmode_cmd(padapter, Ndis802_11AutoUnknown);
  1182. }
  1183. */
  1184. if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==_FALSE){
  1185. ret = -EPERM;
  1186. goto exit;
  1187. }
  1188. rtw_setopmode_cmd(padapter, networkType);
  1189. exit:
  1190. _func_exit_;
  1191. return ret;
  1192. }
  1193. static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
  1194. union iwreq_data *wrqu, char *b)
  1195. {
  1196. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1197. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1198. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,(" rtw_wx_get_mode \n"));
  1199. _func_enter_;
  1200. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
  1201. {
  1202. wrqu->mode = IW_MODE_INFRA;
  1203. }
  1204. else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
  1205. (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
  1206. {
  1207. wrqu->mode = IW_MODE_ADHOC;
  1208. }
  1209. else if(check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
  1210. {
  1211. wrqu->mode = IW_MODE_MASTER;
  1212. }
  1213. else
  1214. {
  1215. wrqu->mode = IW_MODE_AUTO;
  1216. }
  1217. _func_exit_;
  1218. return 0;
  1219. }
  1220. static int rtw_wx_set_pmkid(struct net_device *dev,
  1221. struct iw_request_info *a,
  1222. union iwreq_data *wrqu, char *extra)
  1223. {
  1224. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1225. u8 j,blInserted = _FALSE;
  1226. int intReturn = _FALSE;
  1227. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1228. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1229. struct iw_pmksa* pPMK = ( struct iw_pmksa* ) extra;
  1230. u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 };
  1231. u8 strIssueBssid[ ETH_ALEN ] = { 0x00 };
  1232. /*
  1233. struct iw_pmksa
  1234. {
  1235. __u32 cmd;
  1236. struct sockaddr bssid;
  1237. __u8 pmkid[IW_PMKID_LEN]; //IW_PMKID_LEN=16
  1238. }
  1239. There are the BSSID information in the bssid.sa_data array.
  1240. If cmd is IW_PMKSA_FLUSH, it means the wpa_suppplicant wants to clear all the PMKID information.
  1241. If cmd is IW_PMKSA_ADD, it means the wpa_supplicant wants to add a PMKID/BSSID to driver.
  1242. If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to remove a PMKID/BSSID from driver.
  1243. */
  1244. _rtw_memcpy( strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
  1245. if ( pPMK->cmd == IW_PMKSA_ADD )
  1246. {
  1247. DBG_871X( "[rtw_wx_set_pmkid] IW_PMKSA_ADD!\n" );
  1248. if ( _rtw_memcmp( strIssueBssid, strZeroMacAddress, ETH_ALEN ) == _TRUE )
  1249. {
  1250. return( intReturn );
  1251. }
  1252. else
  1253. {
  1254. intReturn = _TRUE;
  1255. }
  1256. blInserted = _FALSE;
  1257. //overwrite PMKID
  1258. for(j=0 ; j<NUM_PMKID_CACHE; j++)
  1259. {
  1260. if( _rtw_memcmp( psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) ==_TRUE )
  1261. { // BSSID is matched, the same AP => rewrite with new PMKID.
  1262. DBG_871X( "[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n" );
  1263. _rtw_memcpy( psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
  1264. psecuritypriv->PMKIDList[ j ].bUsed = _TRUE;
  1265. psecuritypriv->PMKIDIndex = j+1;
  1266. blInserted = _TRUE;
  1267. break;
  1268. }
  1269. }
  1270. if(!blInserted)
  1271. {
  1272. // Find a new entry
  1273. DBG_871X( "[rtw_wx_set_pmkid] Use the new entry index = %d for this PMKID.\n",
  1274. psecuritypriv->PMKIDIndex );
  1275. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
  1276. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
  1277. psecuritypriv->PMKIDList[ psecuritypriv->PMKIDIndex ].bUsed = _TRUE;
  1278. psecuritypriv->PMKIDIndex++ ;
  1279. if(psecuritypriv->PMKIDIndex==16)
  1280. {
  1281. psecuritypriv->PMKIDIndex =0;
  1282. }
  1283. }
  1284. }
  1285. else if ( pPMK->cmd == IW_PMKSA_REMOVE )
  1286. {
  1287. DBG_871X( "[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n" );
  1288. intReturn = _TRUE;
  1289. for(j=0 ; j<NUM_PMKID_CACHE; j++)
  1290. {
  1291. if( _rtw_memcmp( psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) ==_TRUE )
  1292. { // BSSID is matched, the same AP => Remove this PMKID information and reset it.
  1293. _rtw_memset( psecuritypriv->PMKIDList[ j ].Bssid, 0x00, ETH_ALEN );
  1294. psecuritypriv->PMKIDList[ j ].bUsed = _FALSE;
  1295. break;
  1296. }
  1297. }
  1298. }
  1299. else if ( pPMK->cmd == IW_PMKSA_FLUSH )
  1300. {
  1301. DBG_871X( "[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n" );
  1302. _rtw_memset( &psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof( RT_PMKID_LIST ) * NUM_PMKID_CACHE );
  1303. psecuritypriv->PMKIDIndex = 0;
  1304. intReturn = _TRUE;
  1305. }
  1306. return( intReturn );
  1307. }
  1308. static int rtw_wx_get_sens(struct net_device *dev,
  1309. struct iw_request_info *info,
  1310. union iwreq_data *wrqu, char *extra)
  1311. {
  1312. #ifdef CONFIG_PLATFORM_ROCKCHIPS
  1313. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1314. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1315. /*
  1316. * 20110311 Commented by Jeff
  1317. * For rockchip platform's wpa_driver_wext_get_rssi
  1318. */
  1319. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  1320. //wrqu->sens.value=-padapter->recvpriv.signal_strength;
  1321. wrqu->sens.value=-padapter->recvpriv.rssi;
  1322. //DBG_871X("%s: %d\n", __FUNCTION__, wrqu->sens.value);
  1323. wrqu->sens.fixed = 0; /* no auto select */
  1324. } else
  1325. #endif
  1326. {
  1327. wrqu->sens.value = 0;
  1328. wrqu->sens.fixed = 0; /* no auto select */
  1329. wrqu->sens.disabled = 1;
  1330. }
  1331. return 0;
  1332. }
  1333. static int rtw_wx_get_range(struct net_device *dev,
  1334. struct iw_request_info *info,
  1335. union iwreq_data *wrqu, char *extra)
  1336. {
  1337. struct iw_range *range = (struct iw_range *)extra;
  1338. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1339. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  1340. u16 val;
  1341. int i;
  1342. _func_enter_;
  1343. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_range. cmd_code=%x\n", info->cmd));
  1344. wrqu->data.length = sizeof(*range);
  1345. _rtw_memset(range, 0, sizeof(*range));
  1346. /* Let's try to keep this struct in the same order as in
  1347. * linux/include/wireless.h
  1348. */
  1349. /* TODO: See what values we can set, and remove the ones we can't
  1350. * set, or fill them with some default data.
  1351. */
  1352. /* ~5 Mb/s real (802.11b) */
  1353. range->throughput = 5 * 1000 * 1000;
  1354. // TODO: Not used in 802.11b?
  1355. // range->min_nwid; /* Minimal NWID we are able to set */
  1356. // TODO: Not used in 802.11b?
  1357. // range->max_nwid; /* Maximal NWID we are able to set */
  1358. /* Old Frequency (backward compat - moved lower ) */
  1359. // range->old_num_channels;
  1360. // range->old_num_frequency;
  1361. // range->old_freq[6]; /* Filler to keep "version" at the same offset */
  1362. /* signal level threshold range */
  1363. //percent values between 0 and 100.
  1364. range->max_qual.qual = 100;
  1365. range->max_qual.level = 100;
  1366. range->max_qual.noise = 100;
  1367. range->max_qual.updated = 7; /* Updated all three */
  1368. range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
  1369. /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
  1370. range->avg_qual.level = 20 + -98;
  1371. range->avg_qual.noise = 0;
  1372. range->avg_qual.updated = 7; /* Updated all three */
  1373. range->num_bitrates = RATE_COUNT;
  1374. for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
  1375. range->bitrate[i] = rtw_rates[i];
  1376. }
  1377. range->min_frag = MIN_FRAG_THRESHOLD;
  1378. range->max_frag = MAX_FRAG_THRESHOLD;
  1379. range->pm_capa = 0;
  1380. range->we_version_compiled = WIRELESS_EXT;
  1381. range->we_version_source = 16;
  1382. // range->retry_capa; /* What retry options are supported */
  1383. // range->retry_flags; /* How to decode max/min retry limit */
  1384. // range->r_time_flags; /* How to decode max/min retry life */
  1385. // range->min_retry; /* Minimal number of retries */
  1386. // range->max_retry; /* Maximal number of retries */
  1387. // range->min_r_time; /* Minimal retry lifetime */
  1388. // range->max_r_time; /* Maximal retry lifetime */
  1389. for (i = 0, val = 0; i < MAX_CHANNEL_NUM; i++) {
  1390. // Include only legal frequencies for some countries
  1391. if(pmlmeext->channel_set[i].ChannelNum != 0)
  1392. {
  1393. range->freq[val].i = pmlmeext->channel_set[i].ChannelNum;
  1394. range->freq[val].m = rtw_ch2freq(pmlmeext->channel_set[i].ChannelNum) * 100000;
  1395. range->freq[val].e = 1;
  1396. val++;
  1397. }
  1398. if (val == IW_MAX_FREQUENCIES)
  1399. break;
  1400. }
  1401. range->num_channels = val;
  1402. range->num_frequency = val;
  1403. // Commented by Albert 2009/10/13
  1404. // The following code will proivde the security capability to network manager.
  1405. // If the driver doesn't provide this capability to network manager,
  1406. // the WPA/WPA2 routers can't be choosen in the network manager.
  1407. /*
  1408. #define IW_SCAN_CAPA_NONE 0x00
  1409. #define IW_SCAN_CAPA_ESSID 0x01
  1410. #define IW_SCAN_CAPA_BSSID 0x02
  1411. #define IW_SCAN_CAPA_CHANNEL 0x04
  1412. #define IW_SCAN_CAPA_MODE 0x08
  1413. #define IW_SCAN_CAPA_RATE 0x10
  1414. #define IW_SCAN_CAPA_TYPE 0x20
  1415. #define IW_SCAN_CAPA_TIME 0x40
  1416. */
  1417. #if WIRELESS_EXT > 17
  1418. range->enc_capa = IW_ENC_CAPA_WPA|IW_ENC_CAPA_WPA2|
  1419. IW_ENC_CAPA_CIPHER_TKIP|IW_ENC_CAPA_CIPHER_CCMP;
  1420. #endif
  1421. #ifdef IW_SCAN_CAPA_ESSID //WIRELESS_EXT > 21
  1422. range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE |IW_SCAN_CAPA_BSSID|
  1423. IW_SCAN_CAPA_CHANNEL|IW_SCAN_CAPA_MODE|IW_SCAN_CAPA_RATE;
  1424. #endif
  1425. _func_exit_;
  1426. return 0;
  1427. }
  1428. //set bssid flow
  1429. //s1. rtw_set_802_11_infrastructure_mode()
  1430. //s2. rtw_set_802_11_authentication_mode()
  1431. //s3. set_802_11_encryption_mode()
  1432. //s4. rtw_set_802_11_bssid()
  1433. static int rtw_wx_set_wap(struct net_device *dev,
  1434. struct iw_request_info *info,
  1435. union iwreq_data *awrq,
  1436. char *extra)
  1437. {
  1438. _irqL irqL;
  1439. uint ret = 0;
  1440. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1441. struct sockaddr *temp = (struct sockaddr *)awrq;
  1442. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1443. _list *phead;
  1444. u8 *dst_bssid, *src_bssid;
  1445. _queue *queue = &(pmlmepriv->scanned_queue);
  1446. struct wlan_network *pnetwork = NULL;
  1447. NDIS_802_11_AUTHENTICATION_MODE authmode;
  1448. _func_enter_;
  1449. /*
  1450. #ifdef CONFIG_CONCURRENT_MODE
  1451. if(padapter->iface_type > PRIMARY_IFACE)
  1452. {
  1453. ret = -EINVAL;
  1454. goto exit;
  1455. }
  1456. #endif
  1457. */
  1458. #ifdef CONFIG_CONCURRENT_MODE
  1459. if (check_buddy_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
  1460. {
  1461. DBG_871X("set bssid, but buddy_intf is under scanning or linking\n");
  1462. ret = -EINVAL;
  1463. goto exit;
  1464. }
  1465. #endif
  1466. #ifdef CONFIG_DUALMAC_CONCURRENT
  1467. if (dc_check_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)== _TRUE)
  1468. {
  1469. DBG_871X("set bssid, but buddy_intf is under scanning or linking\n");
  1470. ret = -EINVAL;
  1471. goto exit;
  1472. }
  1473. #endif
  1474. if(_FAIL == rtw_pwr_wakeup(padapter))
  1475. {
  1476. ret= -1;
  1477. goto exit;
  1478. }
  1479. if(!padapter->bup){
  1480. ret = -1;
  1481. goto exit;
  1482. }
  1483. if (temp->sa_family != ARPHRD_ETHER){
  1484. ret = -EINVAL;
  1485. goto exit;
  1486. }
  1487. authmode = padapter->securitypriv.ndisauthtype;
  1488. _enter_critical_bh(&queue->lock, &irqL);
  1489. phead = get_list_head(queue);
  1490. pmlmepriv->pscanned = get_next(phead);
  1491. while (1)
  1492. {
  1493. if ((rtw_end_of_queue_search(phead, pmlmepriv->pscanned)) == _TRUE)
  1494. {
  1495. #if 0
  1496. ret = -EINVAL;
  1497. goto exit;
  1498. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE)
  1499. {
  1500. rtw_set_802_11_bssid(padapter, temp->sa_data);
  1501. goto exit;
  1502. }
  1503. else
  1504. {
  1505. ret = -EINVAL;
  1506. goto exit;
  1507. }
  1508. #endif
  1509. break;
  1510. }
  1511. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  1512. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  1513. dst_bssid = pnetwork->network.MacAddress;
  1514. src_bssid = temp->sa_data;
  1515. if ((_rtw_memcmp(dst_bssid, src_bssid, ETH_ALEN)) == _TRUE)
  1516. {
  1517. if(!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode))
  1518. {
  1519. ret = -1;
  1520. _exit_critical_bh(&queue->lock, &irqL);
  1521. goto exit;
  1522. }
  1523. break;
  1524. }
  1525. }
  1526. _exit_critical_bh(&queue->lock, &irqL);
  1527. rtw_set_802_11_authentication_mode(padapter, authmode);
  1528. //set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus);
  1529. if (rtw_set_802_11_bssid(padapter, temp->sa_data) == _FALSE) {
  1530. ret = -1;
  1531. goto exit;
  1532. }
  1533. exit:
  1534. _func_exit_;
  1535. return ret;
  1536. }
  1537. static int rtw_wx_get_wap(struct net_device *dev,
  1538. struct iw_request_info *info,
  1539. union iwreq_data *wrqu, char *extra)
  1540. {
  1541. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1542. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1543. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  1544. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1545. _rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  1546. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_wap\n"));
  1547. _func_enter_;
  1548. if ( ((check_fwstate(pmlmepriv, _FW_LINKED)) == _TRUE) ||
  1549. ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) == _TRUE) ||
  1550. ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) == _TRUE) )
  1551. {
  1552. _rtw_memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
  1553. }
  1554. else
  1555. {
  1556. _rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  1557. }
  1558. _func_exit_;
  1559. return 0;
  1560. }
  1561. static int rtw_wx_set_mlme(struct net_device *dev,
  1562. struct iw_request_info *info,
  1563. union iwreq_data *wrqu, char *extra)
  1564. {
  1565. #if 0
  1566. /* SIOCSIWMLME data */
  1567. struct iw_mlme
  1568. {
  1569. __u16 cmd; /* IW_MLME_* */
  1570. __u16 reason_code;
  1571. struct sockaddr addr;
  1572. };
  1573. #endif
  1574. int ret=0;
  1575. u16 reason;
  1576. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1577. struct iw_mlme *mlme = (struct iw_mlme *) extra;
  1578. if(mlme==NULL)
  1579. return -1;
  1580. DBG_871X("%s\n", __FUNCTION__);
  1581. reason = cpu_to_le16(mlme->reason_code);
  1582. DBG_871X("%s, cmd=%d, reason=%d\n", __FUNCTION__, mlme->cmd, reason);
  1583. switch (mlme->cmd)
  1584. {
  1585. case IW_MLME_DEAUTH:
  1586. if(!rtw_set_802_11_disassociate(padapter))
  1587. ret = -1;
  1588. break;
  1589. case IW_MLME_DISASSOC:
  1590. if(!rtw_set_802_11_disassociate(padapter))
  1591. ret = -1;
  1592. break;
  1593. default:
  1594. return -EOPNOTSUPP;
  1595. }
  1596. return ret;
  1597. }
  1598. static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
  1599. union iwreq_data *wrqu, char *extra)
  1600. {
  1601. u8 _status = _FALSE;
  1602. int ret = 0;
  1603. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1604. struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
  1605. NDIS_802_11_SSID ssid[RTW_SSID_SCAN_AMOUNT];
  1606. _irqL irqL;
  1607. #ifdef CONFIG_P2P
  1608. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  1609. #endif //CONFIG_P2P
  1610. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_set_scan\n"));
  1611. _func_enter_;
  1612. #ifdef DBG_IOCTL
  1613. DBG_871X("DBG_IOCTL %s:%d\n",__FUNCTION__, __LINE__);
  1614. #endif
  1615. /*
  1616. #ifdef CONFIG_CONCURRENT_MODE
  1617. if(padapter->iface_type > PRIMARY_IFACE)
  1618. {
  1619. ret = -1;
  1620. goto exit;
  1621. }
  1622. #endif
  1623. */
  1624. #ifdef CONFIG_MP_INCLUDED
  1625. if (padapter->registrypriv.mp_mode == 1)
  1626. {
  1627. if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == _TRUE)
  1628. {
  1629. ret = -1;
  1630. goto exit;
  1631. }
  1632. }
  1633. #endif
  1634. if(_FAIL == rtw_pwr_wakeup(padapter))
  1635. {
  1636. ret= -1;
  1637. goto exit;
  1638. }
  1639. if(padapter->bDriverStopped){
  1640. DBG_871X("bDriverStopped=%d\n", padapter->bDriverStopped);
  1641. ret= -1;
  1642. goto exit;
  1643. }
  1644. if(!padapter->bup){
  1645. ret = -1;
  1646. goto exit;
  1647. }
  1648. if (padapter->hw_init_completed==_FALSE){
  1649. ret = -1;
  1650. goto exit;
  1651. }
  1652. // When Busy Traffic, driver do not site survey. So driver return success.
  1653. // wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout.
  1654. // modify by thomas 2011-02-22.
  1655. if (pmlmepriv->LinkDetectInfo.bBusyTraffic == _TRUE)
  1656. {
  1657. indicate_wx_scan_complete_event(padapter);
  1658. goto exit;
  1659. }
  1660. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
  1661. {
  1662. indicate_wx_scan_complete_event(padapter);
  1663. goto exit;
  1664. }
  1665. #ifdef CONFIG_CONCURRENT_MODE
  1666. if (check_buddy_fwstate(padapter,
  1667. _FW_UNDER_SURVEY|_FW_UNDER_LINKING|WIFI_UNDER_WPS) == _TRUE)
  1668. {
  1669. if(check_buddy_fwstate(padapter, _FW_UNDER_SURVEY))
  1670. {
  1671. DBG_871X("scanning_via_buddy_intf\n");
  1672. pmlmepriv->scanning_via_buddy_intf = _TRUE;
  1673. }
  1674. indicate_wx_scan_complete_event(padapter);
  1675. goto exit;
  1676. }
  1677. #endif
  1678. #ifdef CONFIG_DUALMAC_CONCURRENT
  1679. if (dc_check_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)== _TRUE)
  1680. {
  1681. indicate_wx_scan_complete_event(padapter);
  1682. goto exit;
  1683. }
  1684. #endif
  1685. // Mareded by Albert 20101103
  1686. // For the DMP WiFi Display project, the driver won't to scan because
  1687. // the pmlmepriv->scan_interval is always equal to 3.
  1688. // So, the wpa_supplicant won't find out the WPS SoftAP.
  1689. /*
  1690. if(pmlmepriv->scan_interval>10)
  1691. pmlmepriv->scan_interval = 0;
  1692. if(pmlmepriv->scan_interval > 0)
  1693. {
  1694. DBG_871X("scan done\n");
  1695. ret = 0;
  1696. goto exit;
  1697. }
  1698. */
  1699. #ifdef CONFIG_P2P
  1700. if ( pwdinfo->p2p_state != P2P_STATE_NONE )
  1701. {
  1702. rtw_p2p_set_pre_state( pwdinfo, rtw_p2p_state( pwdinfo ) );
  1703. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  1704. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_FULL);
  1705. rtw_free_network_queue(padapter, _TRUE);
  1706. }
  1707. #endif //CONFIG_P2P
  1708. _rtw_memset(ssid, 0, sizeof(NDIS_802_11_SSID)*RTW_SSID_SCAN_AMOUNT);
  1709. #if WIRELESS_EXT >= 17
  1710. if (wrqu->data.length == sizeof(struct iw_scan_req))
  1711. {
  1712. struct iw_scan_req *req = (struct iw_scan_req *)extra;
  1713. if (wrqu->data.flags & IW_SCAN_THIS_ESSID)
  1714. {
  1715. int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE);
  1716. _rtw_memcpy(ssid[0].Ssid, req->essid, len);
  1717. ssid[0].SsidLength = len;
  1718. DBG_871X("IW_SCAN_THIS_ESSID, ssid=%s, len=%d\n", req->essid, req->essid_len);
  1719. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  1720. _status = rtw_sitesurvey_cmd(padapter, ssid, 1, NULL, 0);
  1721. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  1722. }
  1723. else if (req->scan_type == IW_SCAN_TYPE_PASSIVE)
  1724. {
  1725. DBG_871X("rtw_wx_set_scan, req->scan_type == IW_SCAN_TYPE_PASSIVE\n");
  1726. }
  1727. }
  1728. else
  1729. #endif
  1730. if( wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE
  1731. && _rtw_memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
  1732. )
  1733. {
  1734. int len = wrqu->data.length -WEXT_CSCAN_HEADER_SIZE;
  1735. char *pos = extra+WEXT_CSCAN_HEADER_SIZE;
  1736. char section;
  1737. char sec_len;
  1738. int ssid_index = 0;
  1739. //DBG_871X("%s COMBO_SCAN header is recognized\n", __FUNCTION__);
  1740. while(len >= 1) {
  1741. section = *(pos++); len-=1;
  1742. switch(section) {
  1743. case WEXT_CSCAN_SSID_SECTION:
  1744. //DBG_871X("WEXT_CSCAN_SSID_SECTION\n");
  1745. if(len < 1) {
  1746. len = 0;
  1747. break;
  1748. }
  1749. sec_len = *(pos++); len-=1;
  1750. if(sec_len>0 && sec_len<=len) {
  1751. ssid[ssid_index].SsidLength = sec_len;
  1752. _rtw_memcpy(ssid[ssid_index].Ssid, pos, ssid[ssid_index].SsidLength);
  1753. //DBG_871X("%s COMBO_SCAN with specific ssid:%s, %d\n", __FUNCTION__
  1754. // , ssid[ssid_index].Ssid, ssid[ssid_index].SsidLength);
  1755. ssid_index++;
  1756. }
  1757. pos+=sec_len; len-=sec_len;
  1758. break;
  1759. case WEXT_CSCAN_CHANNEL_SECTION:
  1760. //DBG_871X("WEXT_CSCAN_CHANNEL_SECTION\n");
  1761. pos+=1; len-=1;
  1762. break;
  1763. case WEXT_CSCAN_ACTV_DWELL_SECTION:
  1764. //DBG_871X("WEXT_CSCAN_ACTV_DWELL_SECTION\n");
  1765. pos+=2; len-=2;
  1766. break;
  1767. case WEXT_CSCAN_PASV_DWELL_SECTION:
  1768. //DBG_871X("WEXT_CSCAN_PASV_DWELL_SECTION\n");
  1769. pos+=2; len-=2;
  1770. break;
  1771. case WEXT_CSCAN_HOME_DWELL_SECTION:
  1772. //DBG_871X("WEXT_CSCAN_HOME_DWELL_SECTION\n");
  1773. pos+=2; len-=2;
  1774. break;
  1775. case WEXT_CSCAN_TYPE_SECTION:
  1776. //DBG_871X("WEXT_CSCAN_TYPE_SECTION\n");
  1777. pos+=1; len-=1;
  1778. break;
  1779. #if 0
  1780. case WEXT_CSCAN_NPROBE_SECTION:
  1781. DBG_871X("WEXT_CSCAN_NPROBE_SECTION\n");
  1782. break;
  1783. #endif
  1784. default:
  1785. //DBG_871X("Unknown CSCAN section %c\n", section);
  1786. len = 0; // stop parsing
  1787. }
  1788. //DBG_871X("len:%d\n", len);
  1789. }
  1790. //jeff: it has still some scan paramater to parse, we only do this now...
  1791. _status = rtw_set_802_11_bssid_list_scan(padapter, ssid, RTW_SSID_SCAN_AMOUNT);
  1792. } else
  1793. {
  1794. _status = rtw_set_802_11_bssid_list_scan(padapter, NULL, 0);
  1795. }
  1796. if(_status == _FALSE)
  1797. ret = -1;
  1798. exit:
  1799. #ifdef DBG_IOCTL
  1800. DBG_871X("DBG_IOCTL %s:%d return %d\n",__FUNCTION__, __LINE__, ret);
  1801. #endif
  1802. _func_exit_;
  1803. return ret;
  1804. }
  1805. static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
  1806. union iwreq_data *wrqu, char *extra)
  1807. {
  1808. _irqL irqL;
  1809. _list *plist, *phead;
  1810. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1811. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  1812. _queue *queue = &(pmlmepriv->scanned_queue);
  1813. struct wlan_network *pnetwork = NULL;
  1814. char *ev = extra;
  1815. char *stop = ev + wrqu->data.length;
  1816. u32 ret = 0;
  1817. u32 cnt=0;
  1818. u32 wait_for_surveydone;
  1819. sint wait_status;
  1820. #ifdef CONFIG_CONCURRENT_MODE
  1821. //PADAPTER pbuddy_adapter = padapter->pbuddy_adapter;
  1822. //struct mlme_priv *pbuddy_mlmepriv = &(pbuddy_adapter->mlmepriv);
  1823. #endif
  1824. #ifdef CONFIG_P2P
  1825. struct wifidirect_info* pwdinfo = &padapter->wdinfo;
  1826. #endif //CONFIG_P2P
  1827. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_scan\n"));
  1828. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_, (" Start of Query SIOCGIWSCAN .\n"));
  1829. _func_enter_;
  1830. #ifdef DBG_IOCTL
  1831. DBG_871X("DBG_IOCTL %s:%d\n",__FUNCTION__, __LINE__);
  1832. #endif
  1833. /*
  1834. #ifdef CONFIG_CONCURRENT_MODE
  1835. if(padapter->iface_type > PRIMARY_IFACE)
  1836. {
  1837. ret = -EINVAL;
  1838. goto exit;
  1839. }
  1840. #endif
  1841. */
  1842. if(padapter->pwrctrlpriv.brfoffbyhw && padapter->bDriverStopped)
  1843. {
  1844. ret = -EINVAL;
  1845. goto exit;
  1846. }
  1847. #ifdef CONFIG_P2P
  1848. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  1849. {
  1850. // P2P is enabled
  1851. if ( padapter->chip_type == RTL8192D )
  1852. wait_for_surveydone = 300; // Because the 8192du supports more channels.
  1853. else
  1854. wait_for_surveydone = 200;
  1855. }
  1856. else
  1857. {
  1858. // P2P is disabled
  1859. wait_for_surveydone = 100;
  1860. }
  1861. #else
  1862. {
  1863. wait_for_surveydone = 100;
  1864. }
  1865. #endif //CONFIG_P2P
  1866. /*
  1867. #ifdef CONFIG_CONCURRENT_MODE
  1868. if(pmlmepriv->scanning_via_buddy_intf == _TRUE)
  1869. {
  1870. pmlmepriv->scanning_via_buddy_intf = _FALSE;//reset
  1871. // change pointers to buddy interface
  1872. padapter = pbuddy_adapter;
  1873. pmlmepriv = pbuddy_mlmepriv;
  1874. queue = &(pbuddy_mlmepriv->scanned_queue);
  1875. }
  1876. #endif // CONFIG_CONCURRENT_MODE
  1877. */
  1878. wait_status = _FW_UNDER_SURVEY
  1879. #ifndef CONFIG_ANDROID
  1880. |_FW_UNDER_LINKING
  1881. #endif
  1882. ;
  1883. #ifdef CONFIG_DUALMAC_CONCURRENT
  1884. while(dc_check_fwstate(padapter, wait_status)== _TRUE)
  1885. {
  1886. rtw_msleep_os(30);
  1887. cnt++;
  1888. if(cnt > wait_for_surveydone )
  1889. break;
  1890. }
  1891. #endif // CONFIG_DUALMAC_CONCURRENT
  1892. while(check_fwstate(pmlmepriv, wait_status) == _TRUE)
  1893. {
  1894. rtw_msleep_os(30);
  1895. cnt++;
  1896. if(cnt > wait_for_surveydone )
  1897. break;
  1898. }
  1899. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1900. phead = get_list_head(queue);
  1901. plist = get_next(phead);
  1902. while(1)
  1903. {
  1904. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  1905. break;
  1906. if((stop - ev) < SCAN_ITEM_SIZE) {
  1907. ret = -E2BIG;
  1908. break;
  1909. }
  1910. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  1911. //report network only if the current channel set contains the channel to which this network belongs
  1912. if(rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0
  1913. #ifdef CONFIG_VALIDATE_SSID
  1914. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
  1915. #endif
  1916. )
  1917. {
  1918. ev=translate_scan(padapter, a, pnetwork, ev, stop);
  1919. }
  1920. plist = get_next(plist);
  1921. }
  1922. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  1923. wrqu->data.length = ev-extra;
  1924. wrqu->data.flags = 0;
  1925. exit:
  1926. _func_exit_;
  1927. #ifdef DBG_IOCTL
  1928. DBG_871X("DBG_IOCTL %s:%d return %d\n",__FUNCTION__, __LINE__, ret);
  1929. #endif
  1930. return ret ;
  1931. }
  1932. //set ssid flow
  1933. //s1. rtw_set_802_11_infrastructure_mode()
  1934. //s2. set_802_11_authenticaion_mode()
  1935. //s3. set_802_11_encryption_mode()
  1936. //s4. rtw_set_802_11_ssid()
  1937. static int rtw_wx_set_essid(struct net_device *dev,
  1938. struct iw_request_info *a,
  1939. union iwreq_data *wrqu, char *extra)
  1940. {
  1941. _irqL irqL;
  1942. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1943. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1944. _queue *queue = &pmlmepriv->scanned_queue;
  1945. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  1946. _list *phead;
  1947. s8 status = _TRUE;
  1948. struct wlan_network *pnetwork = NULL;
  1949. NDIS_802_11_AUTHENTICATION_MODE authmode;
  1950. NDIS_802_11_SSID ndis_ssid;
  1951. u8 *dst_ssid, *src_ssid;
  1952. uint ret = 0, len;
  1953. _func_enter_;
  1954. #ifdef DBG_IOCTL
  1955. DBG_871X("DBG_IOCTL %s:%d\n",__FUNCTION__, __LINE__);
  1956. #endif
  1957. /*
  1958. #ifdef CONFIG_CONCURRENT_MODE
  1959. if(padapter->iface_type > PRIMARY_IFACE)
  1960. {
  1961. ret = -EINVAL;
  1962. goto exit;
  1963. }
  1964. #endif
  1965. */
  1966. #ifdef CONFIG_CONCURRENT_MODE
  1967. if (check_buddy_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) == _TRUE)
  1968. {
  1969. DBG_871X("set ssid, but buddy_intf is under scanning or linking\n");
  1970. ret = -EINVAL;
  1971. goto exit;
  1972. }
  1973. #endif
  1974. #ifdef CONFIG_DUALMAC_CONCURRENT
  1975. if (dc_check_fwstate(padapter, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)== _TRUE)
  1976. {
  1977. DBG_871X("set bssid, but buddy_intf is under scanning or linking\n");
  1978. ret = -EINVAL;
  1979. goto exit;
  1980. }
  1981. #endif
  1982. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  1983. ("+rtw_wx_set_essid: fw_state=0x%08x\n", get_fwstate(pmlmepriv)));
  1984. if(_FAIL == rtw_pwr_wakeup(padapter))
  1985. {
  1986. ret = -1;
  1987. goto exit;
  1988. }
  1989. if(!padapter->bup){
  1990. ret = -1;
  1991. goto exit;
  1992. }
  1993. #if WIRELESS_EXT <= 20
  1994. if ((wrqu->essid.length-1) > IW_ESSID_MAX_SIZE){
  1995. #else
  1996. if (wrqu->essid.length > IW_ESSID_MAX_SIZE){
  1997. #endif
  1998. ret= -E2BIG;
  1999. goto exit;
  2000. }
  2001. if(check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
  2002. ret = -1;
  2003. goto exit;
  2004. }
  2005. authmode = padapter->securitypriv.ndisauthtype;
  2006. DBG_871X("=>%s\n",__FUNCTION__);
  2007. if (wrqu->essid.flags && wrqu->essid.length)
  2008. {
  2009. // Commented by Albert 20100519
  2010. // We got the codes in "set_info" function of iwconfig source code.
  2011. // =========================================
  2012. // wrq.u.essid.length = strlen(essid) + 1;
  2013. // if(we_kernel_version > 20)
  2014. // wrq.u.essid.length--;
  2015. // =========================================
  2016. // That means, if the WIRELESS_EXT less than or equal to 20, the correct ssid len should subtract 1.
  2017. #if WIRELESS_EXT <= 20
  2018. len = ((wrqu->essid.length-1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length-1) : IW_ESSID_MAX_SIZE;
  2019. #else
  2020. len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
  2021. #endif
  2022. if( wrqu->essid.length != 33 )
  2023. DBG_871X("ssid=%s, len=%d\n", extra, wrqu->essid.length);
  2024. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  2025. ndis_ssid.SsidLength = len;
  2026. _rtw_memcpy(ndis_ssid.Ssid, extra, len);
  2027. src_ssid = ndis_ssid.Ssid;
  2028. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("rtw_wx_set_essid: ssid=[%s]\n", src_ssid));
  2029. _enter_critical_bh(&queue->lock, &irqL);
  2030. phead = get_list_head(queue);
  2031. pmlmepriv->pscanned = get_next(phead);
  2032. while (1)
  2033. {
  2034. if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == _TRUE)
  2035. {
  2036. #if 0
  2037. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE)
  2038. {
  2039. rtw_set_802_11_ssid(padapter, &ndis_ssid);
  2040. goto exit;
  2041. }
  2042. else
  2043. {
  2044. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("rtw_wx_set_ssid(): scanned_queue is empty\n"));
  2045. ret = -EINVAL;
  2046. goto exit;
  2047. }
  2048. #endif
  2049. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_warning_,
  2050. ("rtw_wx_set_essid: scan_q is empty, set ssid to check if scanning again!\n"));
  2051. break;
  2052. }
  2053. pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
  2054. pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
  2055. dst_ssid = pnetwork->network.Ssid.Ssid;
  2056. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  2057. ("rtw_wx_set_essid: dst_ssid=%s\n",
  2058. pnetwork->network.Ssid.Ssid));
  2059. if ((_rtw_memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength) == _TRUE) &&
  2060. (pnetwork->network.Ssid.SsidLength==ndis_ssid.SsidLength))
  2061. {
  2062. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  2063. ("rtw_wx_set_essid: find match, set infra mode\n"));
  2064. if(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE)
  2065. {
  2066. if(pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
  2067. continue;
  2068. }
  2069. if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode) == _FALSE)
  2070. {
  2071. ret = -1;
  2072. _exit_critical_bh(&queue->lock, &irqL);
  2073. goto exit;
  2074. }
  2075. break;
  2076. }
  2077. }
  2078. _exit_critical_bh(&queue->lock, &irqL);
  2079. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  2080. ("set ssid: set_802_11_auth. mode=%d\n", authmode));
  2081. rtw_set_802_11_authentication_mode(padapter, authmode);
  2082. //set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus);
  2083. if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
  2084. ret = -1;
  2085. goto exit;
  2086. }
  2087. }
  2088. exit:
  2089. DBG_871X("<=%s, ret %d\n",__FUNCTION__, ret);
  2090. #ifdef DBG_IOCTL
  2091. DBG_871X("DBG_IOCTL %s:%d return %d\n",__FUNCTION__, __LINE__, ret);
  2092. #endif
  2093. _func_exit_;
  2094. return ret;
  2095. }
  2096. static int rtw_wx_get_essid(struct net_device *dev,
  2097. struct iw_request_info *a,
  2098. union iwreq_data *wrqu, char *extra)
  2099. {
  2100. u32 len,ret = 0;
  2101. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2102. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2103. WLAN_BSSID_EX *pcur_bss = &pmlmepriv->cur_network.network;
  2104. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,("rtw_wx_get_essid\n"));
  2105. _func_enter_;
  2106. if ( (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) ||
  2107. (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE))
  2108. {
  2109. len = pcur_bss->Ssid.SsidLength;
  2110. wrqu->essid.length = len;
  2111. _rtw_memcpy(extra, pcur_bss->Ssid.Ssid, len);
  2112. wrqu->essid.flags = 1;
  2113. }
  2114. else
  2115. {
  2116. ret = -1;
  2117. goto exit;
  2118. }
  2119. exit:
  2120. _func_exit_;
  2121. return ret;
  2122. }
  2123. static int rtw_wx_set_rate(struct net_device *dev,
  2124. struct iw_request_info *a,
  2125. union iwreq_data *wrqu, char *extra)
  2126. {
  2127. int i, ret = 0;
  2128. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2129. u8 datarates[NumRates];
  2130. u32 target_rate = wrqu->bitrate.value;
  2131. u32 fixed = wrqu->bitrate.fixed;
  2132. u32 ratevalue = 0;
  2133. u8 mpdatarate[NumRates]={11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
  2134. _func_enter_;
  2135. RT_TRACE(_module_rtl871x_mlme_c_,_drv_info_,(" rtw_wx_set_rate \n"));
  2136. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("target_rate = %d, fixed = %d\n",target_rate,fixed));
  2137. if(target_rate == -1){
  2138. ratevalue = 11;
  2139. goto set_rate;
  2140. }
  2141. target_rate = target_rate/100000;
  2142. switch(target_rate){
  2143. case 10:
  2144. ratevalue = 0;
  2145. break;
  2146. case 20:
  2147. ratevalue = 1;
  2148. break;
  2149. case 55:
  2150. ratevalue = 2;
  2151. break;
  2152. case 60:
  2153. ratevalue = 3;
  2154. break;
  2155. case 90:
  2156. ratevalue = 4;
  2157. break;
  2158. case 110:
  2159. ratevalue = 5;
  2160. break;
  2161. case 120:
  2162. ratevalue = 6;
  2163. break;
  2164. case 180:
  2165. ratevalue = 7;
  2166. break;
  2167. case 240:
  2168. ratevalue = 8;
  2169. break;
  2170. case 360:
  2171. ratevalue = 9;
  2172. break;
  2173. case 480:
  2174. ratevalue = 10;
  2175. break;
  2176. case 540:
  2177. ratevalue = 11;
  2178. break;
  2179. default:
  2180. ratevalue = 11;
  2181. break;
  2182. }
  2183. set_rate:
  2184. for(i=0; i<NumRates; i++)
  2185. {
  2186. if(ratevalue==mpdatarate[i])
  2187. {
  2188. datarates[i] = mpdatarate[i];
  2189. if(fixed == 0)
  2190. break;
  2191. }
  2192. else{
  2193. datarates[i] = 0xff;
  2194. }
  2195. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("datarate_inx=%d\n",datarates[i]));
  2196. }
  2197. if( rtw_setdatarate_cmd(padapter, datarates) !=_SUCCESS){
  2198. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("rtw_wx_set_rate Fail!!!\n"));
  2199. ret = -1;
  2200. }
  2201. _func_exit_;
  2202. return ret;
  2203. }
  2204. static int rtw_wx_get_rate(struct net_device *dev,
  2205. struct iw_request_info *info,
  2206. union iwreq_data *wrqu, char *extra)
  2207. {
  2208. u16 max_rate = 0;
  2209. max_rate = rtw_get_cur_max_rate((_adapter *)rtw_netdev_priv(dev));
  2210. if(max_rate == 0)
  2211. return -EPERM;
  2212. wrqu->bitrate.fixed = 0; /* no auto select */
  2213. wrqu->bitrate.value = max_rate * 100000;
  2214. return 0;
  2215. }
  2216. static int rtw_wx_set_rts(struct net_device *dev,
  2217. struct iw_request_info *info,
  2218. union iwreq_data *wrqu, char *extra)
  2219. {
  2220. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2221. _func_enter_;
  2222. if (wrqu->rts.disabled)
  2223. padapter->registrypriv.rts_thresh = 2347;
  2224. else {
  2225. if (wrqu->rts.value < 0 ||
  2226. wrqu->rts.value > 2347)
  2227. return -EINVAL;
  2228. padapter->registrypriv.rts_thresh = wrqu->rts.value;
  2229. }
  2230. DBG_871X("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
  2231. _func_exit_;
  2232. return 0;
  2233. }
  2234. static int rtw_wx_get_rts(struct net_device *dev,
  2235. struct iw_request_info *info,
  2236. union iwreq_data *wrqu, char *extra)
  2237. {
  2238. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2239. _func_enter_;
  2240. DBG_871X("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
  2241. wrqu->rts.value = padapter->registrypriv.rts_thresh;
  2242. wrqu->rts.fixed = 0; /* no auto select */
  2243. //wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
  2244. _func_exit_;
  2245. return 0;
  2246. }
  2247. static int rtw_wx_set_frag(struct net_device *dev,
  2248. struct iw_request_info *info,
  2249. union iwreq_data *wrqu, char *extra)
  2250. {
  2251. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2252. _func_enter_;
  2253. if (wrqu->frag.disabled)
  2254. padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
  2255. else {
  2256. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  2257. wrqu->frag.value > MAX_FRAG_THRESHOLD)
  2258. return -EINVAL;
  2259. padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
  2260. }
  2261. DBG_871X("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
  2262. _func_exit_;
  2263. return 0;
  2264. }
  2265. static int rtw_wx_get_frag(struct net_device *dev,
  2266. struct iw_request_info *info,
  2267. union iwreq_data *wrqu, char *extra)
  2268. {
  2269. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2270. _func_enter_;
  2271. DBG_871X("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
  2272. wrqu->frag.value = padapter->xmitpriv.frag_len;
  2273. wrqu->frag.fixed = 0; /* no auto select */
  2274. //wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD);
  2275. _func_exit_;
  2276. return 0;
  2277. }
  2278. static int rtw_wx_get_retry(struct net_device *dev,
  2279. struct iw_request_info *info,
  2280. union iwreq_data *wrqu, char *extra)
  2281. {
  2282. //_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2283. wrqu->retry.value = 7;
  2284. wrqu->retry.fixed = 0; /* no auto select */
  2285. wrqu->retry.disabled = 1;
  2286. return 0;
  2287. }
  2288. #if 0
  2289. #define IW_ENCODE_INDEX 0x00FF /* Token index (if needed) */
  2290. #define IW_ENCODE_FLAGS 0xFF00 /* Flags defined below */
  2291. #define IW_ENCODE_MODE 0xF000 /* Modes defined below */
  2292. #define IW_ENCODE_DISABLED 0x8000 /* Encoding disabled */
  2293. #define IW_ENCODE_ENABLED 0x0000 /* Encoding enabled */
  2294. #define IW_ENCODE_RESTRICTED 0x4000 /* Refuse non-encoded packets */
  2295. #define IW_ENCODE_OPEN 0x2000 /* Accept non-encoded packets */
  2296. #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
  2297. #define IW_ENCODE_TEMP 0x0400 /* Temporary key */
  2298. /*
  2299. iwconfig wlan0 key on -> flags = 0x6001 -> maybe it means auto
  2300. iwconfig wlan0 key off -> flags = 0x8800
  2301. iwconfig wlan0 key open -> flags = 0x2800
  2302. iwconfig wlan0 key open 1234567890 -> flags = 0x2000
  2303. iwconfig wlan0 key restricted -> flags = 0x4800
  2304. iwconfig wlan0 key open [3] 1234567890 -> flags = 0x2003
  2305. iwconfig wlan0 key restricted [2] 1234567890 -> flags = 0x4002
  2306. iwconfig wlan0 key open [3] -> flags = 0x2803
  2307. iwconfig wlan0 key restricted [2] -> flags = 0x4802
  2308. */
  2309. #endif
  2310. static int rtw_wx_set_enc(struct net_device *dev,
  2311. struct iw_request_info *info,
  2312. union iwreq_data *wrqu, char *keybuf)
  2313. {
  2314. u32 key, ret = 0;
  2315. u32 keyindex_provided;
  2316. NDIS_802_11_WEP wep;
  2317. NDIS_802_11_AUTHENTICATION_MODE authmode;
  2318. struct iw_point *erq = &(wrqu->encoding);
  2319. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2320. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  2321. DBG_871X("+rtw_wx_set_enc, flags=0x%x\n", erq->flags);
  2322. _rtw_memset(&wep, 0, sizeof(NDIS_802_11_WEP));
  2323. key = erq->flags & IW_ENCODE_INDEX;
  2324. _func_enter_;
  2325. if (erq->flags & IW_ENCODE_DISABLED)
  2326. {
  2327. DBG_871X("EncryptionDisabled\n");
  2328. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2329. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  2330. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  2331. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_Open; //open system
  2332. authmode = Ndis802_11AuthModeOpen;
  2333. padapter->securitypriv.ndisauthtype=authmode;
  2334. goto exit;
  2335. }
  2336. if (key) {
  2337. if (key > WEP_KEYS)
  2338. return -EINVAL;
  2339. key--;
  2340. keyindex_provided = 1;
  2341. }
  2342. else
  2343. {
  2344. keyindex_provided = 0;
  2345. key = padapter->securitypriv.dot11PrivacyKeyIndex;
  2346. DBG_871X("rtw_wx_set_enc, key=%d\n", key);
  2347. }
  2348. //set authentication mode
  2349. if(erq->flags & IW_ENCODE_OPEN)
  2350. {
  2351. DBG_871X("rtw_wx_set_enc():IW_ENCODE_OPEN\n");
  2352. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;//Ndis802_11EncryptionDisabled;
  2353. #ifdef CONFIG_PLATFORM_MT53XX
  2354. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2355. #else
  2356. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_Open;
  2357. #endif
  2358. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  2359. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  2360. authmode = Ndis802_11AuthModeOpen;
  2361. padapter->securitypriv.ndisauthtype=authmode;
  2362. }
  2363. else if(erq->flags & IW_ENCODE_RESTRICTED)
  2364. {
  2365. DBG_871X("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n");
  2366. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2367. #ifdef CONFIG_PLATFORM_MT53XX
  2368. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2369. #else
  2370. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_Shared;
  2371. #endif
  2372. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  2373. padapter->securitypriv.dot118021XGrpPrivacy=_WEP40_;
  2374. authmode = Ndis802_11AuthModeShared;
  2375. padapter->securitypriv.ndisauthtype=authmode;
  2376. }
  2377. else
  2378. {
  2379. DBG_871X("rtw_wx_set_enc():erq->flags=0x%x\n", erq->flags);
  2380. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;//Ndis802_11EncryptionDisabled;
  2381. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_Open; //open system
  2382. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  2383. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  2384. authmode = Ndis802_11AuthModeOpen;
  2385. padapter->securitypriv.ndisauthtype=authmode;
  2386. }
  2387. wep.KeyIndex = key;
  2388. if (erq->length > 0)
  2389. {
  2390. wep.KeyLength = erq->length <= 5 ? 5 : 13;
  2391. wep.Length = wep.KeyLength + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  2392. }
  2393. else
  2394. {
  2395. wep.KeyLength = 0 ;
  2396. if(keyindex_provided == 1)// set key_id only, no given KeyMaterial(erq->length==0).
  2397. {
  2398. padapter->securitypriv.dot11PrivacyKeyIndex = key;
  2399. DBG_871X("(keyindex_provided == 1), keyid=%d, key_len=%d\n", key, padapter->securitypriv.dot11DefKeylen[key]);
  2400. switch(padapter->securitypriv.dot11DefKeylen[key])
  2401. {
  2402. case 5:
  2403. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP40_;
  2404. break;
  2405. case 13:
  2406. padapter->securitypriv.dot11PrivacyAlgrthm=_WEP104_;
  2407. break;
  2408. default:
  2409. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  2410. break;
  2411. }
  2412. goto exit;
  2413. }
  2414. }
  2415. wep.KeyIndex |= 0x80000000;
  2416. _rtw_memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
  2417. if (rtw_set_802_11_add_wep(padapter, &wep) == _FALSE) {
  2418. if(rf_on == pwrpriv->rf_pwrstate )
  2419. ret = -EOPNOTSUPP;
  2420. goto exit;
  2421. }
  2422. exit:
  2423. _func_exit_;
  2424. return ret;
  2425. }
  2426. static int rtw_wx_get_enc(struct net_device *dev,
  2427. struct iw_request_info *info,
  2428. union iwreq_data *wrqu, char *keybuf)
  2429. {
  2430. uint key, ret =0;
  2431. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2432. struct iw_point *erq = &(wrqu->encoding);
  2433. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2434. _func_enter_;
  2435. if(check_fwstate(pmlmepriv, _FW_LINKED) != _TRUE)
  2436. {
  2437. if(check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE)
  2438. {
  2439. erq->length = 0;
  2440. erq->flags |= IW_ENCODE_DISABLED;
  2441. return 0;
  2442. }
  2443. }
  2444. key = erq->flags & IW_ENCODE_INDEX;
  2445. if (key) {
  2446. if (key > WEP_KEYS)
  2447. return -EINVAL;
  2448. key--;
  2449. } else
  2450. {
  2451. key = padapter->securitypriv.dot11PrivacyKeyIndex;
  2452. }
  2453. erq->flags = key + 1;
  2454. //if(padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
  2455. //{
  2456. // erq->flags |= IW_ENCODE_OPEN;
  2457. //}
  2458. switch(padapter->securitypriv.ndisencryptstatus)
  2459. {
  2460. case Ndis802_11EncryptionNotSupported:
  2461. case Ndis802_11EncryptionDisabled:
  2462. erq->length = 0;
  2463. erq->flags |= IW_ENCODE_DISABLED;
  2464. break;
  2465. case Ndis802_11Encryption1Enabled:
  2466. erq->length = padapter->securitypriv.dot11DefKeylen[key];
  2467. if(erq->length)
  2468. {
  2469. _rtw_memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]);
  2470. erq->flags |= IW_ENCODE_ENABLED;
  2471. if(padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
  2472. {
  2473. erq->flags |= IW_ENCODE_OPEN;
  2474. }
  2475. else if(padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared)
  2476. {
  2477. erq->flags |= IW_ENCODE_RESTRICTED;
  2478. }
  2479. }
  2480. else
  2481. {
  2482. erq->length = 0;
  2483. erq->flags |= IW_ENCODE_DISABLED;
  2484. }
  2485. break;
  2486. case Ndis802_11Encryption2Enabled:
  2487. case Ndis802_11Encryption3Enabled:
  2488. erq->length = 16;
  2489. erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY);
  2490. break;
  2491. default:
  2492. erq->length = 0;
  2493. erq->flags |= IW_ENCODE_DISABLED;
  2494. break;
  2495. }
  2496. _func_exit_;
  2497. return ret;
  2498. }
  2499. static int rtw_wx_get_power(struct net_device *dev,
  2500. struct iw_request_info *info,
  2501. union iwreq_data *wrqu, char *extra)
  2502. {
  2503. //_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2504. wrqu->power.value = 0;
  2505. wrqu->power.fixed = 0; /* no auto select */
  2506. wrqu->power.disabled = 1;
  2507. return 0;
  2508. }
  2509. static int rtw_wx_set_gen_ie(struct net_device *dev,
  2510. struct iw_request_info *info,
  2511. union iwreq_data *wrqu, char *extra)
  2512. {
  2513. int ret;
  2514. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2515. ret = rtw_set_wpa_ie(padapter, extra, wrqu->data.length);
  2516. return ret;
  2517. }
  2518. static int rtw_wx_set_auth(struct net_device *dev,
  2519. struct iw_request_info *info,
  2520. union iwreq_data *wrqu, char *extra)
  2521. {
  2522. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2523. struct iw_param *param = (struct iw_param*)&(wrqu->param);
  2524. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2525. struct security_priv *psecuritypriv = &padapter->securitypriv;
  2526. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  2527. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  2528. u32 value = param->value;
  2529. int ret = 0;
  2530. switch (param->flags & IW_AUTH_INDEX) {
  2531. case IW_AUTH_WPA_VERSION:
  2532. #ifdef CONFIG_WAPI_SUPPORT
  2533. #ifndef CONFIG_IOCTL_CFG80211
  2534. padapter->wapiInfo.bWapiEnable = false;
  2535. if(value == IW_AUTH_WAPI_VERSION_1)
  2536. {
  2537. padapter->wapiInfo.bWapiEnable = true;
  2538. psecuritypriv->dot11PrivacyAlgrthm = _SMS4_;
  2539. psecuritypriv->dot118021XGrpPrivacy = _SMS4_;
  2540. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2541. pmlmeinfo->auth_algo = psecuritypriv->dot11AuthAlgrthm;
  2542. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  2543. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  2544. }
  2545. #endif
  2546. #endif
  2547. break;
  2548. case IW_AUTH_CIPHER_PAIRWISE:
  2549. break;
  2550. case IW_AUTH_CIPHER_GROUP:
  2551. break;
  2552. case IW_AUTH_KEY_MGMT:
  2553. #ifdef CONFIG_WAPI_SUPPORT
  2554. #ifndef CONFIG_IOCTL_CFG80211
  2555. DBG_871X("rtw_wx_set_auth: IW_AUTH_KEY_MGMT case \n");
  2556. if(value == IW_AUTH_KEY_MGMT_WAPI_PSK)
  2557. padapter->wapiInfo.bWapiPSK = true;
  2558. else
  2559. padapter->wapiInfo.bWapiPSK = false;
  2560. DBG_871X("rtw_wx_set_auth: IW_AUTH_KEY_MGMT bwapipsk %d \n",padapter->wapiInfo.bWapiPSK);
  2561. #endif
  2562. #endif
  2563. /*
  2564. * ??? does not use these parameters
  2565. */
  2566. break;
  2567. case IW_AUTH_TKIP_COUNTERMEASURES:
  2568. {
  2569. if ( param->value )
  2570. { // wpa_supplicant is enabling the tkip countermeasure.
  2571. padapter->securitypriv.btkip_countermeasure = _TRUE;
  2572. }
  2573. else
  2574. { // wpa_supplicant is disabling the tkip countermeasure.
  2575. padapter->securitypriv.btkip_countermeasure = _FALSE;
  2576. }
  2577. break;
  2578. }
  2579. case IW_AUTH_DROP_UNENCRYPTED:
  2580. {
  2581. /* HACK:
  2582. *
  2583. * wpa_supplicant calls set_wpa_enabled when the driver
  2584. * is loaded and unloaded, regardless of if WPA is being
  2585. * used. No other calls are made which can be used to
  2586. * determine if encryption will be used or not prior to
  2587. * association being expected. If encryption is not being
  2588. * used, drop_unencrypted is set to false, else true -- we
  2589. * can use this to determine if the CAP_PRIVACY_ON bit should
  2590. * be set.
  2591. */
  2592. if(padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled)
  2593. {
  2594. break;//it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled,
  2595. // then it needn't reset it;
  2596. }
  2597. if(param->value){
  2598. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2599. padapter->securitypriv.dot11PrivacyAlgrthm=_NO_PRIVACY_;
  2600. padapter->securitypriv.dot118021XGrpPrivacy=_NO_PRIVACY_;
  2601. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_Open; //open system
  2602. padapter->securitypriv.ndisauthtype=Ndis802_11AuthModeOpen;
  2603. }
  2604. break;
  2605. }
  2606. case IW_AUTH_80211_AUTH_ALG:
  2607. #if defined(CONFIG_ANDROID) || 1
  2608. /*
  2609. * It's the starting point of a link layer connection using wpa_supplicant
  2610. */
  2611. if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  2612. LeaveAllPowerSaveMode(padapter);
  2613. rtw_disassoc_cmd(padapter, 500, _FALSE);
  2614. DBG_871X("%s...call rtw_indicate_disconnect\n ",__FUNCTION__);
  2615. rtw_indicate_disconnect(padapter);
  2616. rtw_free_assoc_resources(padapter, 1);
  2617. }
  2618. #endif
  2619. ret = wpa_set_auth_algs(dev, (u32)param->value);
  2620. break;
  2621. case IW_AUTH_WPA_ENABLED:
  2622. //if(param->value)
  2623. // padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; //802.1x
  2624. //else
  2625. // padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;//open system
  2626. //_disassociate(priv);
  2627. break;
  2628. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  2629. //ieee->ieee802_1x = param->value;
  2630. break;
  2631. case IW_AUTH_PRIVACY_INVOKED:
  2632. //ieee->privacy_invoked = param->value;
  2633. break;
  2634. #ifdef CONFIG_WAPI_SUPPORT
  2635. #ifndef CONFIG_IOCTL_CFG80211
  2636. case IW_AUTH_WAPI_ENABLED:
  2637. break;
  2638. #endif
  2639. #endif
  2640. default:
  2641. return -EOPNOTSUPP;
  2642. }
  2643. return ret;
  2644. }
  2645. static int rtw_wx_set_enc_ext(struct net_device *dev,
  2646. struct iw_request_info *info,
  2647. union iwreq_data *wrqu, char *extra)
  2648. {
  2649. char *alg_name;
  2650. u32 param_len;
  2651. struct ieee_param *param = NULL;
  2652. struct iw_point *pencoding = &wrqu->encoding;
  2653. struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
  2654. int ret=0;
  2655. param_len = sizeof(struct ieee_param) + pext->key_len;
  2656. param = (struct ieee_param *)rtw_malloc(param_len);
  2657. if (param == NULL)
  2658. return -1;
  2659. _rtw_memset(param, 0, param_len);
  2660. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  2661. _rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
  2662. switch (pext->alg) {
  2663. case IW_ENCODE_ALG_NONE:
  2664. //todo: remove key
  2665. //remove = 1;
  2666. alg_name = "none";
  2667. break;
  2668. case IW_ENCODE_ALG_WEP:
  2669. alg_name = "WEP";
  2670. break;
  2671. case IW_ENCODE_ALG_TKIP:
  2672. alg_name = "TKIP";
  2673. break;
  2674. case IW_ENCODE_ALG_CCMP:
  2675. alg_name = "CCMP";
  2676. break;
  2677. #ifdef CONFIG_WAPI_SUPPORT
  2678. #ifndef CONFIG_IOCTL_CFG80211
  2679. case IW_ENCODE_ALG_SM4:
  2680. alg_name= "SMS4";
  2681. _rtw_memcpy(param->sta_addr, pext->addr.sa_data, ETH_ALEN);
  2682. DBG_871X("rtw_wx_set_enc_ext: SMS4 case \n");
  2683. break;
  2684. #endif
  2685. #endif
  2686. default:
  2687. return -1;
  2688. }
  2689. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  2690. if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
  2691. {
  2692. param->u.crypt.set_tx = 1;
  2693. }
  2694. /* cliW: WEP does not have group key
  2695. * just not checking GROUP key setting
  2696. */
  2697. if ((pext->alg != IW_ENCODE_ALG_WEP) &&
  2698. (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
  2699. {
  2700. param->u.crypt.set_tx = 0;
  2701. }
  2702. param->u.crypt.idx = (pencoding->flags&0x00FF) -1 ;
  2703. if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
  2704. {
  2705. #ifdef CONFIG_WAPI_SUPPORT
  2706. #ifndef CONFIG_IOCTL_CFG80211
  2707. if(pext->alg == IW_ENCODE_ALG_SM4)
  2708. _rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 16);
  2709. else
  2710. #endif
  2711. #endif
  2712. _rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 8);
  2713. }
  2714. if(pext->key_len)
  2715. {
  2716. param->u.crypt.key_len = pext->key_len;
  2717. //_rtw_memcpy(param + 1, pext + 1, pext->key_len);
  2718. _rtw_memcpy(param->u.crypt.key, pext + 1, pext->key_len);
  2719. }
  2720. if (pencoding->flags & IW_ENCODE_DISABLED)
  2721. {
  2722. //todo: remove key
  2723. //remove = 1;
  2724. }
  2725. ret = wpa_set_encryption(dev, param, param_len);
  2726. if(param)
  2727. {
  2728. rtw_mfree((u8*)param, param_len);
  2729. }
  2730. return ret;
  2731. }
  2732. static int rtw_wx_get_nick(struct net_device *dev,
  2733. struct iw_request_info *info,
  2734. union iwreq_data *wrqu, char *extra)
  2735. {
  2736. //_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2737. //struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2738. //struct security_priv *psecuritypriv = &padapter->securitypriv;
  2739. if(extra)
  2740. {
  2741. wrqu->data.length = 14;
  2742. wrqu->data.flags = 1;
  2743. _rtw_memcpy(extra, "<WIFI@REALTEK>", 14);
  2744. }
  2745. //rtw_signal_process(pid, SIGUSR1); //for test
  2746. //dump debug info here
  2747. /*
  2748. u32 dot11AuthAlgrthm; // 802.11 auth, could be open, shared, and 8021x
  2749. u32 dot11PrivacyAlgrthm; // This specify the privacy for shared auth. algorithm.
  2750. u32 dot118021XGrpPrivacy; // This specify the privacy algthm. used for Grp key
  2751. u32 ndisauthtype;
  2752. u32 ndisencryptstatus;
  2753. */
  2754. //DBG_871X("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
  2755. // psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
  2756. // psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
  2757. //DBG_871X("enc_alg=0x%x\n", psecuritypriv->dot11PrivacyAlgrthm);
  2758. //DBG_871X("auth_type=0x%x\n", psecuritypriv->ndisauthtype);
  2759. //DBG_871X("enc_type=0x%x\n", psecuritypriv->ndisencryptstatus);
  2760. #if 0
  2761. DBG_871X("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
  2762. DBG_871X("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
  2763. DBG_871X("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
  2764. DBG_871X("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
  2765. DBG_871X("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
  2766. DBG_871X("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
  2767. DBG_871X("\n");
  2768. DBG_871X("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
  2769. DBG_871X("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
  2770. DBG_871X("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
  2771. DBG_871X("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
  2772. DBG_871X("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
  2773. DBG_871X("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
  2774. DBG_871X("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
  2775. DBG_871X("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
  2776. DBG_871X("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
  2777. DBG_871X("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
  2778. #endif
  2779. return 0;
  2780. }
  2781. static int rtw_wx_read32(struct net_device *dev,
  2782. struct iw_request_info *info,
  2783. union iwreq_data *wrqu, char *extra)
  2784. {
  2785. PADAPTER padapter;
  2786. struct iw_point *p;
  2787. u16 len;
  2788. u32 addr;
  2789. u32 data32;
  2790. u32 bytes;
  2791. u8 *ptmp;
  2792. padapter = (PADAPTER)rtw_netdev_priv(dev);
  2793. p = &wrqu->data;
  2794. len = p->length;
  2795. ptmp = (u8*)rtw_malloc(len);
  2796. if (NULL == ptmp)
  2797. return -ENOMEM;
  2798. if (copy_from_user(ptmp, p->pointer, len)) {
  2799. rtw_mfree(ptmp, len);
  2800. return -EFAULT;
  2801. }
  2802. bytes = 0;
  2803. addr = 0;
  2804. sscanf(ptmp, "%d,%x", &bytes, &addr);
  2805. switch (bytes) {
  2806. case 1:
  2807. data32 = rtw_read8(padapter, addr);
  2808. sprintf(extra, "0x%02X", data32);
  2809. break;
  2810. case 2:
  2811. data32 = rtw_read16(padapter, addr);
  2812. sprintf(extra, "0x%04X", data32);
  2813. break;
  2814. case 4:
  2815. data32 = rtw_read32(padapter, addr);
  2816. sprintf(extra, "0x%08X", data32);
  2817. break;
  2818. default:
  2819. DBG_871X(KERN_INFO "%s: usage> read [bytes],[address(hex)]\n", __func__);
  2820. return -EINVAL;
  2821. }
  2822. DBG_871X(KERN_INFO "%s: addr=0x%08X data=%s\n", __func__, addr, extra);
  2823. rtw_mfree(ptmp, len);
  2824. return 0;
  2825. }
  2826. static int rtw_wx_write32(struct net_device *dev,
  2827. struct iw_request_info *info,
  2828. union iwreq_data *wrqu, char *extra)
  2829. {
  2830. PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
  2831. u32 addr;
  2832. u32 data32;
  2833. u32 bytes;
  2834. bytes = 0;
  2835. addr = 0;
  2836. data32 = 0;
  2837. sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
  2838. switch (bytes) {
  2839. case 1:
  2840. rtw_write8(padapter, addr, (u8)data32);
  2841. DBG_871X(KERN_INFO "%s: addr=0x%08X data=0x%02X\n", __func__, addr, (u8)data32);
  2842. break;
  2843. case 2:
  2844. rtw_write16(padapter, addr, (u16)data32);
  2845. DBG_871X(KERN_INFO "%s: addr=0x%08X data=0x%04X\n", __func__, addr, (u16)data32);
  2846. break;
  2847. case 4:
  2848. rtw_write32(padapter, addr, data32);
  2849. DBG_871X(KERN_INFO "%s: addr=0x%08X data=0x%08X\n", __func__, addr, data32);
  2850. break;
  2851. default:
  2852. DBG_871X(KERN_INFO "%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
  2853. return -EINVAL;
  2854. }
  2855. return 0;
  2856. }
  2857. static int rtw_wx_read_rf(struct net_device *dev,
  2858. struct iw_request_info *info,
  2859. union iwreq_data *wrqu, char *extra)
  2860. {
  2861. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2862. u32 path, addr, data32;
  2863. path = *(u32*)extra;
  2864. addr = *((u32*)extra + 1);
  2865. data32 = rtw_hal_read_rfreg(padapter, path, addr, 0xFFFFF);
  2866. // DBG_871X("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32);
  2867. /*
  2868. * IMPORTANT!!
  2869. * Only when wireless private ioctl is at odd order,
  2870. * "extra" would be copied to user space.
  2871. */
  2872. sprintf(extra, "0x%05x", data32);
  2873. return 0;
  2874. }
  2875. static int rtw_wx_write_rf(struct net_device *dev,
  2876. struct iw_request_info *info,
  2877. union iwreq_data *wrqu, char *extra)
  2878. {
  2879. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2880. u32 path, addr, data32;
  2881. path = *(u32*)extra;
  2882. addr = *((u32*)extra + 1);
  2883. data32 = *((u32*)extra + 2);
  2884. // DBG_871X("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32);
  2885. rtw_hal_write_rfreg(padapter, path, addr, 0xFFFFF, data32);
  2886. return 0;
  2887. }
  2888. static int rtw_wx_priv_null(struct net_device *dev, struct iw_request_info *a,
  2889. union iwreq_data *wrqu, char *b)
  2890. {
  2891. return -1;
  2892. }
  2893. static int dummy(struct net_device *dev, struct iw_request_info *a,
  2894. union iwreq_data *wrqu, char *b)
  2895. {
  2896. //_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2897. //struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2898. //DBG_871X("cmd_code=%x, fwstate=0x%x\n", a->cmd, get_fwstate(pmlmepriv));
  2899. return -1;
  2900. }
  2901. static int rtw_wx_set_channel_plan(struct net_device *dev,
  2902. struct iw_request_info *info,
  2903. union iwreq_data *wrqu, char *extra)
  2904. {
  2905. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2906. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  2907. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2908. extern int rtw_channel_plan;
  2909. u8 channel_plan_req = (u8) (*((int *)wrqu));
  2910. #if 0
  2911. rtw_channel_plan = (int)wrqu->data.pointer;
  2912. pregistrypriv->channel_plan = rtw_channel_plan;
  2913. pmlmepriv->ChannelPlan = pregistrypriv->channel_plan;
  2914. #endif
  2915. if( _SUCCESS == rtw_set_chplan_cmd(padapter, channel_plan_req, 1) ) {
  2916. DBG_871X("%s set channel_plan = 0x%02X\n", __func__, pmlmepriv->ChannelPlan);
  2917. } else
  2918. return -EPERM;
  2919. return 0;
  2920. }
  2921. static int rtw_wx_set_mtk_wps_probe_ie(struct net_device *dev,
  2922. struct iw_request_info *a,
  2923. union iwreq_data *wrqu, char *b)
  2924. {
  2925. #ifdef CONFIG_PLATFORM_MT53XX
  2926. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2927. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2928. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_notice_,
  2929. ("WLAN IOCTL: cmd_code=%x, fwstate=0x%x\n",
  2930. a->cmd, get_fwstate(pmlmepriv)));
  2931. #endif
  2932. return 0;
  2933. }
  2934. static int rtw_wx_get_sensitivity(struct net_device *dev,
  2935. struct iw_request_info *info,
  2936. union iwreq_data *wrqu, char *buf)
  2937. {
  2938. #ifdef CONFIG_PLATFORM_MT53XX
  2939. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2940. // Modified by Albert 20110914
  2941. // This is in dbm format for MTK platform.
  2942. wrqu->qual.level = padapter->recvpriv.rssi;
  2943. DBG_871X(" level = %u\n", wrqu->qual.level );
  2944. #endif
  2945. return 0;
  2946. }
  2947. static int rtw_wx_set_mtk_wps_ie(struct net_device *dev,
  2948. struct iw_request_info *info,
  2949. union iwreq_data *wrqu, char *extra)
  2950. {
  2951. #ifdef CONFIG_PLATFORM_MT53XX
  2952. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2953. return rtw_set_wpa_ie(padapter, wrqu->data.pointer, wrqu->data.length);
  2954. #else
  2955. return 0;
  2956. #endif
  2957. }
  2958. /*
  2959. typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
  2960. union iwreq_data *wrqu, char *extra);
  2961. */
  2962. /*
  2963. * For all data larger than 16 octets, we need to use a
  2964. * pointer to memory allocated in user space.
  2965. */
  2966. static int rtw_drvext_hdl(struct net_device *dev, struct iw_request_info *info,
  2967. union iwreq_data *wrqu, char *extra)
  2968. {
  2969. #if 0
  2970. struct iw_point
  2971. {
  2972. void __user *pointer; /* Pointer to the data (in user space) */
  2973. __u16 length; /* number of fields or size in bytes */
  2974. __u16 flags; /* Optional params */
  2975. };
  2976. #endif
  2977. #ifdef CONFIG_DRVEXT_MODULE
  2978. u8 res;
  2979. struct drvext_handler *phandler;
  2980. struct drvext_oidparam *poidparam;
  2981. int ret;
  2982. u16 len;
  2983. u8 *pparmbuf, bset;
  2984. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  2985. struct iw_point *p = &wrqu->data;
  2986. if( (!p->length) || (!p->pointer)){
  2987. ret = -EINVAL;
  2988. goto _rtw_drvext_hdl_exit;
  2989. }
  2990. bset = (u8)(p->flags&0xFFFF);
  2991. len = p->length;
  2992. pparmbuf = (u8*)rtw_malloc(len);
  2993. if (pparmbuf == NULL){
  2994. ret = -ENOMEM;
  2995. goto _rtw_drvext_hdl_exit;
  2996. }
  2997. if(bset)//set info
  2998. {
  2999. if (copy_from_user(pparmbuf, p->pointer,len)) {
  3000. rtw_mfree(pparmbuf, len);
  3001. ret = -EFAULT;
  3002. goto _rtw_drvext_hdl_exit;
  3003. }
  3004. }
  3005. else//query info
  3006. {
  3007. }
  3008. //
  3009. poidparam = (struct drvext_oidparam *)pparmbuf;
  3010. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("drvext set oid subcode [%d], len[%d], InformationBufferLength[%d]\r\n",
  3011. poidparam->subcode, poidparam->len, len));
  3012. //check subcode
  3013. if ( poidparam->subcode >= MAX_DRVEXT_HANDLERS)
  3014. {
  3015. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("no matching drvext handlers\r\n"));
  3016. ret = -EINVAL;
  3017. goto _rtw_drvext_hdl_exit;
  3018. }
  3019. if ( poidparam->subcode >= MAX_DRVEXT_OID_SUBCODES)
  3020. {
  3021. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("no matching drvext subcodes\r\n"));
  3022. ret = -EINVAL;
  3023. goto _rtw_drvext_hdl_exit;
  3024. }
  3025. phandler = drvextoidhandlers + poidparam->subcode;
  3026. if (poidparam->len != phandler->parmsize)
  3027. {
  3028. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_err_,("no matching drvext param size %d vs %d\r\n",
  3029. poidparam->len , phandler->parmsize));
  3030. ret = -EINVAL;
  3031. goto _rtw_drvext_hdl_exit;
  3032. }
  3033. res = phandler->handler(&padapter->drvextpriv, bset, poidparam->data);
  3034. if(res==0)
  3035. {
  3036. ret = 0;
  3037. if (bset == 0x00) {//query info
  3038. //_rtw_memcpy(p->pointer, pparmbuf, len);
  3039. if (copy_to_user(p->pointer, pparmbuf, len))
  3040. ret = -EFAULT;
  3041. }
  3042. }
  3043. else
  3044. ret = -EFAULT;
  3045. _rtw_drvext_hdl_exit:
  3046. return ret;
  3047. #endif
  3048. return 0;
  3049. }
  3050. static void rtw_dbg_mode_hdl(_adapter *padapter, u32 id, u8 *pdata, u32 len)
  3051. {
  3052. pRW_Reg RegRWStruct;
  3053. struct rf_reg_param *prfreg;
  3054. u8 path;
  3055. u8 offset;
  3056. u32 value;
  3057. DBG_871X("%s\n", __FUNCTION__);
  3058. switch(id)
  3059. {
  3060. case GEN_MP_IOCTL_SUBCODE(MP_START):
  3061. DBG_871X("871x_driver is only for normal mode, can't enter mp mode\n");
  3062. break;
  3063. case GEN_MP_IOCTL_SUBCODE(READ_REG):
  3064. RegRWStruct = (pRW_Reg)pdata;
  3065. switch (RegRWStruct->width)
  3066. {
  3067. case 1:
  3068. RegRWStruct->value = rtw_read8(padapter, RegRWStruct->offset);
  3069. break;
  3070. case 2:
  3071. RegRWStruct->value = rtw_read16(padapter, RegRWStruct->offset);
  3072. break;
  3073. case 4:
  3074. RegRWStruct->value = rtw_read32(padapter, RegRWStruct->offset);
  3075. break;
  3076. default:
  3077. break;
  3078. }
  3079. break;
  3080. case GEN_MP_IOCTL_SUBCODE(WRITE_REG):
  3081. RegRWStruct = (pRW_Reg)pdata;
  3082. switch (RegRWStruct->width)
  3083. {
  3084. case 1:
  3085. rtw_write8(padapter, RegRWStruct->offset, (u8)RegRWStruct->value);
  3086. break;
  3087. case 2:
  3088. rtw_write16(padapter, RegRWStruct->offset, (u16)RegRWStruct->value);
  3089. break;
  3090. case 4:
  3091. rtw_write32(padapter, RegRWStruct->offset, (u32)RegRWStruct->value);
  3092. break;
  3093. default:
  3094. break;
  3095. }
  3096. break;
  3097. case GEN_MP_IOCTL_SUBCODE(READ_RF_REG):
  3098. prfreg = (struct rf_reg_param *)pdata;
  3099. path = (u8)prfreg->path;
  3100. offset = (u8)prfreg->offset;
  3101. value = rtw_hal_read_rfreg(padapter, path, offset, 0xffffffff);
  3102. prfreg->value = value;
  3103. break;
  3104. case GEN_MP_IOCTL_SUBCODE(WRITE_RF_REG):
  3105. prfreg = (struct rf_reg_param *)pdata;
  3106. path = (u8)prfreg->path;
  3107. offset = (u8)prfreg->offset;
  3108. value = prfreg->value;
  3109. rtw_hal_write_rfreg(padapter, path, offset, 0xffffffff, value);
  3110. break;
  3111. case GEN_MP_IOCTL_SUBCODE(TRIGGER_GPIO):
  3112. DBG_871X("==> trigger gpio 0\n");
  3113. rtw_hal_set_hwreg(padapter, HW_VAR_TRIGGER_GPIO_0, 0);
  3114. break;
  3115. #ifdef CONFIG_BT_COEXIST
  3116. case GEN_MP_IOCTL_SUBCODE(SET_DM_BT):
  3117. DBG_871X("==> set dm_bt_coexist:%x\n",*(u8 *)pdata);
  3118. rtw_hal_set_hwreg(padapter, HW_VAR_BT_SET_COEXIST, pdata);
  3119. break;
  3120. case GEN_MP_IOCTL_SUBCODE(DEL_BA):
  3121. DBG_871X("==> delete ba:%x\n",*(u8 *)pdata);
  3122. rtw_hal_set_hwreg(padapter, HW_VAR_BT_ISSUE_DELBA, pdata);
  3123. break;
  3124. #endif
  3125. #ifdef DBG_CONFIG_ERROR_DETECT
  3126. case GEN_MP_IOCTL_SUBCODE(GET_WIFI_STATUS):
  3127. *pdata = rtw_hal_sreset_get_wifi_status(padapter);
  3128. break;
  3129. #endif
  3130. default:
  3131. break;
  3132. }
  3133. }
  3134. static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info,
  3135. union iwreq_data *wrqu, char *extra)
  3136. {
  3137. int ret = 0;
  3138. u32 BytesRead, BytesWritten, BytesNeeded;
  3139. struct oid_par_priv oid_par;
  3140. struct mp_ioctl_handler *phandler;
  3141. struct mp_ioctl_param *poidparam;
  3142. uint status=0;
  3143. u16 len;
  3144. u8 *pparmbuf = NULL, bset;
  3145. PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
  3146. struct iw_point *p = &wrqu->data;
  3147. //DBG_871X("+rtw_mp_ioctl_hdl\n");
  3148. //mutex_lock(&ioctl_mutex);
  3149. if ((!p->length) || (!p->pointer)) {
  3150. ret = -EINVAL;
  3151. goto _rtw_mp_ioctl_hdl_exit;
  3152. }
  3153. pparmbuf = NULL;
  3154. bset = (u8)(p->flags & 0xFFFF);
  3155. len = p->length;
  3156. pparmbuf = (u8*)rtw_malloc(len);
  3157. if (pparmbuf == NULL){
  3158. ret = -ENOMEM;
  3159. goto _rtw_mp_ioctl_hdl_exit;
  3160. }
  3161. if (copy_from_user(pparmbuf, p->pointer, len)) {
  3162. ret = -EFAULT;
  3163. goto _rtw_mp_ioctl_hdl_exit;
  3164. }
  3165. poidparam = (struct mp_ioctl_param *)pparmbuf;
  3166. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_,
  3167. ("rtw_mp_ioctl_hdl: subcode [%d], len[%d], buffer_len[%d]\r\n",
  3168. poidparam->subcode, poidparam->len, len));
  3169. if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
  3170. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("no matching drvext subcodes\r\n"));
  3171. ret = -EINVAL;
  3172. goto _rtw_mp_ioctl_hdl_exit;
  3173. }
  3174. //DBG_871X("%s: %d\n", __func__, poidparam->subcode);
  3175. #ifdef CONFIG_MP_INCLUDED
  3176. if (padapter->registrypriv.mp_mode == 1)
  3177. {
  3178. phandler = mp_ioctl_hdl + poidparam->subcode;
  3179. if ((phandler->paramsize != 0) && (poidparam->len < phandler->paramsize))
  3180. {
  3181. RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_,
  3182. ("no matching drvext param size %d vs %d\r\n",
  3183. poidparam->len, phandler->paramsize));
  3184. ret = -EINVAL;
  3185. goto _rtw_mp_ioctl_hdl_exit;
  3186. }
  3187. if (phandler->handler)
  3188. {
  3189. oid_par.adapter_context = padapter;
  3190. oid_par.oid = phandler->oid;
  3191. oid_par.information_buf = poidparam->data;
  3192. oid_par.information_buf_len = poidparam->len;
  3193. oid_par.dbg = 0;
  3194. BytesWritten = 0;
  3195. BytesNeeded = 0;
  3196. if (bset) {
  3197. oid_par.bytes_rw = &BytesRead;
  3198. oid_par.bytes_needed = &BytesNeeded;
  3199. oid_par.type_of_oid = SET_OID;
  3200. } else {
  3201. oid_par.bytes_rw = &BytesWritten;
  3202. oid_par.bytes_needed = &BytesNeeded;
  3203. oid_par.type_of_oid = QUERY_OID;
  3204. }
  3205. status = phandler->handler(&oid_par);
  3206. //todo:check status, BytesNeeded, etc.
  3207. }
  3208. else {
  3209. DBG_871X("rtw_mp_ioctl_hdl(): err!, subcode=%d, oid=%d, handler=%p\n",
  3210. poidparam->subcode, phandler->oid, phandler->handler);
  3211. ret = -EFAULT;
  3212. goto _rtw_mp_ioctl_hdl_exit;
  3213. }
  3214. }
  3215. else
  3216. #endif
  3217. {
  3218. rtw_dbg_mode_hdl(padapter, poidparam->subcode, poidparam->data, poidparam->len);
  3219. }
  3220. if (bset == 0x00) {//query info
  3221. if (copy_to_user(p->pointer, pparmbuf, len))
  3222. ret = -EFAULT;
  3223. }
  3224. if (status) {
  3225. ret = -EFAULT;
  3226. goto _rtw_mp_ioctl_hdl_exit;
  3227. }
  3228. _rtw_mp_ioctl_hdl_exit:
  3229. if (pparmbuf)
  3230. rtw_mfree(pparmbuf, len);
  3231. //mutex_unlock(&ioctl_mutex);
  3232. return ret;
  3233. }
  3234. static int rtw_get_ap_info(struct net_device *dev,
  3235. struct iw_request_info *info,
  3236. union iwreq_data *wrqu, char *extra)
  3237. {
  3238. int bssid_match, ret = 0;
  3239. u32 cnt=0, wpa_ielen;
  3240. _irqL irqL;
  3241. _list *plist, *phead;
  3242. unsigned char *pbuf;
  3243. u8 bssid[ETH_ALEN];
  3244. char data[32];
  3245. struct wlan_network *pnetwork = NULL;
  3246. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3247. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3248. _queue *queue = &(pmlmepriv->scanned_queue);
  3249. struct iw_point *pdata = &wrqu->data;
  3250. DBG_871X("+rtw_get_aplist_info\n");
  3251. if((padapter->bDriverStopped) || (pdata==NULL))
  3252. {
  3253. ret= -EINVAL;
  3254. goto exit;
  3255. }
  3256. while((check_fwstate(pmlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) == _TRUE)
  3257. {
  3258. rtw_msleep_os(30);
  3259. cnt++;
  3260. if(cnt > 100)
  3261. break;
  3262. }
  3263. //pdata->length = 0;//?
  3264. pdata->flags = 0;
  3265. if(pdata->length>=32)
  3266. {
  3267. if(copy_from_user(data, pdata->pointer, 32))
  3268. {
  3269. ret= -EINVAL;
  3270. goto exit;
  3271. }
  3272. }
  3273. else
  3274. {
  3275. ret= -EINVAL;
  3276. goto exit;
  3277. }
  3278. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3279. phead = get_list_head(queue);
  3280. plist = get_next(phead);
  3281. while(1)
  3282. {
  3283. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  3284. break;
  3285. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3286. //if(hwaddr_aton_i(pdata->pointer, bssid))
  3287. if(hwaddr_aton_i(data, bssid))
  3288. {
  3289. DBG_871X("Invalid BSSID '%s'.\n", (u8*)data);
  3290. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3291. return -EINVAL;
  3292. }
  3293. if(_rtw_memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN) == _TRUE)//BSSID match, then check if supporting wpa/wpa2
  3294. {
  3295. DBG_871X("BSSID:" MAC_FMT "\n", MAC_ARG(bssid));
  3296. pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength-12);
  3297. if(pbuf && (wpa_ielen>0))
  3298. {
  3299. pdata->flags = 1;
  3300. break;
  3301. }
  3302. pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength-12);
  3303. if(pbuf && (wpa_ielen>0))
  3304. {
  3305. pdata->flags = 2;
  3306. break;
  3307. }
  3308. }
  3309. plist = get_next(plist);
  3310. }
  3311. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3312. if(pdata->length>=34)
  3313. {
  3314. if(copy_to_user((u8*)pdata->pointer+32, (u8*)&pdata->flags, 1))
  3315. {
  3316. ret= -EINVAL;
  3317. goto exit;
  3318. }
  3319. }
  3320. exit:
  3321. return ret;
  3322. }
  3323. static int rtw_set_pid(struct net_device *dev,
  3324. struct iw_request_info *info,
  3325. union iwreq_data *wrqu, char *extra)
  3326. {
  3327. int ret = 0;
  3328. _adapter *padapter = rtw_netdev_priv(dev);
  3329. int *pdata = (int *)wrqu;
  3330. int selector;
  3331. if((padapter->bDriverStopped) || (pdata==NULL))
  3332. {
  3333. ret= -EINVAL;
  3334. goto exit;
  3335. }
  3336. selector = *pdata;
  3337. if(selector < 3 && selector >=0) {
  3338. padapter->pid[selector] = *(pdata+1);
  3339. #ifdef CONFIG_GLOBAL_UI_PID
  3340. ui_pid[selector] = *(pdata+1);
  3341. #endif
  3342. DBG_871X("%s set pid[%d]=%d\n", __FUNCTION__, selector ,padapter->pid[selector]);
  3343. }
  3344. else
  3345. DBG_871X("%s selector %d error\n", __FUNCTION__, selector);
  3346. exit:
  3347. return ret;
  3348. }
  3349. static int rtw_wps_start(struct net_device *dev,
  3350. struct iw_request_info *info,
  3351. union iwreq_data *wrqu, char *extra)
  3352. {
  3353. int ret = 0;
  3354. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3355. struct iw_point *pdata = &wrqu->data;
  3356. u32 u32wps_start = 0;
  3357. unsigned int uintRet = 0;
  3358. uintRet = copy_from_user( ( void* ) &u32wps_start, pdata->pointer, 4 );
  3359. if((padapter->bDriverStopped) || (pdata==NULL))
  3360. {
  3361. ret= -EINVAL;
  3362. goto exit;
  3363. }
  3364. if ( u32wps_start == 0 )
  3365. {
  3366. u32wps_start = *extra;
  3367. }
  3368. DBG_871X( "[%s] wps_start = %d\n", __FUNCTION__, u32wps_start );
  3369. if ( u32wps_start == 1 ) // WPS Start
  3370. {
  3371. rtw_led_control(padapter, LED_CTL_START_WPS);
  3372. }
  3373. else if ( u32wps_start == 2 ) // WPS Stop because of wps success
  3374. {
  3375. rtw_led_control(padapter, LED_CTL_STOP_WPS);
  3376. }
  3377. else if ( u32wps_start == 3 ) // WPS Stop because of wps fail
  3378. {
  3379. rtw_led_control(padapter, LED_CTL_STOP_WPS_FAIL);
  3380. }
  3381. #ifdef CONFIG_INTEL_WIDI
  3382. process_intel_widi_wps_status(padapter, u32wps_start);
  3383. #endif //CONFIG_INTEL_WIDI
  3384. exit:
  3385. return ret;
  3386. }
  3387. #ifdef CONFIG_P2P
  3388. static int rtw_wext_p2p_enable(struct net_device *dev,
  3389. struct iw_request_info *info,
  3390. union iwreq_data *wrqu, char *extra)
  3391. {
  3392. int ret = 0;
  3393. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3394. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3395. struct iw_point *pdata = &wrqu->data;
  3396. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3397. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3398. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  3399. enum P2P_ROLE init_role = P2P_ROLE_DISABLE;
  3400. if(*extra == '0' )
  3401. init_role = P2P_ROLE_DISABLE;
  3402. else if(*extra == '1')
  3403. init_role = P2P_ROLE_DEVICE;
  3404. else if(*extra == '2')
  3405. init_role = P2P_ROLE_CLIENT;
  3406. else if(*extra == '3')
  3407. init_role = P2P_ROLE_GO;
  3408. if(_FAIL == rtw_p2p_enable(padapter, init_role))
  3409. {
  3410. ret = -EFAULT;
  3411. goto exit;
  3412. }
  3413. //set channel/bandwidth
  3414. if(init_role != P2P_ROLE_DISABLE)
  3415. {
  3416. u8 channel, ch_offset;
  3417. u16 bwmode;
  3418. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN))
  3419. {
  3420. // Stay at the listen state and wait for discovery.
  3421. channel = pwdinfo->listen_channel;
  3422. pwdinfo->operating_channel = pwdinfo->listen_channel;
  3423. ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  3424. bwmode = CHANNEL_WIDTH_20;
  3425. }
  3426. #ifdef CONFIG_CONCURRENT_MODE
  3427. else if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
  3428. {
  3429. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  3430. //struct wifidirect_info *pbuddy_wdinfo = &pbuddy_adapter->wdinfo;
  3431. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  3432. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  3433. _set_timer( &pwdinfo->ap_p2p_switch_timer, pwdinfo->ext_listen_interval );
  3434. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  3435. {
  3436. pwdinfo->operating_channel = pbuddy_mlmeext->cur_channel;
  3437. // How about the ch_offset and bwmode ??
  3438. }
  3439. else
  3440. {
  3441. pwdinfo->operating_channel = pwdinfo->listen_channel;
  3442. }
  3443. channel = pbuddy_mlmeext->cur_channel;
  3444. ch_offset = pbuddy_mlmeext->cur_ch_offset;
  3445. bwmode = pbuddy_mlmeext->cur_bwmode;
  3446. }
  3447. #endif
  3448. else
  3449. {
  3450. pwdinfo->operating_channel = pmlmeext->cur_channel;
  3451. channel = pwdinfo->operating_channel;
  3452. ch_offset = pmlmeext->cur_ch_offset;
  3453. bwmode = pmlmeext->cur_bwmode;
  3454. }
  3455. set_channel_bwmode(padapter, channel, ch_offset, bwmode);
  3456. }
  3457. exit:
  3458. return ret;
  3459. }
  3460. static int rtw_p2p_set_go_nego_ssid(struct net_device *dev,
  3461. struct iw_request_info *info,
  3462. union iwreq_data *wrqu, char *extra)
  3463. {
  3464. int ret = 0;
  3465. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3466. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3467. struct iw_point *pdata = &wrqu->data;
  3468. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3469. DBG_871X( "[%s] ssid = %s, len = %zu\n", __FUNCTION__, extra, strlen( extra ) );
  3470. _rtw_memcpy( pwdinfo->nego_ssid, extra, strlen( extra ) );
  3471. pwdinfo->nego_ssidlen = strlen( extra );
  3472. return ret;
  3473. }
  3474. static int rtw_p2p_set_intent(struct net_device *dev,
  3475. struct iw_request_info *info,
  3476. union iwreq_data *wrqu, char *extra)
  3477. {
  3478. int ret = 0;
  3479. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3480. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3481. u8 intent = pwdinfo->intent;
  3482. switch( wrqu->data.length )
  3483. {
  3484. case 1:
  3485. {
  3486. intent = extra[ 0 ] - '0';
  3487. break;
  3488. }
  3489. case 2:
  3490. {
  3491. intent = str_2char2num( extra[ 0 ], extra[ 1 ]);
  3492. break;
  3493. }
  3494. }
  3495. if ( intent <= 15 )
  3496. {
  3497. pwdinfo->intent= intent;
  3498. }
  3499. else
  3500. {
  3501. ret = -1;
  3502. }
  3503. DBG_871X( "[%s] intent = %d\n", __FUNCTION__, intent);
  3504. return ret;
  3505. }
  3506. static int rtw_p2p_set_listen_ch(struct net_device *dev,
  3507. struct iw_request_info *info,
  3508. union iwreq_data *wrqu, char *extra)
  3509. {
  3510. int ret = 0;
  3511. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3512. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3513. u8 listen_ch = pwdinfo->listen_channel; // Listen channel number
  3514. switch( wrqu->data.length )
  3515. {
  3516. case 1:
  3517. {
  3518. listen_ch = extra[ 0 ] - '0';
  3519. break;
  3520. }
  3521. case 2:
  3522. {
  3523. listen_ch = str_2char2num( extra[ 0 ], extra[ 1 ]);
  3524. break;
  3525. }
  3526. }
  3527. if ( ( listen_ch == 1 ) || ( listen_ch == 6 ) || ( listen_ch == 11 ) )
  3528. {
  3529. pwdinfo->listen_channel = listen_ch;
  3530. set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  3531. }
  3532. else
  3533. {
  3534. ret = -1;
  3535. }
  3536. DBG_871X( "[%s] listen_ch = %d\n", __FUNCTION__, pwdinfo->listen_channel );
  3537. return ret;
  3538. }
  3539. static int rtw_p2p_set_op_ch(struct net_device *dev,
  3540. struct iw_request_info *info,
  3541. union iwreq_data *wrqu, char *extra)
  3542. {
  3543. // Commented by Albert 20110524
  3544. // This function is used to set the operating channel if the driver will become the group owner
  3545. int ret = 0;
  3546. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3547. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3548. u8 op_ch = pwdinfo->operating_channel; // Operating channel number
  3549. switch( wrqu->data.length )
  3550. {
  3551. case 1:
  3552. {
  3553. op_ch = extra[ 0 ] - '0';
  3554. break;
  3555. }
  3556. case 2:
  3557. {
  3558. op_ch = str_2char2num( extra[ 0 ], extra[ 1 ]);
  3559. break;
  3560. }
  3561. }
  3562. if ( op_ch > 0 )
  3563. {
  3564. pwdinfo->operating_channel = op_ch;
  3565. }
  3566. else
  3567. {
  3568. ret = -1;
  3569. }
  3570. DBG_871X( "[%s] op_ch = %d\n", __FUNCTION__, pwdinfo->operating_channel );
  3571. return ret;
  3572. }
  3573. static int rtw_p2p_profilefound(struct net_device *dev,
  3574. struct iw_request_info *info,
  3575. union iwreq_data *wrqu, char *extra)
  3576. {
  3577. int ret = 0;
  3578. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3579. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3580. // Comment by Albert 2010/10/13
  3581. // Input data format:
  3582. // Ex: 0
  3583. // Ex: 1XX:XX:XX:XX:XX:XXYYSSID
  3584. // 0 => Reflush the profile record list.
  3585. // 1 => Add the profile list
  3586. // XX:XX:XX:XX:XX:XX => peer's MAC Address ( ex: 00:E0:4C:00:00:01 )
  3587. // YY => SSID Length
  3588. // SSID => SSID for persistence group
  3589. DBG_871X( "[%s] In value = %s, len = %d \n", __FUNCTION__, extra, wrqu->data.length -1);
  3590. // The upper application should pass the SSID to driver by using this rtw_p2p_profilefound function.
  3591. if(!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3592. {
  3593. if ( extra[ 0 ] == '0' )
  3594. {
  3595. // Remove all the profile information of wifidirect_info structure.
  3596. _rtw_memset( &pwdinfo->profileinfo[ 0 ], 0x00, sizeof( struct profile_info ) * P2P_MAX_PERSISTENT_GROUP_NUM );
  3597. pwdinfo->profileindex = 0;
  3598. }
  3599. else
  3600. {
  3601. if ( pwdinfo->profileindex >= P2P_MAX_PERSISTENT_GROUP_NUM )
  3602. {
  3603. ret = -1;
  3604. }
  3605. else
  3606. {
  3607. int jj, kk;
  3608. // Add this profile information into pwdinfo->profileinfo
  3609. // Ex: 1XX:XX:XX:XX:XX:XXYYSSID
  3610. for( jj = 0, kk = 1; jj < ETH_ALEN; jj++, kk += 3 )
  3611. {
  3612. pwdinfo->profileinfo[ pwdinfo->profileindex ].peermac[ jj ] = key_2char2num(extra[ kk ], extra[ kk+ 1 ]);
  3613. }
  3614. //pwdinfo->profileinfo[ pwdinfo->profileindex ].ssidlen = ( extra[18] - '0' ) * 10 + ( extra[ 19 ] - '0' );
  3615. //_rtw_memcpy( pwdinfo->profileinfo[ pwdinfo->profileindex ].ssid, &extra[ 20 ], pwdinfo->profileinfo[ pwdinfo->profileindex ].ssidlen );
  3616. pwdinfo->profileindex++;
  3617. }
  3618. }
  3619. }
  3620. return ret;
  3621. }
  3622. static int rtw_p2p_setDN(struct net_device *dev,
  3623. struct iw_request_info *info,
  3624. union iwreq_data *wrqu, char *extra)
  3625. {
  3626. int ret = 0;
  3627. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3628. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  3629. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  3630. _rtw_memset( pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN );
  3631. _rtw_memcpy( pwdinfo->device_name, extra, wrqu->data.length - 1 );
  3632. pwdinfo->device_name_len = wrqu->data.length - 1;
  3633. return ret;
  3634. }
  3635. static int rtw_p2p_get_status(struct net_device *dev,
  3636. struct iw_request_info *info,
  3637. union iwreq_data *wrqu, char *extra)
  3638. {
  3639. int ret = 0;
  3640. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3641. struct iw_point *pdata = &wrqu->data;
  3642. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3643. #ifdef CONFIG_CONCURRENT_MODE
  3644. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  3645. struct wifidirect_info *pbuddy_wdinfo = &pbuddy_adapter->wdinfo;
  3646. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  3647. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  3648. #endif
  3649. if ( padapter->bShowGetP2PState )
  3650. {
  3651. DBG_871X( "[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3652. pwdinfo->p2p_peer_interface_addr[ 0 ], pwdinfo->p2p_peer_interface_addr[ 1 ], pwdinfo->p2p_peer_interface_addr[ 2 ],
  3653. pwdinfo->p2p_peer_interface_addr[ 3 ], pwdinfo->p2p_peer_interface_addr[ 4 ], pwdinfo->p2p_peer_interface_addr[ 5 ]);
  3654. }
  3655. // Commented by Albert 2010/10/12
  3656. // Because of the output size limitation, I had removed the "Role" information.
  3657. // About the "Role" information, we will use the new private IOCTL to get the "Role" information.
  3658. sprintf( extra, "\n\nStatus=%.2d\n", rtw_p2p_state(pwdinfo) );
  3659. wrqu->data.length = strlen( extra );
  3660. return ret;
  3661. }
  3662. // Commented by Albert 20110520
  3663. // This function will return the config method description
  3664. // This config method description will show us which config method the remote P2P device is intented to use
  3665. // by sending the provisioning discovery request frame.
  3666. static int rtw_p2p_get_req_cm(struct net_device *dev,
  3667. struct iw_request_info *info,
  3668. union iwreq_data *wrqu, char *extra)
  3669. {
  3670. int ret = 0;
  3671. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3672. struct iw_point *pdata = &wrqu->data;
  3673. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3674. sprintf( extra, "\n\nCM=%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req );
  3675. wrqu->data.length = strlen( extra );
  3676. return ret;
  3677. }
  3678. static int rtw_p2p_get_role(struct net_device *dev,
  3679. struct iw_request_info *info,
  3680. union iwreq_data *wrqu, char *extra)
  3681. {
  3682. int ret = 0;
  3683. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3684. struct iw_point *pdata = &wrqu->data;
  3685. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3686. DBG_871X( "[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3687. pwdinfo->p2p_peer_interface_addr[ 0 ], pwdinfo->p2p_peer_interface_addr[ 1 ], pwdinfo->p2p_peer_interface_addr[ 2 ],
  3688. pwdinfo->p2p_peer_interface_addr[ 3 ], pwdinfo->p2p_peer_interface_addr[ 4 ], pwdinfo->p2p_peer_interface_addr[ 5 ]);
  3689. sprintf( extra, "\n\nRole=%.2d\n", rtw_p2p_role(pwdinfo) );
  3690. wrqu->data.length = strlen( extra );
  3691. return ret;
  3692. }
  3693. static int rtw_p2p_get_peer_ifaddr(struct net_device *dev,
  3694. struct iw_request_info *info,
  3695. union iwreq_data *wrqu, char *extra)
  3696. {
  3697. int ret = 0;
  3698. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3699. struct iw_point *pdata = &wrqu->data;
  3700. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3701. DBG_871X( "[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3702. pwdinfo->p2p_peer_interface_addr[ 0 ], pwdinfo->p2p_peer_interface_addr[ 1 ], pwdinfo->p2p_peer_interface_addr[ 2 ],
  3703. pwdinfo->p2p_peer_interface_addr[ 3 ], pwdinfo->p2p_peer_interface_addr[ 4 ], pwdinfo->p2p_peer_interface_addr[ 5 ]);
  3704. sprintf( extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3705. pwdinfo->p2p_peer_interface_addr[ 0 ], pwdinfo->p2p_peer_interface_addr[ 1 ], pwdinfo->p2p_peer_interface_addr[ 2 ],
  3706. pwdinfo->p2p_peer_interface_addr[ 3 ], pwdinfo->p2p_peer_interface_addr[ 4 ], pwdinfo->p2p_peer_interface_addr[ 5 ]);
  3707. wrqu->data.length = strlen( extra );
  3708. return ret;
  3709. }
  3710. static int rtw_p2p_get_peer_devaddr(struct net_device *dev,
  3711. struct iw_request_info *info,
  3712. union iwreq_data *wrqu, char *extra)
  3713. {
  3714. int ret = 0;
  3715. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3716. struct iw_point *pdata = &wrqu->data;
  3717. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3718. DBG_871X( "[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3719. pwdinfo->rx_prov_disc_info.peerDevAddr[ 0 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 1 ],
  3720. pwdinfo->rx_prov_disc_info.peerDevAddr[ 2 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 3 ],
  3721. pwdinfo->rx_prov_disc_info.peerDevAddr[ 4 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 5 ]);
  3722. sprintf( extra, "\n%.2X%.2X%.2X%.2X%.2X%.2X",
  3723. pwdinfo->rx_prov_disc_info.peerDevAddr[ 0 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 1 ],
  3724. pwdinfo->rx_prov_disc_info.peerDevAddr[ 2 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 3 ],
  3725. pwdinfo->rx_prov_disc_info.peerDevAddr[ 4 ], pwdinfo->rx_prov_disc_info.peerDevAddr[ 5 ]);
  3726. wrqu->data.length = strlen( extra );
  3727. return ret;
  3728. }
  3729. static int rtw_p2p_get_peer_devaddr_by_invitation(struct net_device *dev,
  3730. struct iw_request_info *info,
  3731. union iwreq_data *wrqu, char *extra)
  3732. {
  3733. int ret = 0;
  3734. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3735. struct iw_point *pdata = &wrqu->data;
  3736. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3737. DBG_871X( "[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
  3738. pwdinfo->p2p_peer_device_addr[ 0 ], pwdinfo->p2p_peer_device_addr[ 1 ],
  3739. pwdinfo->p2p_peer_device_addr[ 2 ], pwdinfo->p2p_peer_device_addr[ 3 ],
  3740. pwdinfo->p2p_peer_device_addr[ 4 ], pwdinfo->p2p_peer_device_addr[ 5 ]);
  3741. sprintf( extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3742. pwdinfo->p2p_peer_device_addr[ 0 ], pwdinfo->p2p_peer_device_addr[ 1 ],
  3743. pwdinfo->p2p_peer_device_addr[ 2 ], pwdinfo->p2p_peer_device_addr[ 3 ],
  3744. pwdinfo->p2p_peer_device_addr[ 4 ], pwdinfo->p2p_peer_device_addr[ 5 ]);
  3745. wrqu->data.length = strlen( extra );
  3746. return ret;
  3747. }
  3748. static int rtw_p2p_get_groupid(struct net_device *dev,
  3749. struct iw_request_info *info,
  3750. union iwreq_data *wrqu, char *extra)
  3751. {
  3752. int ret = 0;
  3753. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3754. struct iw_point *pdata = &wrqu->data;
  3755. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3756. sprintf( extra, "\n%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s",
  3757. pwdinfo->groupid_info.go_device_addr[ 0 ], pwdinfo->groupid_info.go_device_addr[ 1 ],
  3758. pwdinfo->groupid_info.go_device_addr[ 2 ], pwdinfo->groupid_info.go_device_addr[ 3 ],
  3759. pwdinfo->groupid_info.go_device_addr[ 4 ], pwdinfo->groupid_info.go_device_addr[ 5 ],
  3760. pwdinfo->groupid_info.ssid);
  3761. wrqu->data.length = strlen( extra );
  3762. return ret;
  3763. }
  3764. static int rtw_p2p_get_op_ch(struct net_device *dev,
  3765. struct iw_request_info *info,
  3766. union iwreq_data *wrqu, char *extra)
  3767. {
  3768. int ret = 0;
  3769. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3770. struct iw_point *pdata = &wrqu->data;
  3771. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3772. DBG_871X( "[%s] Op_ch = %02x\n", __FUNCTION__, pwdinfo->operating_channel);
  3773. sprintf( extra, "\n\nOp_ch=%.2d\n", pwdinfo->operating_channel );
  3774. wrqu->data.length = strlen( extra );
  3775. return ret;
  3776. }
  3777. inline static void macstr2num(u8 *dst, u8 *src)
  3778. {
  3779. int jj, kk;
  3780. for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
  3781. {
  3782. dst[jj] = key_2char2num(src[kk], src[kk + 1]);
  3783. }
  3784. }
  3785. static int rtw_p2p_get_wps_configmethod(struct net_device *dev,
  3786. struct iw_request_info *info,
  3787. union iwreq_data *wrqu, char *extra, char *subcmd)
  3788. {
  3789. int ret = 0;
  3790. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3791. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3792. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3793. _irqL irqL;
  3794. _list * plist,*phead;
  3795. _queue *queue = &(pmlmepriv->scanned_queue);
  3796. struct wlan_network *pnetwork = NULL;
  3797. u8 blnMatch = 0;
  3798. u16 attr_content = 0;
  3799. uint attr_contentlen = 0;
  3800. u8 attr_content_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3801. // Commented by Albert 20110727
  3802. // The input data is the MAC address which the application wants to know its WPS config method.
  3803. // After knowing its WPS config method, the application can decide the config method for provisioning discovery.
  3804. // Format: iwpriv wlanx p2p_get_wpsCM 00:E0:4C:00:00:05
  3805. DBG_871X("[%s] data = %s\n", __FUNCTION__, subcmd);
  3806. macstr2num(peerMAC, subcmd);
  3807. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3808. phead = get_list_head(queue);
  3809. plist = get_next(phead);
  3810. while (1)
  3811. {
  3812. if (rtw_end_of_queue_search(phead, plist) == _TRUE) break;
  3813. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3814. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN))
  3815. {
  3816. u8 *wpsie;
  3817. uint wpsie_len = 0;
  3818. // The mac address is matched.
  3819. if ((wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len)))
  3820. {
  3821. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *)&attr_content, &attr_contentlen);
  3822. if (attr_contentlen)
  3823. {
  3824. attr_content = be16_to_cpu(attr_content);
  3825. sprintf(attr_content_str, "\n\nM=%.4d", attr_content);
  3826. blnMatch = 1;
  3827. }
  3828. }
  3829. break;
  3830. }
  3831. plist = get_next(plist);
  3832. }
  3833. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3834. if (!blnMatch)
  3835. {
  3836. sprintf(attr_content_str, "\n\nM=0000");
  3837. }
  3838. wrqu->data.length = strlen(attr_content_str);
  3839. _rtw_memcpy(extra, attr_content_str, wrqu->data.length);
  3840. return ret;
  3841. }
  3842. #ifdef CONFIG_WFD
  3843. static int rtw_p2p_get_peer_wfd_port(struct net_device *dev,
  3844. struct iw_request_info *info,
  3845. union iwreq_data *wrqu, char *extra)
  3846. {
  3847. int ret = 0;
  3848. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3849. struct iw_point *pdata = &wrqu->data;
  3850. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3851. DBG_871X( "[%s] p2p_state = %d\n", __FUNCTION__, rtw_p2p_state(pwdinfo) );
  3852. sprintf( extra, "\n\nPort=%d\n", pwdinfo->wfd_info->peer_rtsp_ctrlport );
  3853. DBG_871X( "[%s] remote port = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_rtsp_ctrlport );
  3854. wrqu->data.length = strlen( extra );
  3855. return ret;
  3856. }
  3857. static int rtw_p2p_get_peer_wfd_preferred_connection(struct net_device *dev,
  3858. struct iw_request_info *info,
  3859. union iwreq_data *wrqu, char *extra)
  3860. {
  3861. int ret = 0;
  3862. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3863. struct iw_point *pdata = &wrqu->data;
  3864. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3865. sprintf( extra, "\n\nwfd_pc=%d\n", pwdinfo->wfd_info->wfd_pc );
  3866. DBG_871X( "[%s] wfd_pc = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_pc );
  3867. wrqu->data.length = strlen( extra );
  3868. pwdinfo->wfd_info->wfd_pc = _FALSE; // Reset the WFD preferred connection to P2P
  3869. return ret;
  3870. }
  3871. static int rtw_p2p_get_peer_wfd_session_available(struct net_device *dev,
  3872. struct iw_request_info *info,
  3873. union iwreq_data *wrqu, char *extra)
  3874. {
  3875. int ret = 0;
  3876. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3877. struct iw_point *pdata = &wrqu->data;
  3878. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  3879. sprintf( extra, "\n\nwfd_sa=%d\n", pwdinfo->wfd_info->peer_session_avail );
  3880. DBG_871X( "[%s] wfd_sa = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_session_avail );
  3881. wrqu->data.length = strlen( extra );
  3882. pwdinfo->wfd_info->peer_session_avail = _TRUE; // Reset the WFD session available
  3883. return ret;
  3884. }
  3885. #endif // CONFIG_WFD
  3886. static int rtw_p2p_get_go_device_address(struct net_device *dev,
  3887. struct iw_request_info *info,
  3888. union iwreq_data *wrqu, char *extra, char *subcmd)
  3889. {
  3890. int ret = 0;
  3891. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3892. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3893. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3894. _irqL irqL;
  3895. _list *plist, *phead;
  3896. _queue *queue = &(pmlmepriv->scanned_queue);
  3897. struct wlan_network *pnetwork = NULL;
  3898. u8 blnMatch = 0;
  3899. u8 *p2pie;
  3900. uint p2pielen = 0, attr_contentlen = 0;
  3901. u8 attr_content[100] = { 0x00 };
  3902. u8 go_devadd_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  3903. // Commented by Albert 20121209
  3904. // The input data is the GO's interface address which the application wants to know its device address.
  3905. // Format: iwpriv wlanx p2p_get2 go_devadd=00:E0:4C:00:00:05
  3906. DBG_871X("[%s] data = %s\n", __FUNCTION__, subcmd);
  3907. macstr2num(peerMAC, subcmd);
  3908. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3909. phead = get_list_head(queue);
  3910. plist = get_next(phead);
  3911. while (1)
  3912. {
  3913. if (rtw_end_of_queue_search(phead, plist) == _TRUE) break;
  3914. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3915. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN))
  3916. {
  3917. // Commented by Albert 2011/05/18
  3918. // Match the device address located in the P2P IE
  3919. // This is for the case that the P2P device address is not the same as the P2P interface address.
  3920. if ((p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen)))
  3921. {
  3922. while (p2pie)
  3923. {
  3924. // The P2P Device ID attribute is included in the Beacon frame.
  3925. // The P2P Device Info attribute is included in the probe response frame.
  3926. _rtw_memset(attr_content, 0x00, 100);
  3927. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen))
  3928. {
  3929. // Handle the P2P Device ID attribute of Beacon first
  3930. blnMatch = 1;
  3931. break;
  3932. } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen))
  3933. {
  3934. // Handle the P2P Device Info attribute of probe response
  3935. blnMatch = 1;
  3936. break;
  3937. }
  3938. //Get the next P2P IE
  3939. p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
  3940. }
  3941. }
  3942. }
  3943. plist = get_next(plist);
  3944. }
  3945. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3946. if (!blnMatch)
  3947. {
  3948. sprintf(go_devadd_str, "\n\ndev_add=NULL");
  3949. } else
  3950. {
  3951. sprintf(go_devadd_str, "\n\ndev_add=%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
  3952. attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
  3953. }
  3954. wrqu->data.length = strlen(go_devadd_str);
  3955. _rtw_memcpy(extra, go_devadd_str, wrqu->data.length);
  3956. return ret;
  3957. }
  3958. static int rtw_p2p_get_device_type(struct net_device *dev,
  3959. struct iw_request_info *info,
  3960. union iwreq_data *wrqu, char *extra, char *subcmd)
  3961. {
  3962. int ret = 0;
  3963. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  3964. u8 peerMAC[ETH_ALEN] = { 0x00 };
  3965. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  3966. _irqL irqL;
  3967. _list *plist, *phead;
  3968. _queue *queue = &(pmlmepriv->scanned_queue);
  3969. struct wlan_network *pnetwork = NULL;
  3970. u8 blnMatch = 0;
  3971. u8 dev_type[8] = { 0x00 };
  3972. uint dev_type_len = 0;
  3973. 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
  3974. // Commented by Albert 20121209
  3975. // The input data is the MAC address which the application wants to know its device type.
  3976. // Such user interface could know the device type.
  3977. // Format: iwpriv wlanx p2p_get2 dev_type=00:E0:4C:00:00:05
  3978. DBG_871X("[%s] data = %s\n", __FUNCTION__, subcmd);
  3979. macstr2num(peerMAC, subcmd);
  3980. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  3981. phead = get_list_head(queue);
  3982. plist = get_next(phead);
  3983. while (1)
  3984. {
  3985. if (rtw_end_of_queue_search(phead, plist) == _TRUE) break;
  3986. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  3987. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN))
  3988. {
  3989. u8 *wpsie;
  3990. uint wpsie_len = 0;
  3991. // The mac address is matched.
  3992. if ((wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len)))
  3993. {
  3994. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_PRIMARY_DEV_TYPE, dev_type, &dev_type_len);
  3995. if (dev_type_len)
  3996. {
  3997. u16 type = 0;
  3998. _rtw_memcpy(&type, dev_type, 2);
  3999. type = be16_to_cpu(type);
  4000. sprintf(dev_type_str, "\n\nN=%.2d", type);
  4001. blnMatch = 1;
  4002. }
  4003. }
  4004. break;
  4005. }
  4006. plist = get_next(plist);
  4007. }
  4008. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4009. if (!blnMatch)
  4010. {
  4011. sprintf(dev_type_str, "\n\nN=00");
  4012. }
  4013. wrqu->data.length = strlen(dev_type_str);
  4014. _rtw_memcpy(extra, dev_type_str, wrqu->data.length);
  4015. return ret;
  4016. }
  4017. static int rtw_p2p_get_device_name(struct net_device *dev,
  4018. struct iw_request_info *info,
  4019. union iwreq_data *wrqu, char *extra, char *subcmd)
  4020. {
  4021. int ret = 0;
  4022. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4023. u8 peerMAC[ETH_ALEN] = { 0x00 };
  4024. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4025. _irqL irqL;
  4026. _list *plist, *phead;
  4027. _queue *queue = &(pmlmepriv->scanned_queue);
  4028. struct wlan_network *pnetwork = NULL;
  4029. u8 blnMatch = 0;
  4030. u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = { 0x00 };
  4031. uint dev_len = 0;
  4032. u8 dev_name_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  4033. // Commented by Albert 20121225
  4034. // The input data is the MAC address which the application wants to know its device name.
  4035. // Such user interface could show peer device's device name instead of ssid.
  4036. // Format: iwpriv wlanx p2p_get2 devN=00:E0:4C:00:00:05
  4037. DBG_871X("[%s] data = %s\n", __FUNCTION__, subcmd);
  4038. macstr2num(peerMAC, subcmd);
  4039. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4040. phead = get_list_head(queue);
  4041. plist = get_next(phead);
  4042. while (1)
  4043. {
  4044. if (rtw_end_of_queue_search(phead, plist) == _TRUE) break;
  4045. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4046. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN))
  4047. {
  4048. u8 *wpsie;
  4049. uint wpsie_len = 0;
  4050. // The mac address is matched.
  4051. if ((wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len)))
  4052. {
  4053. rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len);
  4054. if (dev_len)
  4055. {
  4056. sprintf(dev_name_str, "\n\nN=%s", dev_name);
  4057. blnMatch = 1;
  4058. }
  4059. }
  4060. break;
  4061. }
  4062. plist = get_next(plist);
  4063. }
  4064. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4065. if (!blnMatch)
  4066. {
  4067. sprintf(dev_name_str, "\n\nN=0000");
  4068. }
  4069. wrqu->data.length = strlen(dev_name_str);
  4070. _rtw_memcpy(extra, dev_name_str, wrqu->data.length);
  4071. return ret;
  4072. }
  4073. static int rtw_p2p_get_invitation_procedure(struct net_device *dev,
  4074. struct iw_request_info *info,
  4075. union iwreq_data *wrqu, char *extra, char *subcmd)
  4076. {
  4077. int ret = 0;
  4078. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4079. u8 peerMAC[ETH_ALEN] = { 0x00 };
  4080. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4081. _irqL irqL;
  4082. _list *plist, *phead;
  4083. _queue *queue = &(pmlmepriv->scanned_queue);
  4084. struct wlan_network *pnetwork = NULL;
  4085. u8 blnMatch = 0;
  4086. u8 *p2pie;
  4087. uint p2pielen = 0, attr_contentlen = 0;
  4088. u8 attr_content[2] = { 0x00 };
  4089. u8 inv_proc_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
  4090. // Commented by Ouden 20121226
  4091. // The application wants to know P2P initation procedure is support or not.
  4092. // Format: iwpriv wlanx p2p_get2 InvProc=00:E0:4C:00:00:05
  4093. DBG_871X("[%s] data = %s\n", __FUNCTION__, subcmd);
  4094. macstr2num(peerMAC, subcmd);
  4095. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4096. phead = get_list_head(queue);
  4097. plist = get_next(phead);
  4098. while (1)
  4099. {
  4100. if (rtw_end_of_queue_search(phead, plist) == _TRUE) break;
  4101. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4102. if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN))
  4103. {
  4104. // Commented by Albert 20121226
  4105. // Match the device address located in the P2P IE
  4106. // This is for the case that the P2P device address is not the same as the P2P interface address.
  4107. if ((p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen)))
  4108. {
  4109. while (p2pie)
  4110. {
  4111. //_rtw_memset( attr_content, 0x00, 2);
  4112. if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_CAPABILITY, attr_content, &attr_contentlen))
  4113. {
  4114. // Handle the P2P capability attribute
  4115. blnMatch = 1;
  4116. break;
  4117. }
  4118. //Get the next P2P IE
  4119. p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
  4120. }
  4121. }
  4122. }
  4123. plist = get_next(plist);
  4124. }
  4125. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4126. if (!blnMatch)
  4127. {
  4128. sprintf(inv_proc_str, "\nIP=-1");
  4129. } else
  4130. {
  4131. if (attr_content[0] && 0x20)
  4132. {
  4133. sprintf(inv_proc_str, "\nIP=1");
  4134. } else
  4135. {
  4136. sprintf(inv_proc_str, "\nIP=0");
  4137. }
  4138. }
  4139. wrqu->data.length = strlen(inv_proc_str);
  4140. _rtw_memcpy(extra, inv_proc_str, wrqu->data.length);
  4141. return ret;
  4142. }
  4143. static int rtw_p2p_connect(struct net_device *dev,
  4144. struct iw_request_info *info,
  4145. union iwreq_data *wrqu, char *extra)
  4146. {
  4147. int ret = 0;
  4148. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4149. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4150. u8 peerMAC[ ETH_ALEN ] = { 0x00 };
  4151. int jj,kk;
  4152. u8 peerMACStr[ ETH_ALEN * 2 ] = { 0x00 };
  4153. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4154. _irqL irqL;
  4155. _list *plist, *phead;
  4156. _queue *queue = &(pmlmepriv->scanned_queue);
  4157. struct wlan_network *pnetwork = NULL;
  4158. uint uintPeerChannel = 0;
  4159. #ifdef CONFIG_CONCURRENT_MODE
  4160. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  4161. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  4162. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  4163. #endif // CONFIG_CONCURRENT_MODE
  4164. // Commented by Albert 20110304
  4165. // The input data contains two informations.
  4166. // 1. First information is the MAC address which wants to formate with
  4167. // 2. Second information is the WPS PINCode or "pbc" string for push button method
  4168. // Format: 00:E0:4C:00:00:05
  4169. // Format: 00:E0:4C:00:00:05
  4170. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4171. if ( pwdinfo->p2p_state == P2P_STATE_NONE )
  4172. {
  4173. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4174. return ret;
  4175. }
  4176. if ( pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO )
  4177. {
  4178. return -1;
  4179. }
  4180. for( jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3 )
  4181. {
  4182. peerMAC[ jj ] = key_2char2num( extra[kk], extra[kk+ 1] );
  4183. }
  4184. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4185. phead = get_list_head(queue);
  4186. plist = get_next(phead);
  4187. while(1)
  4188. {
  4189. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  4190. break;
  4191. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4192. if ( _rtw_memcmp( pnetwork->network.MacAddress, peerMAC, ETH_ALEN ) )
  4193. {
  4194. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4195. break;
  4196. }
  4197. plist = get_next(plist);
  4198. }
  4199. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4200. if ( uintPeerChannel )
  4201. {
  4202. #ifdef CONFIG_CONCURRENT_MODE
  4203. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4204. {
  4205. _cancel_timer_ex( &pwdinfo->ap_p2p_switch_timer );
  4206. }
  4207. #endif // CONFIG_CONCURRENT_MODE
  4208. _rtw_memset( &pwdinfo->nego_req_info, 0x00, sizeof( struct tx_nego_req_info ) );
  4209. _rtw_memset( &pwdinfo->groupid_info, 0x00, sizeof( struct group_id_info ) );
  4210. pwdinfo->nego_req_info.peer_channel_num[ 0 ] = uintPeerChannel;
  4211. _rtw_memcpy( pwdinfo->nego_req_info.peerDevAddr, pnetwork->network.MacAddress, ETH_ALEN );
  4212. pwdinfo->nego_req_info.benable = _TRUE;
  4213. _cancel_timer_ex( &pwdinfo->restore_p2p_state_timer );
  4214. if ( rtw_p2p_state(pwdinfo) != P2P_STATE_GONEGO_OK )
  4215. {
  4216. // Restore to the listen state if the current p2p state is not nego OK
  4217. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN );
  4218. }
  4219. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  4220. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
  4221. #ifdef CONFIG_CONCURRENT_MODE
  4222. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4223. {
  4224. // Have to enter the power saving with the AP
  4225. set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
  4226. issue_nulldata(pbuddy_adapter, NULL, 1, 3, 500);
  4227. }
  4228. #endif // CONFIG_CONCURRENT_MODE
  4229. DBG_871X( "[%s] Start PreTx Procedure!\n", __FUNCTION__ );
  4230. _set_timer( &pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT );
  4231. #ifdef CONFIG_CONCURRENT_MODE
  4232. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4233. {
  4234. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_GO_NEGO_TIMEOUT );
  4235. }
  4236. else
  4237. {
  4238. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT );
  4239. }
  4240. #else
  4241. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT );
  4242. #endif // CONFIG_CONCURRENT_MODE
  4243. }
  4244. else
  4245. {
  4246. DBG_871X( "[%s] Not Found in Scanning Queue~\n", __FUNCTION__ );
  4247. ret = -1;
  4248. }
  4249. exit:
  4250. return ret;
  4251. }
  4252. static int rtw_p2p_invite_req(struct net_device *dev,
  4253. struct iw_request_info *info,
  4254. union iwreq_data *wrqu, char *extra)
  4255. {
  4256. int ret = 0;
  4257. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4258. struct iw_point *pdata = &wrqu->data;
  4259. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4260. int jj,kk;
  4261. u8 peerMACStr[ ETH_ALEN * 2 ] = { 0x00 };
  4262. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4263. _list *plist, *phead;
  4264. _queue *queue = &(pmlmepriv->scanned_queue);
  4265. struct wlan_network *pnetwork = NULL;
  4266. uint uintPeerChannel = 0;
  4267. u8 attr_content[50] = { 0x00 }, _status = 0;
  4268. u8 *p2pie;
  4269. uint p2pielen = 0, attr_contentlen = 0;
  4270. _irqL irqL;
  4271. struct tx_invite_req_info* pinvite_req_info = &pwdinfo->invitereq_info;
  4272. #ifdef CONFIG_CONCURRENT_MODE
  4273. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  4274. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  4275. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  4276. #endif // CONFIG_CONCURRENT_MODE
  4277. #ifdef CONFIG_WFD
  4278. struct wifi_display_info* pwfd_info = pwdinfo->wfd_info;
  4279. #endif // CONFIG_WFD
  4280. // Commented by Albert 20120321
  4281. // The input data contains two informations.
  4282. // 1. First information is the P2P device address which you want to send to.
  4283. // 2. Second information is the group id which combines with GO's mac address, space and GO's ssid.
  4284. // Command line sample: iwpriv wlan0 p2p_set invite="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy"
  4285. // Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy
  4286. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4287. if ( wrqu->data.length <= 37 )
  4288. {
  4289. DBG_871X( "[%s] Wrong format!\n", __FUNCTION__ );
  4290. return ret;
  4291. }
  4292. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  4293. {
  4294. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4295. return ret;
  4296. }
  4297. else
  4298. {
  4299. // Reset the content of struct tx_invite_req_info
  4300. pinvite_req_info->benable = _FALSE;
  4301. _rtw_memset( pinvite_req_info->go_bssid, 0x00, ETH_ALEN );
  4302. _rtw_memset( pinvite_req_info->go_ssid, 0x00, WLAN_SSID_MAXLEN );
  4303. pinvite_req_info->ssidlen = 0x00;
  4304. pinvite_req_info->operating_ch = pwdinfo->operating_channel;
  4305. _rtw_memset( pinvite_req_info->peer_macaddr, 0x00, ETH_ALEN );
  4306. pinvite_req_info->token = 3;
  4307. }
  4308. for( jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3 )
  4309. {
  4310. pinvite_req_info->peer_macaddr[ jj ] = key_2char2num( extra[kk], extra[kk+ 1] );
  4311. }
  4312. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4313. phead = get_list_head(queue);
  4314. plist = get_next(phead);
  4315. while(1)
  4316. {
  4317. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  4318. break;
  4319. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4320. // Commented by Albert 2011/05/18
  4321. // Match the device address located in the P2P IE
  4322. // This is for the case that the P2P device address is not the same as the P2P interface address.
  4323. if ( (p2pie=rtw_get_p2p_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen)) )
  4324. {
  4325. // The P2P Device ID attribute is included in the Beacon frame.
  4326. // The P2P Device Info attribute is included in the probe response frame.
  4327. if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen) )
  4328. {
  4329. // Handle the P2P Device ID attribute of Beacon first
  4330. if ( _rtw_memcmp( attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN ) )
  4331. {
  4332. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4333. break;
  4334. }
  4335. }
  4336. else if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen) )
  4337. {
  4338. // Handle the P2P Device Info attribute of probe response
  4339. if ( _rtw_memcmp( attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN ) )
  4340. {
  4341. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4342. break;
  4343. }
  4344. }
  4345. }
  4346. plist = get_next(plist);
  4347. }
  4348. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4349. #ifdef CONFIG_WFD
  4350. if ( uintPeerChannel )
  4351. {
  4352. u8 wfd_ie[ 128 ] = { 0x00 };
  4353. uint wfd_ielen = 0;
  4354. if ( rtw_get_wfd_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, wfd_ie, &wfd_ielen ) )
  4355. {
  4356. u8 wfd_devinfo[ 6 ] = { 0x00 };
  4357. uint wfd_devlen = 6;
  4358. DBG_871X( "[%s] Found WFD IE!\n", __FUNCTION__ );
  4359. if ( rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, wfd_devinfo, &wfd_devlen ) )
  4360. {
  4361. u16 wfd_devinfo_field = 0;
  4362. // Commented by Albert 20120319
  4363. // The first two bytes are the WFD device information field of WFD device information subelement.
  4364. // In big endian format.
  4365. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  4366. if ( wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL )
  4367. {
  4368. pwfd_info->peer_session_avail = _TRUE;
  4369. }
  4370. else
  4371. {
  4372. pwfd_info->peer_session_avail = _FALSE;
  4373. }
  4374. }
  4375. }
  4376. if ( _FALSE == pwfd_info->peer_session_avail )
  4377. {
  4378. DBG_871X( "[%s] WFD Session not avaiable!\n", __FUNCTION__ );
  4379. goto exit;
  4380. }
  4381. }
  4382. #endif // CONFIG_WFD
  4383. if ( uintPeerChannel )
  4384. {
  4385. #ifdef CONFIG_CONCURRENT_MODE
  4386. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4387. {
  4388. _cancel_timer_ex( &pwdinfo->ap_p2p_switch_timer );
  4389. }
  4390. #endif // CONFIG_CONCURRENT_MODE
  4391. // Store the GO's bssid
  4392. for( jj = 0, kk = 18; jj < ETH_ALEN; jj++, kk += 3 )
  4393. {
  4394. pinvite_req_info->go_bssid[ jj ] = key_2char2num( extra[kk], extra[kk+ 1] );
  4395. }
  4396. // Store the GO's ssid
  4397. pinvite_req_info->ssidlen = wrqu->data.length - 36;
  4398. _rtw_memcpy( pinvite_req_info->go_ssid, &extra[ 36 ], (u32) pinvite_req_info->ssidlen );
  4399. pinvite_req_info->benable = _TRUE;
  4400. pinvite_req_info->peer_ch = uintPeerChannel;
  4401. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  4402. rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INVITE_REQ);
  4403. #ifdef CONFIG_CONCURRENT_MODE
  4404. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4405. {
  4406. // Have to enter the power saving with the AP
  4407. set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
  4408. issue_nulldata(pbuddy_adapter, NULL, 1, 3, 500);
  4409. }
  4410. else
  4411. {
  4412. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4413. }
  4414. #else
  4415. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4416. #endif
  4417. _set_timer( &pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT );
  4418. #ifdef CONFIG_CONCURRENT_MODE
  4419. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4420. {
  4421. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_INVITE_TIMEOUT );
  4422. }
  4423. else
  4424. {
  4425. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT );
  4426. }
  4427. #else
  4428. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT );
  4429. #endif // CONFIG_CONCURRENT_MODE
  4430. }
  4431. else
  4432. {
  4433. DBG_871X( "[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__ );
  4434. }
  4435. exit:
  4436. return ret;
  4437. }
  4438. static int rtw_p2p_set_persistent(struct net_device *dev,
  4439. struct iw_request_info *info,
  4440. union iwreq_data *wrqu, char *extra)
  4441. {
  4442. int ret = 0;
  4443. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4444. struct iw_point *pdata = &wrqu->data;
  4445. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4446. int jj,kk;
  4447. u8 peerMACStr[ ETH_ALEN * 2 ] = { 0x00 };
  4448. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4449. _list *plist, *phead;
  4450. _queue *queue = &(pmlmepriv->scanned_queue);
  4451. struct wlan_network *pnetwork = NULL;
  4452. uint uintPeerChannel = 0;
  4453. u8 attr_content[50] = { 0x00 }, _status = 0;
  4454. u8 *p2pie;
  4455. uint p2pielen = 0, attr_contentlen = 0;
  4456. _irqL irqL;
  4457. struct tx_invite_req_info* pinvite_req_info = &pwdinfo->invitereq_info;
  4458. #ifdef CONFIG_CONCURRENT_MODE
  4459. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  4460. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  4461. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  4462. #endif // CONFIG_CONCURRENT_MODE
  4463. #ifdef CONFIG_WFD
  4464. struct wifi_display_info* pwfd_info = pwdinfo->wfd_info;
  4465. #endif // CONFIG_WFD
  4466. // Commented by Albert 20120328
  4467. // The input data is 0 or 1
  4468. // 0: disable persistent group functionality
  4469. // 1: enable persistent group founctionality
  4470. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4471. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  4472. {
  4473. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4474. return ret;
  4475. }
  4476. else
  4477. {
  4478. if ( extra[ 0 ] == '0' ) // Disable the persistent group function.
  4479. {
  4480. pwdinfo->persistent_supported = _FALSE;
  4481. }
  4482. else if ( extra[ 0 ] == '1' ) // Enable the persistent group function.
  4483. {
  4484. pwdinfo->persistent_supported = _TRUE;
  4485. }
  4486. else
  4487. {
  4488. pwdinfo->persistent_supported = _FALSE;
  4489. }
  4490. }
  4491. printk( "[%s] persistent_supported = %d\n", __FUNCTION__, pwdinfo->persistent_supported );
  4492. exit:
  4493. return ret;
  4494. }
  4495. #ifdef CONFIG_WFD
  4496. static int rtw_p2p_set_pc(struct net_device *dev,
  4497. struct iw_request_info *info,
  4498. union iwreq_data *wrqu, char *extra)
  4499. {
  4500. int ret = 0;
  4501. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4502. struct iw_point *pdata = &wrqu->data;
  4503. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4504. u8 peerMAC[ ETH_ALEN ] = { 0x00 };
  4505. int jj,kk;
  4506. u8 peerMACStr[ ETH_ALEN * 2 ] = { 0x00 };
  4507. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4508. _list *plist, *phead;
  4509. _queue *queue = &(pmlmepriv->scanned_queue);
  4510. struct wlan_network *pnetwork = NULL;
  4511. u8 attr_content[50] = { 0x00 }, _status = 0;
  4512. u8 *p2pie;
  4513. uint p2pielen = 0, attr_contentlen = 0;
  4514. _irqL irqL;
  4515. uint uintPeerChannel = 0;
  4516. #ifdef CONFIG_CONCURRENT_MODE
  4517. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  4518. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  4519. #endif // CONFIG_CONCURRENT_MODE
  4520. struct wifi_display_info* pwfd_info = pwdinfo->wfd_info;
  4521. // Commented by Albert 20120512
  4522. // 1. Input information is the MAC address which wants to know the Preferred Connection bit (PC bit)
  4523. // Format: 00:E0:4C:00:00:05
  4524. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4525. if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  4526. {
  4527. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4528. return ret;
  4529. }
  4530. for( jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3 )
  4531. {
  4532. peerMAC[ jj ] = key_2char2num( extra[kk], extra[kk+ 1] );
  4533. }
  4534. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4535. phead = get_list_head(queue);
  4536. plist = get_next(phead);
  4537. while(1)
  4538. {
  4539. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  4540. break;
  4541. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4542. // Commented by Albert 2011/05/18
  4543. // Match the device address located in the P2P IE
  4544. // This is for the case that the P2P device address is not the same as the P2P interface address.
  4545. if ( (p2pie=rtw_get_p2p_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen)) )
  4546. {
  4547. // The P2P Device ID attribute is included in the Beacon frame.
  4548. // The P2P Device Info attribute is included in the probe response frame.
  4549. printk( "[%s] Got P2P IE\n", __FUNCTION__ );
  4550. if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen) )
  4551. {
  4552. // Handle the P2P Device ID attribute of Beacon first
  4553. printk( "[%s] P2P_ATTR_DEVICE_ID \n", __FUNCTION__ );
  4554. if ( _rtw_memcmp( attr_content, peerMAC, ETH_ALEN ) )
  4555. {
  4556. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4557. break;
  4558. }
  4559. }
  4560. else if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen) )
  4561. {
  4562. // Handle the P2P Device Info attribute of probe response
  4563. printk( "[%s] P2P_ATTR_DEVICE_INFO \n", __FUNCTION__ );
  4564. if ( _rtw_memcmp( attr_content, peerMAC, ETH_ALEN ) )
  4565. {
  4566. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4567. break;
  4568. }
  4569. }
  4570. }
  4571. plist = get_next(plist);
  4572. }
  4573. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4574. printk( "[%s] channel = %d\n", __FUNCTION__, uintPeerChannel );
  4575. if ( uintPeerChannel )
  4576. {
  4577. u8 wfd_ie[ 128 ] = { 0x00 };
  4578. uint wfd_ielen = 0;
  4579. if ( rtw_get_wfd_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, wfd_ie, &wfd_ielen ) )
  4580. {
  4581. u8 wfd_devinfo[ 6 ] = { 0x00 };
  4582. uint wfd_devlen = 6;
  4583. DBG_871X( "[%s] Found WFD IE!\n", __FUNCTION__ );
  4584. if ( rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, wfd_devinfo, &wfd_devlen ) )
  4585. {
  4586. u16 wfd_devinfo_field = 0;
  4587. // Commented by Albert 20120319
  4588. // The first two bytes are the WFD device information field of WFD device information subelement.
  4589. // In big endian format.
  4590. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  4591. if ( wfd_devinfo_field & WFD_DEVINFO_PC_TDLS )
  4592. {
  4593. pwfd_info->wfd_pc = _TRUE;
  4594. }
  4595. else
  4596. {
  4597. pwfd_info->wfd_pc = _FALSE;
  4598. }
  4599. }
  4600. }
  4601. }
  4602. else
  4603. {
  4604. DBG_871X( "[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__ );
  4605. }
  4606. exit:
  4607. return ret;
  4608. }
  4609. static int rtw_p2p_set_wfd_device_type(struct net_device *dev,
  4610. struct iw_request_info *info,
  4611. union iwreq_data *wrqu, char *extra)
  4612. {
  4613. int ret = 0;
  4614. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4615. struct iw_point *pdata = &wrqu->data;
  4616. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4617. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  4618. // Commented by Albert 20120328
  4619. // The input data is 0 or 1
  4620. // 0: specify to Miracast source device
  4621. // 1 or others: specify to Miracast sink device (display device)
  4622. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4623. if ( extra[ 0 ] == '0' ) // Set to Miracast source device.
  4624. {
  4625. pwfd_info->wfd_device_type = WFD_DEVINFO_SOURCE;
  4626. }
  4627. else // Set to Miracast sink device.
  4628. {
  4629. pwfd_info->wfd_device_type = WFD_DEVINFO_PSINK;
  4630. }
  4631. exit:
  4632. return ret;
  4633. }
  4634. static int rtw_p2p_set_wfd_enable(struct net_device *dev,
  4635. struct iw_request_info *info,
  4636. union iwreq_data *wrqu, char *extra)
  4637. {
  4638. // Commented by Kurt 20121206
  4639. // This function is used to set wfd enabled
  4640. int ret = 0;
  4641. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4642. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  4643. if(*extra == '0' )
  4644. pwdinfo->wfd_info->wfd_enable = _FALSE;
  4645. else if(*extra == '1')
  4646. pwdinfo->wfd_info->wfd_enable = _TRUE;
  4647. DBG_871X( "[%s] wfd_enable = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_enable );
  4648. return ret;
  4649. }
  4650. static int rtw_p2p_set_driver_iface(struct net_device *dev,
  4651. struct iw_request_info *info,
  4652. union iwreq_data *wrqu, char *extra)
  4653. {
  4654. // Commented by Kurt 20121206
  4655. // This function is used to set driver iface is WEXT or CFG80211
  4656. int ret = 0;
  4657. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4658. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  4659. if(*extra == '1' )
  4660. {
  4661. pwdinfo->driver_interface = DRIVER_WEXT;
  4662. DBG_871X( "[%s] driver_interface = WEXT\n", __FUNCTION__);
  4663. }
  4664. else if(*extra == '2')
  4665. {
  4666. pwdinfo->driver_interface = DRIVER_CFG80211;
  4667. DBG_871X( "[%s] driver_interface = CFG80211\n", __FUNCTION__);
  4668. }
  4669. return ret;
  4670. }
  4671. // To set the WFD session available to enable or disable
  4672. static int rtw_p2p_set_sa(struct net_device *dev,
  4673. struct iw_request_info *info,
  4674. union iwreq_data *wrqu, char *extra)
  4675. {
  4676. int ret = 0;
  4677. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4678. struct iw_point *pdata = &wrqu->data;
  4679. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4680. struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
  4681. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4682. if( 0 )
  4683. {
  4684. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4685. return ret;
  4686. }
  4687. else
  4688. {
  4689. if ( extra[ 0 ] == '0' ) // Disable the session available.
  4690. {
  4691. pwdinfo->session_available = _FALSE;
  4692. }
  4693. else if ( extra[ 0 ] == '1' ) // Enable the session available.
  4694. {
  4695. pwdinfo->session_available = _TRUE;
  4696. }
  4697. else
  4698. {
  4699. pwdinfo->session_available = _FALSE;
  4700. }
  4701. }
  4702. printk( "[%s] session available = %d\n", __FUNCTION__, pwdinfo->session_available );
  4703. exit:
  4704. return ret;
  4705. }
  4706. #endif // CONFIG_WFD
  4707. static int rtw_p2p_prov_disc(struct net_device *dev,
  4708. struct iw_request_info *info,
  4709. union iwreq_data *wrqu, char *extra)
  4710. {
  4711. int ret = 0;
  4712. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4713. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4714. u8 peerMAC[ ETH_ALEN ] = { 0x00 };
  4715. int jj,kk;
  4716. u8 peerMACStr[ ETH_ALEN * 2 ] = { 0x00 };
  4717. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  4718. _list *plist, *phead;
  4719. _queue *queue = &(pmlmepriv->scanned_queue);
  4720. struct wlan_network *pnetwork = NULL;
  4721. uint uintPeerChannel = 0;
  4722. u8 attr_content[100] = { 0x00 }, _status = 0;
  4723. u8 *p2pie;
  4724. uint p2pielen = 0, attr_contentlen = 0;
  4725. _irqL irqL;
  4726. u8 ie_offset;
  4727. #ifdef CONFIG_CONCURRENT_MODE
  4728. _adapter *pbuddy_adapter = padapter->pbuddy_adapter;
  4729. struct mlme_priv *pbuddy_mlmepriv = &pbuddy_adapter->mlmepriv;
  4730. struct mlme_ext_priv *pbuddy_mlmeext = &pbuddy_adapter->mlmeextpriv;
  4731. #endif // CONFIG_CONCURRENT_MODE
  4732. #ifdef CONFIG_WFD
  4733. struct wifi_display_info* pwfd_info = pwdinfo->wfd_info;
  4734. #endif // CONFIG_WFD
  4735. // Commented by Albert 20110301
  4736. // The input data contains two informations.
  4737. // 1. First information is the MAC address which wants to issue the provisioning discovery request frame.
  4738. // 2. Second information is the WPS configuration method which wants to discovery
  4739. // Format: 00:E0:4C:00:00:05_display
  4740. // Format: 00:E0:4C:00:00:05_keypad
  4741. // Format: 00:E0:4C:00:00:05_pbc
  4742. // Format: 00:E0:4C:00:00:05_label
  4743. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4744. if ( pwdinfo->p2p_state == P2P_STATE_NONE )
  4745. {
  4746. DBG_871X( "[%s] WiFi Direct is disable!\n", __FUNCTION__ );
  4747. return ret;
  4748. }
  4749. else
  4750. {
  4751. #ifdef CONFIG_INTEL_WIDI
  4752. if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE){
  4753. DBG_871X( "[%s] WiFi is under survey!\n", __FUNCTION__ );
  4754. return ret;
  4755. }
  4756. #endif //CONFIG_INTEL_WIDI
  4757. // Reset the content of struct tx_provdisc_req_info excluded the wps_config_method_request.
  4758. _rtw_memset( pwdinfo->tx_prov_disc_info.peerDevAddr, 0x00, ETH_ALEN );
  4759. _rtw_memset( pwdinfo->tx_prov_disc_info.peerIFAddr, 0x00, ETH_ALEN );
  4760. _rtw_memset( &pwdinfo->tx_prov_disc_info.ssid, 0x00, sizeof( NDIS_802_11_SSID ) );
  4761. pwdinfo->tx_prov_disc_info.peer_channel_num[ 0 ] = 0;
  4762. pwdinfo->tx_prov_disc_info.peer_channel_num[ 1 ] = 0;
  4763. pwdinfo->tx_prov_disc_info.benable = _FALSE;
  4764. }
  4765. for( jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3 )
  4766. {
  4767. peerMAC[ jj ] = key_2char2num( extra[kk], extra[kk+ 1] );
  4768. }
  4769. if ( _rtw_memcmp( &extra[ 18 ], "display", 7 ) )
  4770. {
  4771. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
  4772. }
  4773. else if ( _rtw_memcmp( &extra[ 18 ], "keypad", 7 ) )
  4774. {
  4775. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
  4776. }
  4777. else if ( _rtw_memcmp( &extra[ 18 ], "pbc", 3 ) )
  4778. {
  4779. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  4780. }
  4781. else if ( _rtw_memcmp( &extra[ 18 ], "label", 5 ) )
  4782. {
  4783. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
  4784. }
  4785. else
  4786. {
  4787. DBG_871X( "[%s] Unknown WPS config methodn", __FUNCTION__ );
  4788. return( ret );
  4789. }
  4790. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4791. phead = get_list_head(queue);
  4792. plist = get_next(phead);
  4793. while(1)
  4794. {
  4795. if (rtw_end_of_queue_search(phead,plist)== _TRUE)
  4796. break;
  4797. if( uintPeerChannel != 0 )
  4798. break;
  4799. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  4800. // Commented by Albert 2011/05/18
  4801. // Match the device address located in the P2P IE
  4802. // This is for the case that the P2P device address is not the same as the P2P interface address.
  4803. if (pnetwork->network.Reserved[0] == 2) { // Probe Request
  4804. ie_offset = 0;
  4805. } else { // Beacon or Probe Respones
  4806. ie_offset = 12;
  4807. }
  4808. if ( (p2pie=rtw_get_p2p_ie( &pnetwork->network.IEs[ie_offset], pnetwork->network.IELength - ie_offset, NULL, &p2pielen)) )
  4809. {
  4810. while ( p2pie )
  4811. {
  4812. // The P2P Device ID attribute is included in the Beacon frame.
  4813. // The P2P Device Info attribute is included in the probe response frame.
  4814. if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen) )
  4815. {
  4816. // Handle the P2P Device ID attribute of Beacon first
  4817. if ( _rtw_memcmp( attr_content, peerMAC, ETH_ALEN ) )
  4818. {
  4819. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4820. break;
  4821. }
  4822. }
  4823. else if ( rtw_get_p2p_attr_content( p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen) )
  4824. {
  4825. // Handle the P2P Device Info attribute of probe response
  4826. if ( _rtw_memcmp( attr_content, peerMAC, ETH_ALEN ) )
  4827. {
  4828. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4829. break;
  4830. }
  4831. }
  4832. //Get the next P2P IE
  4833. p2pie = rtw_get_p2p_ie(p2pie+p2pielen, pnetwork->network.IELength - ie_offset -(p2pie -&pnetwork->network.IEs[ie_offset] + p2pielen), NULL, &p2pielen);
  4834. }
  4835. }
  4836. #ifdef CONFIG_INTEL_WIDI
  4837. // Some Intel WiDi source may not provide P2P IE,
  4838. // so we could only compare mac addr by 802.11 Source Address
  4839. if( pmlmepriv->widi_state == INTEL_WIDI_STATE_WFD_CONNECTION
  4840. && uintPeerChannel == 0 )
  4841. {
  4842. if ( _rtw_memcmp( pnetwork->network.MacAddress, peerMAC, ETH_ALEN ) )
  4843. {
  4844. uintPeerChannel = pnetwork->network.Configuration.DSConfig;
  4845. break;
  4846. }
  4847. }
  4848. #endif //CONFIG_INTEL_WIDI
  4849. plist = get_next(plist);
  4850. }
  4851. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  4852. if ( uintPeerChannel )
  4853. {
  4854. #ifdef CONFIG_WFD
  4855. {
  4856. u8 wfd_ie[ 128 ] = { 0x00 };
  4857. uint wfd_ielen = 0;
  4858. if ( rtw_get_wfd_ie( &pnetwork->network.IEs[12], pnetwork->network.IELength - 12, wfd_ie, &wfd_ielen ) )
  4859. {
  4860. u8 wfd_devinfo[ 6 ] = { 0x00 };
  4861. uint wfd_devlen = 6;
  4862. DBG_871X( "[%s] Found WFD IE!\n", __FUNCTION__ );
  4863. if ( rtw_get_wfd_attr_content( wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, wfd_devinfo, &wfd_devlen ) )
  4864. {
  4865. u16 wfd_devinfo_field = 0;
  4866. // Commented by Albert 20120319
  4867. // The first two bytes are the WFD device information field of WFD device information subelement.
  4868. // In big endian format.
  4869. wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
  4870. if ( wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL )
  4871. {
  4872. pwfd_info->peer_session_avail = _TRUE;
  4873. }
  4874. else
  4875. {
  4876. pwfd_info->peer_session_avail = _FALSE;
  4877. }
  4878. }
  4879. }
  4880. if ( _FALSE == pwfd_info->peer_session_avail )
  4881. {
  4882. DBG_871X( "[%s] WFD Session not avaiable!\n", __FUNCTION__ );
  4883. goto exit;
  4884. }
  4885. }
  4886. #endif // CONFIG_WFD
  4887. DBG_871X( "[%s] peer channel: %d!\n", __FUNCTION__, uintPeerChannel );
  4888. #ifdef CONFIG_CONCURRENT_MODE
  4889. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4890. {
  4891. _cancel_timer_ex( &pwdinfo->ap_p2p_switch_timer );
  4892. }
  4893. #endif // CONFIG_CONCURRENT_MODE
  4894. _rtw_memcpy( pwdinfo->tx_prov_disc_info.peerIFAddr, pnetwork->network.MacAddress, ETH_ALEN );
  4895. _rtw_memcpy( pwdinfo->tx_prov_disc_info.peerDevAddr, peerMAC, ETH_ALEN );
  4896. pwdinfo->tx_prov_disc_info.peer_channel_num[0] = ( u16 ) uintPeerChannel;
  4897. pwdinfo->tx_prov_disc_info.benable = _TRUE;
  4898. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  4899. rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ);
  4900. if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT))
  4901. {
  4902. _rtw_memcpy( &pwdinfo->tx_prov_disc_info.ssid, &pnetwork->network.Ssid, sizeof( NDIS_802_11_SSID ) );
  4903. }
  4904. else if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
  4905. {
  4906. _rtw_memcpy( pwdinfo->tx_prov_disc_info.ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN );
  4907. pwdinfo->tx_prov_disc_info.ssid.SsidLength= P2P_WILDCARD_SSID_LEN;
  4908. }
  4909. #ifdef CONFIG_CONCURRENT_MODE
  4910. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4911. {
  4912. // Have to enter the power saving with the AP
  4913. set_channel_bwmode(padapter, pbuddy_mlmeext->cur_channel, pbuddy_mlmeext->cur_ch_offset, pbuddy_mlmeext->cur_bwmode);
  4914. issue_nulldata(pbuddy_adapter, NULL, 1, 3, 500);
  4915. }
  4916. else
  4917. {
  4918. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4919. }
  4920. #else
  4921. set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  4922. #endif
  4923. _set_timer( &pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT );
  4924. #ifdef CONFIG_CONCURRENT_MODE
  4925. if ( check_fwstate( pbuddy_mlmepriv, _FW_LINKED ) )
  4926. {
  4927. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_PROVISION_TIMEOUT );
  4928. }
  4929. else
  4930. {
  4931. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT );
  4932. }
  4933. #else
  4934. _set_timer( &pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT );
  4935. #endif // CONFIG_CONCURRENT_MODE
  4936. }
  4937. else
  4938. {
  4939. DBG_871X( "[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__ );
  4940. #ifdef CONFIG_INTEL_WIDI
  4941. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  4942. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  4943. rtw_free_network_queue(padapter, _TRUE);
  4944. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  4945. rtw_sitesurvey_cmd(padapter, NULL, 0, NULL, 0);
  4946. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  4947. #endif //CONFIG_INTEL_WIDI
  4948. }
  4949. exit:
  4950. return ret;
  4951. }
  4952. // Added by Albert 20110328
  4953. // This function is used to inform the driver the user had specified the pin code value or pbc
  4954. // to application.
  4955. static int rtw_p2p_got_wpsinfo(struct net_device *dev,
  4956. struct iw_request_info *info,
  4957. union iwreq_data *wrqu, char *extra)
  4958. {
  4959. int ret = 0;
  4960. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4961. struct wifidirect_info *pwdinfo = &( padapter->wdinfo );
  4962. DBG_871X( "[%s] data = %s\n", __FUNCTION__, extra );
  4963. // Added by Albert 20110328
  4964. // if the input data is P2P_NO_WPSINFO -> reset the wpsinfo
  4965. // if the input data is P2P_GOT_WPSINFO_PEER_DISPLAY_PIN -> the utility just input the PIN code got from the peer P2P device.
  4966. // if the input data is P2P_GOT_WPSINFO_SELF_DISPLAY_PIN -> the utility just got the PIN code from itself.
  4967. // if the input data is P2P_GOT_WPSINFO_PBC -> the utility just determine to use the PBC
  4968. if ( *extra == '0' )
  4969. {
  4970. pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
  4971. }
  4972. else if ( *extra == '1' )
  4973. {
  4974. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PEER_DISPLAY_PIN;
  4975. }
  4976. else if ( *extra == '2' )
  4977. {
  4978. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_SELF_DISPLAY_PIN;
  4979. }
  4980. else if ( *extra == '3' )
  4981. {
  4982. pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PBC;
  4983. }
  4984. else
  4985. {
  4986. pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
  4987. }
  4988. return ret;
  4989. }
  4990. #endif //CONFIG_P2P
  4991. static int rtw_p2p_set(struct net_device *dev,
  4992. struct iw_request_info *info,
  4993. union iwreq_data *wrqu, char *extra)
  4994. {
  4995. int ret = 0;
  4996. #ifdef CONFIG_P2P
  4997. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  4998. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4999. struct iw_point *pdata = &wrqu->data;
  5000. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  5001. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  5002. DBG_871X( "[%s] extra = %s\n", __FUNCTION__, extra );
  5003. if ( _rtw_memcmp( extra, "enable=", 7 ) )
  5004. {
  5005. rtw_wext_p2p_enable( dev, info, wrqu, &extra[7] );
  5006. }
  5007. else if ( _rtw_memcmp( extra, "setDN=", 6 ) )
  5008. {
  5009. wrqu->data.length -= 6;
  5010. rtw_p2p_setDN( dev, info, wrqu, &extra[6] );
  5011. }
  5012. else if ( _rtw_memcmp( extra, "profilefound=", 13 ) )
  5013. {
  5014. wrqu->data.length -= 13;
  5015. rtw_p2p_profilefound( dev, info, wrqu, &extra[13] );
  5016. }
  5017. else if ( _rtw_memcmp( extra, "prov_disc=", 10 ) )
  5018. {
  5019. wrqu->data.length -= 10;
  5020. rtw_p2p_prov_disc( dev, info, wrqu, &extra[10] );
  5021. }
  5022. else if ( _rtw_memcmp( extra, "nego=", 5 ) )
  5023. {
  5024. wrqu->data.length -= 5;
  5025. rtw_p2p_connect( dev, info, wrqu, &extra[5] );
  5026. }
  5027. else if ( _rtw_memcmp( extra, "intent=", 7 ) )
  5028. {
  5029. // Commented by Albert 2011/03/23
  5030. // The wrqu->data.length will include the null character
  5031. // So, we will decrease 7 + 1
  5032. wrqu->data.length -= 8;
  5033. rtw_p2p_set_intent( dev, info, wrqu, &extra[7] );
  5034. }
  5035. else if ( _rtw_memcmp( extra, "ssid=", 5 ) )
  5036. {
  5037. wrqu->data.length -= 5;
  5038. rtw_p2p_set_go_nego_ssid( dev, info, wrqu, &extra[5] );
  5039. }
  5040. else if ( _rtw_memcmp( extra, "got_wpsinfo=", 12 ) )
  5041. {
  5042. wrqu->data.length -= 12;
  5043. rtw_p2p_got_wpsinfo( dev, info, wrqu, &extra[12] );
  5044. }
  5045. else if ( _rtw_memcmp( extra, "listen_ch=", 10 ) )
  5046. {
  5047. // Commented by Albert 2011/05/24
  5048. // The wrqu->data.length will include the null character
  5049. // So, we will decrease (10 + 1)
  5050. wrqu->data.length -= 11;
  5051. rtw_p2p_set_listen_ch( dev, info, wrqu, &extra[10] );
  5052. }
  5053. else if ( _rtw_memcmp( extra, "op_ch=", 6 ) )
  5054. {
  5055. // Commented by Albert 2011/05/24
  5056. // The wrqu->data.length will include the null character
  5057. // So, we will decrease (6 + 1)
  5058. wrqu->data.length -= 7;
  5059. rtw_p2p_set_op_ch( dev, info, wrqu, &extra[6] );
  5060. }
  5061. else if ( _rtw_memcmp( extra, "invite=", 7 ) )
  5062. {
  5063. wrqu->data.length -= 8;
  5064. rtw_p2p_invite_req( dev, info, wrqu, &extra[7] );
  5065. }
  5066. else if ( _rtw_memcmp( extra, "persistent=", 11 ) )
  5067. {
  5068. wrqu->data.length -= 11;
  5069. rtw_p2p_set_persistent( dev, info, wrqu, &extra[11] );
  5070. }
  5071. #ifdef CONFIG_WFD
  5072. else if ( _rtw_memcmp( extra, "sa=", 3 ) )
  5073. {
  5074. // sa: WFD Session Available information
  5075. wrqu->data.length -= 3;
  5076. rtw_p2p_set_sa( dev, info, wrqu, &extra[3] );
  5077. }
  5078. else if ( _rtw_memcmp( extra, "pc=", 3 ) )
  5079. {
  5080. // pc: WFD Preferred Connection
  5081. wrqu->data.length -= 3;
  5082. rtw_p2p_set_pc( dev, info, wrqu, &extra[3] );
  5083. }
  5084. else if ( _rtw_memcmp( extra, "wfd_type=", 9 ) )
  5085. {
  5086. // pc: WFD Preferred Connection
  5087. wrqu->data.length -= 9;
  5088. rtw_p2p_set_wfd_device_type( dev, info, wrqu, &extra[9] );
  5089. }
  5090. else if ( _rtw_memcmp( extra, "wfd_enable=", 11 ) )
  5091. {
  5092. wrqu->data.length -= 11;
  5093. rtw_p2p_set_wfd_enable( dev, info, wrqu, &extra[11] );
  5094. }
  5095. else if ( _rtw_memcmp( extra, "driver_iface=", 13 ) )
  5096. {
  5097. wrqu->data.length -= 13;
  5098. rtw_p2p_set_driver_iface( dev, info, wrqu, &extra[13] );
  5099. }
  5100. #endif //CONFIG_WFD
  5101. #endif //CONFIG_P2P
  5102. return ret;
  5103. }
  5104. static int rtw_p2p_get(struct net_device *dev,
  5105. struct iw_request_info *info,
  5106. union iwreq_data *wrqu, char *extra)
  5107. {
  5108. int ret = 0;
  5109. #ifdef CONFIG_P2P
  5110. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5111. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5112. struct iw_point *pdata = &wrqu->data;
  5113. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  5114. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  5115. if ( padapter->bShowGetP2PState )
  5116. {
  5117. DBG_871X( "[%s] extra = %s\n", __FUNCTION__, (char*) wrqu->data.pointer );
  5118. }
  5119. if ( _rtw_memcmp( wrqu->data.pointer, "status", 6 ) )
  5120. {
  5121. rtw_p2p_get_status( dev, info, wrqu, extra );
  5122. }
  5123. else if ( _rtw_memcmp( wrqu->data.pointer, "role", 4 ) )
  5124. {
  5125. rtw_p2p_get_role( dev, info, wrqu, extra);
  5126. }
  5127. else if ( _rtw_memcmp( wrqu->data.pointer, "peer_ifa", 8 ) )
  5128. {
  5129. rtw_p2p_get_peer_ifaddr( dev, info, wrqu, extra);
  5130. }
  5131. else if ( _rtw_memcmp( wrqu->data.pointer, "req_cm", 6 ) )
  5132. {
  5133. rtw_p2p_get_req_cm( dev, info, wrqu, extra);
  5134. }
  5135. else if ( _rtw_memcmp( wrqu->data.pointer, "peer_deva", 9 ) )
  5136. {
  5137. // Get the P2P device address when receiving the provision discovery request frame.
  5138. rtw_p2p_get_peer_devaddr( dev, info, wrqu, extra);
  5139. }
  5140. else if ( _rtw_memcmp( wrqu->data.pointer, "group_id", 8 ) )
  5141. {
  5142. rtw_p2p_get_groupid( dev, info, wrqu, extra);
  5143. }
  5144. else if ( _rtw_memcmp( wrqu->data.pointer, "inv_peer_deva", 13 ) )
  5145. {
  5146. // Get the P2P device address when receiving the P2P Invitation request frame.
  5147. rtw_p2p_get_peer_devaddr_by_invitation( dev, info, wrqu, extra);
  5148. }
  5149. else if ( _rtw_memcmp( wrqu->data.pointer, "op_ch", 5 ) )
  5150. {
  5151. rtw_p2p_get_op_ch( dev, info, wrqu, extra);
  5152. }
  5153. #ifdef CONFIG_WFD
  5154. else if ( _rtw_memcmp( wrqu->data.pointer, "peer_port", 9 ) )
  5155. {
  5156. rtw_p2p_get_peer_wfd_port( dev, info, wrqu, extra );
  5157. }
  5158. else if ( _rtw_memcmp( wrqu->data.pointer, "wfd_sa", 6 ) )
  5159. {
  5160. rtw_p2p_get_peer_wfd_session_available( dev, info, wrqu, extra );
  5161. }
  5162. else if ( _rtw_memcmp( wrqu->data.pointer, "wfd_pc", 6 ) )
  5163. {
  5164. rtw_p2p_get_peer_wfd_preferred_connection( dev, info, wrqu, extra );
  5165. }
  5166. #endif // CONFIG_WFD
  5167. #endif //CONFIG_P2P
  5168. return ret;
  5169. }
  5170. static int rtw_p2p_get2(struct net_device *dev,
  5171. struct iw_request_info *info,
  5172. union iwreq_data *wrqu, char *extra)
  5173. {
  5174. int ret = 0;
  5175. #ifdef CONFIG_P2P
  5176. int length = wrqu->data.length;
  5177. char *buffer = (u8 *)rtw_malloc(length);
  5178. if (buffer == NULL)
  5179. {
  5180. ret = -ENOMEM;
  5181. goto bad;
  5182. }
  5183. if (copy_from_user(buffer, wrqu->data.pointer, wrqu->data.length))
  5184. {
  5185. ret - EFAULT;
  5186. goto bad;
  5187. }
  5188. DBG_871X("[%s] buffer = %s\n", __FUNCTION__, buffer);
  5189. if (_rtw_memcmp(buffer, "wpsCM=", 6))
  5190. {
  5191. ret = rtw_p2p_get_wps_configmethod(dev, info, wrqu, extra, &buffer[6]);
  5192. } else if (_rtw_memcmp(buffer, "devN=", 5))
  5193. {
  5194. ret = rtw_p2p_get_device_name(dev, info, wrqu, extra, &buffer[5]);
  5195. } else if (_rtw_memcmp(buffer, "dev_type=", 9))
  5196. {
  5197. ret = rtw_p2p_get_device_type(dev, info, wrqu, extra, &buffer[9]);
  5198. } else if (_rtw_memcmp(buffer, "go_devadd=", 10))
  5199. {
  5200. ret = rtw_p2p_get_go_device_address(dev, info, wrqu, extra, &buffer[10]);
  5201. } else if (_rtw_memcmp(buffer, "InvProc=", 8))
  5202. {
  5203. ret = rtw_p2p_get_invitation_procedure(dev, info, wrqu, extra, &buffer[8]);
  5204. } else
  5205. {
  5206. snprintf(extra, sizeof("Command not found."), "Command not found.");
  5207. wrqu->data.length = strlen(extra);
  5208. }
  5209. bad:
  5210. if (buffer)
  5211. {
  5212. _rtw_mfree(buffer, length);
  5213. }
  5214. #endif //CONFIG_P2P
  5215. return ret;
  5216. }
  5217. static int rtw_cta_test_start(struct net_device *dev,
  5218. struct iw_request_info *info,
  5219. union iwreq_data *wrqu, char *extra)
  5220. {
  5221. int ret = 0;
  5222. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5223. DBG_871X("%s %s\n", __func__, extra);
  5224. if (!strcmp(extra, "1"))
  5225. padapter->in_cta_test = 1;
  5226. else
  5227. padapter->in_cta_test = 0;
  5228. if(padapter->in_cta_test)
  5229. {
  5230. u32 v = rtw_read32(padapter, REG_RCR);
  5231. v &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN );//| RCR_ADF
  5232. rtw_write32(padapter, REG_RCR, v);
  5233. DBG_871X("enable RCR_ADF\n");
  5234. }
  5235. else
  5236. {
  5237. u32 v = rtw_read32(padapter, REG_RCR);
  5238. v |= RCR_CBSSID_DATA | RCR_CBSSID_BCN ;//| RCR_ADF
  5239. rtw_write32(padapter, REG_RCR, v);
  5240. DBG_871X("disable RCR_ADF\n");
  5241. }
  5242. return ret;
  5243. }
  5244. extern int rtw_change_ifname(_adapter *padapter, const char *ifname);
  5245. static int rtw_rereg_nd_name(struct net_device *dev,
  5246. struct iw_request_info *info,
  5247. union iwreq_data *wrqu, char *extra)
  5248. {
  5249. int ret = 0;
  5250. _adapter *padapter = rtw_netdev_priv(dev);
  5251. struct rereg_nd_name_data *rereg_priv = &padapter->rereg_nd_name_priv;
  5252. char new_ifname[IFNAMSIZ];
  5253. if(rereg_priv->old_ifname[0] == 0) {
  5254. char *reg_ifname;
  5255. #ifdef CONFIG_CONCURRENT_MODE
  5256. if (padapter->isprimary)
  5257. reg_ifname = padapter->registrypriv.ifname;
  5258. else
  5259. #endif
  5260. reg_ifname = padapter->registrypriv.if2name;
  5261. strncpy(rereg_priv->old_ifname, reg_ifname, IFNAMSIZ);
  5262. rereg_priv->old_ifname[IFNAMSIZ-1] = 0;
  5263. }
  5264. //DBG_871X("%s wrqu->data.length:%d\n", __FUNCTION__, wrqu->data.length);
  5265. if(wrqu->data.length > IFNAMSIZ)
  5266. return -EFAULT;
  5267. if ( copy_from_user(new_ifname, wrqu->data.pointer, IFNAMSIZ) ) {
  5268. return -EFAULT;
  5269. }
  5270. if( 0 == strcmp(rereg_priv->old_ifname, new_ifname) ) {
  5271. return ret;
  5272. }
  5273. DBG_871X("%s new_ifname:%s\n", __FUNCTION__, new_ifname);
  5274. if( 0 != (ret = rtw_change_ifname(padapter, new_ifname)) ) {
  5275. goto exit;
  5276. }
  5277. if(_rtw_memcmp(rereg_priv->old_ifname, "disable%d", 9) == _TRUE) {
  5278. padapter->ledpriv.bRegUseLed= rereg_priv->old_bRegUseLed;
  5279. rtw_hal_sw_led_init(padapter);
  5280. rtw_ips_mode_req(&padapter->pwrctrlpriv, rereg_priv->old_ips_mode);
  5281. }
  5282. strncpy(rereg_priv->old_ifname, new_ifname, IFNAMSIZ);
  5283. rereg_priv->old_ifname[IFNAMSIZ-1] = 0;
  5284. if(_rtw_memcmp(new_ifname, "disable%d", 9) == _TRUE) {
  5285. DBG_871X("%s disable\n", __FUNCTION__);
  5286. // free network queue for Android's timming issue
  5287. rtw_free_network_queue(padapter, _TRUE);
  5288. // close led
  5289. rtw_led_control(padapter, LED_CTL_POWER_OFF);
  5290. rereg_priv->old_bRegUseLed = padapter->ledpriv.bRegUseLed;
  5291. padapter->ledpriv.bRegUseLed= _FALSE;
  5292. rtw_hal_sw_led_deinit(padapter);
  5293. // the interface is being "disabled", we can do deeper IPS
  5294. rereg_priv->old_ips_mode = rtw_get_ips_mode_req(&padapter->pwrctrlpriv);
  5295. rtw_ips_mode_req(&padapter->pwrctrlpriv, IPS_NORMAL);
  5296. }
  5297. exit:
  5298. return ret;
  5299. }
  5300. #if 0
  5301. void mac_reg_dump(_adapter *padapter)
  5302. {
  5303. int i,j=1;
  5304. DBG_871X("\n======= MAC REG =======\n");
  5305. for(i=0x0;i<0x300;i+=4)
  5306. {
  5307. if(j%4==1) DBG_871X("0x%02x",i);
  5308. DBG_871X(" 0x%08x ",rtw_read32(padapter,i));
  5309. if((j++)%4 == 0) DBG_871X("\n");
  5310. }
  5311. for(i=0x400;i<0x800;i+=4)
  5312. {
  5313. if(j%4==1) DBG_871X("0x%02x",i);
  5314. DBG_871X(" 0x%08x ",rtw_read32(padapter,i));
  5315. if((j++)%4 == 0) DBG_871X("\n");
  5316. }
  5317. }
  5318. void bb_reg_dump(_adapter *padapter)
  5319. {
  5320. int i,j=1;
  5321. DBG_871X("\n======= BB REG =======\n");
  5322. for(i=0x800;i<0x1000;i+=4)
  5323. {
  5324. if(j%4==1) DBG_871X("0x%02x",i);
  5325. DBG_871X(" 0x%08x ",rtw_read32(padapter,i));
  5326. if((j++)%4 == 0) DBG_871X("\n");
  5327. }
  5328. }
  5329. void rf_reg_dump(_adapter *padapter)
  5330. {
  5331. int i,j=1,path;
  5332. u32 value;
  5333. DBG_871X("\n======= RF REG =======\n");
  5334. for(path=0;path<2;path++)
  5335. {
  5336. DBG_871X("\nRF_Path(%x)\n",path);
  5337. for(i=0;i<0x100;i++)
  5338. {
  5339. value = PHY_QueryRFReg(padapter, path,i, bMaskDWord);
  5340. if(j%4==1) DBG_871X("0x%02x ",i);
  5341. DBG_871X(" 0x%08x ",value);
  5342. if((j++)%4==0) DBG_871X("\n");
  5343. }
  5344. }
  5345. }
  5346. #endif
  5347. void mac_reg_dump(_adapter *padapter)
  5348. {
  5349. int i,j=1;
  5350. printk("\n======= MAC REG =======\n");
  5351. for(i=0x0;i<0x300;i+=4)
  5352. {
  5353. if(j%4==1) printk("0x%02x",i);
  5354. printk(" 0x%08x ",rtw_read32(padapter,i));
  5355. if((j++)%4 == 0) printk("\n");
  5356. }
  5357. for(i=0x400;i<0x800;i+=4)
  5358. {
  5359. if(j%4==1) printk("0x%02x",i);
  5360. printk(" 0x%08x ",rtw_read32(padapter,i));
  5361. if((j++)%4 == 0) printk("\n");
  5362. }
  5363. }
  5364. void bb_reg_dump(_adapter *padapter)
  5365. {
  5366. int i,j=1;
  5367. printk("\n======= BB REG =======\n");
  5368. for(i=0x800;i<0x1000;i+=4)
  5369. {
  5370. if(j%4==1) printk("0x%02x",i);
  5371. printk(" 0x%08x ",rtw_read32(padapter,i));
  5372. if((j++)%4 == 0) printk("\n");
  5373. }
  5374. }
  5375. void rf_reg_dump(_adapter *padapter)
  5376. {
  5377. int i,j=1,path;
  5378. u32 value;
  5379. u8 rf_type,path_nums = 0;
  5380. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  5381. printk("\n======= RF REG =======\n");
  5382. if((RF_1T2R == rf_type) ||(RF_1T1R ==rf_type ))
  5383. path_nums = 1;
  5384. else
  5385. path_nums = 2;
  5386. for(path=0;path<path_nums;path++)
  5387. {
  5388. printk("\nRF_Path(%x)\n",path);
  5389. for(i=0;i<0x100;i++)
  5390. {
  5391. //value = PHY_QueryRFReg(padapter, path,i, bMaskDWord);
  5392. value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
  5393. if(j%4==1) printk("0x%02x ",i);
  5394. printk(" 0x%08x ",value);
  5395. if((j++)%4==0) printk("\n");
  5396. }
  5397. }
  5398. }
  5399. #ifdef CONFIG_IOL
  5400. #include <rtw_iol.h>
  5401. #endif
  5402. static int rtw_dbg_port(struct net_device *dev,
  5403. struct iw_request_info *info,
  5404. union iwreq_data *wrqu, char *extra)
  5405. {
  5406. _irqL irqL;
  5407. int ret = 0;
  5408. u8 major_cmd, minor_cmd;
  5409. u16 arg;
  5410. u32 extra_arg, *pdata, val32;
  5411. struct sta_info *psta;
  5412. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  5413. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  5414. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  5415. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  5416. struct security_priv *psecuritypriv = &padapter->securitypriv;
  5417. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  5418. struct sta_priv *pstapriv = &padapter->stapriv;
  5419. pdata = (u32*)&wrqu->data;
  5420. val32 = *pdata;
  5421. arg = (u16)(val32&0x0000ffff);
  5422. major_cmd = (u8)(val32>>24);
  5423. minor_cmd = (u8)((val32>>16)&0x00ff);
  5424. extra_arg = *(pdata+1);
  5425. switch(major_cmd)
  5426. {
  5427. case 0x70://read_reg
  5428. switch(minor_cmd)
  5429. {
  5430. case 1:
  5431. DBG_871X("rtw_read8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
  5432. break;
  5433. case 2:
  5434. DBG_871X("rtw_read16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
  5435. break;
  5436. case 4:
  5437. DBG_871X("rtw_read32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
  5438. break;
  5439. }
  5440. break;
  5441. case 0x71://write_reg
  5442. switch(minor_cmd)
  5443. {
  5444. case 1:
  5445. rtw_write8(padapter, arg, extra_arg);
  5446. DBG_871X("rtw_write8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
  5447. break;
  5448. case 2:
  5449. rtw_write16(padapter, arg, extra_arg);
  5450. DBG_871X("rtw_write16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
  5451. break;
  5452. case 4:
  5453. rtw_write32(padapter, arg, extra_arg);
  5454. DBG_871X("rtw_write32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
  5455. break;
  5456. }
  5457. break;
  5458. case 0x72://read_bb
  5459. DBG_871X("read_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
  5460. break;
  5461. case 0x73://write_bb
  5462. rtw_hal_write_bbreg(padapter, arg, 0xffffffff, extra_arg);
  5463. DBG_871X("write_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
  5464. break;
  5465. case 0x74://read_rf
  5466. DBG_871X("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));
  5467. break;
  5468. case 0x75://write_rf
  5469. rtw_hal_write_rfreg(padapter, minor_cmd, arg, 0xffffffff, extra_arg);
  5470. DBG_871X("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));
  5471. break;
  5472. case 0x76:
  5473. switch(minor_cmd)
  5474. {
  5475. case 0x00: //normal mode,
  5476. padapter->recvpriv.is_signal_dbg = 0;
  5477. break;
  5478. case 0x01: //dbg mode
  5479. padapter->recvpriv.is_signal_dbg = 1;
  5480. extra_arg = extra_arg>100?100:extra_arg;
  5481. extra_arg = extra_arg<0?0:extra_arg;
  5482. padapter->recvpriv.signal_strength_dbg=extra_arg;
  5483. break;
  5484. }
  5485. break;
  5486. case 0x78: //IOL test
  5487. switch(minor_cmd)
  5488. {
  5489. #ifdef CONFIG_IOL
  5490. case 0x04: //LLT table initialization test
  5491. {
  5492. u8 page_boundary = 0xf9;
  5493. {
  5494. struct xmit_frame *xmit_frame;
  5495. if((xmit_frame=rtw_IOL_accquire_xmit_frame(padapter)) == NULL) {
  5496. ret = -ENOMEM;
  5497. break;
  5498. }
  5499. rtw_IOL_append_LLT_cmd(xmit_frame, page_boundary);
  5500. if(_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 500,0) )
  5501. ret = -EPERM;
  5502. }
  5503. }
  5504. break;
  5505. case 0x05: //blink LED test
  5506. {
  5507. u16 reg = 0x4c;
  5508. u32 blink_num = 50;
  5509. u32 blink_delay_ms = 200;
  5510. int i;
  5511. {
  5512. struct xmit_frame *xmit_frame;
  5513. if((xmit_frame=rtw_IOL_accquire_xmit_frame(padapter)) == NULL) {
  5514. ret = -ENOMEM;
  5515. break;
  5516. }
  5517. for(i=0;i<blink_num;i++){
  5518. #ifdef CONFIG_IOL_NEW_GENERATION
  5519. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00,0xff);
  5520. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  5521. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08,0xff);
  5522. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  5523. #else
  5524. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00);
  5525. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  5526. rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08);
  5527. rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
  5528. #endif
  5529. }
  5530. if(_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, (blink_delay_ms*blink_num*2)+200,0) )
  5531. ret = -EPERM;
  5532. }
  5533. }
  5534. break;
  5535. case 0x06: //continuous wirte byte test
  5536. {
  5537. u16 reg = arg;
  5538. u16 start_value = 0;
  5539. u32 write_num = extra_arg;
  5540. int i;
  5541. u8 final;
  5542. {
  5543. struct xmit_frame *xmit_frame;
  5544. if((xmit_frame=rtw_IOL_accquire_xmit_frame(padapter)) == NULL) {
  5545. ret = -ENOMEM;
  5546. break;
  5547. }
  5548. for(i=0;i<write_num;i++){
  5549. #ifdef CONFIG_IOL_NEW_GENERATION
  5550. rtw_IOL_append_WB_cmd(xmit_frame, reg, i+start_value,0xFF);
  5551. #else
  5552. rtw_IOL_append_WB_cmd(xmit_frame, reg, i+start_value);
  5553. #endif
  5554. }
  5555. if(_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000,0))
  5556. ret = -EPERM;
  5557. }
  5558. if(start_value+write_num-1 == (final=rtw_read8(padapter, reg)) ) {
  5559. DBG_871X("continuous IOL_CMD_WB_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  5560. } else {
  5561. DBG_871X("continuous IOL_CMD_WB_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  5562. }
  5563. }
  5564. break;
  5565. case 0x07: //continuous wirte word test
  5566. {
  5567. u16 reg = arg;
  5568. u16 start_value = 200;
  5569. u32 write_num = extra_arg;
  5570. int i;
  5571. u16 final;
  5572. {
  5573. struct xmit_frame *xmit_frame;
  5574. if((xmit_frame=rtw_IOL_accquire_xmit_frame(padapter)) == NULL) {
  5575. ret = -ENOMEM;
  5576. break;
  5577. }
  5578. for(i=0;i<write_num;i++){
  5579. #ifdef CONFIG_IOL_NEW_GENERATION
  5580. rtw_IOL_append_WW_cmd(xmit_frame, reg, i+start_value,0xFFFF);
  5581. #else
  5582. rtw_IOL_append_WW_cmd(xmit_frame, reg, i+start_value);
  5583. #endif
  5584. }
  5585. if(_SUCCESS !=rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000,0))
  5586. ret = -EPERM;
  5587. }
  5588. if(start_value+write_num-1 == (final=rtw_read16(padapter, reg)) ) {
  5589. DBG_871X("continuous IOL_CMD_WW_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  5590. } else {
  5591. DBG_871X("continuous IOL_CMD_WW_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  5592. }
  5593. }
  5594. break;
  5595. case 0x08: //continuous wirte dword test
  5596. {
  5597. u16 reg = arg;
  5598. u32 start_value = 0x110000c7;
  5599. u32 write_num = extra_arg;
  5600. int i;
  5601. u32 final;
  5602. {
  5603. struct xmit_frame *xmit_frame;
  5604. if((xmit_frame=rtw_IOL_accquire_xmit_frame(padapter)) == NULL) {
  5605. ret = -ENOMEM;
  5606. break;
  5607. }
  5608. for(i=0;i<write_num;i++){
  5609. #ifdef CONFIG_IOL_NEW_GENERATION
  5610. rtw_IOL_append_WD_cmd(xmit_frame, reg, i+start_value,0xFFFFFFFF);
  5611. #else
  5612. rtw_IOL_append_WD_cmd(xmit_frame, reg, i+start_value);
  5613. #endif
  5614. }
  5615. if(_SUCCESS !=rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000,0))
  5616. ret = -EPERM;
  5617. }
  5618. if(start_value+write_num-1 == (final=rtw_read32(padapter, reg)) ) {
  5619. DBG_871X("continuous IOL_CMD_WD_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
  5620. } else {
  5621. DBG_871X("continuous IOL_CMD_WD_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
  5622. }
  5623. }
  5624. break;
  5625. #endif //CONFIG_IOL
  5626. }
  5627. break;
  5628. case 0x79:
  5629. {
  5630. /*
  5631. * dbg 0x79000000 [value], set RESP_TXAGC to + value, value:0~15
  5632. * dbg 0x79010000 [value], set RESP_TXAGC to - value, value:0~15
  5633. */
  5634. u8 value = extra_arg & 0x0f;
  5635. u8 sign = minor_cmd;
  5636. u16 write_value = 0;
  5637. DBG_871X("%s set RESP_TXAGC to %s %u\n", __func__, sign?"minus":"plus", value);
  5638. if (sign)
  5639. value = value | 0x10;
  5640. write_value = value | (value << 5);
  5641. rtw_write16(padapter, 0x6d9, write_value);
  5642. }
  5643. break;
  5644. case 0x7a:
  5645. receive_disconnect(padapter, pmlmeinfo->network.MacAddress
  5646. , WLAN_REASON_EXPIRATION_CHK);
  5647. break;
  5648. case 0x7F:
  5649. switch(minor_cmd)
  5650. {
  5651. case 0x0:
  5652. DBG_871X("fwstate=0x%x\n", get_fwstate(pmlmepriv));
  5653. break;
  5654. case 0x01:
  5655. DBG_871X("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
  5656. psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
  5657. psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
  5658. break;
  5659. case 0x02:
  5660. DBG_871X("pmlmeinfo->state=0x%x\n", pmlmeinfo->state);
  5661. break;
  5662. case 0x03:
  5663. DBG_871X("qos_option=%d\n", pmlmepriv->qospriv.qos_option);
  5664. #ifdef CONFIG_80211N_HT
  5665. DBG_871X("ht_option=%d\n", pmlmepriv->htpriv.ht_option);
  5666. #endif //CONFIG_80211N_HT
  5667. break;
  5668. case 0x04:
  5669. DBG_871X("cur_ch=%d\n", pmlmeext->cur_channel);
  5670. DBG_871X("cur_bw=%d\n", pmlmeext->cur_bwmode);
  5671. DBG_871X("cur_ch_off=%d\n", pmlmeext->cur_ch_offset);
  5672. break;
  5673. case 0x05:
  5674. psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
  5675. if(psta)
  5676. {
  5677. int i;
  5678. struct recv_reorder_ctrl *preorder_ctrl;
  5679. DBG_871X("SSID=%s\n", cur_network->network.Ssid.Ssid);
  5680. DBG_871X("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->hwaddr));
  5681. DBG_871X("cur_channel=%d, cur_bwmode=%d, cur_ch_offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
  5682. DBG_871X("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
  5683. DBG_871X("state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
  5684. #ifdef CONFIG_80211N_HT
  5685. DBG_871X("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
  5686. DBG_871X("bwmode=%d, ch_offset=%d, sgi=%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
  5687. DBG_871X("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
  5688. DBG_871X("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
  5689. #endif //CONFIG_80211N_HT
  5690. for(i=0;i<16;i++)
  5691. {
  5692. preorder_ctrl = &psta->recvreorder_ctrl[i];
  5693. if(preorder_ctrl->enable)
  5694. {
  5695. DBG_871X("tid=%d, indicate_seq=%d\n", i, preorder_ctrl->indicate_seq);
  5696. }
  5697. }
  5698. }
  5699. else
  5700. {
  5701. DBG_871X("can't get sta's macaddr, cur_network's macaddr:" MAC_FMT "\n", MAC_ARG(cur_network->network.MacAddress));
  5702. }
  5703. break;
  5704. case 0x06:
  5705. {
  5706. u32 ODMFlag;
  5707. rtw_hal_get_hwreg(padapter, HW_VAR_DM_FLAG, (u8*)(&ODMFlag));
  5708. DBG_871X("(B)DMFlag=0x%x, arg=0x%x\n", ODMFlag, arg);
  5709. ODMFlag = (u32)(0x0f&arg);
  5710. DBG_871X("(A)DMFlag=0x%x\n", ODMFlag);
  5711. rtw_hal_set_hwreg(padapter, HW_VAR_DM_FLAG, (u8 *)(&ODMFlag));
  5712. }
  5713. break;
  5714. case 0x07:
  5715. DBG_871X("bSurpriseRemoved=%d, bDriverStopped=%d\n",
  5716. padapter->bSurpriseRemoved, padapter->bDriverStopped);
  5717. break;
  5718. case 0x08:
  5719. {
  5720. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  5721. struct recv_priv *precvpriv = &padapter->recvpriv;
  5722. DBG_871X("free_xmitbuf_cnt=%d, free_xmitframe_cnt=%d"
  5723. ", free_xmit_extbuf_cnt=%d, free_xframe_ext_cnt=%d"
  5724. ", free_recvframe_cnt=%d\n",
  5725. pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt,
  5726. pxmitpriv->free_xmit_extbuf_cnt, pxmitpriv->free_xframe_ext_cnt,
  5727. precvpriv->free_recvframe_cnt);
  5728. #ifdef CONFIG_USB_HCI
  5729. DBG_871X("rx_urb_pending_cn=%d\n", precvpriv->rx_pending_cnt);
  5730. #endif
  5731. }
  5732. break;
  5733. case 0x09:
  5734. {
  5735. int i, j;
  5736. _list *plist, *phead;
  5737. struct recv_reorder_ctrl *preorder_ctrl;
  5738. #ifdef CONFIG_AP_MODE
  5739. DBG_871X("sta_dz_bitmap=0x%x, tim_bitmap=0x%x\n", pstapriv->sta_dz_bitmap, pstapriv->tim_bitmap);
  5740. #endif
  5741. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  5742. for(i=0; i< NUM_STA; i++)
  5743. {
  5744. phead = &(pstapriv->sta_hash[i]);
  5745. plist = get_next(phead);
  5746. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  5747. {
  5748. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  5749. plist = get_next(plist);
  5750. if(extra_arg == psta->aid)
  5751. {
  5752. DBG_871X("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->hwaddr));
  5753. DBG_871X("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
  5754. DBG_871X("state=0x%x, aid=%d, macid=%d, raid=%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
  5755. #ifdef CONFIG_80211N_HT
  5756. DBG_871X("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
  5757. DBG_871X("bwmode=%d, ch_offset=%d, sgi=%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
  5758. DBG_871X("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
  5759. DBG_871X("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
  5760. #endif //CONFIG_80211N_HT
  5761. #ifdef CONFIG_AP_MODE
  5762. DBG_871X("capability=0x%x\n", psta->capability);
  5763. DBG_871X("flags=0x%x\n", psta->flags);
  5764. DBG_871X("wpa_psk=0x%x\n", psta->wpa_psk);
  5765. DBG_871X("wpa2_group_cipher=0x%x\n", psta->wpa2_group_cipher);
  5766. DBG_871X("wpa2_pairwise_cipher=0x%x\n", psta->wpa2_pairwise_cipher);
  5767. DBG_871X("qos_info=0x%x\n", psta->qos_info);
  5768. #endif
  5769. DBG_871X("dot118021XPrivacy=0x%x\n", psta->dot118021XPrivacy);
  5770. for(j=0;j<16;j++)
  5771. {
  5772. preorder_ctrl = &psta->recvreorder_ctrl[j];
  5773. if(preorder_ctrl->enable)
  5774. {
  5775. DBG_871X("tid=%d, indicate_seq=%d\n", j, preorder_ctrl->indicate_seq);
  5776. }
  5777. }
  5778. }
  5779. }
  5780. }
  5781. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  5782. }
  5783. break;
  5784. case 0x0c://dump rx/tx packet
  5785. {
  5786. if(arg == 0){
  5787. DBG_871X("dump rx packet (%d)\n",extra_arg);
  5788. //pHalData->bDumpRxPkt =extra_arg;
  5789. rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_RXPKT, &(extra_arg));
  5790. }
  5791. else if(arg==1){
  5792. DBG_871X("dump tx packet (%d)\n",extra_arg);
  5793. rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_TXPKT, &(extra_arg));
  5794. }
  5795. }
  5796. break;
  5797. #if 0
  5798. case 0x0d://dump cam
  5799. {
  5800. //u8 entry = (u8) extra_arg;
  5801. u8 entry=0;
  5802. //dump cam
  5803. for(entry=0;entry<32;entry++)
  5804. read_cam(padapter,entry);
  5805. }
  5806. break;
  5807. #endif
  5808. #ifdef DBG_CONFIG_ERROR_DETECT
  5809. case 0x0f:
  5810. {
  5811. if(extra_arg == 0){
  5812. DBG_871X("###### silent reset test.......#####\n");
  5813. rtw_hal_sreset_reset(padapter);
  5814. } else {
  5815. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  5816. struct sreset_priv *psrtpriv = &pHalData->srestpriv;
  5817. psrtpriv->dbg_trigger_point = extra_arg;
  5818. }
  5819. }
  5820. break;
  5821. case 0x15:
  5822. {
  5823. struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
  5824. DBG_871X("==>silent resete cnts:%d\n",pwrpriv->ips_enter_cnts);
  5825. }
  5826. break;
  5827. #endif
  5828. case 0x10:// driver version display
  5829. DBG_871X("rtw driver version=%s\n", DRIVERVERSION);
  5830. break;
  5831. case 0x11:
  5832. {
  5833. DBG_871X("linked info dump func %s \n",(extra_arg>=1)?"enable":"disable");
  5834. DBG_871X("extra_arg_ID: RA Info BIT-0 ,DIG Info BIT-1, FA Info BIT-2 \n");
  5835. padapter->bLinkInfoDump = extra_arg ;
  5836. }
  5837. break;
  5838. #ifdef CONFIG_80211N_HT
  5839. case 0x12: //set rx_stbc
  5840. {
  5841. struct registry_priv *pregpriv = &padapter->registrypriv;
  5842. // 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, 0x3: enable both 2.4g and 5g
  5843. //default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ
  5844. if( pregpriv && (extra_arg == 0 || extra_arg == 1|| extra_arg == 2 || extra_arg == 3))
  5845. {
  5846. pregpriv->rx_stbc= extra_arg;
  5847. DBG_871X("set rx_stbc=%d\n",pregpriv->rx_stbc);
  5848. }
  5849. else
  5850. DBG_871X("get rx_stbc=%d\n",pregpriv->rx_stbc);
  5851. }
  5852. break;
  5853. case 0x13: //set ampdu_enable
  5854. {
  5855. struct registry_priv *pregpriv = &padapter->registrypriv;
  5856. // 0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec)
  5857. if( pregpriv && extra_arg >= 0 && extra_arg < 3 )
  5858. {
  5859. pregpriv->ampdu_enable= extra_arg;
  5860. DBG_871X("set ampdu_enable=%d\n",pregpriv->ampdu_enable);
  5861. }
  5862. else
  5863. DBG_871X("get ampdu_enable=%d\n",pregpriv->ampdu_enable);
  5864. }
  5865. break;
  5866. #endif
  5867. case 0x14: //get wifi_spec
  5868. {
  5869. struct registry_priv *pregpriv = &padapter->registrypriv;
  5870. DBG_871X("get wifi_spec=%d\n",pregpriv->wifi_spec);
  5871. }
  5872. break;
  5873. case 0x16:
  5874. {
  5875. if(arg == 0xff){
  5876. printk("ODM_COMP_DIG\t\tBIT0\n");
  5877. printk("ODM_COMP_RA_MASK\t\tBIT1\n");
  5878. printk("ODM_COMP_DYNAMIC_TXPWR\tBIT2\n");
  5879. printk("ODM_COMP_FA_CNT\t\tBIT3\n");
  5880. printk("ODM_COMP_RSSI_MONITOR\tBIT4\n");
  5881. printk("ODM_COMP_CCK_PD\t\tBIT5\n");
  5882. printk("ODM_COMP_ANT_DIV\t\tBIT6\n");
  5883. printk("ODM_COMP_PWR_SAVE\t\tBIT7\n");
  5884. printk("ODM_COMP_PWR_TRAIN\tBIT8\n");
  5885. printk("ODM_COMP_RATE_ADAPTIVE\tBIT9\n");
  5886. printk("ODM_COMP_PATH_DIV\t\tBIT10\n");
  5887. printk("ODM_COMP_PSD \tBIT11\n");
  5888. printk("ODM_COMP_DYNAMIC_PRICCA\tBIT12\n");
  5889. printk("ODM_COMP_RXHP\t\tBIT13\n");
  5890. printk("ODM_COMP_EDCA_TURBO\tBIT16\n");
  5891. printk("ODM_COMP_EARLY_MODE\tBIT17\n");
  5892. printk("ODM_COMP_TX_PWR_TRACK\tBIT24\n");
  5893. printk("ODM_COMP_RX_GAIN_TRACK\tBIT25\n");
  5894. printk("ODM_COMP_CALIBRATION\tBIT26\n");
  5895. rtw_hal_get_def_var(padapter, HW_DEF_ODM_DBG_FLAG,&extra_arg);
  5896. }
  5897. else{
  5898. rtw_hal_set_def_var(padapter, HW_DEF_ODM_DBG_FLAG,&extra_arg);
  5899. }
  5900. }
  5901. break;
  5902. #ifdef DBG_FIXED_CHAN
  5903. case 0x17:
  5904. {
  5905. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5906. printk("===> Fixed channel to %d \n",extra_arg);
  5907. pmlmeext->fixed_chan = extra_arg;
  5908. }
  5909. break;
  5910. #endif
  5911. case 0x18:
  5912. {
  5913. printk("===> Switch USB Mode %d \n",extra_arg);
  5914. rtw_hal_set_hwreg(padapter, HW_VAR_USB_MODE, (u8 *)&extra_arg);
  5915. }
  5916. break;
  5917. case 0x23:
  5918. {
  5919. DBG_871X("turn %s the bNotifyChannelChange Variable\n",(extra_arg==1)?"on":"off");
  5920. padapter->bNotifyChannelChange = extra_arg;
  5921. break;
  5922. }
  5923. case 0x24:
  5924. {
  5925. #ifdef CONFIG_P2P
  5926. DBG_871X("turn %s the bShowGetP2PState Variable\n",(extra_arg==1)?"on":"off");
  5927. padapter->bShowGetP2PState = extra_arg;
  5928. #endif // CONFIG_P2P
  5929. break;
  5930. }
  5931. case 0xaa:
  5932. {
  5933. if(extra_arg> 0x3F) extra_arg = 0xFF;
  5934. DBG_871X("chang data rate to :0x%02x\n",extra_arg);
  5935. padapter->fix_rate = extra_arg;
  5936. }
  5937. break;
  5938. case 0xdd://registers dump , 0 for mac reg,1 for bb reg, 2 for rf reg
  5939. {
  5940. if(extra_arg==0){
  5941. mac_reg_dump(padapter);
  5942. }
  5943. else if(extra_arg==1){
  5944. bb_reg_dump(padapter);
  5945. }
  5946. else if(extra_arg==2){
  5947. rf_reg_dump(padapter);
  5948. }
  5949. }
  5950. break;
  5951. case 0xee://turn on/off dynamic funcs
  5952. {
  5953. u32 odm_flag;
  5954. if(0xf==extra_arg){
  5955. rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC,&odm_flag);
  5956. DBG_871X(" === DMFlag(0x%08x) === \n",odm_flag);
  5957. DBG_871X("extra_arg = 0 - disable all dynamic func \n");
  5958. DBG_871X("extra_arg = 1 - disable DIG- BIT(0)\n");
  5959. DBG_871X("extra_arg = 2 - disable High power - BIT(1)\n");
  5960. DBG_871X("extra_arg = 3 - disable tx power tracking - BIT(2)\n");
  5961. DBG_871X("extra_arg = 4 - disable BT coexistence - BIT(3)\n");
  5962. DBG_871X("extra_arg = 5 - disable antenna diversity - BIT(4)\n");
  5963. DBG_871X("extra_arg = 6 - enable all dynamic func \n");
  5964. }
  5965. else{
  5966. /* extra_arg = 0 - disable all dynamic func
  5967. extra_arg = 1 - disable DIG
  5968. extra_arg = 2 - disable tx power tracking
  5969. extra_arg = 3 - turn on all dynamic func
  5970. */
  5971. rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &(extra_arg));
  5972. rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC,&odm_flag);
  5973. DBG_871X(" === DMFlag(0x%08x) === \n",odm_flag);
  5974. }
  5975. }
  5976. break;
  5977. case 0xfd:
  5978. rtw_write8(padapter, 0xc50, arg);
  5979. DBG_871X("wr(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
  5980. rtw_write8(padapter, 0xc58, arg);
  5981. DBG_871X("wr(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
  5982. break;
  5983. case 0xfe:
  5984. DBG_871X("rd(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
  5985. DBG_871X("rd(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
  5986. break;
  5987. case 0xff:
  5988. {
  5989. DBG_871X("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
  5990. DBG_871X("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
  5991. DBG_871X("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
  5992. DBG_871X("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
  5993. DBG_871X("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
  5994. DBG_871X("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
  5995. DBG_871X("\n");
  5996. DBG_871X("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
  5997. DBG_871X("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
  5998. DBG_871X("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
  5999. DBG_871X("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
  6000. DBG_871X("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
  6001. DBG_871X("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
  6002. DBG_871X("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
  6003. DBG_871X("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
  6004. DBG_871X("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
  6005. DBG_871X("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
  6006. }
  6007. break;
  6008. }
  6009. break;
  6010. default:
  6011. DBG_871X("error dbg cmd!\n");
  6012. break;
  6013. }
  6014. return ret;
  6015. }
  6016. static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
  6017. {
  6018. uint ret=0;
  6019. u32 flags;
  6020. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6021. switch (name){
  6022. case IEEE_PARAM_WPA_ENABLED:
  6023. padapter->securitypriv.dot11AuthAlgrthm= dot11AuthAlgrthm_8021X; //802.1x
  6024. //ret = ieee80211_wpa_enable(ieee, value);
  6025. switch((value)&0xff)
  6026. {
  6027. case 1 : //WPA
  6028. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; //WPA_PSK
  6029. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  6030. break;
  6031. case 2: //WPA2
  6032. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; //WPA2_PSK
  6033. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  6034. break;
  6035. }
  6036. RT_TRACE(_module_rtl871x_ioctl_os_c,_drv_info_,("wpa_set_param:padapter->securitypriv.ndisauthtype=%d\n", padapter->securitypriv.ndisauthtype));
  6037. break;
  6038. case IEEE_PARAM_TKIP_COUNTERMEASURES:
  6039. //ieee->tkip_countermeasures=value;
  6040. break;
  6041. case IEEE_PARAM_DROP_UNENCRYPTED:
  6042. {
  6043. /* HACK:
  6044. *
  6045. * wpa_supplicant calls set_wpa_enabled when the driver
  6046. * is loaded and unloaded, regardless of if WPA is being
  6047. * used. No other calls are made which can be used to
  6048. * determine if encryption will be used or not prior to
  6049. * association being expected. If encryption is not being
  6050. * used, drop_unencrypted is set to false, else true -- we
  6051. * can use this to determine if the CAP_PRIVACY_ON bit should
  6052. * be set.
  6053. */
  6054. #if 0
  6055. struct ieee80211_security sec = {
  6056. .flags = SEC_ENABLED,
  6057. .enabled = value,
  6058. };
  6059. ieee->drop_unencrypted = value;
  6060. /* We only change SEC_LEVEL for open mode. Others
  6061. * are set by ipw_wpa_set_encryption.
  6062. */
  6063. if (!value) {
  6064. sec.flags |= SEC_LEVEL;
  6065. sec.level = SEC_LEVEL_0;
  6066. }
  6067. else {
  6068. sec.flags |= SEC_LEVEL;
  6069. sec.level = SEC_LEVEL_1;
  6070. }
  6071. if (ieee->set_security)
  6072. ieee->set_security(ieee->dev, &sec);
  6073. #endif
  6074. break;
  6075. }
  6076. case IEEE_PARAM_PRIVACY_INVOKED:
  6077. //ieee->privacy_invoked=value;
  6078. break;
  6079. case IEEE_PARAM_AUTH_ALGS:
  6080. ret = wpa_set_auth_algs(dev, value);
  6081. break;
  6082. case IEEE_PARAM_IEEE_802_1X:
  6083. //ieee->ieee802_1x=value;
  6084. break;
  6085. case IEEE_PARAM_WPAX_SELECT:
  6086. // added for WPA2 mixed mode
  6087. //DBG_871X(KERN_WARNING "------------------------>wpax value = %x\n", value);
  6088. /*
  6089. spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
  6090. ieee->wpax_type_set = 1;
  6091. ieee->wpax_type_notify = value;
  6092. spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
  6093. */
  6094. break;
  6095. default:
  6096. ret = -EOPNOTSUPP;
  6097. break;
  6098. }
  6099. return ret;
  6100. }
  6101. static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
  6102. {
  6103. int ret = 0;
  6104. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6105. switch (command)
  6106. {
  6107. case IEEE_MLME_STA_DEAUTH:
  6108. if(!rtw_set_802_11_disassociate(padapter))
  6109. ret = -1;
  6110. break;
  6111. case IEEE_MLME_STA_DISASSOC:
  6112. if(!rtw_set_802_11_disassociate(padapter))
  6113. ret = -1;
  6114. break;
  6115. default:
  6116. ret = -EOPNOTSUPP;
  6117. break;
  6118. }
  6119. return ret;
  6120. }
  6121. static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
  6122. {
  6123. struct ieee_param *param;
  6124. uint ret=0;
  6125. //down(&ieee->wx_sem);
  6126. if (p->length < sizeof(struct ieee_param) || !p->pointer){
  6127. ret = -EINVAL;
  6128. goto out;
  6129. }
  6130. param = (struct ieee_param *)rtw_malloc(p->length);
  6131. if (param == NULL)
  6132. {
  6133. ret = -ENOMEM;
  6134. goto out;
  6135. }
  6136. if (copy_from_user(param, p->pointer, p->length))
  6137. {
  6138. rtw_mfree((u8*)param, p->length);
  6139. ret = -EFAULT;
  6140. goto out;
  6141. }
  6142. switch (param->cmd) {
  6143. case IEEE_CMD_SET_WPA_PARAM:
  6144. ret = wpa_set_param(dev, param->u.wpa_param.name, param->u.wpa_param.value);
  6145. break;
  6146. case IEEE_CMD_SET_WPA_IE:
  6147. //ret = wpa_set_wpa_ie(dev, param, p->length);
  6148. ret = rtw_set_wpa_ie((_adapter *)rtw_netdev_priv(dev), (char*)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len);
  6149. break;
  6150. case IEEE_CMD_SET_ENCRYPTION:
  6151. ret = wpa_set_encryption(dev, param, p->length);
  6152. break;
  6153. case IEEE_CMD_MLME:
  6154. ret = wpa_mlme(dev, param->u.mlme.command, param->u.mlme.reason_code);
  6155. break;
  6156. default:
  6157. DBG_871X("Unknown WPA supplicant request: %d\n", param->cmd);
  6158. ret = -EOPNOTSUPP;
  6159. break;
  6160. }
  6161. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  6162. ret = -EFAULT;
  6163. rtw_mfree((u8 *)param, p->length);
  6164. out:
  6165. //up(&ieee->wx_sem);
  6166. return ret;
  6167. }
  6168. #ifdef CONFIG_AP_MODE
  6169. static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
  6170. {
  6171. int ret = 0;
  6172. u32 wep_key_idx, wep_key_len,wep_total_len;
  6173. NDIS_802_11_WEP *pwep = NULL;
  6174. struct sta_info *psta = NULL, *pbcmc_sta = NULL;
  6175. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6176. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  6177. struct security_priv* psecuritypriv=&(padapter->securitypriv);
  6178. struct sta_priv *pstapriv = &padapter->stapriv;
  6179. DBG_871X("%s\n", __FUNCTION__);
  6180. param->u.crypt.err = 0;
  6181. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  6182. //sizeof(struct ieee_param) = 64 bytes;
  6183. //if (param_len != (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len)
  6184. if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len)
  6185. {
  6186. ret = -EINVAL;
  6187. goto exit;
  6188. }
  6189. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6190. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6191. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6192. {
  6193. if (param->u.crypt.idx >= WEP_KEYS)
  6194. {
  6195. ret = -EINVAL;
  6196. goto exit;
  6197. }
  6198. }
  6199. else
  6200. {
  6201. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6202. if(!psta)
  6203. {
  6204. //ret = -EINVAL;
  6205. DBG_871X("rtw_set_encryption(), sta has already been removed or never been added\n");
  6206. goto exit;
  6207. }
  6208. }
  6209. if (strcmp(param->u.crypt.alg, "none") == 0 && (psta==NULL))
  6210. {
  6211. //todo:clear default encryption keys
  6212. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  6213. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  6214. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  6215. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  6216. DBG_871X("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
  6217. goto exit;
  6218. }
  6219. if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta==NULL))
  6220. {
  6221. DBG_871X("r871x_set_encryption, crypt.alg = WEP\n");
  6222. wep_key_idx = param->u.crypt.idx;
  6223. wep_key_len = param->u.crypt.key_len;
  6224. DBG_871X("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
  6225. if((wep_key_idx >= WEP_KEYS) || (wep_key_len<=0))
  6226. {
  6227. ret = -EINVAL;
  6228. goto exit;
  6229. }
  6230. if (wep_key_len > 0)
  6231. {
  6232. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  6233. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  6234. pwep =(NDIS_802_11_WEP *)rtw_malloc(wep_total_len);
  6235. if(pwep == NULL){
  6236. DBG_871X(" r871x_set_encryption: pwep allocate fail !!!\n");
  6237. goto exit;
  6238. }
  6239. _rtw_memset(pwep, 0, wep_total_len);
  6240. pwep->KeyLength = wep_key_len;
  6241. pwep->Length = wep_total_len;
  6242. }
  6243. pwep->KeyIndex = wep_key_idx;
  6244. _rtw_memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
  6245. if(param->u.crypt.set_tx)
  6246. {
  6247. DBG_871X("wep, set_tx=1\n");
  6248. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  6249. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  6250. psecuritypriv->dot11PrivacyAlgrthm=_WEP40_;
  6251. psecuritypriv->dot118021XGrpPrivacy=_WEP40_;
  6252. if(pwep->KeyLength==13)
  6253. {
  6254. psecuritypriv->dot11PrivacyAlgrthm=_WEP104_;
  6255. psecuritypriv->dot118021XGrpPrivacy=_WEP104_;
  6256. }
  6257. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  6258. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
  6259. psecuritypriv->dot11DefKeylen[wep_key_idx]=pwep->KeyLength;
  6260. rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 1);
  6261. }
  6262. else
  6263. {
  6264. DBG_871X("wep, set_tx=0\n");
  6265. //don't update "psecuritypriv->dot11PrivacyAlgrthm" and
  6266. //"psecuritypriv->dot11PrivacyKeyIndex=keyid", but can rtw_set_key to cam
  6267. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
  6268. psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
  6269. rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 0);
  6270. }
  6271. goto exit;
  6272. }
  6273. if(!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) // //group key
  6274. {
  6275. if(param->u.crypt.set_tx ==1)
  6276. {
  6277. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  6278. {
  6279. DBG_871X("%s, set group_key, WEP\n", __FUNCTION__);
  6280. _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));
  6281. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  6282. if(param->u.crypt.key_len==13)
  6283. {
  6284. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  6285. }
  6286. }
  6287. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  6288. {
  6289. DBG_871X("%s, set group_key, TKIP\n", __FUNCTION__);
  6290. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  6291. _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));
  6292. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  6293. //set mic key
  6294. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  6295. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  6296. psecuritypriv->busetkipkey = _TRUE;
  6297. }
  6298. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  6299. {
  6300. DBG_871X("%s, set group_key, CCMP\n", __FUNCTION__);
  6301. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  6302. _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));
  6303. }
  6304. else
  6305. {
  6306. DBG_871X("%s, set group_key, none\n", __FUNCTION__);
  6307. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  6308. }
  6309. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  6310. psecuritypriv->binstallGrpkey = _TRUE;
  6311. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
  6312. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  6313. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  6314. if(pbcmc_sta)
  6315. {
  6316. pbcmc_sta->ieee8021x_blocked = _FALSE;
  6317. pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
  6318. }
  6319. }
  6320. goto exit;
  6321. }
  6322. if(psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) // psk/802_1x
  6323. {
  6324. if(check_fwstate(pmlmepriv, WIFI_AP_STATE))
  6325. {
  6326. if(param->u.crypt.set_tx ==1)
  6327. {
  6328. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len));
  6329. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  6330. {
  6331. DBG_871X("%s, set pairwise key, WEP\n", __FUNCTION__);
  6332. psta->dot118021XPrivacy = _WEP40_;
  6333. if(param->u.crypt.key_len==13)
  6334. {
  6335. psta->dot118021XPrivacy = _WEP104_;
  6336. }
  6337. }
  6338. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  6339. {
  6340. DBG_871X("%s, set pairwise key, TKIP\n", __FUNCTION__);
  6341. psta->dot118021XPrivacy = _TKIP_;
  6342. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  6343. //set mic key
  6344. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  6345. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  6346. psecuritypriv->busetkipkey = _TRUE;
  6347. }
  6348. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  6349. {
  6350. DBG_871X("%s, set pairwise key, CCMP\n", __FUNCTION__);
  6351. psta->dot118021XPrivacy = _AES_;
  6352. }
  6353. else
  6354. {
  6355. DBG_871X("%s, set pairwise key, none\n", __FUNCTION__);
  6356. psta->dot118021XPrivacy = _NO_PRIVACY_;
  6357. }
  6358. rtw_ap_set_pairwise_key(padapter, psta);
  6359. psta->ieee8021x_blocked = _FALSE;
  6360. }
  6361. else//group key???
  6362. {
  6363. if(strcmp(param->u.crypt.alg, "WEP") == 0)
  6364. {
  6365. _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));
  6366. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  6367. if(param->u.crypt.key_len==13)
  6368. {
  6369. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  6370. }
  6371. }
  6372. else if(strcmp(param->u.crypt.alg, "TKIP") == 0)
  6373. {
  6374. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  6375. _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));
  6376. //DEBUG_ERR("set key length :param->u.crypt.key_len=%d\n", param->u.crypt.key_len);
  6377. //set mic key
  6378. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  6379. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  6380. psecuritypriv->busetkipkey = _TRUE;
  6381. }
  6382. else if(strcmp(param->u.crypt.alg, "CCMP") == 0)
  6383. {
  6384. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  6385. _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));
  6386. }
  6387. else
  6388. {
  6389. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  6390. }
  6391. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  6392. psecuritypriv->binstallGrpkey = _TRUE;
  6393. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;//!!!
  6394. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  6395. pbcmc_sta=rtw_get_bcmc_stainfo(padapter);
  6396. if(pbcmc_sta)
  6397. {
  6398. pbcmc_sta->ieee8021x_blocked = _FALSE;
  6399. pbcmc_sta->dot118021XPrivacy= psecuritypriv->dot118021XGrpPrivacy;//rx will use bmc_sta's dot118021XPrivacy
  6400. }
  6401. }
  6402. }
  6403. }
  6404. exit:
  6405. if(pwep)
  6406. {
  6407. rtw_mfree((u8 *)pwep, wep_total_len);
  6408. }
  6409. return ret;
  6410. }
  6411. static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int len)
  6412. {
  6413. int ret=0;
  6414. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6415. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6416. struct sta_priv *pstapriv = &padapter->stapriv;
  6417. unsigned char *pbuf = param->u.bcn_ie.buf;
  6418. DBG_871X("%s, len=%d\n", __FUNCTION__, len);
  6419. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6420. return -EINVAL;
  6421. _rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2);
  6422. if((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0))
  6423. pstapriv->max_num_sta = NUM_STA;
  6424. if(rtw_check_beacon_data(padapter, pbuf, (len-12-2)) == _SUCCESS)// 12 = param header, 2:no packed
  6425. ret = 0;
  6426. else
  6427. ret = -EINVAL;
  6428. return ret;
  6429. }
  6430. static int rtw_hostapd_sta_flush(struct net_device *dev)
  6431. {
  6432. //_irqL irqL;
  6433. //_list *phead, *plist;
  6434. int ret=0;
  6435. //struct sta_info *psta = NULL;
  6436. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6437. //struct sta_priv *pstapriv = &padapter->stapriv;
  6438. DBG_871X("%s\n", __FUNCTION__);
  6439. flush_all_cam_entry(padapter); //clear CAM
  6440. ret = rtw_sta_flush(padapter);
  6441. return ret;
  6442. }
  6443. static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
  6444. {
  6445. _irqL irqL;
  6446. int ret=0;
  6447. struct sta_info *psta = NULL;
  6448. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6449. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6450. struct sta_priv *pstapriv = &padapter->stapriv;
  6451. DBG_871X("rtw_add_sta(aid=%d)=" MAC_FMT "\n", param->u.add_sta.aid, MAC_ARG(param->sta_addr));
  6452. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
  6453. {
  6454. return -EINVAL;
  6455. }
  6456. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6457. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6458. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6459. {
  6460. return -EINVAL;
  6461. }
  6462. /*
  6463. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6464. if(psta)
  6465. {
  6466. DBG_871X("rtw_add_sta(), free has been added psta=%p\n", psta);
  6467. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  6468. rtw_free_stainfo(padapter, psta);
  6469. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
  6470. psta = NULL;
  6471. }
  6472. */
  6473. //psta = rtw_alloc_stainfo(pstapriv, param->sta_addr);
  6474. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6475. if(psta)
  6476. {
  6477. int flags = param->u.add_sta.flags;
  6478. //DBG_871X("rtw_add_sta(), init sta's variables, psta=%p\n", psta);
  6479. psta->aid = param->u.add_sta.aid;//aid=1~2007
  6480. _rtw_memcpy(psta->bssrateset, param->u.add_sta.tx_supp_rates, 16);
  6481. //check wmm cap.
  6482. if(WLAN_STA_WME&flags)
  6483. psta->qos_option = 1;
  6484. else
  6485. psta->qos_option = 0;
  6486. if(pmlmepriv->qospriv.qos_option == 0)
  6487. psta->qos_option = 0;
  6488. #ifdef CONFIG_80211N_HT
  6489. //chec 802.11n ht cap.
  6490. if(WLAN_STA_HT&flags)
  6491. {
  6492. psta->htpriv.ht_option = _TRUE;
  6493. psta->qos_option = 1;
  6494. _rtw_memcpy((void*)&psta->htpriv.ht_cap, (void*)&param->u.add_sta.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
  6495. }
  6496. else
  6497. {
  6498. psta->htpriv.ht_option = _FALSE;
  6499. }
  6500. if(pmlmepriv->htpriv.ht_option == _FALSE)
  6501. psta->htpriv.ht_option = _FALSE;
  6502. #endif
  6503. update_sta_info_apmode(padapter, psta);
  6504. }
  6505. else
  6506. {
  6507. ret = -ENOMEM;
  6508. }
  6509. return ret;
  6510. }
  6511. static int rtw_del_sta(struct net_device *dev, struct ieee_param *param)
  6512. {
  6513. _irqL irqL;
  6514. int ret=0;
  6515. struct sta_info *psta = NULL;
  6516. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6517. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6518. struct sta_priv *pstapriv = &padapter->stapriv;
  6519. DBG_871X("rtw_del_sta=" MAC_FMT "\n", MAC_ARG(param->sta_addr));
  6520. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
  6521. {
  6522. return -EINVAL;
  6523. }
  6524. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6525. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6526. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6527. {
  6528. return -EINVAL;
  6529. }
  6530. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6531. if(psta)
  6532. {
  6533. u8 updated;
  6534. //DBG_871X("free psta=%p, aid=%d\n", psta, psta->aid);
  6535. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  6536. if(rtw_is_list_empty(&psta->asoc_list)==_FALSE)
  6537. {
  6538. rtw_list_delete(&psta->asoc_list);
  6539. pstapriv->asoc_list_cnt--;
  6540. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING);
  6541. }
  6542. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  6543. associated_clients_update(padapter, updated);
  6544. psta = NULL;
  6545. }
  6546. else
  6547. {
  6548. DBG_871X("rtw_del_sta(), sta has already been removed or never been added\n");
  6549. //ret = -1;
  6550. }
  6551. return ret;
  6552. }
  6553. static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *param, int len)
  6554. {
  6555. int ret=0;
  6556. struct sta_info *psta = NULL;
  6557. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6558. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6559. struct sta_priv *pstapriv = &padapter->stapriv;
  6560. struct ieee_param_ex *param_ex = (struct ieee_param_ex *)param;
  6561. struct sta_data *psta_data = (struct sta_data *)param_ex->data;
  6562. DBG_871X("rtw_ioctl_get_sta_info, sta_addr: " MAC_FMT "\n", MAC_ARG(param_ex->sta_addr));
  6563. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
  6564. {
  6565. return -EINVAL;
  6566. }
  6567. if (param_ex->sta_addr[0] == 0xff && param_ex->sta_addr[1] == 0xff &&
  6568. param_ex->sta_addr[2] == 0xff && param_ex->sta_addr[3] == 0xff &&
  6569. param_ex->sta_addr[4] == 0xff && param_ex->sta_addr[5] == 0xff)
  6570. {
  6571. return -EINVAL;
  6572. }
  6573. psta = rtw_get_stainfo(pstapriv, param_ex->sta_addr);
  6574. if(psta)
  6575. {
  6576. #if 0
  6577. struct {
  6578. u16 aid;
  6579. u16 capability;
  6580. int flags;
  6581. u32 sta_set;
  6582. u8 tx_supp_rates[16];
  6583. u32 tx_supp_rates_len;
  6584. struct rtw_ieee80211_ht_cap ht_cap;
  6585. u64 rx_pkts;
  6586. u64 rx_bytes;
  6587. u64 rx_drops;
  6588. u64 tx_pkts;
  6589. u64 tx_bytes;
  6590. u64 tx_drops;
  6591. } get_sta;
  6592. #endif
  6593. psta_data->aid = (u16)psta->aid;
  6594. psta_data->capability = psta->capability;
  6595. psta_data->flags = psta->flags;
  6596. /*
  6597. nonerp_set : BIT(0)
  6598. no_short_slot_time_set : BIT(1)
  6599. no_short_preamble_set : BIT(2)
  6600. no_ht_gf_set : BIT(3)
  6601. no_ht_set : BIT(4)
  6602. ht_20mhz_set : BIT(5)
  6603. */
  6604. psta_data->sta_set =((psta->nonerp_set) |
  6605. (psta->no_short_slot_time_set <<1) |
  6606. (psta->no_short_preamble_set <<2) |
  6607. (psta->no_ht_gf_set <<3) |
  6608. (psta->no_ht_set <<4) |
  6609. (psta->ht_20mhz_set <<5));
  6610. psta_data->tx_supp_rates_len = psta->bssratelen;
  6611. _rtw_memcpy(psta_data->tx_supp_rates, psta->bssrateset, psta->bssratelen);
  6612. #ifdef CONFIG_80211N_HT
  6613. _rtw_memcpy(&psta_data->ht_cap, &psta->htpriv.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
  6614. #endif //CONFIG_80211N_HT
  6615. psta_data->rx_pkts = psta->sta_stats.rx_data_pkts;
  6616. psta_data->rx_bytes = psta->sta_stats.rx_bytes;
  6617. psta_data->rx_drops = psta->sta_stats.rx_drops;
  6618. psta_data->tx_pkts = psta->sta_stats.tx_pkts;
  6619. psta_data->tx_bytes = psta->sta_stats.tx_bytes;
  6620. psta_data->tx_drops = psta->sta_stats.tx_drops;
  6621. }
  6622. else
  6623. {
  6624. ret = -1;
  6625. }
  6626. return ret;
  6627. }
  6628. static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
  6629. {
  6630. int ret=0;
  6631. struct sta_info *psta = NULL;
  6632. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6633. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6634. struct sta_priv *pstapriv = &padapter->stapriv;
  6635. DBG_871X("rtw_get_sta_wpaie, sta_addr: " MAC_FMT "\n", MAC_ARG(param->sta_addr));
  6636. if(check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != _TRUE)
  6637. {
  6638. return -EINVAL;
  6639. }
  6640. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6641. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6642. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6643. {
  6644. return -EINVAL;
  6645. }
  6646. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  6647. if(psta)
  6648. {
  6649. if((psta->wpa_ie[0] == WLAN_EID_RSN) || (psta->wpa_ie[0] == WLAN_EID_GENERIC))
  6650. {
  6651. int wpa_ie_len;
  6652. int copy_len;
  6653. wpa_ie_len = psta->wpa_ie[1];
  6654. copy_len = ((wpa_ie_len+2) > sizeof(psta->wpa_ie)) ? (sizeof(psta->wpa_ie)):(wpa_ie_len+2);
  6655. param->u.wpa_ie.len = copy_len;
  6656. _rtw_memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len);
  6657. }
  6658. else
  6659. {
  6660. //ret = -1;
  6661. DBG_871X("sta's wpa_ie is NONE\n");
  6662. }
  6663. }
  6664. else
  6665. {
  6666. ret = -1;
  6667. }
  6668. return ret;
  6669. }
  6670. static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len)
  6671. {
  6672. int ret=0;
  6673. unsigned char wps_oui[4]={0x0,0x50,0xf2,0x04};
  6674. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6675. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6676. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  6677. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  6678. int ie_len;
  6679. DBG_871X("%s, len=%d\n", __FUNCTION__, len);
  6680. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6681. return -EINVAL;
  6682. ie_len = len-12-2;// 12 = param header, 2:no packed
  6683. if(pmlmepriv->wps_beacon_ie)
  6684. {
  6685. rtw_mfree(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len);
  6686. pmlmepriv->wps_beacon_ie = NULL;
  6687. }
  6688. if(ie_len>0)
  6689. {
  6690. pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
  6691. pmlmepriv->wps_beacon_ie_len = ie_len;
  6692. if ( pmlmepriv->wps_beacon_ie == NULL) {
  6693. DBG_871X("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6694. return -EINVAL;
  6695. }
  6696. _rtw_memcpy(pmlmepriv->wps_beacon_ie, param->u.bcn_ie.buf, ie_len);
  6697. update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
  6698. pmlmeext->bstart_bss = _TRUE;
  6699. }
  6700. return ret;
  6701. }
  6702. static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len)
  6703. {
  6704. int ret=0;
  6705. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6706. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6707. int ie_len;
  6708. DBG_871X("%s, len=%d\n", __FUNCTION__, len);
  6709. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6710. return -EINVAL;
  6711. ie_len = len-12-2;// 12 = param header, 2:no packed
  6712. if(pmlmepriv->wps_probe_resp_ie)
  6713. {
  6714. rtw_mfree(pmlmepriv->wps_probe_resp_ie, pmlmepriv->wps_probe_resp_ie_len);
  6715. pmlmepriv->wps_probe_resp_ie = NULL;
  6716. }
  6717. if(ie_len>0)
  6718. {
  6719. pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
  6720. pmlmepriv->wps_probe_resp_ie_len = ie_len;
  6721. if ( pmlmepriv->wps_probe_resp_ie == NULL) {
  6722. DBG_871X("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6723. return -EINVAL;
  6724. }
  6725. _rtw_memcpy(pmlmepriv->wps_probe_resp_ie, param->u.bcn_ie.buf, ie_len);
  6726. }
  6727. return ret;
  6728. }
  6729. static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len)
  6730. {
  6731. int ret=0;
  6732. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6733. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6734. int ie_len;
  6735. DBG_871X("%s, len=%d\n", __FUNCTION__, len);
  6736. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6737. return -EINVAL;
  6738. ie_len = len-12-2;// 12 = param header, 2:no packed
  6739. if(pmlmepriv->wps_assoc_resp_ie)
  6740. {
  6741. rtw_mfree(pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
  6742. pmlmepriv->wps_assoc_resp_ie = NULL;
  6743. }
  6744. if(ie_len>0)
  6745. {
  6746. pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
  6747. pmlmepriv->wps_assoc_resp_ie_len = ie_len;
  6748. if ( pmlmepriv->wps_assoc_resp_ie == NULL) {
  6749. DBG_871X("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6750. return -EINVAL;
  6751. }
  6752. _rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len);
  6753. }
  6754. return ret;
  6755. }
  6756. static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len)
  6757. {
  6758. int ret=0;
  6759. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6760. struct mlme_priv *mlmepriv = &(adapter->mlmepriv);
  6761. struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
  6762. struct mlme_ext_info *mlmeinfo = &(mlmeext->mlmext_info);
  6763. int ie_len;
  6764. u8 *ssid_ie;
  6765. char ssid[NDIS_802_11_LENGTH_SSID + 1];
  6766. sint ssid_len;
  6767. u8 ignore_broadcast_ssid;
  6768. if(check_fwstate(mlmepriv, WIFI_AP_STATE) != _TRUE)
  6769. return -EPERM;
  6770. if (param->u.bcn_ie.reserved[0] != 0xea)
  6771. return -EINVAL;
  6772. mlmeinfo->hidden_ssid_mode = ignore_broadcast_ssid = param->u.bcn_ie.reserved[1];
  6773. ie_len = len-12-2;// 12 = param header, 2:no packed
  6774. ssid_ie = rtw_get_ie(param->u.bcn_ie.buf, WLAN_EID_SSID, &ssid_len, ie_len);
  6775. if (ssid_ie && ssid_len) {
  6776. WLAN_BSSID_EX *pbss_network = &mlmepriv->cur_network.network;
  6777. WLAN_BSSID_EX *pbss_network_ext = &mlmeinfo->network;
  6778. _rtw_memcpy(ssid, ssid_ie+2, ssid_len);
  6779. ssid[ssid_len>NDIS_802_11_LENGTH_SSID?NDIS_802_11_LENGTH_SSID:ssid_len] = 0x0;
  6780. if(0)
  6781. DBG_871X(FUNC_ADPT_FMT" ssid:(%s,%d), from ie:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  6782. ssid, ssid_len,
  6783. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  6784. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  6785. _rtw_memcpy(pbss_network->Ssid.Ssid, (void *)ssid, ssid_len);
  6786. pbss_network->Ssid.SsidLength = ssid_len;
  6787. _rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)ssid, ssid_len);
  6788. pbss_network_ext->Ssid.SsidLength = ssid_len;
  6789. if(0)
  6790. DBG_871X(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  6791. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  6792. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  6793. }
  6794. DBG_871X(FUNC_ADPT_FMT" ignore_broadcast_ssid:%d, %s,%d\n", FUNC_ADPT_ARG(adapter),
  6795. ignore_broadcast_ssid, ssid, ssid_len);
  6796. return ret;
  6797. }
  6798. static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
  6799. {
  6800. int ret=0;
  6801. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6802. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6803. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6804. return -EINVAL;
  6805. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6806. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6807. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6808. {
  6809. return -EINVAL;
  6810. }
  6811. ret = rtw_acl_remove_sta(padapter, param->sta_addr);
  6812. return ret;
  6813. }
  6814. static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len)
  6815. {
  6816. int ret=0;
  6817. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6818. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6819. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6820. return -EINVAL;
  6821. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  6822. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  6823. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
  6824. {
  6825. return -EINVAL;
  6826. }
  6827. ret = rtw_acl_add_sta(padapter, param->sta_addr);
  6828. return ret;
  6829. }
  6830. static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
  6831. {
  6832. int ret=0;
  6833. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6834. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6835. if(check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  6836. return -EINVAL;
  6837. rtw_set_macaddr_acl(padapter, param->u.mlme.command);
  6838. return ret;
  6839. }
  6840. static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
  6841. {
  6842. struct ieee_param *param;
  6843. int ret=0;
  6844. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6845. //DBG_871X("%s\n", __FUNCTION__);
  6846. /*
  6847. * this function is expect to call in master mode, which allows no power saving
  6848. * so, we just check hw_init_completed
  6849. */
  6850. if (padapter->hw_init_completed==_FALSE){
  6851. ret = -EPERM;
  6852. goto out;
  6853. }
  6854. //if (p->length < sizeof(struct ieee_param) || !p->pointer){
  6855. if(!p->pointer){
  6856. ret = -EINVAL;
  6857. goto out;
  6858. }
  6859. param = (struct ieee_param *)rtw_malloc(p->length);
  6860. if (param == NULL)
  6861. {
  6862. ret = -ENOMEM;
  6863. goto out;
  6864. }
  6865. if (copy_from_user(param, p->pointer, p->length))
  6866. {
  6867. rtw_mfree((u8*)param, p->length);
  6868. ret = -EFAULT;
  6869. goto out;
  6870. }
  6871. //DBG_871X("%s, cmd=%d\n", __FUNCTION__, param->cmd);
  6872. switch (param->cmd)
  6873. {
  6874. case RTL871X_HOSTAPD_FLUSH:
  6875. ret = rtw_hostapd_sta_flush(dev);
  6876. break;
  6877. case RTL871X_HOSTAPD_ADD_STA:
  6878. ret = rtw_add_sta(dev, param);
  6879. break;
  6880. case RTL871X_HOSTAPD_REMOVE_STA:
  6881. ret = rtw_del_sta(dev, param);
  6882. break;
  6883. case RTL871X_HOSTAPD_SET_BEACON:
  6884. ret = rtw_set_beacon(dev, param, p->length);
  6885. break;
  6886. case RTL871X_SET_ENCRYPTION:
  6887. ret = rtw_set_encryption(dev, param, p->length);
  6888. break;
  6889. case RTL871X_HOSTAPD_GET_WPAIE_STA:
  6890. ret = rtw_get_sta_wpaie(dev, param);
  6891. break;
  6892. case RTL871X_HOSTAPD_SET_WPS_BEACON:
  6893. ret = rtw_set_wps_beacon(dev, param, p->length);
  6894. break;
  6895. case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP:
  6896. ret = rtw_set_wps_probe_resp(dev, param, p->length);
  6897. break;
  6898. case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP:
  6899. ret = rtw_set_wps_assoc_resp(dev, param, p->length);
  6900. break;
  6901. case RTL871X_HOSTAPD_SET_HIDDEN_SSID:
  6902. ret = rtw_set_hidden_ssid(dev, param, p->length);
  6903. break;
  6904. case RTL871X_HOSTAPD_GET_INFO_STA:
  6905. ret = rtw_ioctl_get_sta_data(dev, param, p->length);
  6906. break;
  6907. case RTL871X_HOSTAPD_SET_MACADDR_ACL:
  6908. ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length);
  6909. break;
  6910. case RTL871X_HOSTAPD_ACL_ADD_STA:
  6911. ret = rtw_ioctl_acl_add_sta(dev, param, p->length);
  6912. break;
  6913. case RTL871X_HOSTAPD_ACL_REMOVE_STA:
  6914. ret = rtw_ioctl_acl_remove_sta(dev, param, p->length);
  6915. break;
  6916. default:
  6917. DBG_871X("Unknown hostapd request: %d\n", param->cmd);
  6918. ret = -EOPNOTSUPP;
  6919. break;
  6920. }
  6921. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  6922. ret = -EFAULT;
  6923. rtw_mfree((u8 *)param, p->length);
  6924. out:
  6925. return ret;
  6926. }
  6927. #endif
  6928. static int rtw_wx_set_priv(struct net_device *dev,
  6929. struct iw_request_info *info,
  6930. union iwreq_data *awrq,
  6931. char *extra)
  6932. {
  6933. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6934. char *ext_dbg;
  6935. #endif
  6936. int ret = 0;
  6937. int len = 0;
  6938. char *ext;
  6939. int i;
  6940. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  6941. struct iw_point *dwrq = (struct iw_point*)awrq;
  6942. //RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_notice_, ("+rtw_wx_set_priv\n"));
  6943. if(dwrq->length == 0)
  6944. return -EFAULT;
  6945. len = dwrq->length;
  6946. if (!(ext = rtw_vmalloc(len)))
  6947. return -ENOMEM;
  6948. if (copy_from_user(ext, dwrq->pointer, len)) {
  6949. rtw_vmfree(ext, len);
  6950. return -EFAULT;
  6951. }
  6952. //RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_notice_,
  6953. // ("rtw_wx_set_priv: %s req=%s\n",
  6954. // dev->name, ext));
  6955. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  6956. if (!(ext_dbg = rtw_vmalloc(len)))
  6957. {
  6958. rtw_vmfree(ext, len);
  6959. return -ENOMEM;
  6960. }
  6961. _rtw_memcpy(ext_dbg, ext, len);
  6962. #endif
  6963. //added for wps2.0 @20110524
  6964. if(dwrq->flags == 0x8766 && len > 8)
  6965. {
  6966. u32 cp_sz;
  6967. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  6968. u8 *probereq_wpsie = ext;
  6969. int probereq_wpsie_len = len;
  6970. u8 wps_oui[4]={0x0,0x50,0xf2,0x04};
  6971. if((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
  6972. (_rtw_memcmp(&probereq_wpsie[2], wps_oui, 4) ==_TRUE))
  6973. {
  6974. cp_sz = probereq_wpsie_len>MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN:probereq_wpsie_len;
  6975. //_rtw_memcpy(pmlmepriv->probereq_wpsie, probereq_wpsie, cp_sz);
  6976. //pmlmepriv->probereq_wpsie_len = cp_sz;
  6977. if(pmlmepriv->wps_probe_req_ie)
  6978. {
  6979. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  6980. pmlmepriv->wps_probe_req_ie_len = 0;
  6981. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  6982. pmlmepriv->wps_probe_req_ie = NULL;
  6983. }
  6984. pmlmepriv->wps_probe_req_ie = rtw_malloc(cp_sz);
  6985. if ( pmlmepriv->wps_probe_req_ie == NULL) {
  6986. printk("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  6987. ret = -EINVAL;
  6988. goto FREE_EXT;
  6989. }
  6990. _rtw_memcpy(pmlmepriv->wps_probe_req_ie, probereq_wpsie, cp_sz);
  6991. pmlmepriv->wps_probe_req_ie_len = cp_sz;
  6992. }
  6993. goto FREE_EXT;
  6994. }
  6995. if( len >= WEXT_CSCAN_HEADER_SIZE
  6996. && _rtw_memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
  6997. ){
  6998. ret = rtw_wx_set_scan(dev, info, awrq, ext);
  6999. goto FREE_EXT;
  7000. }
  7001. #ifdef CONFIG_ANDROID
  7002. //DBG_871X("rtw_wx_set_priv: %s req=%s\n", dev->name, ext);
  7003. i = rtw_android_cmdstr_to_num(ext);
  7004. switch(i) {
  7005. case ANDROID_WIFI_CMD_START :
  7006. indicate_wx_custom_event(padapter, "START");
  7007. break;
  7008. case ANDROID_WIFI_CMD_STOP :
  7009. indicate_wx_custom_event(padapter, "STOP");
  7010. break;
  7011. case ANDROID_WIFI_CMD_RSSI :
  7012. {
  7013. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7014. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  7015. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  7016. sprintf(ext, "%s rssi %d", pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
  7017. } else {
  7018. sprintf(ext, "OK");
  7019. }
  7020. }
  7021. break;
  7022. case ANDROID_WIFI_CMD_LINKSPEED :
  7023. {
  7024. u16 mbps = rtw_get_cur_max_rate(padapter)/10;
  7025. sprintf(ext, "LINKSPEED %d", mbps);
  7026. }
  7027. break;
  7028. case ANDROID_WIFI_CMD_MACADDR :
  7029. sprintf(ext, "MACADDR = " MAC_FMT, MAC_ARG(dev->dev_addr));
  7030. break;
  7031. case ANDROID_WIFI_CMD_SCAN_ACTIVE :
  7032. {
  7033. //rtw_set_scan_mode(padapter, SCAN_ACTIVE);
  7034. sprintf(ext, "OK");
  7035. }
  7036. break;
  7037. case ANDROID_WIFI_CMD_SCAN_PASSIVE :
  7038. {
  7039. //rtw_set_scan_mode(padapter, SCAN_PASSIVE);
  7040. sprintf(ext, "OK");
  7041. }
  7042. break;
  7043. case ANDROID_WIFI_CMD_COUNTRY :
  7044. {
  7045. char country_code[10];
  7046. sscanf(ext, "%*s %s", country_code);
  7047. rtw_set_country(padapter, country_code);
  7048. sprintf(ext, "OK");
  7049. }
  7050. break;
  7051. default :
  7052. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  7053. DBG_871X("%s: %s unknowned req=%s\n", __FUNCTION__,
  7054. dev->name, ext_dbg);
  7055. #endif
  7056. sprintf(ext, "OK");
  7057. }
  7058. if (copy_to_user(dwrq->pointer, ext, min(dwrq->length, (u16)(strlen(ext)+1)) ) )
  7059. ret = -EFAULT;
  7060. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  7061. DBG_871X("%s: %s req=%s rep=%s dwrq->length=%d, strlen(ext)+1=%d\n", __FUNCTION__,
  7062. dev->name, ext_dbg ,ext, dwrq->length, (u16)(strlen(ext)+1));
  7063. #endif
  7064. #endif //end of CONFIG_ANDROID
  7065. FREE_EXT:
  7066. rtw_vmfree(ext, len);
  7067. #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
  7068. rtw_vmfree(ext_dbg, len);
  7069. #endif
  7070. //DBG_871X("rtw_wx_set_priv: (SIOCSIWPRIV) %s ret=%d\n",
  7071. // dev->name, ret);
  7072. return ret;
  7073. }
  7074. static int rtw_pm_set(struct net_device *dev,
  7075. struct iw_request_info *info,
  7076. union iwreq_data *wrqu, char *extra)
  7077. {
  7078. int ret = 0;
  7079. unsigned mode = 0;
  7080. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  7081. DBG_871X( "[%s] extra = %s\n", __FUNCTION__, extra );
  7082. if ( _rtw_memcmp( extra, "lps=", 4 ) )
  7083. {
  7084. sscanf(extra+4, "%u", &mode);
  7085. ret = rtw_pm_set_lps(padapter,mode);
  7086. }
  7087. else if ( _rtw_memcmp( extra, "ips=", 4 ) )
  7088. {
  7089. sscanf(extra+4, "%u", &mode);
  7090. ret = rtw_pm_set_ips(padapter,mode);
  7091. }
  7092. else{
  7093. ret = -EINVAL;
  7094. }
  7095. return ret;
  7096. }
  7097. static int rtw_mp_efuse_get(struct net_device *dev,
  7098. struct iw_request_info *info,
  7099. union iwreq_data *wdata, char *extra)
  7100. {
  7101. PADAPTER padapter = rtw_netdev_priv(dev);
  7102. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  7103. PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
  7104. PEFUSE_HAL pEfuseHal;
  7105. struct iw_point *wrqu;
  7106. u8 *PROMContent = pEEPROM->efuse_eeprom_data;
  7107. u8 ips_mode,lps_mode;
  7108. struct pwrctrl_priv *pwrctrlpriv ;
  7109. u8 *data = NULL;
  7110. u8 *rawdata = NULL;
  7111. char *pch, *ptmp, *token, *tmp[3]={0x00,0x00,0x00};
  7112. u16 i=0, j=0, mapLen=0, addr=0, cnts=0;
  7113. u16 max_available_size=0, raw_cursize=0, raw_maxsize=0;
  7114. int err;
  7115. #ifdef CONFIG_IOL
  7116. u8 org_fw_iol = padapter->registrypriv.fw_iol;// 0:Disable, 1:enable, 2:by usb speed
  7117. #endif
  7118. wrqu = (struct iw_point*)wdata;
  7119. pwrctrlpriv = &padapter->pwrctrlpriv;
  7120. pEfuseHal = &pHalData->EfuseHal;
  7121. err = 0;
  7122. data = _rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
  7123. if (data == NULL)
  7124. {
  7125. err = -ENOMEM;
  7126. goto exit;
  7127. }
  7128. rawdata = _rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
  7129. if (rawdata == NULL)
  7130. {
  7131. err = -ENOMEM;
  7132. goto exit;
  7133. }
  7134. if (copy_from_user(extra, wrqu->pointer, wrqu->length))
  7135. {
  7136. err = -EFAULT;
  7137. goto exit;
  7138. }
  7139. #ifdef CONFIG_LPS
  7140. lps_mode = pwrctrlpriv->power_mgnt;//keep org value
  7141. rtw_pm_set_lps(padapter,PS_MODE_ACTIVE);
  7142. #endif
  7143. #ifdef CONFIG_IPS
  7144. ips_mode = pwrctrlpriv->ips_mode;//keep org value
  7145. rtw_pm_set_ips(padapter,IPS_NONE);
  7146. #endif
  7147. pch = extra;
  7148. DBG_871X("%s: in=%s\n", __FUNCTION__, extra);
  7149. i = 0;
  7150. //mac 16 "00e04c871200" rmap,00,2
  7151. while ((token = strsep(&pch, ",")) != NULL)
  7152. {
  7153. if (i > 2) break;
  7154. tmp[i] = token;
  7155. i++;
  7156. }
  7157. #ifdef CONFIG_IOL
  7158. padapter->registrypriv.fw_iol = 0;// 0:Disable, 1:enable, 2:by usb speed
  7159. #endif
  7160. if(strcmp(tmp[0], "status") == 0){
  7161. sprintf(extra, "Load File efuse=%s,Load File MAC=%s",(pEEPROM->bloadfile_fail_flag? "FAIL" : "OK"),(pEEPROM->bloadmac_fail_flag? "FAIL" : "OK"));
  7162. goto exit;
  7163. }
  7164. else if (strcmp(tmp[0], "filemap") == 0)
  7165. {
  7166. mapLen = EFUSE_MAP_SIZE;
  7167. sprintf(extra, "\n");
  7168. for (i = 0; i < EFUSE_MAP_SIZE; i += 16)
  7169. {
  7170. // DBG_871X("0x%02x\t", i);
  7171. sprintf(extra, "%s0x%02x\t", extra, i);
  7172. for (j=0; j<8; j++) {
  7173. // DBG_871X("%02X ", data[i+j]);
  7174. sprintf(extra, "%s%02X ", extra, PROMContent[i+j]);
  7175. }
  7176. // DBG_871X("\t");
  7177. sprintf(extra, "%s\t", extra);
  7178. for (; j<16; j++) {
  7179. // DBG_871X("%02X ", data[i+j]);
  7180. sprintf(extra, "%s%02X ", extra, PROMContent[i+j]);
  7181. }
  7182. // DBG_871X("\n");
  7183. sprintf(extra,"%s\n",extra);
  7184. }
  7185. // DBG_871X("\n");
  7186. }
  7187. else if (strcmp(tmp[0], "realmap") == 0)
  7188. {
  7189. mapLen = EFUSE_MAP_SIZE;
  7190. if (rtw_efuse_map_read(padapter, 0, mapLen, pEfuseHal->fakeEfuseInitMap) == _FAIL)
  7191. {
  7192. DBG_871X("%s: read realmap Fail!!\n", __FUNCTION__);
  7193. err = -EFAULT;
  7194. goto exit;
  7195. }
  7196. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7197. sprintf(extra, "\n");
  7198. for (i = 0; i < EFUSE_MAP_SIZE; i += 16)
  7199. {
  7200. // DBG_871X("0x%02x\t", i);
  7201. sprintf(extra, "%s0x%02x\t", extra, i);
  7202. for (j=0; j<8 && i+j<EFUSE_MAX_MAP_LEN; j++) {
  7203. // DBG_871X("%02X ", data[i+j]);
  7204. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeEfuseInitMap[i+j]);
  7205. }
  7206. // DBG_871X("\t");
  7207. sprintf(extra, "%s\t", extra);
  7208. for (; j<16 && i+j<EFUSE_MAX_MAP_LEN; j++) {
  7209. // DBG_871X("%02X ", data[i+j]);
  7210. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeEfuseInitMap[i+j]);
  7211. }
  7212. // DBG_871X("\n");
  7213. sprintf(extra,"%s\n",extra);
  7214. }
  7215. // DBG_871X("\n");
  7216. }
  7217. else if (strcmp(tmp[0], "rmap") == 0)
  7218. {
  7219. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  7220. {
  7221. DBG_871X("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
  7222. err = -EINVAL;
  7223. goto exit;
  7224. }
  7225. // rmap addr cnts
  7226. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7227. DBG_871X("%s: addr=%x\n", __FUNCTION__, addr);
  7228. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  7229. if (cnts == 0)
  7230. {
  7231. DBG_871X("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
  7232. err = -EINVAL;
  7233. goto exit;
  7234. }
  7235. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7236. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7237. if ((addr + cnts) > max_available_size)
  7238. {
  7239. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7240. err = -EINVAL;
  7241. goto exit;
  7242. }
  7243. if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL)
  7244. {
  7245. DBG_871X("%s: rtw_efuse_map_read error!\n", __FUNCTION__);
  7246. err = -EFAULT;
  7247. goto exit;
  7248. }
  7249. // DBG_871X("%s: data={", __FUNCTION__);
  7250. *extra = 0;
  7251. for (i=0; i<cnts; i++) {
  7252. // DBG_871X("0x%02x ", data[i]);
  7253. sprintf(extra, "%s0x%02X ", extra, data[i]);
  7254. }
  7255. // DBG_871X("}\n");
  7256. }
  7257. else if (strcmp(tmp[0], "realraw") == 0)
  7258. {
  7259. addr = 0;
  7260. mapLen = EFUSE_MAX_SIZE;
  7261. if (rtw_efuse_access(padapter, _FALSE, addr, mapLen, rawdata) == _FAIL)
  7262. {
  7263. DBG_871X("%s: rtw_efuse_access Fail!!\n", __FUNCTION__);
  7264. err = -EFAULT;
  7265. goto exit;
  7266. }
  7267. // DBG_871X("%s: realraw={\n", __FUNCTION__);
  7268. sprintf(extra, "\n");
  7269. for (i=0; i<mapLen; i++)
  7270. {
  7271. // DBG_871X("%02X", rawdata[i]);
  7272. sprintf(extra, "%s%02X", extra, rawdata[i]);
  7273. if ((i & 0xF) == 0xF) {
  7274. // DBG_871X("\n");
  7275. sprintf(extra, "%s\n", extra);
  7276. }
  7277. else if ((i & 0x7) == 0x7){
  7278. // DBG_871X("\t");
  7279. sprintf(extra, "%s\t", extra);
  7280. } else {
  7281. // DBG_871X(" ");
  7282. sprintf(extra, "%s ", extra);
  7283. }
  7284. }
  7285. // DBG_871X("}\n");
  7286. }
  7287. else if (strcmp(tmp[0], "mac") == 0)
  7288. {
  7289. #ifdef CONFIG_RTL8192C
  7290. addr = EEPROM_MAC_ADDR_92C;
  7291. #endif // CONFIG_RTL8192C
  7292. #ifdef CONFIG_RTL8192D
  7293. #ifdef CONFIG_USB_HCI
  7294. if (pHalData->interfaceIndex == 0)
  7295. addr = EEPROM_MAC_ADDR_MAC0_92DU;
  7296. else
  7297. addr = EEPROM_MAC_ADDR_MAC1_92DU;
  7298. #else
  7299. if (pHalData->interfaceIndex == 0)
  7300. addr = EEPROM_MAC_ADDR_MAC0_92DE;
  7301. else
  7302. addr = EEPROM_MAC_ADDR_MAC1_92DE;
  7303. #endif
  7304. #endif // CONFIG_RTL8192D
  7305. #ifdef CONFIG_RTL8723A
  7306. #ifdef CONFIG_SDIO_HCI
  7307. addr = EEPROM_MAC_ADDR_8723AS;
  7308. #endif
  7309. #ifdef CONFIG_GSPI_HCI
  7310. addr = EEPROM_MAC_ADDR_8723AS;
  7311. #endif
  7312. #ifdef CONFIG_USB_HCI
  7313. addr = EEPROM_MAC_ADDR_8723AU;
  7314. #endif
  7315. #endif // CONFIG_RTL8723A
  7316. #ifdef CONFIG_RTL8188E
  7317. #ifdef CONFIG_USB_HCI
  7318. addr = EEPROM_MAC_ADDR_88EU;
  7319. #endif
  7320. #ifdef CONFIG_SDIO_HCI
  7321. addr = EEPROM_MAC_ADDR_88ES;
  7322. #endif
  7323. #ifdef CONFIG_PCI_HCI
  7324. addr = EEPROM_MAC_ADDR_88EE;
  7325. #endif
  7326. #endif // CONFIG_RTL8188E
  7327. #ifdef CONFIG_RTL8192E
  7328. #ifdef CONFIG_USB_HCI
  7329. addr = EEPROM_MAC_ADDR_8192EU;
  7330. #endif
  7331. #ifdef CONFIG_SDIO_HCI
  7332. addr = EEPROM_MAC_ADDR_8192ES;
  7333. #endif
  7334. #ifdef CONFIG_PCI_HCI
  7335. addr = EEPROM_MAC_ADDR_8192EE;
  7336. #endif
  7337. #endif
  7338. #ifdef CONFIG_RTL8723B
  7339. #ifdef CONFIG_SDIO_HCI
  7340. addr = EEPROM_MAC_ADDR_8723BS;
  7341. #endif
  7342. #ifdef CONFIG_GSPI_HCI
  7343. addr = EEPROM_MAC_ADDR_8723BS;
  7344. #endif
  7345. #ifdef CONFIG_USB_HCI
  7346. addr = EEPROM_MAC_ADDR_8723BU;
  7347. #endif
  7348. #endif // CONFIG_RTL8723B
  7349. cnts = 6;
  7350. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7351. if ((addr + cnts) > max_available_size) {
  7352. DBG_871X("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7353. err = -EFAULT;
  7354. goto exit;
  7355. }
  7356. if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL)
  7357. {
  7358. DBG_871X("%s: rtw_efuse_map_read error!\n", __FUNCTION__);
  7359. err = -EFAULT;
  7360. goto exit;
  7361. }
  7362. // DBG_871X("%s: MAC address={", __FUNCTION__);
  7363. *extra = 0;
  7364. for (i=0; i<cnts; i++)
  7365. {
  7366. // DBG_871X("%02X", data[i]);
  7367. sprintf(extra, "%s%02X", extra, data[i]);
  7368. if (i != (cnts-1))
  7369. {
  7370. // DBG_871X(":");
  7371. sprintf(extra,"%s:",extra);
  7372. }
  7373. }
  7374. // DBG_871X("}\n");
  7375. }
  7376. else if (strcmp(tmp[0], "vidpid") == 0)
  7377. {
  7378. #ifdef CONFIG_RTL8192C
  7379. addr = EEPROM_VID_92C;
  7380. #endif // CONFIG_RTL8192C
  7381. #ifdef CONFIG_RTL8192D
  7382. #ifdef CONFIG_USB_HCI
  7383. addr = EEPROM_VID_92DU;
  7384. #else
  7385. addr = EEPROM_VID_92DE;
  7386. #endif
  7387. #endif // CONFIG_RTL8192D
  7388. #ifdef CONFIG_RTL8723A
  7389. #ifdef CONFIG_USB_HCI
  7390. addr = EEPROM_VID_8723AU;
  7391. #endif
  7392. #endif // CONFIG_RTL8723A
  7393. #ifdef CONFIG_RTL8188E
  7394. #ifdef CONFIG_USB_HCI
  7395. addr = EEPROM_VID_88EU;
  7396. #endif
  7397. #ifdef CONFIG_PCI_HCI
  7398. addr = EEPROM_VID_88EE;
  7399. #endif
  7400. #endif // CONFIG_RTL8188E
  7401. #ifdef CONFIG_RTL8192E
  7402. #ifdef CONFIG_USB_HCI
  7403. addr = EEPROM_VID_8192EU;
  7404. #endif
  7405. #ifdef CONFIG_PCI_HCI
  7406. addr = EEPROM_VID_8192EE;
  7407. #endif
  7408. #endif // CONFIG_RTL8192E
  7409. #ifdef CONFIG_RTL8723B
  7410. addr = EEPROM_VID_8723BU;
  7411. #endif // CONFIG_RTL8192E
  7412. cnts = 4;
  7413. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7414. if ((addr + cnts) > max_available_size)
  7415. {
  7416. DBG_871X("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7417. err = -EFAULT;
  7418. goto exit;
  7419. }
  7420. if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL)
  7421. {
  7422. DBG_871X("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7423. err = -EFAULT;
  7424. goto exit;
  7425. }
  7426. // DBG_871X("%s: {VID,PID}={", __FUNCTION__);
  7427. *extra = 0;
  7428. for (i=0; i<cnts; i++)
  7429. {
  7430. // DBG_871X("0x%02x", data[i]);
  7431. sprintf(extra, "%s0x%02X", extra, data[i]);
  7432. if (i != (cnts-1))
  7433. {
  7434. // DBG_871X(",");
  7435. sprintf(extra,"%s,",extra);
  7436. }
  7437. }
  7438. // DBG_871X("}\n");
  7439. }
  7440. else if (strcmp(tmp[0], "ableraw") == 0)
  7441. {
  7442. efuse_GetCurrentSize(padapter,&raw_cursize);
  7443. raw_maxsize = efuse_GetMaxSize(padapter);
  7444. sprintf(extra, "[available raw size]= %d bytes", raw_maxsize-raw_cursize);
  7445. }
  7446. else if (strcmp(tmp[0], "btfmap") == 0)
  7447. {
  7448. mapLen = EFUSE_BT_MAX_MAP_LEN;
  7449. if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL)
  7450. {
  7451. DBG_871X("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
  7452. err = -EFAULT;
  7453. goto exit;
  7454. }
  7455. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7456. sprintf(extra, "\n");
  7457. for (i=0; i<512; i+=16) // set 512 because the iwpriv's extra size have limit 0x7FF
  7458. {
  7459. // DBG_871X("0x%03x\t", i);
  7460. sprintf(extra, "%s0x%03x\t", extra, i);
  7461. for (j=0; j<8; j++) {
  7462. // DBG_871X("%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7463. sprintf(extra, "%s%02X ", extra, pEfuseHal->BTEfuseInitMap[i+j]);
  7464. }
  7465. // DBG_871X("\t");
  7466. sprintf(extra,"%s\t",extra);
  7467. for (; j<16; j++) {
  7468. // DBG_871X("%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
  7469. sprintf(extra, "%s%02X ", extra, pEfuseHal->BTEfuseInitMap[i+j]);
  7470. }
  7471. // DBG_871X("\n");
  7472. sprintf(extra, "%s\n", extra);
  7473. }
  7474. // DBG_871X("\n");
  7475. }
  7476. else if (strcmp(tmp[0],"btbmap") == 0)
  7477. {
  7478. mapLen = EFUSE_BT_MAX_MAP_LEN;
  7479. if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL)
  7480. {
  7481. DBG_871X("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
  7482. err = -EFAULT;
  7483. goto exit;
  7484. }
  7485. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7486. sprintf(extra, "\n");
  7487. for (i=512; i<1024 ; i+=16)
  7488. {
  7489. // DBG_871X("0x%03x\t", i);
  7490. sprintf(extra, "%s0x%03x\t", extra, i);
  7491. for (j=0; j<8; j++)
  7492. {
  7493. // DBG_871X("%02X ", data[i+j]);
  7494. sprintf(extra, "%s%02X ", extra, pEfuseHal->BTEfuseInitMap[i+j]);
  7495. }
  7496. // DBG_871X("\t");
  7497. sprintf(extra,"%s\t",extra);
  7498. for (; j<16; j++) {
  7499. // DBG_871X("%02X ", data[i+j]);
  7500. sprintf(extra, "%s%02X ", extra, pEfuseHal->BTEfuseInitMap[i+j]);
  7501. }
  7502. // DBG_871X("\n");
  7503. sprintf(extra, "%s\n", extra);
  7504. }
  7505. // DBG_871X("\n");
  7506. }
  7507. else if (strcmp(tmp[0],"btrmap") == 0)
  7508. {
  7509. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  7510. {
  7511. err = -EINVAL;
  7512. goto exit;
  7513. }
  7514. // rmap addr cnts
  7515. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7516. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7517. cnts = simple_strtoul(tmp[2], &ptmp, 10);
  7518. if (cnts == 0)
  7519. {
  7520. DBG_871X("%s: btrmap Fail!! cnts error!\n", __FUNCTION__);
  7521. err = -EINVAL;
  7522. goto exit;
  7523. }
  7524. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7525. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7526. if ((addr + cnts) > max_available_size)
  7527. {
  7528. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7529. err = -EFAULT;
  7530. goto exit;
  7531. }
  7532. if (rtw_BT_efuse_map_read(padapter, addr, cnts, data) == _FAIL)
  7533. {
  7534. DBG_871X("%s: rtw_BT_efuse_map_read error!!\n", __FUNCTION__);
  7535. err = -EFAULT;
  7536. goto exit;
  7537. }
  7538. *extra = 0;
  7539. // DBG_871X("%s: bt efuse data={", __FUNCTION__);
  7540. for (i=0; i<cnts; i++)
  7541. {
  7542. // DBG_871X("0x%02x ", data[i]);
  7543. sprintf(extra, "%s 0x%02X ", extra, data[i]);
  7544. }
  7545. // DBG_871X("}\n");
  7546. }
  7547. else if (strcmp(tmp[0], "btffake") == 0)
  7548. {
  7549. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7550. sprintf(extra, "\n");
  7551. for (i=0; i<512; i+=16)
  7552. {
  7553. // DBG_871X("0x%03x\t", i);
  7554. sprintf(extra, "%s0x%03x\t", extra, i);
  7555. for (j=0; j<8; j++) {
  7556. // DBG_871X("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7557. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7558. }
  7559. // DBG_871X("\t");
  7560. sprintf(extra, "%s\t", extra);
  7561. for (; j<16; j++) {
  7562. // DBG_871X("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7563. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7564. }
  7565. // DBG_871X("\n");
  7566. sprintf(extra, "%s\n", extra);
  7567. }
  7568. // DBG_871X("\n");
  7569. }
  7570. else if (strcmp(tmp[0],"btbfake") == 0)
  7571. {
  7572. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7573. sprintf(extra, "\n");
  7574. for (i=512; i<1024; i+=16)
  7575. {
  7576. // DBG_871X("0x%03x\t", i);
  7577. sprintf(extra, "%s0x%03x\t", extra, i);
  7578. for (j=0; j<8; j++) {
  7579. // DBG_871X("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7580. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7581. }
  7582. // DBG_871X("\t");
  7583. sprintf(extra, "%s\t", extra);
  7584. for (; j<16; j++) {
  7585. // DBG_871X("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7586. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
  7587. }
  7588. // DBG_871X("\n");
  7589. sprintf(extra, "%s\n", extra);
  7590. }
  7591. // DBG_871X("\n");
  7592. }
  7593. else if (strcmp(tmp[0],"wlrfkmap")== 0)
  7594. {
  7595. // DBG_871X("OFFSET\tVALUE(hex)\n");
  7596. sprintf(extra, "\n");
  7597. for (i=0; i<EFUSE_MAP_SIZE; i+=16)
  7598. {
  7599. // DBG_871X("\t0x%02x\t", i);
  7600. sprintf(extra, "%s0x%02x\t", extra, i);
  7601. for (j=0; j<8 && i+j<EFUSE_MAX_MAP_LEN; j++) {
  7602. // DBG_871X("%02X ", pEfuseHal->fakeEfuseModifiedMap[i+j]);
  7603. sprintf(extra, "%s%02X ", extra, pEfuseHal->fakeEfuseModifiedMap[i+j]);
  7604. }
  7605. // DBG_871X("\t");
  7606. sprintf(extra, "%s\t", extra);
  7607. for (; j<16 && i+j<EFUSE_MAX_MAP_LEN; j++) {
  7608. // DBG_871X("%02X ", pEfuseHal->fakeEfuseModifiedMap[i+j]);
  7609. sprintf(extra, "%s %02X", extra, pEfuseHal->fakeEfuseModifiedMap[i+j]);
  7610. }
  7611. // DBG_871X("\n");
  7612. sprintf(extra, "%s\n", extra);
  7613. }
  7614. // DBG_871X("\n");
  7615. }
  7616. else
  7617. {
  7618. sprintf(extra, "Command not found!");
  7619. }
  7620. exit:
  7621. if (data)
  7622. _rtw_mfree(data, EFUSE_BT_MAX_MAP_LEN);
  7623. if (rawdata)
  7624. _rtw_mfree(rawdata, EFUSE_BT_MAX_MAP_LEN);
  7625. if (!err)
  7626. wrqu->length = strlen(extra);
  7627. #ifdef CONFIG_IPS
  7628. rtw_pm_set_ips(padapter, ips_mode);
  7629. #endif
  7630. #ifdef CONFIG_LPS
  7631. rtw_pm_set_lps(padapter, lps_mode);
  7632. #endif
  7633. #ifdef CONFIG_IOL
  7634. padapter->registrypriv.fw_iol = org_fw_iol;// 0:Disable, 1:enable, 2:by usb speed
  7635. #endif
  7636. return err;
  7637. }
  7638. static int rtw_mp_efuse_set(struct net_device *dev,
  7639. struct iw_request_info *info,
  7640. union iwreq_data *wdata, char *extra)
  7641. {
  7642. struct iw_point *wrqu;
  7643. PADAPTER padapter;
  7644. struct pwrctrl_priv *pwrctrlpriv ;
  7645. PHAL_DATA_TYPE pHalData;
  7646. PEFUSE_HAL pEfuseHal;
  7647. u8 ips_mode,lps_mode;
  7648. u32 i, jj, kk;
  7649. u8 *setdata = NULL;
  7650. u8 *ShadowMapBT = NULL;
  7651. u8 *ShadowMapWiFi = NULL;
  7652. u8 *setrawdata = NULL;
  7653. char *pch, *ptmp, *token, *tmp[3]={0x00,0x00,0x00};
  7654. u16 addr=0, cnts=0, max_available_size=0;
  7655. int err;
  7656. wrqu = (struct iw_point*)wdata;
  7657. padapter = rtw_netdev_priv(dev);
  7658. pwrctrlpriv = &padapter->pwrctrlpriv;
  7659. pHalData = GET_HAL_DATA(padapter);
  7660. pEfuseHal = &pHalData->EfuseHal;
  7661. err = 0;
  7662. setdata = _rtw_zmalloc(1024);
  7663. if (setdata == NULL)
  7664. {
  7665. err = -ENOMEM;
  7666. goto exit;
  7667. }
  7668. ShadowMapBT = _rtw_malloc(EFUSE_BT_MAX_MAP_LEN);
  7669. if (ShadowMapBT == NULL)
  7670. {
  7671. err = -ENOMEM;
  7672. goto exit;
  7673. }
  7674. ShadowMapWiFi = _rtw_malloc(EFUSE_MAP_SIZE);
  7675. if (ShadowMapWiFi == NULL)
  7676. {
  7677. err = -ENOMEM;
  7678. goto exit;
  7679. }
  7680. setrawdata = _rtw_malloc(EFUSE_MAX_SIZE);
  7681. if (setrawdata == NULL)
  7682. {
  7683. err = -ENOMEM;
  7684. goto exit;
  7685. }
  7686. #ifdef CONFIG_LPS
  7687. lps_mode = pwrctrlpriv->power_mgnt;//keep org value
  7688. rtw_pm_set_lps(padapter,PS_MODE_ACTIVE);
  7689. #endif
  7690. #ifdef CONFIG_IPS
  7691. ips_mode = pwrctrlpriv->ips_mode;//keep org value
  7692. rtw_pm_set_ips(padapter,IPS_NONE);
  7693. #endif
  7694. pch = extra;
  7695. DBG_871X("%s: in=%s\n", __FUNCTION__, extra);
  7696. i = 0;
  7697. while ((token = strsep(&pch, ",")) != NULL)
  7698. {
  7699. if (i > 2) break;
  7700. tmp[i] = token;
  7701. i++;
  7702. }
  7703. // tmp[0],[1],[2]
  7704. // wmap,addr,00e04c871200
  7705. if (strcmp(tmp[0], "wmap") == 0)
  7706. {
  7707. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  7708. {
  7709. err = -EINVAL;
  7710. goto exit;
  7711. }
  7712. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7713. addr &= 0xFFF;
  7714. cnts = strlen(tmp[2]);
  7715. if (cnts%2)
  7716. {
  7717. err = -EINVAL;
  7718. goto exit;
  7719. }
  7720. cnts /= 2;
  7721. if (cnts == 0)
  7722. {
  7723. err = -EINVAL;
  7724. goto exit;
  7725. }
  7726. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7727. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7728. DBG_871X("%s: map data=%s\n", __FUNCTION__, tmp[2]);
  7729. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  7730. {
  7731. setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk+1]);
  7732. }
  7733. #ifndef CONFIG_RTL8188E
  7734. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7735. #else
  7736. //Change to check TYPE_EFUSE_MAP_LEN ,beacuse 8188E raw 256,logic map over 256.
  7737. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_size, _FALSE);
  7738. #endif
  7739. if ((addr+cnts) > max_available_size)
  7740. {
  7741. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7742. err = -EFAULT;
  7743. goto exit;
  7744. }
  7745. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL)
  7746. {
  7747. DBG_871X("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7748. err = -EFAULT;
  7749. goto exit;
  7750. }
  7751. }
  7752. else if (strcmp(tmp[0], "wraw") == 0)
  7753. {
  7754. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  7755. {
  7756. err = -EINVAL;
  7757. goto exit;
  7758. }
  7759. addr = simple_strtoul( tmp[1], &ptmp, 16 );
  7760. addr &= 0xFFF;
  7761. cnts = strlen(tmp[2]);
  7762. if (cnts%2)
  7763. {
  7764. err = -EINVAL;
  7765. goto exit;
  7766. }
  7767. cnts /= 2;
  7768. if (cnts == 0)
  7769. {
  7770. err = -EINVAL;
  7771. goto exit;
  7772. }
  7773. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7774. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7775. DBG_871X("%s: raw data=%s\n", __FUNCTION__, tmp[2]);
  7776. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  7777. {
  7778. setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk+1]);
  7779. }
  7780. if (rtw_efuse_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL)
  7781. {
  7782. DBG_871X("%s: rtw_efuse_access error!!\n", __FUNCTION__);
  7783. err = -EFAULT;
  7784. goto exit;
  7785. }
  7786. }
  7787. else if (strcmp(tmp[0], "mac") == 0)
  7788. {
  7789. if (tmp[1]==NULL)
  7790. {
  7791. err = -EINVAL;
  7792. goto exit;
  7793. }
  7794. //mac,00e04c871200
  7795. #ifdef CONFIG_RTL8192C
  7796. addr = EEPROM_MAC_ADDR_92C;
  7797. #endif
  7798. #ifdef CONFIG_RTL8192D
  7799. #ifdef CONFIG_USB_HCI
  7800. if (pHalData->interfaceIndex == 0)
  7801. addr = EEPROM_MAC_ADDR_MAC0_92DU;
  7802. else
  7803. addr = EEPROM_MAC_ADDR_MAC1_92DU;
  7804. #else
  7805. if (pHalData->interfaceIndex == 0)
  7806. addr = EEPROM_MAC_ADDR_MAC0_92DE;
  7807. else
  7808. addr = EEPROM_MAC_ADDR_MAC1_92DE;
  7809. #endif
  7810. #endif
  7811. #ifdef CONFIG_RTL8723A
  7812. #ifdef CONFIG_SDIO_HCI
  7813. addr = EEPROM_MAC_ADDR_8723AS;
  7814. #endif
  7815. #ifdef CONFIG_GSPI_HCI
  7816. addr = EEPROM_MAC_ADDR_8723AS;
  7817. #endif
  7818. #ifdef CONFIG_USB_HCI
  7819. addr = EEPROM_MAC_ADDR_8723AU;
  7820. #endif
  7821. #endif // CONFIG_RTL8723A
  7822. #ifdef CONFIG_RTL8188E
  7823. #ifdef CONFIG_USB_HCI
  7824. addr = EEPROM_MAC_ADDR_88EU;
  7825. #endif
  7826. #ifdef CONFIG_SDIO_HCI
  7827. addr = EEPROM_MAC_ADDR_88ES;
  7828. #endif
  7829. #ifdef CONFIG_PCI_HCI
  7830. addr = EEPROM_MAC_ADDR_88EE;
  7831. #endif
  7832. #endif //#ifdef CONFIG_RTL8188E
  7833. #ifdef CONFIG_RTL8192E
  7834. #ifdef CONFIG_USB_HCI
  7835. addr = EEPROM_MAC_ADDR_8192EU;
  7836. #endif
  7837. #ifdef CONFIG_SDIO_HCI
  7838. addr = EEPROM_MAC_ADDR_8192ES;
  7839. #endif
  7840. #ifdef CONFIG_PCI_HCI
  7841. addr = EEPROM_MAC_ADDR_8192EE;
  7842. #endif
  7843. #endif //#ifdef CONFIG_RTL8192E
  7844. #ifdef CONFIG_RTL8723B
  7845. #ifdef CONFIG_SDIO_HCI
  7846. addr = EEPROM_MAC_ADDR_8723BS;
  7847. #endif
  7848. #ifdef CONFIG_GSPI_HCI
  7849. addr = EEPROM_MAC_ADDR_8723BS;
  7850. #endif
  7851. #ifdef CONFIG_USB_HCI
  7852. addr = EEPROM_MAC_ADDR_8723BU;
  7853. #endif
  7854. #endif // CONFIG_RTL8723B
  7855. cnts = strlen(tmp[1]);
  7856. if (cnts%2)
  7857. {
  7858. err = -EINVAL;
  7859. goto exit;
  7860. }
  7861. cnts /= 2;
  7862. if (cnts == 0)
  7863. {
  7864. err = -EINVAL;
  7865. goto exit;
  7866. }
  7867. if (cnts > 6)
  7868. {
  7869. DBG_871X("%s: error data for mac addr=\"%s\"\n", __FUNCTION__, tmp[1]);
  7870. err = -EFAULT;
  7871. goto exit;
  7872. }
  7873. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7874. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7875. DBG_871X("%s: MAC address=%s\n", __FUNCTION__, tmp[1]);
  7876. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  7877. {
  7878. setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk+1]);
  7879. }
  7880. #ifndef CONFIG_RTL8188E
  7881. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7882. #else
  7883. //Change to check TYPE_EFUSE_MAP_LEN ,beacuse 8188E raw 256,logic map over 256.
  7884. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&max_available_size, _FALSE);
  7885. #endif
  7886. if ((addr+cnts) > max_available_size)
  7887. {
  7888. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7889. err = -EFAULT;
  7890. goto exit;
  7891. }
  7892. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL)
  7893. {
  7894. DBG_871X("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7895. err = -EFAULT;
  7896. goto exit;
  7897. }
  7898. }
  7899. else if (strcmp(tmp[0], "vidpid") == 0)
  7900. {
  7901. if (tmp[1]==NULL)
  7902. {
  7903. err = -EINVAL;
  7904. goto exit;
  7905. }
  7906. // pidvid,da0b7881
  7907. #ifdef CONFIG_RTL8192C
  7908. addr = EEPROM_VID_92C;
  7909. #endif // CONFIG_RTL8192C
  7910. #ifdef CONFIG_RTL8192D
  7911. #ifdef CONFIG_USB_HCI
  7912. addr = EEPROM_VID_92DU;
  7913. #else
  7914. addr = EEPROM_VID_92DE;
  7915. #endif
  7916. #endif // CONFIG_RTL8192D
  7917. #ifdef CONFIG_RTL8723A
  7918. #ifdef CONFIG_USB_HCI
  7919. addr = EEPROM_VID_8723AU;
  7920. #endif
  7921. #endif // CONFIG_RTL8723A
  7922. #ifdef CONFIG_RTL8188E
  7923. #ifdef CONFIG_USB_HCI
  7924. addr = EEPROM_VID_88EU;
  7925. #endif
  7926. #ifdef CONFIG_PCI_HCI
  7927. addr = EEPROM_VID_88EE;
  7928. #endif
  7929. #endif // CONFIG_RTL8188E
  7930. #ifdef CONFIG_RTL8192E
  7931. #ifdef CONFIG_USB_HCI
  7932. addr = EEPROM_VID_8192EU;
  7933. #endif
  7934. #ifdef CONFIG_PCI_HCI
  7935. addr = EEPROM_VID_8192EE;
  7936. #endif
  7937. #endif // CONFIG_RTL8188E
  7938. #ifdef CONFIG_RTL8723B
  7939. addr = EEPROM_VID_8723BU;
  7940. #endif
  7941. cnts = strlen(tmp[1]);
  7942. if (cnts%2)
  7943. {
  7944. err = -EINVAL;
  7945. goto exit;
  7946. }
  7947. cnts /= 2;
  7948. if (cnts == 0)
  7949. {
  7950. err = -EINVAL;
  7951. goto exit;
  7952. }
  7953. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7954. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7955. DBG_871X("%s: VID/PID=%s\n", __FUNCTION__, tmp[1]);
  7956. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  7957. {
  7958. setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk+1]);
  7959. }
  7960. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  7961. if ((addr+cnts) > max_available_size)
  7962. {
  7963. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  7964. err = -EFAULT;
  7965. goto exit;
  7966. }
  7967. if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL)
  7968. {
  7969. DBG_871X("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
  7970. err = -EFAULT;
  7971. goto exit;
  7972. }
  7973. }
  7974. else if (strcmp(tmp[0], "btwmap") == 0)
  7975. {
  7976. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  7977. {
  7978. err = -EINVAL;
  7979. goto exit;
  7980. }
  7981. addr = simple_strtoul(tmp[1], &ptmp, 16);
  7982. addr &= 0xFFF;
  7983. cnts = strlen(tmp[2]);
  7984. if (cnts%2)
  7985. {
  7986. err = -EINVAL;
  7987. goto exit;
  7988. }
  7989. cnts /= 2;
  7990. if (cnts == 0)
  7991. {
  7992. err = -EINVAL;
  7993. goto exit;
  7994. }
  7995. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  7996. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  7997. DBG_871X("%s: BT data=%s\n", __FUNCTION__, tmp[2]);
  7998. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  7999. {
  8000. setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk+1]);
  8001. }
  8002. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  8003. if ((addr+cnts) > max_available_size)
  8004. {
  8005. DBG_871X("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
  8006. err = -EFAULT;
  8007. goto exit;
  8008. }
  8009. if (rtw_BT_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL)
  8010. {
  8011. DBG_871X("%s: rtw_BT_efuse_map_write error!!\n", __FUNCTION__);
  8012. err = -EFAULT;
  8013. goto exit;
  8014. }
  8015. }
  8016. else if (strcmp(tmp[0], "btwfake") == 0)
  8017. {
  8018. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  8019. {
  8020. err = -EINVAL;
  8021. goto exit;
  8022. }
  8023. addr = simple_strtoul(tmp[1], &ptmp, 16);
  8024. addr &= 0xFFF;
  8025. cnts = strlen(tmp[2]);
  8026. if (cnts%2)
  8027. {
  8028. err = -EINVAL;
  8029. goto exit;
  8030. }
  8031. cnts /= 2;
  8032. if (cnts == 0)
  8033. {
  8034. err = -EINVAL;
  8035. goto exit;
  8036. }
  8037. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  8038. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  8039. DBG_871X("%s: BT tmp data=%s\n", __FUNCTION__, tmp[2]);
  8040. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  8041. {
  8042. pEfuseHal->fakeBTEfuseModifiedMap[addr+jj] = key_2char2num(tmp[2][kk], tmp[2][kk+1]);
  8043. }
  8044. }
  8045. else if (strcmp(tmp[0], "btdumpfake") == 0)
  8046. {
  8047. if (rtw_BT_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _SUCCESS) {
  8048. DBG_871X("%s: BT read all map success\n", __FUNCTION__);
  8049. } else {
  8050. DBG_871X("%s: BT read all map Fail!\n", __FUNCTION__);
  8051. err = -EFAULT;
  8052. }
  8053. }
  8054. else if (strcmp(tmp[0], "wldumpfake") == 0)
  8055. {
  8056. if (rtw_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeEfuseModifiedMap) == _SUCCESS) {
  8057. DBG_871X("%s: BT read all map success \n", __FUNCTION__);
  8058. } else {
  8059. DBG_871X("%s: BT read all map Fail \n", __FUNCTION__);
  8060. err = -EFAULT;
  8061. }
  8062. }
  8063. else if (strcmp(tmp[0], "btfk2map") == 0)
  8064. {
  8065. _rtw_memcpy(pEfuseHal->BTEfuseModifiedMap, pEfuseHal->fakeBTEfuseModifiedMap, EFUSE_BT_MAX_MAP_LEN);
  8066. EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  8067. if (max_available_size < 1)
  8068. {
  8069. err = -EFAULT;
  8070. goto exit;
  8071. }
  8072. if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL)
  8073. {
  8074. DBG_871X("%s: rtw_BT_efuse_map_write error!\n", __FUNCTION__);
  8075. err = -EFAULT;
  8076. goto exit;
  8077. }
  8078. }
  8079. else if (strcmp(tmp[0], "wlfk2map") == 0)
  8080. {
  8081. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  8082. if (max_available_size < 1)
  8083. {
  8084. err = -EFAULT;
  8085. goto exit;
  8086. }
  8087. if (rtw_efuse_map_write(padapter, 0x00, EFUSE_MAX_MAP_LEN, pEfuseHal->fakeEfuseModifiedMap) == _FAIL)
  8088. {
  8089. DBG_871X("%s: rtw_efuse_map_write error!\n", __FUNCTION__);
  8090. err = -EFAULT;
  8091. goto exit;
  8092. }
  8093. }
  8094. else if (strcmp(tmp[0], "wlwfake") == 0)
  8095. {
  8096. if ((tmp[1]==NULL) || (tmp[2]==NULL))
  8097. {
  8098. err = -EINVAL;
  8099. goto exit;
  8100. }
  8101. addr = simple_strtoul(tmp[1], &ptmp, 16);
  8102. addr &= 0xFFF;
  8103. cnts = strlen(tmp[2]);
  8104. if (cnts%2)
  8105. {
  8106. err = -EINVAL;
  8107. goto exit;
  8108. }
  8109. cnts /= 2;
  8110. if (cnts == 0)
  8111. {
  8112. err = -EINVAL;
  8113. goto exit;
  8114. }
  8115. DBG_871X("%s: addr=0x%X\n", __FUNCTION__, addr);
  8116. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  8117. DBG_871X("%s: map tmp data=%s\n", __FUNCTION__, tmp[2]);
  8118. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  8119. {
  8120. pEfuseHal->fakeEfuseModifiedMap[addr+jj] = key_2char2num(tmp[2][kk], tmp[2][kk+1]);
  8121. }
  8122. }
  8123. exit:
  8124. if (setdata)
  8125. _rtw_mfree(setdata, 1024);
  8126. if (ShadowMapBT)
  8127. _rtw_mfree(ShadowMapBT, EFUSE_BT_MAX_MAP_LEN);
  8128. if (ShadowMapWiFi)
  8129. _rtw_mfree(ShadowMapWiFi, EFUSE_MAP_SIZE);
  8130. if (setrawdata)
  8131. _rtw_mfree(setrawdata, EFUSE_MAX_SIZE);
  8132. #ifdef CONFIG_IPS
  8133. rtw_pm_set_ips(padapter, ips_mode);
  8134. #endif
  8135. #ifdef CONFIG_LPS
  8136. rtw_pm_set_lps(padapter, lps_mode);
  8137. #endif
  8138. return err;
  8139. }
  8140. #if defined(CONFIG_MP_INCLUDED) && defined(CONFIG_MP_IWPRIV_SUPPORT)
  8141. /*
  8142. * Input Format: %s,%d,%d
  8143. * %s is width, could be
  8144. * "b" for 1 byte
  8145. * "w" for WORD (2 bytes)
  8146. * "dw" for DWORD (4 bytes)
  8147. * 1st %d is address(offset)
  8148. * 2st %d is data to write
  8149. */
  8150. static int rtw_mp_write_reg(struct net_device *dev,
  8151. struct iw_request_info *info,
  8152. struct iw_point *wrqu, char *extra)
  8153. {
  8154. char *pch, *pnext, *ptmp;
  8155. char *width_str;
  8156. char width;
  8157. u32 addr, data;
  8158. int ret;
  8159. PADAPTER padapter = rtw_netdev_priv(dev);
  8160. pch = extra;
  8161. pnext = strpbrk(pch, " ,.-");
  8162. if (pnext == NULL) return -EINVAL;
  8163. *pnext = 0;
  8164. width_str = pch;
  8165. pch = pnext + 1;
  8166. pnext = strpbrk(pch, " ,.-");
  8167. if (pnext == NULL) return -EINVAL;
  8168. *pnext = 0;
  8169. addr = simple_strtoul(pch, &ptmp, 16);
  8170. if (addr > 0x3FFF) return -EINVAL;
  8171. pch = pnext + 1;
  8172. if ((pch - extra) >= wrqu->length) return -EINVAL;
  8173. data = simple_strtoul(pch, &ptmp, 16);
  8174. ret = 0;
  8175. width = width_str[0];
  8176. switch (width) {
  8177. case 'b':
  8178. // 1 byte
  8179. if (data > 0xFF) {
  8180. ret = -EINVAL;
  8181. break;
  8182. }
  8183. rtw_write8(padapter, addr, data);
  8184. break;
  8185. case 'w':
  8186. // 2 bytes
  8187. if (data > 0xFFFF) {
  8188. ret = -EINVAL;
  8189. break;
  8190. }
  8191. rtw_write16(padapter, addr, data);
  8192. break;
  8193. case 'd':
  8194. // 4 bytes
  8195. rtw_write32(padapter, addr, data);
  8196. break;
  8197. default:
  8198. ret = -EINVAL;
  8199. break;
  8200. }
  8201. return ret;
  8202. }
  8203. /*
  8204. * Input Format: %s,%d
  8205. * %s is width, could be
  8206. * "b" for 1 byte
  8207. * "w" for WORD (2 bytes)
  8208. * "dw" for DWORD (4 bytes)
  8209. * %d is address(offset)
  8210. *
  8211. * Return:
  8212. * %d for data readed
  8213. */
  8214. static int rtw_mp_read_reg(struct net_device *dev,
  8215. struct iw_request_info *info,
  8216. struct iw_point *wrqu, char *extra)
  8217. {
  8218. char input[wrqu->length];
  8219. char *pch, *pnext, *ptmp;
  8220. char *width_str;
  8221. char width;
  8222. char data[20],tmp[20];
  8223. u32 addr;
  8224. //u32 *data = (u32*)extra;
  8225. u32 ret, i=0, j=0, strtout=0;
  8226. PADAPTER padapter = rtw_netdev_priv(dev);
  8227. if (wrqu->length > 128)
  8228. return -EFAULT;
  8229. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8230. return -EFAULT;
  8231. _rtw_memset(data, 0, 20);
  8232. _rtw_memset(tmp, 0, 20);
  8233. _rtw_memset(extra, 0, wrqu->length);
  8234. pch = input;
  8235. pnext = strpbrk(pch, " ,.-");
  8236. if (pnext == NULL) return -EINVAL;
  8237. *pnext = 0;
  8238. width_str = pch;
  8239. pch = pnext + 1;
  8240. if ((pch - input) >= wrqu->length) return -EINVAL;
  8241. addr = simple_strtoul(pch, &ptmp, 16);
  8242. if (addr > 0x3FFF) return -EINVAL;
  8243. ret = 0;
  8244. width = width_str[0];
  8245. switch (width)
  8246. {
  8247. case 'b':
  8248. // 1 byte
  8249. // *(u8*)data = rtw_read8(padapter, addr);
  8250. sprintf(extra, "%d\n", rtw_read8(padapter, addr));
  8251. wrqu->length = strlen(extra);
  8252. break;
  8253. case 'w':
  8254. // 2 bytes
  8255. //*(u16*)data = rtw_read16(padapter, addr);
  8256. sprintf(data, "%04x\n", rtw_read16(padapter, addr));
  8257. for( i=0 ; i <= strlen(data) ; i++)
  8258. {
  8259. if( i%2==0 )
  8260. {
  8261. tmp[j]=' ';
  8262. j++;
  8263. }
  8264. if ( data[i] != '\0' )
  8265. tmp[j] = data[i];
  8266. j++;
  8267. }
  8268. pch = tmp;
  8269. DBG_871X("pch=%s",pch);
  8270. while( *pch != '\0' )
  8271. {
  8272. pnext = strpbrk(pch, " ");
  8273. if (!pnext)
  8274. break;
  8275. pnext++;
  8276. if ( *pnext != '\0' )
  8277. {
  8278. strtout = simple_strtoul (pnext , &ptmp, 16);
  8279. sprintf( extra, "%s %d" ,extra ,strtout );
  8280. }
  8281. else{
  8282. break;
  8283. }
  8284. pch = pnext;
  8285. }
  8286. wrqu->length = 6;
  8287. break;
  8288. case 'd':
  8289. // 4 bytes
  8290. //*data = rtw_read32(padapter, addr);
  8291. sprintf(data, "%08x", rtw_read32(padapter, addr));
  8292. //add read data format blank
  8293. for( i=0 ; i <= strlen(data) ; i++)
  8294. {
  8295. if( i%2==0 )
  8296. {
  8297. tmp[j]=' ';
  8298. j++;
  8299. }
  8300. if ( data[i] != '\0' )
  8301. tmp[j] = data[i];
  8302. j++;
  8303. }
  8304. pch = tmp;
  8305. DBG_871X("pch=%s",pch);
  8306. while( *pch != '\0' )
  8307. {
  8308. pnext = strpbrk(pch, " ");
  8309. if (!pnext)
  8310. break;
  8311. pnext++;
  8312. if ( *pnext != '\0' )
  8313. {
  8314. strtout = simple_strtoul (pnext , &ptmp, 16);
  8315. sprintf( extra, "%s %d" ,extra ,strtout );
  8316. }
  8317. else{
  8318. break;
  8319. }
  8320. pch = pnext;
  8321. }
  8322. wrqu->length = strlen(extra);
  8323. break;
  8324. default:
  8325. wrqu->length = 0;
  8326. ret = -EINVAL;
  8327. break;
  8328. }
  8329. return ret;
  8330. }
  8331. /*
  8332. * Input Format: %d,%x,%x
  8333. * %d is RF path, should be smaller than MAX_RF_PATH_NUMS
  8334. * 1st %x is address(offset)
  8335. * 2st %x is data to write
  8336. */
  8337. static int rtw_mp_write_rf(struct net_device *dev,
  8338. struct iw_request_info *info,
  8339. struct iw_point *wrqu, char *extra)
  8340. {
  8341. /*static int rtw_mp_write_rf(struct net_device *dev,
  8342. struct iw_request_info *info,
  8343. union iwreq_data *wrqu, char *extra)
  8344. */
  8345. u32 path, addr, data;
  8346. int ret;
  8347. PADAPTER padapter = rtw_netdev_priv(dev);
  8348. ret = sscanf(extra, "%d,%x,%x", &path, &addr, &data);
  8349. if (ret < 3) return -EINVAL;
  8350. if (path >= GET_HAL_RFPATH_NUM(padapter)) return -EINVAL;
  8351. if (addr > 0xFF) return -EINVAL;
  8352. if (data > 0xFFFFF) return -EINVAL;
  8353. _rtw_memset(extra, 0, wrqu->length);
  8354. write_rfreg(padapter, path, addr, data);
  8355. sprintf(extra, "write_rf completed \n");
  8356. wrqu->length = strlen(extra);
  8357. return 0;
  8358. }
  8359. /*
  8360. * Input Format: %d,%x
  8361. * %d is RF path, should be smaller than MAX_RF_PATH_NUMS
  8362. * %x is address(offset)
  8363. *
  8364. * Return:
  8365. * %d for data readed
  8366. */
  8367. static int rtw_mp_read_rf(struct net_device *dev,
  8368. struct iw_request_info *info,
  8369. struct iw_point *wrqu, char *extra)
  8370. {
  8371. char input[wrqu->length];
  8372. char *pch, *pnext, *ptmp;
  8373. char data[20],tmp[20];
  8374. //u32 *data = (u32*)extra;
  8375. u32 path, addr;
  8376. u32 ret,i=0 ,j=0,strtou=0;
  8377. PADAPTER padapter = rtw_netdev_priv(dev);
  8378. if (wrqu->length > 128) return -EFAULT;
  8379. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8380. return -EFAULT;
  8381. ret = sscanf(input, "%d,%x", &path, &addr);
  8382. if (ret < 2) return -EINVAL;
  8383. if (path >= GET_HAL_RFPATH_NUM(padapter)) return -EINVAL;
  8384. if (addr > 0xFF) return -EINVAL;
  8385. _rtw_memset(extra, 0, wrqu->length);
  8386. //*data = read_rfreg(padapter, path, addr);
  8387. sprintf(data, "%08x", read_rfreg(padapter, path, addr));
  8388. //add read data format blank
  8389. for( i=0 ; i <= strlen(data) ; i++)
  8390. {
  8391. if( i%2==0 )
  8392. {
  8393. tmp[j]=' ';
  8394. j++;
  8395. }
  8396. tmp[j] = data[i];
  8397. j++;
  8398. }
  8399. pch = tmp;
  8400. DBG_871X("pch=%s",pch);
  8401. while( *pch != '\0' )
  8402. {
  8403. pnext = strpbrk(pch, " ");
  8404. pnext++;
  8405. if ( *pnext != '\0' )
  8406. {
  8407. strtou = simple_strtoul (pnext , &ptmp, 16);
  8408. sprintf( extra, "%s %d" ,extra ,strtou );
  8409. }
  8410. else{
  8411. break;
  8412. }
  8413. pch = pnext;
  8414. }
  8415. wrqu->length = strlen(extra);
  8416. return 0;
  8417. }
  8418. static int rtw_mp_start(struct net_device *dev,
  8419. struct iw_request_info *info,
  8420. struct iw_point *wrqu, char *extra)
  8421. {
  8422. u8 val8;
  8423. PADAPTER padapter = rtw_netdev_priv(dev);
  8424. if(padapter->registrypriv.mp_mode ==0)
  8425. {
  8426. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  8427. DBG_871X("_rtw_mp_xmit_priv for Download BT patch FW\n");
  8428. _rtw_mp_xmit_priv(&padapter->xmitpriv);
  8429. #endif
  8430. padapter->registrypriv.mp_mode =1;
  8431. rtw_pm_set_ips(padapter,IPS_NONE);
  8432. LeaveAllPowerSaveMode(padapter);
  8433. MPT_InitializeAdapter(padapter, 1);
  8434. }
  8435. if (padapter->registrypriv.mp_mode == 0)
  8436. return -EPERM;
  8437. if (padapter->mppriv.mode == MP_OFF) {
  8438. if (mp_start_test(padapter) == _FAIL)
  8439. return -EPERM;
  8440. padapter->mppriv.mode = MP_ON;
  8441. }
  8442. return 0;
  8443. }
  8444. static int rtw_mp_stop(struct net_device *dev,
  8445. struct iw_request_info *info,
  8446. struct iw_point *wrqu, char *extra)
  8447. {
  8448. PADAPTER padapter = rtw_netdev_priv(dev);
  8449. if(padapter->registrypriv.mp_mode ==1)
  8450. {
  8451. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  8452. DBG_871X("_rtw_mp_xmit_priv reinit for normal mode\n");
  8453. _rtw_mp_xmit_priv(&padapter->xmitpriv);
  8454. #endif
  8455. MPT_DeInitAdapter(padapter);
  8456. padapter->registrypriv.mp_mode=0;
  8457. }
  8458. if (padapter->mppriv.mode != MP_OFF) {
  8459. mp_stop_test(padapter);
  8460. padapter->mppriv.mode = MP_OFF;
  8461. }
  8462. return 0;
  8463. }
  8464. extern int wifirate2_ratetbl_inx(unsigned char rate);
  8465. static int rtw_mp_rate(struct net_device *dev,
  8466. struct iw_request_info *info,
  8467. struct iw_point *wrqu, char *extra)
  8468. {
  8469. u32 rate = MPT_RATE_1M;
  8470. u8 input[wrqu->length];
  8471. PADAPTER padapter = rtw_netdev_priv(dev);
  8472. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8473. return -EFAULT;
  8474. rate = rtw_atoi(input);
  8475. sprintf( extra, "Set data rate to %d" , rate );
  8476. if(rate <= 0x7f)
  8477. rate = wifirate2_ratetbl_inx( (u8)rate);
  8478. else
  8479. rate =(rate-0x80+MPT_RATE_MCS0);
  8480. //DBG_871X("%s: rate=%d\n", __func__, rate);
  8481. if (rate >= MPT_RATE_LAST )
  8482. return -EINVAL;
  8483. padapter->mppriv.rateidx = rate;
  8484. Hal_SetDataRate(padapter);
  8485. wrqu->length = strlen(extra) + 1;
  8486. return 0;
  8487. }
  8488. static int rtw_mp_channel(struct net_device *dev,
  8489. struct iw_request_info *info,
  8490. struct iw_point *wrqu, char *extra)
  8491. {
  8492. PADAPTER padapter = rtw_netdev_priv(dev);
  8493. u8 input[wrqu->length];
  8494. u32 channel = 1;
  8495. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8496. return -EFAULT;
  8497. channel = rtw_atoi(input);
  8498. //DBG_871X("%s: channel=%d\n", __func__, channel);
  8499. sprintf( extra, "Change channel %d to channel %d", padapter->mppriv.channel , channel );
  8500. padapter->mppriv.channel = channel;
  8501. Hal_SetChannel(padapter);
  8502. wrqu->length = strlen(extra) + 1;
  8503. return 0;
  8504. }
  8505. static int rtw_mp_bandwidth(struct net_device *dev,
  8506. struct iw_request_info *info,
  8507. struct iw_point *wrqu, char *extra)
  8508. {
  8509. u32 bandwidth=0, sg=0;
  8510. //u8 buffer[40];
  8511. PADAPTER padapter = rtw_netdev_priv(dev);
  8512. //if (copy_from_user(buffer, (void*)wrqu->data.pointer, wrqu->data.length))
  8513. // return -EFAULT;
  8514. //DBG_871X("%s:iwpriv in=%s\n", __func__, extra);
  8515. sscanf(extra, "40M=%d,shortGI=%d", &bandwidth, &sg);
  8516. if (bandwidth == 1)
  8517. bandwidth=CHANNEL_WIDTH_40;
  8518. else if (bandwidth == 2)
  8519. bandwidth=CHANNEL_WIDTH_80;
  8520. DBG_871X("%s: bw=%d sg=%d \n", __func__, bandwidth , sg);
  8521. padapter->mppriv.bandwidth = (u8)bandwidth;
  8522. padapter->mppriv.preamble = sg;
  8523. SetBandwidth(padapter);
  8524. return 0;
  8525. }
  8526. static int rtw_mp_txpower_index(struct net_device *dev,
  8527. struct iw_request_info *info,
  8528. struct iw_point *wrqu, char *extra)
  8529. {
  8530. PADAPTER padapter = rtw_netdev_priv(dev);
  8531. char input[wrqu->length];
  8532. u32 rfpath;
  8533. u32 txpower_inx;
  8534. if (wrqu->length > 128)
  8535. return -EFAULT;
  8536. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8537. return -EFAULT;
  8538. rfpath = rtw_atoi(input);
  8539. txpower_inx = mpt_ProQueryCalTxPower(padapter, rfpath);
  8540. sprintf(extra, " %d", txpower_inx);
  8541. wrqu->length = strlen(extra) + 1;
  8542. return 0;
  8543. }
  8544. static int rtw_mp_txpower(struct net_device *dev,
  8545. struct iw_request_info *info,
  8546. struct iw_point *wrqu, char *extra)
  8547. {
  8548. u32 idx_a=0,idx_b=0;
  8549. u8 input[wrqu->length];
  8550. PADAPTER padapter = rtw_netdev_priv(dev);
  8551. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8552. return -EFAULT;
  8553. sscanf(input,"patha=%d,pathb=%d",&idx_a,&idx_b);
  8554. //DBG_871X("%s: tx_pwr_idx_a=%x b=%x\n", __func__, idx_a, idx_b);
  8555. sprintf( extra, "Set power level path_A:%d path_B:%d", idx_a , idx_b );
  8556. padapter->mppriv.txpoweridx = (u8)idx_a;
  8557. padapter->mppriv.txpoweridx_b = (u8)idx_b;
  8558. padapter->mppriv.bSetTxPower = 1;
  8559. //Hal_SetAntennaPathPower(padapter);
  8560. SetTxPower(padapter);
  8561. wrqu->length = strlen(extra) + 1;
  8562. return 0;
  8563. }
  8564. static int rtw_mp_ant_tx(struct net_device *dev,
  8565. struct iw_request_info *info,
  8566. struct iw_point *wrqu, char *extra)
  8567. {
  8568. u8 i;
  8569. u8 input[wrqu->length];
  8570. u16 antenna = 0;
  8571. PADAPTER padapter = rtw_netdev_priv(dev);
  8572. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8573. return -EFAULT;
  8574. //DBG_871X("%s: input=%s\n", __func__, input);
  8575. sprintf( extra, "switch Tx antenna to %s", input );
  8576. for (i=0; i < strlen(input); i++)
  8577. {
  8578. switch(input[i])
  8579. {
  8580. case 'a' :
  8581. antenna|=ANTENNA_A;
  8582. break;
  8583. case 'b':
  8584. antenna|=ANTENNA_B;
  8585. break;
  8586. }
  8587. }
  8588. //antenna |= BIT(extra[i]-'a');
  8589. //DBG_871X("%s: antenna=0x%x\n", __func__, antenna);
  8590. padapter->mppriv.antenna_tx = antenna;
  8591. //DBG_871X("%s:mppriv.antenna_rx=%d\n", __func__, padapter->mppriv.antenna_tx);
  8592. Hal_SetAntenna(padapter);
  8593. wrqu->length = strlen(extra) + 1;
  8594. return 0;
  8595. }
  8596. static int rtw_mp_ant_rx(struct net_device *dev,
  8597. struct iw_request_info *info,
  8598. struct iw_point *wrqu, char *extra)
  8599. {
  8600. u8 i;
  8601. u16 antenna = 0;
  8602. u8 input[wrqu->length];
  8603. PADAPTER padapter = rtw_netdev_priv(dev);
  8604. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8605. return -EFAULT;
  8606. //DBG_871X("%s: input=%s\n", __func__, input);
  8607. _rtw_memset(extra, 0, wrqu->length);
  8608. sprintf( extra, "switch Rx antenna to %s", input );
  8609. for (i=0; i < strlen(input); i++) {
  8610. switch( input[i] )
  8611. {
  8612. case 'a' :
  8613. antenna|=ANTENNA_A;
  8614. break;
  8615. case 'b':
  8616. antenna|=ANTENNA_B;
  8617. break;
  8618. case 'c' :
  8619. antenna|=ANTENNA_C;
  8620. break;
  8621. }
  8622. }
  8623. //DBG_871X("%s: antenna=0x%x\n", __func__, antenna);
  8624. padapter->mppriv.antenna_rx = antenna;
  8625. //DBG_871X("%s:mppriv.antenna_rx=%d\n", __func__, padapter->mppriv.antenna_rx);
  8626. Hal_SetAntenna(padapter);
  8627. wrqu->length = strlen(extra);
  8628. return 0;
  8629. }
  8630. static int rtw_mp_ctx(struct net_device *dev,
  8631. struct iw_request_info *info,
  8632. struct iw_point *wrqu, char *extra)
  8633. {
  8634. u32 pkTx = 1, countPkTx = 1, cotuTx = 1, CarrSprTx = 1, scTx = 1, sgleTx = 1, stop = 1;
  8635. u32 bStartTest = 1;
  8636. u32 count = 0;
  8637. struct mp_priv *pmp_priv;
  8638. struct pkt_attrib *pattrib;
  8639. PADAPTER padapter = rtw_netdev_priv(dev);
  8640. pmp_priv = &padapter->mppriv;
  8641. if (copy_from_user(extra, wrqu->pointer, wrqu->length))
  8642. return -EFAULT;
  8643. DBG_871X("%s: in=%s\n", __func__, extra);
  8644. countPkTx = strncmp(extra, "count=", 5); // strncmp TRUE is 0
  8645. cotuTx = strncmp(extra, "background", 20);
  8646. CarrSprTx = strncmp(extra, "background,cs", 20);
  8647. scTx = strncmp(extra, "background,sc", 20);
  8648. sgleTx = strncmp(extra, "background,stone", 20);
  8649. pkTx = strncmp(extra, "background,pkt", 20);
  8650. stop = strncmp(extra, "stop", 4);
  8651. sscanf(extra, "count=%d,pkt", &count);
  8652. //DBG_871X("%s: count=%d countPkTx=%d cotuTx=%d CarrSprTx=%d scTx=%d sgleTx=%d pkTx=%d stop=%d\n", __func__, count, countPkTx, cotuTx, CarrSprTx, pkTx, sgleTx, scTx, stop);
  8653. _rtw_memset(extra, '\0', sizeof(extra));
  8654. if (stop == 0) {
  8655. bStartTest = 0; // To set Stop
  8656. pmp_priv->tx.stop = 1;
  8657. sprintf( extra, "Stop continuous Tx");
  8658. } else {
  8659. bStartTest = 1;
  8660. if (pmp_priv->mode != MP_ON) {
  8661. if (pmp_priv->tx.stop != 1) {
  8662. DBG_871X("%s: MP_MODE != ON %d\n", __func__, pmp_priv->mode);
  8663. return -EFAULT;
  8664. }
  8665. }
  8666. }
  8667. if (pkTx == 0 || countPkTx == 0)
  8668. pmp_priv->mode = MP_PACKET_TX;
  8669. if (sgleTx == 0)
  8670. pmp_priv->mode = MP_SINGLE_TONE_TX;
  8671. if (cotuTx == 0)
  8672. pmp_priv->mode = MP_CONTINUOUS_TX;
  8673. if (CarrSprTx == 0)
  8674. pmp_priv->mode = MP_CARRIER_SUPPRISSION_TX;
  8675. if (scTx == 0)
  8676. pmp_priv->mode = MP_SINGLE_CARRIER_TX;
  8677. switch (pmp_priv->mode)
  8678. {
  8679. case MP_PACKET_TX:
  8680. //DBG_871X("%s:pkTx %d\n", __func__,bStartTest);
  8681. if (bStartTest == 0)
  8682. {
  8683. pmp_priv->tx.stop = 1;
  8684. pmp_priv->mode = MP_ON;
  8685. sprintf( extra, "Stop continuous Tx");
  8686. }
  8687. else if (pmp_priv->tx.stop == 1)
  8688. {
  8689. sprintf( extra, "Start continuous DA=ffffffffffff len=1500 count=%u,\n",count);
  8690. //DBG_871X("%s:countPkTx %d\n", __func__,count);
  8691. pmp_priv->tx.stop = 0;
  8692. pmp_priv->tx.count = count;
  8693. pmp_priv->tx.payload = 2;
  8694. pattrib = &pmp_priv->tx.attrib;
  8695. pattrib->pktlen = 1000;
  8696. _rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
  8697. SetPacketTx(padapter);
  8698. }
  8699. else {
  8700. //DBG_871X("%s: pkTx not stop\n", __func__);
  8701. return -EFAULT;
  8702. }
  8703. wrqu->length = strlen(extra);
  8704. return 0;
  8705. case MP_SINGLE_TONE_TX:
  8706. //DBG_871X("%s: sgleTx %d \n", __func__, bStartTest);
  8707. if (bStartTest != 0){
  8708. sprintf( extra, "Start continuous DA=ffffffffffff len=1500 \n infinite=yes.");
  8709. }
  8710. Hal_SetSingleToneTx(padapter, (u8)bStartTest);
  8711. break;
  8712. case MP_CONTINUOUS_TX:
  8713. //DBG_871X("%s: cotuTx %d\n", __func__, bStartTest);
  8714. if (bStartTest != 0){
  8715. sprintf( extra, "Start continuous DA=ffffffffffff len=1500 \n infinite=yes.");
  8716. }
  8717. Hal_SetContinuousTx(padapter, (u8)bStartTest);
  8718. break;
  8719. case MP_CARRIER_SUPPRISSION_TX:
  8720. //DBG_871X("%s: CarrSprTx %d\n", __func__, bStartTest);
  8721. if (bStartTest != 0){
  8722. if( pmp_priv->rateidx <= MPT_RATE_11M )
  8723. {
  8724. sprintf( extra, "Start continuous DA=ffffffffffff len=1500 \n infinite=yes.");
  8725. Hal_SetCarrierSuppressionTx(padapter, (u8)bStartTest);
  8726. }else
  8727. sprintf( extra, "Specify carrier suppression but not CCK rate");
  8728. }
  8729. break;
  8730. case MP_SINGLE_CARRIER_TX:
  8731. //DBG_871X("%s: scTx %d\n", __func__, bStartTest);
  8732. if (bStartTest != 0){
  8733. sprintf( extra, "Start continuous DA=ffffffffffff len=1500 \n infinite=yes.");
  8734. }
  8735. Hal_SetSingleCarrierTx(padapter, (u8)bStartTest);
  8736. break;
  8737. default:
  8738. //DBG_871X("%s:No Match MP_MODE\n", __func__);
  8739. sprintf( extra, "Error! Continuous-Tx is not on-going.");
  8740. return -EFAULT;
  8741. }
  8742. if ( bStartTest==1 && pmp_priv->mode != MP_ON) {
  8743. struct mp_priv *pmp_priv = &padapter->mppriv;
  8744. if (pmp_priv->tx.stop == 0) {
  8745. pmp_priv->tx.stop = 1;
  8746. //DBG_871X("%s: pkt tx is running...\n", __func__);
  8747. rtw_msleep_os(5);
  8748. }
  8749. pmp_priv->tx.stop = 0;
  8750. pmp_priv->tx.count = 1;
  8751. SetPacketTx(padapter);
  8752. } else {
  8753. pmp_priv->mode = MP_ON;
  8754. }
  8755. wrqu->length = strlen(extra);
  8756. return 0;
  8757. }
  8758. static int rtw_mp_arx(struct net_device *dev,
  8759. struct iw_request_info *info,
  8760. struct iw_point *wrqu, char *extra)
  8761. {
  8762. u8 bStartRx=0,bStopRx=0,bQueryPhy;
  8763. u32 cckok=0,cckcrc=0,ofdmok=0,ofdmcrc=0,htok=0,htcrc=0,OFDM_FA=0,CCK_FA=0;
  8764. u8 input[wrqu->length];
  8765. PADAPTER padapter = rtw_netdev_priv(dev);
  8766. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8767. return -EFAULT;
  8768. DBG_871X("%s: %s\n", __func__, input);
  8769. bStartRx = (strncmp(input, "start", 5)==0)?1:0; // strncmp TRUE is 0
  8770. bStopRx = (strncmp(input, "stop", 5)==0)?1:0; // strncmp TRUE is 0
  8771. bQueryPhy = (strncmp(input, "phy", 3)==0)?1:0; // strncmp TRUE is 0
  8772. if(bStartRx)
  8773. {
  8774. sprintf( extra, "start");
  8775. SetPacketRx(padapter, bStartRx);
  8776. }
  8777. else if(bStopRx)
  8778. {
  8779. SetPacketRx(padapter, 0);
  8780. sprintf( extra, "Received packet OK:%d CRC error:%d",padapter->mppriv.rx_pktcount,padapter->mppriv.rx_crcerrpktcount);
  8781. }
  8782. else if(bQueryPhy)
  8783. {
  8784. /*
  8785. OFDM FA
  8786. RegCF0[15:0]
  8787. RegCF2[31:16]
  8788. RegDA0[31:16]
  8789. RegDA4[15:0]
  8790. RegDA4[31:16]
  8791. RegDA8[15:0]
  8792. CCK FA
  8793. (RegA5B<<8) | RegA5C
  8794. */
  8795. cckok = read_bbreg(padapter, 0xf88, 0xffffffff );
  8796. cckcrc = read_bbreg(padapter, 0xf84, 0xffffffff );
  8797. ofdmok = read_bbreg(padapter, 0xf94, 0x0000FFFF );
  8798. ofdmcrc = read_bbreg(padapter, 0xf94 , 0xFFFF0000 );
  8799. htok = read_bbreg(padapter, 0xf90, 0x0000FFFF );
  8800. htcrc = read_bbreg(padapter,0xf90, 0xFFFF0000 );
  8801. OFDM_FA=+read_bbreg(padapter, 0xcf0, 0x0000FFFF );
  8802. OFDM_FA=+read_bbreg(padapter, 0xcf2, 0xFFFF0000 );
  8803. OFDM_FA=+read_bbreg(padapter, 0xda0, 0xFFFF0000 );
  8804. OFDM_FA=+read_bbreg(padapter, 0xda4, 0x0000FFFF );
  8805. OFDM_FA=+read_bbreg(padapter, 0xda4, 0xFFFF0000 );
  8806. OFDM_FA=+read_bbreg(padapter, 0xda8, 0x0000FFFF );
  8807. CCK_FA=(rtw_read8(padapter, 0xa5b )<<8 ) | (rtw_read8(padapter, 0xa5c));
  8808. sprintf( extra, "Phy Received packet OK:%d CRC error:%d FA Counter: %d",cckok+ofdmok+htok,cckcrc+ofdmcrc+htcrc,OFDM_FA+CCK_FA);
  8809. }
  8810. wrqu->length = strlen(extra) + 1;
  8811. return 0;
  8812. }
  8813. static int rtw_mp_trx_query(struct net_device *dev,
  8814. struct iw_request_info *info,
  8815. struct iw_point *wrqu, char *extra)
  8816. {
  8817. u32 txok,txfail,rxok,rxfail;
  8818. PADAPTER padapter = rtw_netdev_priv(dev);
  8819. //if (copy_from_user(extra, wrqu->data.pointer, wrqu->data.length))
  8820. // return -EFAULT;
  8821. txok=padapter->mppriv.tx.sended;
  8822. txfail=0;
  8823. rxok = padapter->mppriv.rx_pktcount;
  8824. rxfail = padapter->mppriv.rx_crcerrpktcount;
  8825. _rtw_memset(extra, '\0', 128);
  8826. sprintf(extra, "Tx OK:%d, Tx Fail:%d, Rx OK:%d, CRC error:%d ", txok, txfail,rxok,rxfail);
  8827. wrqu->length=strlen(extra)+1;
  8828. return 0;
  8829. }
  8830. static int rtw_mp_pwrtrk(struct net_device *dev,
  8831. struct iw_request_info *info,
  8832. struct iw_point *wrqu, char *extra)
  8833. {
  8834. u8 enable;
  8835. u32 thermal;
  8836. s32 ret;
  8837. PADAPTER padapter = rtw_netdev_priv(dev);
  8838. HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
  8839. u8 input[wrqu->length];
  8840. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8841. return -EFAULT;
  8842. _rtw_memset(extra, 0, wrqu->length);
  8843. enable = 1;
  8844. if (wrqu->length > 1) { // not empty string
  8845. if (strncmp(input, "stop", 4) == 0)
  8846. {
  8847. enable = 0;
  8848. sprintf(extra, "mp tx power tracking stop");
  8849. pHalData->TxPowerTrackControl = _FALSE;
  8850. }
  8851. else if (sscanf(input, "ther=%d", &thermal)) {
  8852. pHalData->TxPowerTrackControl = _TRUE;
  8853. ret = Hal_SetThermalMeter(padapter, (u8)thermal);
  8854. if (ret == _FAIL) return -EPERM;
  8855. sprintf(extra, "mp tx power tracking start,target value=%d ok ",thermal);
  8856. }else {
  8857. return -EINVAL;
  8858. }
  8859. }
  8860. ret = Hal_SetPowerTracking(padapter, enable);
  8861. if (ret == _FAIL) return -EPERM;
  8862. wrqu->length = strlen(extra);
  8863. return 0;
  8864. }
  8865. static int rtw_mp_psd(struct net_device *dev,
  8866. struct iw_request_info *info,
  8867. struct iw_point *wrqu, char *extra)
  8868. {
  8869. PADAPTER padapter = rtw_netdev_priv(dev);
  8870. u8 input[wrqu->length];
  8871. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  8872. return -EFAULT;
  8873. strcpy(extra,input);
  8874. wrqu->length = mp_query_psd(padapter, extra);
  8875. return 0;
  8876. }
  8877. static int rtw_mp_thermal(struct net_device *dev,
  8878. struct iw_request_info *info,
  8879. struct iw_point *wrqu, char *extra)
  8880. {
  8881. u8 val;
  8882. u16 bwrite=1;
  8883. #ifdef CONFIG_RTL8192C
  8884. u16 addr=EEPROM_THERMAL_METER_92C;
  8885. #endif
  8886. #ifdef CONFIG_RTL8192D
  8887. u16 addr=EEPROM_THERMAL_METER_92D;
  8888. #endif
  8889. #ifdef CONFIG_RTL8723A
  8890. u16 addr=EEPROM_THERMAL_METER_8723A;
  8891. #endif
  8892. #ifdef CONFIG_RTL8188E
  8893. u16 addr=EEPROM_THERMAL_METER_88E;
  8894. #endif
  8895. #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
  8896. u16 addr=EEPROM_THERMAL_METER_8812;
  8897. #endif
  8898. #ifdef CONFIG_RTL8192E
  8899. u16 addr=EEPROM_THERMAL_METER_8192E;
  8900. #endif
  8901. #ifdef CONFIG_RTL8723B
  8902. u16 addr=EEPROM_THERMAL_METER_8723B;
  8903. #endif
  8904. u16 cnt=1;
  8905. u16 max_available_size=0;
  8906. PADAPTER padapter = rtw_netdev_priv(dev);
  8907. if (copy_from_user(extra, wrqu->pointer, wrqu->length))
  8908. return -EFAULT;
  8909. //DBG_871X("print extra %s \n",extra);
  8910. bwrite = strncmp(extra, "write", 6); // strncmp TRUE is 0
  8911. Hal_GetThermalMeter(padapter, &val);
  8912. if( bwrite == 0 )
  8913. {
  8914. //DBG_871X("to write val:%d",val);
  8915. EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE);
  8916. if( 2 > max_available_size )
  8917. {
  8918. DBG_871X("no available efuse!\n");
  8919. return -EFAULT;
  8920. }
  8921. if ( rtw_efuse_map_write(padapter, addr, cnt, &val) == _FAIL )
  8922. {
  8923. DBG_871X("rtw_efuse_map_write error \n");
  8924. return -EFAULT;
  8925. }
  8926. else
  8927. {
  8928. sprintf(extra, " efuse write ok :%d", val);
  8929. }
  8930. }
  8931. else
  8932. {
  8933. sprintf(extra, "%d", val);
  8934. }
  8935. wrqu->length = strlen(extra);
  8936. return 0;
  8937. }
  8938. static int rtw_mp_reset_stats(struct net_device *dev,
  8939. struct iw_request_info *info,
  8940. struct iw_point *wrqu, char *extra)
  8941. {
  8942. struct mp_priv *pmp_priv;
  8943. struct pkt_attrib *pattrib;
  8944. PADAPTER padapter = rtw_netdev_priv(dev);
  8945. pmp_priv = &padapter->mppriv;
  8946. pmp_priv->tx.sended = 0;
  8947. pmp_priv->tx_pktcount = 0;
  8948. pmp_priv->rx_pktcount = 0;
  8949. pmp_priv->rx_crcerrpktcount = 0;
  8950. //reset phy counter
  8951. write_bbreg(padapter,0xf14,BIT16,0x1);
  8952. rtw_msleep_os(10);
  8953. write_bbreg(padapter,0xf14,BIT16,0x0);
  8954. return 0;
  8955. }
  8956. static int rtw_mp_dump(struct net_device *dev,
  8957. struct iw_request_info *info,
  8958. struct iw_point *wrqu, char *extra)
  8959. {
  8960. struct mp_priv *pmp_priv;
  8961. struct pkt_attrib *pattrib;
  8962. u32 value;
  8963. u8 rf_type,path_nums = 0;
  8964. u32 i,j=1,path;
  8965. PADAPTER padapter = rtw_netdev_priv(dev);
  8966. pmp_priv = &padapter->mppriv;
  8967. //if (copy_from_user(extra, wrqu->data.pointer, wrqu->data.length))
  8968. // return -EFAULT;
  8969. if ( strncmp(extra, "all", 4)==0 )
  8970. {
  8971. DBG_871X("\n======= MAC REG =======\n");
  8972. for ( i=0x0;i<0x300;i+=4 )
  8973. {
  8974. if(j%4==1) DBG_871X("0x%02x",i);
  8975. DBG_871X(" 0x%08x ",rtw_read32(padapter,i));
  8976. if((j++)%4 == 0) DBG_871X("\n");
  8977. }
  8978. for( i=0x400;i<0x1000;i+=4 )
  8979. {
  8980. if(j%4==1) DBG_871X("0x%02x",i);
  8981. DBG_871X(" 0x%08x ",rtw_read32(padapter,i));
  8982. if((j++)%4 == 0) DBG_871X("\n");
  8983. }
  8984. i,j=1;
  8985. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  8986. DBG_871X("\n======= RF REG =======\n");
  8987. if(( RF_1T2R == rf_type ) ||( RF_1T1R ==rf_type ))
  8988. path_nums = 1;
  8989. else
  8990. path_nums = 2;
  8991. for(path=0;path<path_nums;path++)
  8992. {
  8993. #ifdef CONFIG_RTL8192D
  8994. for (i = 0; i < 0x50; i++)
  8995. #else
  8996. #ifdef CONFIG_RTL8723B
  8997. for (i = 0; i < 0x100; i++)
  8998. #else
  8999. for (i = 0; i < 0x34; i++)
  9000. #endif
  9001. #endif
  9002. {
  9003. //value = PHY_QueryRFReg(padapter, (RF_RADIO_PATH_E)path,i, bMaskDWord);
  9004. value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
  9005. if(j%4==1) DBG_871X("0x%02x ",i);
  9006. DBG_871X(" 0x%08x ",value);
  9007. if((j++)%4==0) DBG_871X("\n");
  9008. }
  9009. }
  9010. }
  9011. return 0;
  9012. }
  9013. static int rtw_mp_phypara(struct net_device *dev,
  9014. struct iw_request_info *info,
  9015. struct iw_point *wrqu, char *extra)
  9016. {
  9017. PADAPTER padapter = rtw_netdev_priv(dev);
  9018. char input[wrqu->length];
  9019. u32 valxcap;
  9020. if (copy_from_user(input, wrqu->pointer, wrqu->length))
  9021. return -EFAULT;
  9022. DBG_871X("%s:iwpriv in=%s\n", __func__, input);
  9023. sscanf(input, "xcap=%d", &valxcap);
  9024. Hal_ProSetCrystalCap( padapter , valxcap );
  9025. sprintf( extra, "Set xcap=%d",valxcap );
  9026. wrqu->length = strlen(extra) + 1;
  9027. return 0;
  9028. }
  9029. static int rtw_mp_SetRFPath(struct net_device *dev,
  9030. struct iw_request_info *info,
  9031. union iwreq_data *wrqu, char *extra)
  9032. {
  9033. PADAPTER padapter = rtw_netdev_priv(dev);
  9034. char input[wrqu->data.length];
  9035. u8 bMain=1,bTurnoff=1;
  9036. if (copy_from_user(input, wrqu->data.pointer, wrqu->data.length))
  9037. return -EFAULT;
  9038. DBG_871X("%s:iwpriv in=%s\n", __func__, input);
  9039. bMain = strncmp(input, "1", 2); // strncmp TRUE is 0
  9040. bTurnoff = strncmp(input, "0", 3); // strncmp TRUE is 0
  9041. if(bMain==0)
  9042. {
  9043. MP_PHY_SetRFPathSwitch(padapter,_TRUE);
  9044. DBG_871X("%s:PHY_SetRFPathSwitch=TRUE\n", __func__);
  9045. }
  9046. else if(bTurnoff==0)
  9047. {
  9048. MP_PHY_SetRFPathSwitch(padapter,_FALSE);
  9049. DBG_871X("%s:PHY_SetRFPathSwitch=FALSE\n", __func__);
  9050. }
  9051. return 0;
  9052. }
  9053. static int rtw_mp_QueryDrv(struct net_device *dev,
  9054. struct iw_request_info *info,
  9055. union iwreq_data *wrqu, char *extra)
  9056. {
  9057. PADAPTER padapter = rtw_netdev_priv(dev);
  9058. char input[wrqu->data.length];
  9059. u8 qAutoLoad=1;
  9060. EEPROM_EFUSE_PRIV *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
  9061. if (copy_from_user(input, wrqu->data.pointer, wrqu->data.length))
  9062. return -EFAULT;
  9063. DBG_871X("%s:iwpriv in=%s\n", __func__, input);
  9064. qAutoLoad = strncmp(input, "autoload", 8); // strncmp TRUE is 0
  9065. if(qAutoLoad==0)
  9066. {
  9067. DBG_871X("%s:qAutoLoad\n", __func__);
  9068. if(pEEPROM->bautoload_fail_flag)
  9069. sprintf(extra, "fail");
  9070. else
  9071. sprintf(extra, "ok");
  9072. }
  9073. wrqu->data.length = strlen(extra) + 1;
  9074. return 0;
  9075. }
  9076. /* update Tx AGC offset */
  9077. static int rtw_mp_antBdiff(struct net_device *dev,
  9078. struct iw_request_info *info,
  9079. struct iw_point *wrqu, char *extra)
  9080. {
  9081. // MPT_ProSetTxAGCOffset
  9082. return 0;
  9083. }
  9084. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  9085. /* update Tx AGC offset */
  9086. static int rtw_mp_SetBT(struct net_device *dev,
  9087. struct iw_request_info *info,
  9088. union iwreq_data *wrqu, char *extra)
  9089. {
  9090. PADAPTER padapter = rtw_netdev_priv(dev);
  9091. BT_REQ_CMD BtReq;
  9092. PMPT_CONTEXT pMptCtx=&(padapter->mppriv.MptCtx);
  9093. PBT_RSP_CMD pBtRsp=(PBT_RSP_CMD)&pMptCtx->mptOutBuf[0];
  9094. char input[128];
  9095. char *pch, *ptmp, *token, *tmp[2]={0x00,0x00};
  9096. u8 setdata[100];
  9097. u16 testmode=1,ready=1,trxparam=1,setgen=1,getgen=1,testctrl=1,testbt=1;
  9098. u32 i,ii,jj,kk,cnts,status;
  9099. if (copy_from_user(extra, wrqu->data.pointer, wrqu->data.length))
  9100. return -EFAULT;
  9101. if(strlen(extra)<1) return -EFAULT;
  9102. DBG_871X("%s:iwpriv in=%s\n", __func__, extra);
  9103. ready = strncmp(extra, "ready", 5);
  9104. testmode = strncmp(extra, "testmode", 8); // strncmp TRUE is 0
  9105. trxparam = strncmp(extra, "trxparam", 8);
  9106. setgen = strncmp(extra, "setgen", 6);
  9107. getgen = strncmp(extra, "getgen", 6);
  9108. testctrl = strncmp(extra, "testctrl", 8);
  9109. testbt = strncmp(extra, "testbt", 6);
  9110. if ( strncmp(extra, "dlfw", 4) == 0)
  9111. {
  9112. #if defined(CONFIG_PLATFORM_SPRD) && (MP_DRIVER == 1)
  9113. // Pull up BT reset pin.
  9114. DBG_871X("%s: pull up BT reset pin when bt start mp test\n", __FUNCTION__);
  9115. rtw_wifi_gpio_wlan_ctrl(WLAN_BT_PWDN_ON);
  9116. #endif
  9117. #ifdef CONFIG_RTL8723A
  9118. status = rtl8723a_FirmwareDownload(padapter);
  9119. #elif defined(CONFIG_RTL8723B)
  9120. status = rtl8723b_FirmwareDownload(padapter, _FALSE);
  9121. #endif
  9122. if(status==_SUCCESS)
  9123. {
  9124. _rtw_memset(extra,'\0', wrqu->data.length);
  9125. DBG_871X("%s: download FW %s\n", __func__, (_FAIL==status) ? "FAIL!":"OK.");
  9126. sprintf(extra, "download FW %s", (_FAIL==status) ? "FAIL!":"OK.");
  9127. wrqu->data.length = strlen(extra) + 1;
  9128. }
  9129. goto exit;
  9130. }
  9131. if( testbt==0 )
  9132. {
  9133. BtReq.opCodeVer=1;
  9134. BtReq.OpCode=6;
  9135. BtReq.paraLength=cnts/2;
  9136. goto todo;
  9137. }
  9138. if( ready==0 )
  9139. {
  9140. BtReq.opCodeVer=1;
  9141. BtReq.OpCode=0;
  9142. BtReq.paraLength=0;
  9143. goto todo;
  9144. }
  9145. DBG_871X("%s:after strncmp\n", __func__);
  9146. pch = extra;
  9147. i = 0;
  9148. while ((token = strsep(&pch, ",")) != NULL)
  9149. {
  9150. if (i > 1) break;
  9151. tmp[i] = token;
  9152. i++;
  9153. }
  9154. if ((tmp[0]==NULL) && (tmp[1]==NULL))
  9155. {
  9156. return -EFAULT;
  9157. }
  9158. else
  9159. {
  9160. cnts = strlen(tmp[1]);
  9161. if (cnts<1) return -EFAULT;
  9162. DBG_871X("%s: cnts=%d\n", __FUNCTION__, cnts);
  9163. DBG_871X("%s: data=%s\n", __FUNCTION__, tmp[1]);
  9164. for (jj=0, kk=0; jj<cnts; jj++, kk+=2)
  9165. {
  9166. BtReq.pParamStart[jj] = key_2char2num(tmp[1][kk], tmp[1][kk+1]);
  9167. DBG_871X("BtReq.pParamStart[%d]=%x \n",ii,BtReq.pParamStart[jj]);
  9168. }
  9169. }
  9170. if( testmode==0 )
  9171. {
  9172. BtReq.opCodeVer=1;
  9173. BtReq.OpCode=1;
  9174. BtReq.paraLength=1;
  9175. }
  9176. if( trxparam==0 )
  9177. {
  9178. BtReq.opCodeVer=1;
  9179. BtReq.OpCode=2;
  9180. BtReq.paraLength=cnts/2;
  9181. }
  9182. if( setgen==0 )
  9183. {
  9184. DBG_871X("%s: BT_SET_GENERAL \n", __func__);
  9185. BtReq.opCodeVer=1;
  9186. BtReq.OpCode=3; //BT_SET_GENERAL 3
  9187. BtReq.paraLength=cnts/2;
  9188. }
  9189. if( getgen==0 )
  9190. {
  9191. DBG_871X("%s: BT_GET_GENERAL \n", __func__);
  9192. BtReq.opCodeVer=1;
  9193. BtReq.OpCode=4; //BT_GET_GENERAL 4
  9194. BtReq.paraLength=cnts/2;
  9195. }
  9196. if( testctrl==0 )
  9197. {
  9198. DBG_871X("%s: BT_TEST_CTRL \n", __func__);
  9199. BtReq.opCodeVer=1;
  9200. BtReq.OpCode=5; //BT_TEST_CTRL 5
  9201. BtReq.paraLength=cnts/2;
  9202. }
  9203. DBG_871X("%s: BtReq.paraLength =%d\n", __FUNCTION__, BtReq.paraLength);
  9204. DBG_871X("opCodeVer=%d,OpCode=%d \n",BtReq.opCodeVer,BtReq.OpCode);
  9205. if(BtReq.paraLength<1)
  9206. goto todo;
  9207. for(i=0;i<BtReq.paraLength;i++)
  9208. {
  9209. DBG_871X("%s: BtReq.pParamStart[ %d ] = 0x%02x \n", __func__,i,BtReq.pParamStart[i]);
  9210. }
  9211. todo:
  9212. _rtw_memset(extra,'\0', wrqu->data.length);
  9213. mptbt_BtControlProcess(padapter,&BtReq);
  9214. for (i=4; i<pMptCtx->mptOutLen; i++)
  9215. {
  9216. DBG_8192C("0x%x ", pMptCtx->mptOutBuf[i]);
  9217. sprintf(extra, "%s 0x%x ", extra, pMptCtx->mptOutBuf[i]);
  9218. }
  9219. exit:
  9220. wrqu->data.length = strlen(extra) + 1;
  9221. return status;
  9222. }
  9223. #endif //#ifdef CONFIG_RTL8723A
  9224. static int rtw_mp_set(struct net_device *dev,
  9225. struct iw_request_info *info,
  9226. union iwreq_data *wdata, char *extra)
  9227. {
  9228. struct iw_point *wrqu = (struct iw_point *)wdata;
  9229. u32 subcmd = wrqu->flags;
  9230. PADAPTER padapter = rtw_netdev_priv(dev);
  9231. if (padapter == NULL)
  9232. {
  9233. return -ENETDOWN;
  9234. }
  9235. //_rtw_memset(extra, 0x00, IW_PRIV_SIZE_MASK);
  9236. if (extra == NULL)
  9237. {
  9238. wrqu->length = 0;
  9239. return -EIO;
  9240. }
  9241. switch(subcmd)
  9242. {
  9243. case MP_START:
  9244. DBG_871X("set case mp_start \n");
  9245. rtw_mp_start (dev,info,wrqu,extra);
  9246. break;
  9247. case MP_STOP:
  9248. DBG_871X("set case mp_stop \n");
  9249. rtw_mp_stop (dev,info,wrqu,extra);
  9250. break;
  9251. case MP_BANDWIDTH:
  9252. DBG_871X("set case mp_bandwidth \n");
  9253. rtw_mp_bandwidth (dev,info,wrqu,extra);
  9254. break;
  9255. case MP_RESET_STATS:
  9256. DBG_871X("set case MP_RESET_STATS \n");
  9257. rtw_mp_reset_stats (dev,info,wrqu,extra);
  9258. break;
  9259. case MP_SetRFPathSwh:
  9260. DBG_871X("set MP_SetRFPathSwitch \n");
  9261. rtw_mp_SetRFPath (dev,info,wdata,extra);
  9262. break;
  9263. case CTA_TEST:
  9264. DBG_871X("set CTA_TEST\n");
  9265. rtw_cta_test_start (dev, info, wdata, extra);
  9266. break;
  9267. }
  9268. return 0;
  9269. }
  9270. static int rtw_mp_get(struct net_device *dev,
  9271. struct iw_request_info *info,
  9272. union iwreq_data *wdata, char *extra)
  9273. {
  9274. struct iw_point *wrqu = (struct iw_point *)wdata;
  9275. u32 subcmd = wrqu->flags;
  9276. PADAPTER padapter = rtw_netdev_priv(dev);
  9277. //DBG_871X("in mp_get extra= %s \n",extra);
  9278. if (padapter == NULL)
  9279. {
  9280. return -ENETDOWN;
  9281. }
  9282. if (extra == NULL)
  9283. {
  9284. wrqu->length = 0;
  9285. return -EIO;
  9286. }
  9287. switch(subcmd)
  9288. {
  9289. case WRITE_REG :
  9290. rtw_mp_write_reg (dev,info,wrqu,extra);
  9291. break;
  9292. case WRITE_RF:
  9293. rtw_mp_write_rf (dev,info,wrqu,extra);
  9294. break;
  9295. case MP_PHYPARA:
  9296. DBG_871X("mp_get MP_PHYPARA \n");
  9297. rtw_mp_phypara(dev,info,wrqu,extra);
  9298. break;
  9299. case MP_CHANNEL:
  9300. DBG_871X("set case mp_channel \n");
  9301. rtw_mp_channel (dev,info,wrqu,extra);
  9302. break;
  9303. case READ_REG:
  9304. DBG_871X("mp_get READ_REG \n");
  9305. rtw_mp_read_reg (dev,info,wrqu,extra);
  9306. break;
  9307. case READ_RF:
  9308. DBG_871X("mp_get READ_RF \n");
  9309. rtw_mp_read_rf (dev,info,wrqu,extra);
  9310. break;
  9311. case MP_RATE:
  9312. DBG_871X("set case mp_rate \n");
  9313. rtw_mp_rate (dev,info,wrqu,extra);
  9314. break;
  9315. case MP_TXPOWER:
  9316. DBG_871X("set case MP_TXPOWER \n");
  9317. rtw_mp_txpower (dev,info,wrqu,extra);
  9318. break;
  9319. case MP_ANT_TX:
  9320. DBG_871X("set case MP_ANT_TX \n");
  9321. rtw_mp_ant_tx (dev,info,wrqu,extra);
  9322. break;
  9323. case MP_ANT_RX:
  9324. DBG_871X("set case MP_ANT_RX \n");
  9325. rtw_mp_ant_rx (dev,info,wrqu,extra);
  9326. break;
  9327. case MP_QUERY:
  9328. //DBG_871X("mp_get mp_query MP_QUERY \n");
  9329. rtw_mp_trx_query(dev,info,wrqu,extra);
  9330. break;
  9331. case MP_CTX:
  9332. DBG_871X("set case MP_CTX \n");
  9333. rtw_mp_ctx (dev,info,wrqu,extra);
  9334. break;
  9335. case MP_ARX:
  9336. DBG_871X("set case MP_ARX \n");
  9337. rtw_mp_arx (dev,info,wrqu,extra);
  9338. break;
  9339. case EFUSE_GET:
  9340. DBG_871X("efuse get EFUSE_GET \n");
  9341. rtw_mp_efuse_get(dev,info,wdata,extra);
  9342. break;
  9343. case MP_DUMP:
  9344. DBG_871X("set case MP_DUMP \n");
  9345. rtw_mp_dump (dev,info,wrqu,extra);
  9346. break;
  9347. case MP_PSD:
  9348. DBG_871X("set case MP_PSD \n");
  9349. rtw_mp_psd (dev,info,wrqu,extra);
  9350. break;
  9351. case MP_THER:
  9352. DBG_871X("set case MP_THER \n");
  9353. rtw_mp_thermal (dev,info,wrqu,extra);
  9354. break;
  9355. case MP_QueryDrvStats:
  9356. DBG_871X("mp_get MP_QueryDrvStats \n");
  9357. rtw_mp_QueryDrv (dev,info,wdata,extra);
  9358. break;
  9359. case MP_PWRTRK:
  9360. DBG_871X("set case MP_PWRTRK \n");
  9361. rtw_mp_pwrtrk (dev,info,wrqu,extra);
  9362. break;
  9363. case EFUSE_SET:
  9364. DBG_871X("set case efuse set \n");
  9365. rtw_mp_efuse_set (dev,info,wdata,extra);
  9366. break;
  9367. case MP_GET_TXPOWER_INX:
  9368. DBG_871X("mp_get MP_GET_TXPOWER_INX \n");
  9369. rtw_mp_txpower_index (dev,info,wrqu,extra);
  9370. break;
  9371. #if defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B)
  9372. case MP_SetBT:
  9373. DBG_871X("set MP_SetBT \n");
  9374. rtw_mp_SetBT (dev,info,wdata,extra);
  9375. break;
  9376. #endif
  9377. }
  9378. rtw_msleep_os(10); //delay 5ms for sending pkt before exit adb shell operation
  9379. return 0;
  9380. }
  9381. #endif //#if defined(CONFIG_MP_INCLUDED) && defined(CONFIG_MP_IWPRIV_SUPPORT)
  9382. static int rtw_wfd_tdls_enable(struct net_device *dev,
  9383. struct iw_request_info *info,
  9384. union iwreq_data *wrqu, char *extra)
  9385. {
  9386. int ret = 0;
  9387. #ifdef CONFIG_TDLS
  9388. #ifdef CONFIG_WFD
  9389. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9390. printk( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9391. if ( extra[ 0 ] == '0' )
  9392. {
  9393. padapter->wdinfo.wfd_tdls_enable = 0;
  9394. }
  9395. else
  9396. {
  9397. padapter->wdinfo.wfd_tdls_enable = 1;
  9398. }
  9399. #endif //CONFIG_WFD
  9400. #endif //CONFIG_TDLS
  9401. return ret;
  9402. }
  9403. static int rtw_tdls_weaksec(struct net_device *dev,
  9404. struct iw_request_info *info,
  9405. union iwreq_data *wrqu, char *extra)
  9406. {
  9407. int ret = 0;
  9408. #ifdef CONFIG_TDLS
  9409. u8 i, j;
  9410. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9411. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9412. if ( extra[ 0 ] == '0' )
  9413. {
  9414. padapter->wdinfo.wfd_tdls_weaksec = 0;
  9415. }
  9416. else
  9417. {
  9418. padapter->wdinfo.wfd_tdls_weaksec = 1;
  9419. }
  9420. #endif
  9421. return ret;
  9422. }
  9423. static int rtw_tdls_enable(struct net_device *dev,
  9424. struct iw_request_info *info,
  9425. union iwreq_data *wrqu, char *extra)
  9426. {
  9427. int ret = 0;
  9428. #ifdef CONFIG_TDLS
  9429. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9430. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9431. _irqL irqL;
  9432. _list *plist, *phead;
  9433. s32 index;
  9434. struct sta_info *psta = NULL;
  9435. struct sta_priv *pstapriv = &padapter->stapriv;
  9436. u8 tdls_sta[NUM_STA][ETH_ALEN];
  9437. u8 empty_hwaddr[ETH_ALEN] = { 0x00 };
  9438. printk( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9439. _rtw_memset(tdls_sta, 0x00, sizeof(tdls_sta));
  9440. if ( extra[ 0 ] == '0' )
  9441. {
  9442. ptdlsinfo->enable = 0;
  9443. if(pstapriv->asoc_sta_count==1)
  9444. return ret;
  9445. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  9446. for(index=0; index< NUM_STA; index++)
  9447. {
  9448. phead = &(pstapriv->sta_hash[index]);
  9449. plist = get_next(phead);
  9450. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
  9451. {
  9452. psta = LIST_CONTAINOR(plist, struct sta_info ,hash_list);
  9453. plist = get_next(plist);
  9454. if(psta->tdls_sta_state != TDLS_STATE_NONE)
  9455. {
  9456. _rtw_memcpy(tdls_sta[index], psta->hwaddr, ETH_ALEN);
  9457. }
  9458. }
  9459. }
  9460. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  9461. for(index=0; index< NUM_STA; index++)
  9462. {
  9463. if( !_rtw_memcmp(tdls_sta[index], empty_hwaddr, ETH_ALEN) )
  9464. {
  9465. printk("issue tear down to "MAC_FMT"\n", MAC_ARG(tdls_sta[index]));
  9466. issue_tdls_teardown(padapter, tdls_sta[index]);
  9467. }
  9468. }
  9469. rtw_tdls_cmd(padapter, myid(&(padapter->eeprompriv)), TDLS_RS_RCR);
  9470. rtw_reset_tdls_info(padapter);
  9471. }
  9472. else if ( extra[ 0 ] == '1' )
  9473. {
  9474. ptdlsinfo->enable = 1;
  9475. }
  9476. #endif //CONFIG_TDLS
  9477. return ret;
  9478. }
  9479. static int rtw_tdls_setup(struct net_device *dev,
  9480. struct iw_request_info *info,
  9481. union iwreq_data *wrqu, char *extra)
  9482. {
  9483. int ret = 0;
  9484. #ifdef CONFIG_TDLS
  9485. u8 i, j;
  9486. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9487. u8 mac_addr[ETH_ALEN];
  9488. #ifdef CONFIG_WFD
  9489. struct wifidirect_info *pwdinfo= &(padapter->wdinfo);
  9490. #endif // CONFIG_WFD
  9491. printk( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9492. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9493. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9494. }
  9495. #ifdef CONFIG_WFD
  9496. if ( _AES_ != padapter->securitypriv.dot11PrivacyAlgrthm )
  9497. {
  9498. // Weak Security situation with AP.
  9499. if ( 0 == pwdinfo->wfd_tdls_weaksec )
  9500. {
  9501. // Can't send the tdls setup request out!!
  9502. DBG_871X( "[%s] Current link is not AES, SKIP sending the tdls setup request!!\n", __FUNCTION__ );
  9503. }
  9504. else
  9505. {
  9506. issue_tdls_setup_req(padapter, mac_addr);
  9507. }
  9508. }
  9509. else
  9510. #endif // CONFIG_WFD
  9511. {
  9512. issue_tdls_setup_req(padapter, mac_addr);
  9513. }
  9514. #endif
  9515. return ret;
  9516. }
  9517. static int rtw_tdls_teardown(struct net_device *dev,
  9518. struct iw_request_info *info,
  9519. union iwreq_data *wrqu, char *extra)
  9520. {
  9521. int ret = 0;
  9522. #ifdef CONFIG_TDLS
  9523. u8 i,j;
  9524. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9525. struct sta_info *ptdls_sta = NULL;
  9526. u8 mac_addr[ETH_ALEN];
  9527. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9528. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9529. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9530. }
  9531. ptdls_sta = rtw_get_stainfo( &(padapter->stapriv), mac_addr);
  9532. if(ptdls_sta != NULL)
  9533. {
  9534. ptdls_sta->stat_code = _RSON_TDLS_TEAR_UN_RSN_;
  9535. issue_tdls_teardown(padapter, mac_addr);
  9536. }
  9537. #endif //CONFIG_TDLS
  9538. return ret;
  9539. }
  9540. static int rtw_tdls_discovery(struct net_device *dev,
  9541. struct iw_request_info *info,
  9542. union iwreq_data *wrqu, char *extra)
  9543. {
  9544. int ret = 0;
  9545. #ifdef CONFIG_TDLS
  9546. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9547. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  9548. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9549. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9550. issue_tdls_dis_req(padapter, NULL);
  9551. #endif //CONFIG_TDLS
  9552. return ret;
  9553. }
  9554. static int rtw_tdls_ch_switch(struct net_device *dev,
  9555. struct iw_request_info *info,
  9556. union iwreq_data *wrqu, char *extra)
  9557. {
  9558. int ret = 0;
  9559. #ifdef CONFIG_TDLS
  9560. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9561. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9562. u8 i, j, mac_addr[ETH_ALEN];
  9563. struct sta_info *ptdls_sta = NULL;
  9564. DBG_8192C( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9565. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9566. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9567. }
  9568. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  9569. if( ptdls_sta == NULL )
  9570. return ret;
  9571. ptdlsinfo->ch_sensing=1;
  9572. rtw_tdls_cmd(padapter, ptdls_sta->hwaddr, TDLS_INIT_CH_SEN);
  9573. #endif //CONFIG_TDLS
  9574. return ret;
  9575. }
  9576. static int rtw_tdls_pson(struct net_device *dev,
  9577. struct iw_request_info *info,
  9578. union iwreq_data *wrqu, char *extra)
  9579. {
  9580. int ret = 0;
  9581. #ifdef CONFIG_TDLS
  9582. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9583. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  9584. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9585. u8 i, j, mac_addr[ETH_ALEN];
  9586. struct sta_info *ptdls_sta = NULL;
  9587. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9588. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9589. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9590. }
  9591. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  9592. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta, 1);
  9593. #endif //CONFIG_TDLS
  9594. return ret;
  9595. }
  9596. static int rtw_tdls_psoff(struct net_device *dev,
  9597. struct iw_request_info *info,
  9598. union iwreq_data *wrqu, char *extra)
  9599. {
  9600. int ret = 0;
  9601. #ifdef CONFIG_TDLS
  9602. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9603. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  9604. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  9605. u8 i, j, mac_addr[ETH_ALEN];
  9606. struct sta_info *ptdls_sta = NULL;
  9607. DBG_8192C( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9608. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9609. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9610. }
  9611. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  9612. issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta, 0);
  9613. #endif //CONFIG_TDLS
  9614. return ret;
  9615. }
  9616. static int rtw_tdls_setip(struct net_device *dev,
  9617. struct iw_request_info *info,
  9618. union iwreq_data *wrqu, char *extra)
  9619. {
  9620. int ret = 0;
  9621. #ifdef CONFIG_TDLS
  9622. #ifdef CONFIG_WFD
  9623. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9624. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9625. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  9626. u8 i=0, j=0, k=0, tag=0, ip[3] = { 0xff }, *ptr = extra;
  9627. printk( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1 );
  9628. while( i < 4 )
  9629. {
  9630. for( j=0; j < 4; j++)
  9631. {
  9632. if( *( extra + j + tag ) == '.' || *( extra + j + tag ) == '\0' )
  9633. {
  9634. if( j == 1 )
  9635. pwfd_info->ip_address[i]=convert_ip_addr( '0', '0', *(extra+(j-1)+tag));
  9636. if( j == 2 )
  9637. pwfd_info->ip_address[i]=convert_ip_addr( '0', *(extra+(j-2)+tag), *(extra+(j-1)+tag));
  9638. if( j == 3 )
  9639. pwfd_info->ip_address[i]=convert_ip_addr( *(extra+(j-3)+tag), *(extra+(j-2)+tag), *(extra+(j-1)+tag));
  9640. tag += j + 1;
  9641. break;
  9642. }
  9643. }
  9644. i++;
  9645. }
  9646. printk( "[%s] Set IP = %u.%u.%u.%u \n", __FUNCTION__,
  9647. ptdlsinfo->wfd_info->ip_address[0], ptdlsinfo->wfd_info->ip_address[1],
  9648. ptdlsinfo->wfd_info->ip_address[2], ptdlsinfo->wfd_info->ip_address[3]
  9649. );
  9650. #endif //CONFIG_WFD
  9651. #endif //CONFIG_TDLS
  9652. return ret;
  9653. }
  9654. static int rtw_tdls_getip(struct net_device *dev,
  9655. struct iw_request_info *info,
  9656. union iwreq_data *wrqu, char *extra)
  9657. {
  9658. int ret = 0;
  9659. #ifdef CONFIG_TDLS
  9660. #ifdef CONFIG_WFD
  9661. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9662. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9663. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  9664. printk( "[%s]\n", __FUNCTION__);
  9665. sprintf( extra, "\n\n%u.%u.%u.%u\n",
  9666. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  9667. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]
  9668. );
  9669. printk( "[%s] IP=%u.%u.%u.%u\n", __FUNCTION__,
  9670. pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
  9671. pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]
  9672. );
  9673. wrqu->data.length = strlen( extra );
  9674. #endif //CONFIG_WFD
  9675. #endif //CONFIG_TDLS
  9676. return ret;
  9677. }
  9678. static int rtw_tdls_getport(struct net_device *dev,
  9679. struct iw_request_info *info,
  9680. union iwreq_data *wrqu, char *extra)
  9681. {
  9682. int ret = 0;
  9683. #ifdef CONFIG_TDLS
  9684. #ifdef CONFIG_WFD
  9685. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9686. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9687. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  9688. printk( "[%s]\n", __FUNCTION__);
  9689. sprintf( extra, "\n\n%d\n", pwfd_info->peer_rtsp_ctrlport );
  9690. printk( "[%s] remote port = %d\n", __FUNCTION__, pwfd_info->peer_rtsp_ctrlport );
  9691. wrqu->data.length = strlen( extra );
  9692. #endif //CONFIG_WFD
  9693. #endif //CONFIG_TDLS
  9694. return ret;
  9695. }
  9696. //WFDTDLS, for sigma test
  9697. static int rtw_tdls_dis_result(struct net_device *dev,
  9698. struct iw_request_info *info,
  9699. union iwreq_data *wrqu, char *extra)
  9700. {
  9701. int ret = 0;
  9702. #ifdef CONFIG_TDLS
  9703. #ifdef CONFIG_WFD
  9704. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9705. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9706. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  9707. printk( "[%s]\n", __FUNCTION__);
  9708. if(ptdlsinfo->dev_discovered == 1 )
  9709. {
  9710. sprintf( extra, "\n\nDis=1\n" );
  9711. ptdlsinfo->dev_discovered = 0;
  9712. }
  9713. wrqu->data.length = strlen( extra );
  9714. #endif //CONFIG_WFD
  9715. #endif //CONFIG_TDLS
  9716. return ret;
  9717. }
  9718. //WFDTDLS, for sigma test
  9719. static int rtw_wfd_tdls_status(struct net_device *dev,
  9720. struct iw_request_info *info,
  9721. union iwreq_data *wrqu, char *extra)
  9722. {
  9723. int ret = 0;
  9724. #ifdef CONFIG_TDLS
  9725. #ifdef CONFIG_WFD
  9726. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9727. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  9728. struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
  9729. printk( "[%s]\n", __FUNCTION__);
  9730. if(ptdlsinfo->setup_state == TDLS_LINKED_STATE )
  9731. {
  9732. sprintf( extra, "\n\nStatus=1\n" );
  9733. }
  9734. else
  9735. {
  9736. sprintf( extra, "\n\nStatus=0\n" );
  9737. }
  9738. wrqu->data.length = strlen( extra );
  9739. #endif //CONFIG_WFD
  9740. #endif //CONFIG_TDLS
  9741. return ret;
  9742. }
  9743. static int rtw_tdls_ch_switch_off(struct net_device *dev,
  9744. struct iw_request_info *info,
  9745. union iwreq_data *wrqu, char *extra)
  9746. {
  9747. int ret = 0;
  9748. #ifdef CONFIG_TDLS
  9749. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9750. u8 i, j, mac_addr[ETH_ALEN];
  9751. struct sta_info *ptdls_sta = NULL;
  9752. DBG_871X( "[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length -1 );
  9753. for( i=0, j=0 ; i < ETH_ALEN; i++, j+=3 ){
  9754. mac_addr[i]=key_2char2num(*(extra+j), *(extra+j+1));
  9755. }
  9756. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
  9757. ptdls_sta->tdls_sta_state |= TDLS_SW_OFF_STATE;
  9758. /*
  9759. if((ptdls_sta->tdls_sta_state & TDLS_AT_OFF_CH_STATE) && (ptdls_sta->tdls_sta_state & TDLS_PEER_AT_OFF_STATE)){
  9760. pmlmeinfo->tdls_candidate_ch= pmlmeext->cur_channel;
  9761. issue_tdls_ch_switch_req(padapter, mac_addr);
  9762. DBG_871X("issue tdls ch switch req back to base channel\n");
  9763. }
  9764. */
  9765. #endif //CONFIG_TDLS
  9766. return ret;
  9767. }
  9768. static int rtw_tdls(struct net_device *dev,
  9769. struct iw_request_info *info,
  9770. union iwreq_data *wrqu, char *extra)
  9771. {
  9772. int ret = 0;
  9773. #ifdef CONFIG_TDLS
  9774. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9775. DBG_871X( "[%s] extra = %s\n", __FUNCTION__, extra );
  9776. // WFD Sigma will use the tdls enable command to let the driver know we want to test the tdls now!
  9777. if ( _rtw_memcmp( extra, "wfdenable=", 10 ) )
  9778. {
  9779. wrqu->data.length -=10;
  9780. rtw_wfd_tdls_enable( dev, info, wrqu, &extra[10] );
  9781. return ret;
  9782. }
  9783. else if ( _rtw_memcmp( extra, "weaksec=", 8 ) )
  9784. {
  9785. wrqu->data.length -=8;
  9786. rtw_tdls_weaksec( dev, info, wrqu, &extra[8] );
  9787. return ret;
  9788. }
  9789. else if ( _rtw_memcmp( extra, "tdlsenable=", 11 ) )
  9790. {
  9791. wrqu->data.length -=11;
  9792. rtw_tdls_enable( dev, info, wrqu, &extra[11] );
  9793. return ret;
  9794. }
  9795. if( padapter->tdlsinfo.enable == 0 )
  9796. {
  9797. printk("tdls haven't enabled\n");
  9798. return 0;
  9799. }
  9800. if ( _rtw_memcmp( extra, "setup=", 6 ) )
  9801. {
  9802. wrqu->data.length -=6;
  9803. rtw_tdls_setup( dev, info, wrqu, &extra[6] );
  9804. }
  9805. else if (_rtw_memcmp( extra, "tear=", 5 ) )
  9806. {
  9807. wrqu->data.length -= 5;
  9808. rtw_tdls_teardown( dev, info, wrqu, &extra[5] );
  9809. }
  9810. else if (_rtw_memcmp( extra, "dis=", 4 ) )
  9811. {
  9812. wrqu->data.length -= 4;
  9813. rtw_tdls_discovery( dev, info, wrqu, &extra[4] );
  9814. }
  9815. else if (_rtw_memcmp( extra, "sw=", 3 ) )
  9816. {
  9817. wrqu->data.length -= 3;
  9818. rtw_tdls_ch_switch( dev, info, wrqu, &extra[3] );
  9819. }
  9820. else if (_rtw_memcmp( extra, "swoff=", 6 ) )
  9821. {
  9822. wrqu->data.length -= 6;
  9823. rtw_tdls_ch_switch_off( dev, info, wrqu, &extra[6] );
  9824. }
  9825. else if (_rtw_memcmp( extra, "pson=", 5 ) )
  9826. {
  9827. wrqu->data.length -= 5;
  9828. rtw_tdls_pson( dev, info, wrqu, &extra[5] );
  9829. }
  9830. else if (_rtw_memcmp( extra, "psoff=", 6 ) )
  9831. {
  9832. wrqu->data.length -= 6;
  9833. rtw_tdls_psoff( dev, info, wrqu, &extra[6] );
  9834. }
  9835. #ifdef CONFIG_WFD
  9836. else if (_rtw_memcmp( extra, "setip=", 6 ) )
  9837. {
  9838. wrqu->data.length -= 6;
  9839. rtw_tdls_setip( dev, info, wrqu, &extra[6] );
  9840. }
  9841. else if (_rtw_memcmp( extra, "tprobe=", 6 ) )
  9842. {
  9843. issue_tunneled_probe_req((_adapter *)rtw_netdev_priv(dev));
  9844. }
  9845. #endif //CONFIG_WFD
  9846. #endif //CONFIG_TDLS
  9847. return ret;
  9848. }
  9849. static int rtw_tdls_get(struct net_device *dev,
  9850. struct iw_request_info *info,
  9851. union iwreq_data *wrqu, char *extra)
  9852. {
  9853. int ret = 0;
  9854. #ifdef CONFIG_WFD
  9855. DBG_871X( "[%s] extra = %s\n", __FUNCTION__, (char*) wrqu->data.pointer );
  9856. if ( _rtw_memcmp( wrqu->data.pointer, "ip", 2 ) )
  9857. {
  9858. rtw_tdls_getip( dev, info, wrqu, extra );
  9859. }
  9860. if ( _rtw_memcmp( wrqu->data.pointer, "port", 4 ) )
  9861. {
  9862. rtw_tdls_getport( dev, info, wrqu, extra );
  9863. }
  9864. //WFDTDLS, for sigma test
  9865. if ( _rtw_memcmp( wrqu->data.pointer, "dis", 3 ) )
  9866. {
  9867. rtw_tdls_dis_result( dev, info, wrqu, extra );
  9868. }
  9869. if ( _rtw_memcmp( wrqu->data.pointer, "status", 6 ) )
  9870. {
  9871. rtw_wfd_tdls_status( dev, info, wrqu, extra );
  9872. }
  9873. #endif //CONFIG_WFD
  9874. return ret;
  9875. }
  9876. #ifdef CONFIG_INTEL_WIDI
  9877. static int rtw_widi_set(struct net_device *dev,
  9878. struct iw_request_info *info,
  9879. union iwreq_data *wrqu, char *extra)
  9880. {
  9881. int ret = 0;
  9882. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9883. process_intel_widi_cmd(padapter, extra);
  9884. return ret;
  9885. }
  9886. static int rtw_widi_set_probe_request(struct net_device *dev,
  9887. struct iw_request_info *info,
  9888. union iwreq_data *wrqu, char *extra)
  9889. {
  9890. int ret = 0;
  9891. u8 *pbuf = NULL;
  9892. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  9893. pbuf = rtw_malloc(sizeof(l2_msg_t));
  9894. if(pbuf)
  9895. {
  9896. copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length);
  9897. //_rtw_memcpy(pbuf, wrqu->data.pointer, wrqu->data.length);
  9898. if( wrqu->data.flags == 0 )
  9899. intel_widi_wk_cmd(padapter, INTEL_WIDI_ISSUE_PROB_WK, pbuf);
  9900. else if( wrqu->data.flags == 1 )
  9901. rtw_set_wfd_rds_sink_info( padapter, (l2_msg_t *)pbuf );
  9902. }
  9903. return ret;
  9904. }
  9905. #endif // CONFIG_INTEL_WIDI
  9906. #ifdef CONFIG_RTL8723A
  9907. #include <rtl8723a_hal.h>
  9908. //extern u8 _InitPowerOn(PADAPTER padapter);
  9909. extern s32 FillH2CCmd(PADAPTER padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer);
  9910. #endif
  9911. #ifdef CONFIG_RTL8723B
  9912. #include <rtl8723b_hal.h>
  9913. //extern u8 _InitPowerOn(PADAPTER padapter);
  9914. extern s32 FillH2CCmd8723B(PADAPTER padapter, u8 ElementID, u32 CmdLen, u8 *pCmdBuffer);
  9915. #endif
  9916. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  9917. #ifdef CONFIG_RTL8723A
  9918. extern void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9919. #define cal_txdesc_chksum rtl8723a_cal_txdesc_chksum
  9920. extern void rtl8723a_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9921. #define fill_default_txdesc rtl8723a_fill_default_txdesc
  9922. #endif
  9923. #if defined(CONFIG_RTL8188E)
  9924. #include <rtl8188e_hal.h>
  9925. extern void rtl8188e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9926. #define cal_txdesc_chksum rtl8188e_cal_txdesc_chksum
  9927. #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
  9928. extern void rtl8188es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9929. #define fill_default_txdesc rtl8188es_fill_default_txdesc
  9930. #endif // CONFIG_SDIO_HCI
  9931. #endif // CONFIG_RTL8188E
  9932. #if defined(CONFIG_RTL8723B)
  9933. extern void rtl8723b_cal_txdesc_chksum(struct tx_desc *ptxdesc);
  9934. #define cal_txdesc_chksum rtl8723b_cal_txdesc_chksum
  9935. extern void rtl8723b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
  9936. #define fill_default_txdesc rtl8723b_fill_default_txdesc
  9937. #endif // CONFIG_RTL8723B
  9938. static s32 initLoopback(PADAPTER padapter)
  9939. {
  9940. PLOOPBACKDATA ploopback;
  9941. if (padapter->ploopback == NULL) {
  9942. ploopback = (PLOOPBACKDATA)rtw_zmalloc(sizeof(LOOPBACKDATA));
  9943. if (ploopback == NULL) return -ENOMEM;
  9944. _rtw_init_sema(&ploopback->sema, 0);
  9945. ploopback->bstop = _TRUE;
  9946. ploopback->cnt = 0;
  9947. ploopback->size = 300;
  9948. _rtw_memset(ploopback->msg, 0, sizeof(ploopback->msg));
  9949. padapter->ploopback = ploopback;
  9950. }
  9951. return 0;
  9952. }
  9953. static void freeLoopback(PADAPTER padapter)
  9954. {
  9955. PLOOPBACKDATA ploopback;
  9956. ploopback = padapter->ploopback;
  9957. if (ploopback) {
  9958. rtw_mfree((u8*)ploopback, sizeof(LOOPBACKDATA));
  9959. padapter->ploopback = NULL;
  9960. }
  9961. }
  9962. static s32 initpseudoadhoc(PADAPTER padapter)
  9963. {
  9964. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  9965. s32 err;
  9966. networkType = Ndis802_11IBSS;
  9967. err = rtw_set_802_11_infrastructure_mode(padapter, networkType);
  9968. if (err == _FALSE) return _FAIL;
  9969. err = rtw_setopmode_cmd(padapter, networkType);
  9970. if (err == _FAIL) return _FAIL;
  9971. return _SUCCESS;
  9972. }
  9973. static s32 createpseudoadhoc(PADAPTER padapter)
  9974. {
  9975. NDIS_802_11_AUTHENTICATION_MODE authmode;
  9976. struct mlme_priv *pmlmepriv;
  9977. NDIS_802_11_SSID *passoc_ssid;
  9978. WLAN_BSSID_EX *pdev_network;
  9979. u8 *pibss;
  9980. u8 ssid[] = "pseduo_ad-hoc";
  9981. s32 err;
  9982. _irqL irqL;
  9983. pmlmepriv = &padapter->mlmepriv;
  9984. authmode = Ndis802_11AuthModeOpen;
  9985. err = rtw_set_802_11_authentication_mode(padapter, authmode);
  9986. if (err == _FALSE) return _FAIL;
  9987. passoc_ssid = &pmlmepriv->assoc_ssid;
  9988. _rtw_memset(passoc_ssid, 0, sizeof(NDIS_802_11_SSID));
  9989. passoc_ssid->SsidLength = sizeof(ssid) - 1;
  9990. _rtw_memcpy(passoc_ssid->Ssid, ssid, passoc_ssid->SsidLength);
  9991. pdev_network = &padapter->registrypriv.dev_network;
  9992. pibss = padapter->registrypriv.dev_network.MacAddress;
  9993. _rtw_memcpy(&pdev_network->Ssid, passoc_ssid, sizeof(NDIS_802_11_SSID));
  9994. rtw_update_registrypriv_dev_network(padapter);
  9995. rtw_generate_random_ibss(pibss);
  9996. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  9997. pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
  9998. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  9999. #if 0
  10000. err = rtw_createbss_cmd(padapter);
  10001. if (err == _FAIL) return _FAIL;
  10002. #else
  10003. {
  10004. struct wlan_network *pcur_network;
  10005. struct sta_info *psta;
  10006. //3 create a new psta
  10007. pcur_network = &pmlmepriv->cur_network;
  10008. //clear psta in the cur_network, if any
  10009. psta = rtw_get_stainfo(&padapter->stapriv, pcur_network->network.MacAddress);
  10010. if (psta) rtw_free_stainfo(padapter, psta);
  10011. psta = rtw_alloc_stainfo(&padapter->stapriv, pibss);
  10012. if (psta == NULL) return _FAIL;
  10013. //3 join psudo AdHoc
  10014. pcur_network->join_res = 1;
  10015. pcur_network->aid = psta->aid = 1;
  10016. _rtw_memcpy(&pcur_network->network, pdev_network, get_WLAN_BSSID_EX_sz(pdev_network));
  10017. // set msr to WIFI_FW_ADHOC_STATE
  10018. #if 0
  10019. Set_NETYPE0_MSR(padapter, WIFI_FW_ADHOC_STATE);
  10020. #else
  10021. {
  10022. u8 val8;
  10023. val8 = rtw_read8(padapter, MSR);
  10024. val8 &= 0xFC; // clear NETYPE0
  10025. val8 |= WIFI_FW_ADHOC_STATE & 0x3;
  10026. rtw_write8(padapter, MSR, val8);
  10027. }
  10028. #endif
  10029. }
  10030. #endif
  10031. return _SUCCESS;
  10032. }
  10033. static struct xmit_frame* createloopbackpkt(PADAPTER padapter, u32 size)
  10034. {
  10035. struct xmit_priv *pxmitpriv;
  10036. struct xmit_frame *pframe;
  10037. struct xmit_buf *pxmitbuf;
  10038. struct pkt_attrib *pattrib;
  10039. struct tx_desc *desc;
  10040. u8 *pkt_start, *pkt_end, *ptr;
  10041. struct rtw_ieee80211_hdr *hdr;
  10042. s32 bmcast;
  10043. _irqL irqL;
  10044. if ((TXDESC_SIZE + WLANHDR_OFFSET + size) > MAX_XMITBUF_SZ) return NULL;
  10045. pxmitpriv = &padapter->xmitpriv;
  10046. pframe = NULL;
  10047. //2 1. allocate xmit frame
  10048. pframe = rtw_alloc_xmitframe(pxmitpriv);
  10049. if (pframe == NULL) return NULL;
  10050. pframe->padapter = padapter;
  10051. //2 2. allocate xmit buffer
  10052. _enter_critical_bh(&pxmitpriv->lock, &irqL);
  10053. pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
  10054. _exit_critical_bh(&pxmitpriv->lock, &irqL);
  10055. if (pxmitbuf == NULL) {
  10056. rtw_free_xmitframe(pxmitpriv, pframe);
  10057. return NULL;
  10058. }
  10059. pframe->pxmitbuf = pxmitbuf;
  10060. pframe->buf_addr = pxmitbuf->pbuf;
  10061. pxmitbuf->priv_data = pframe;
  10062. //2 3. update_attrib()
  10063. pattrib = &pframe->attrib;
  10064. // init xmitframe attribute
  10065. _rtw_memset(pattrib, 0, sizeof(struct pkt_attrib));
  10066. pattrib->ether_type = 0x8723;
  10067. _rtw_memcpy(pattrib->src, padapter->eeprompriv.mac_addr, ETH_ALEN);
  10068. _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
  10069. _rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
  10070. _rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
  10071. // pattrib->dhcp_pkt = 0;
  10072. // pattrib->pktlen = 0;
  10073. pattrib->ack_policy = 0;
  10074. // pattrib->pkt_hdrlen = ETH_HLEN;
  10075. pattrib->hdrlen = WLAN_HDR_A3_LEN;
  10076. pattrib->subtype = WIFI_DATA;
  10077. pattrib->priority = 0;
  10078. pattrib->qsel = pattrib->priority;
  10079. // do_queue_select(padapter, pattrib);
  10080. pattrib->nr_frags = 1;
  10081. pattrib->encrypt = 0;
  10082. pattrib->bswenc = _FALSE;
  10083. pattrib->qos_en = _FALSE;
  10084. bmcast = IS_MCAST(pattrib->ra);
  10085. if (bmcast) {
  10086. pattrib->mac_id = 1;
  10087. pattrib->psta = rtw_get_bcmc_stainfo(padapter);
  10088. } else {
  10089. pattrib->mac_id = 0;
  10090. pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
  10091. }
  10092. pattrib->pktlen = size;
  10093. pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
  10094. //2 4. fill TX descriptor
  10095. desc = (struct tx_desc*)pframe->buf_addr;
  10096. _rtw_memset(desc, 0, TXDESC_SIZE);
  10097. fill_default_txdesc(pframe, (u8*)desc);
  10098. // Hw set sequence number
  10099. ((PTXDESC)desc)->hwseq_en = 0; // HWSEQ_EN, 0:disable, 1:enable
  10100. // ((PTXDESC)desc)->hwseq_sel = 0; // HWSEQ_SEL
  10101. ((PTXDESC)desc)->disdatafb = 1;
  10102. // convert to little endian
  10103. desc->txdw0 = cpu_to_le32(desc->txdw0);
  10104. desc->txdw1 = cpu_to_le32(desc->txdw1);
  10105. desc->txdw2 = cpu_to_le32(desc->txdw2);
  10106. desc->txdw3 = cpu_to_le32(desc->txdw3);
  10107. desc->txdw4 = cpu_to_le32(desc->txdw4);
  10108. desc->txdw5 = cpu_to_le32(desc->txdw5);
  10109. desc->txdw6 = cpu_to_le32(desc->txdw6);
  10110. desc->txdw7 = cpu_to_le32(desc->txdw7);
  10111. #ifdef CONFIG_PCI_HCI
  10112. desc->txdw8 = cpu_to_le32(desc->txdw8);
  10113. desc->txdw9 = cpu_to_le32(desc->txdw9);
  10114. desc->txdw10 = cpu_to_le32(desc->txdw10);
  10115. desc->txdw11 = cpu_to_le32(desc->txdw11);
  10116. desc->txdw12 = cpu_to_le32(desc->txdw12);
  10117. desc->txdw13 = cpu_to_le32(desc->txdw13);
  10118. desc->txdw14 = cpu_to_le32(desc->txdw14);
  10119. desc->txdw15 = cpu_to_le32(desc->txdw15);
  10120. #endif
  10121. cal_txdesc_chksum(desc);
  10122. //2 5. coalesce
  10123. pkt_start = pframe->buf_addr + TXDESC_SIZE;
  10124. pkt_end = pkt_start + pattrib->last_txcmdsz;
  10125. //3 5.1. make wlan header, make_wlanhdr()
  10126. hdr = (struct rtw_ieee80211_hdr *)pkt_start;
  10127. SetFrameSubType(&hdr->frame_ctl, pattrib->subtype);
  10128. _rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); // DA
  10129. _rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); // SA
  10130. _rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); // RA, BSSID
  10131. //3 5.2. make payload
  10132. ptr = pkt_start + pattrib->hdrlen;
  10133. get_random_bytes(ptr, pkt_end - ptr);
  10134. pxmitbuf->len = TXDESC_SIZE + pattrib->last_txcmdsz;
  10135. pxmitbuf->ptail += pxmitbuf->len;
  10136. return pframe;
  10137. }
  10138. static void freeloopbackpkt(PADAPTER padapter, struct xmit_frame *pframe)
  10139. {
  10140. struct xmit_priv *pxmitpriv;
  10141. struct xmit_buf *pxmitbuf;
  10142. pxmitpriv = &padapter->xmitpriv;
  10143. pxmitbuf = pframe->pxmitbuf;
  10144. rtw_free_xmitframe(pxmitpriv, pframe);
  10145. rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
  10146. }
  10147. static void printdata(u8 *pbuf, u32 len)
  10148. {
  10149. u32 i, val;
  10150. for (i = 0; (i+4) <= len; i+=4) {
  10151. printk("%08X", *(u32*)(pbuf + i));
  10152. if ((i+4) & 0x1F) printk(" ");
  10153. else printk("\n");
  10154. }
  10155. if (i < len)
  10156. {
  10157. #ifdef CONFIG_BIG_ENDIAN
  10158. for (; i < len, i++)
  10159. printk("%02X", pbuf+i);
  10160. #else // CONFIG_LITTLE_ENDIAN
  10161. #if 0
  10162. val = 0;
  10163. _rtw_memcpy(&val, pbuf + i, len - i);
  10164. printk("%8X", val);
  10165. #else
  10166. u8 str[9];
  10167. u8 n;
  10168. val = 0;
  10169. n = len - i;
  10170. _rtw_memcpy(&val, pbuf+i, n);
  10171. sprintf(str, "%08X", val);
  10172. n = (4 - n) * 2;
  10173. printk("%8s", str+n);
  10174. #endif
  10175. #endif // CONFIG_LITTLE_ENDIAN
  10176. }
  10177. printk("\n");
  10178. }
  10179. static u8 pktcmp(PADAPTER padapter, u8 *txbuf, u32 txsz, u8 *rxbuf, u32 rxsz)
  10180. {
  10181. PHAL_DATA_TYPE phal;
  10182. struct recv_stat *prxstat;
  10183. struct recv_stat report;
  10184. PRXREPORT prxreport;
  10185. u32 drvinfosize;
  10186. u32 rxpktsize;
  10187. u8 fcssize;
  10188. u8 ret = _FALSE;
  10189. prxstat = (struct recv_stat*)rxbuf;
  10190. report.rxdw0 = le32_to_cpu(prxstat->rxdw0);
  10191. report.rxdw1 = le32_to_cpu(prxstat->rxdw1);
  10192. report.rxdw2 = le32_to_cpu(prxstat->rxdw2);
  10193. report.rxdw3 = le32_to_cpu(prxstat->rxdw3);
  10194. report.rxdw4 = le32_to_cpu(prxstat->rxdw4);
  10195. report.rxdw5 = le32_to_cpu(prxstat->rxdw5);
  10196. prxreport = (PRXREPORT)&report;
  10197. drvinfosize = prxreport->drvinfosize << 3;
  10198. rxpktsize = prxreport->pktlen;
  10199. phal = GET_HAL_DATA(padapter);
  10200. if (phal->ReceiveConfig & RCR_APPFCS) fcssize = IEEE80211_FCS_LEN;
  10201. else fcssize = 0;
  10202. if ((txsz - TXDESC_SIZE) != (rxpktsize - fcssize)) {
  10203. DBG_8192C("%s: ERROR! size not match tx/rx=%d/%d !\n",
  10204. __func__, txsz - TXDESC_SIZE, rxpktsize - fcssize);
  10205. ret = _FALSE;
  10206. } else {
  10207. ret = _rtw_memcmp(txbuf + TXDESC_SIZE,\
  10208. rxbuf + RXDESC_SIZE + drvinfosize,\
  10209. txsz - TXDESC_SIZE);
  10210. if (ret == _FALSE) {
  10211. DBG_8192C("%s: ERROR! pkt content mismatch!\n", __func__);
  10212. }
  10213. }
  10214. if (ret == _FALSE)
  10215. {
  10216. DBG_8192C("\n%s: TX PKT total=%d, desc=%d, content=%d\n",
  10217. __func__, txsz, TXDESC_SIZE, txsz - TXDESC_SIZE);
  10218. DBG_8192C("%s: TX DESC size=%d\n", __func__, TXDESC_SIZE);
  10219. printdata(txbuf, TXDESC_SIZE);
  10220. DBG_8192C("%s: TX content size=%d\n", __func__, txsz - TXDESC_SIZE);
  10221. printdata(txbuf + TXDESC_SIZE, txsz - TXDESC_SIZE);
  10222. DBG_8192C("\n%s: RX PKT read=%d offset=%d(%d,%d) content=%d\n",
  10223. __func__, rxsz, RXDESC_SIZE + drvinfosize, RXDESC_SIZE, drvinfosize, rxpktsize);
  10224. if (rxpktsize != 0)
  10225. {
  10226. DBG_8192C("%s: RX DESC size=%d\n", __func__, RXDESC_SIZE);
  10227. printdata(rxbuf, RXDESC_SIZE);
  10228. DBG_8192C("%s: RX drvinfo size=%d\n", __func__, drvinfosize);
  10229. printdata(rxbuf + RXDESC_SIZE, drvinfosize);
  10230. DBG_8192C("%s: RX content size=%d\n", __func__, rxpktsize);
  10231. printdata(rxbuf + RXDESC_SIZE + drvinfosize, rxpktsize);
  10232. } else {
  10233. DBG_8192C("%s: RX data size=%d\n", __func__, rxsz);
  10234. printdata(rxbuf, rxsz);
  10235. }
  10236. }
  10237. return ret;
  10238. }
  10239. thread_return lbk_thread(thread_context context)
  10240. {
  10241. s32 err;
  10242. PADAPTER padapter;
  10243. PLOOPBACKDATA ploopback;
  10244. struct xmit_frame *pxmitframe;
  10245. u32 cnt, ok, fail, headerlen;
  10246. u32 pktsize;
  10247. u32 ff_hwaddr;
  10248. padapter = (PADAPTER)context;
  10249. ploopback = padapter->ploopback;
  10250. if (ploopback == NULL) return -1;
  10251. cnt = 0;
  10252. ok = 0;
  10253. fail = 0;
  10254. daemonize("%s", "RTW_LBK_THREAD");
  10255. allow_signal(SIGTERM);
  10256. do {
  10257. if (ploopback->size == 0) {
  10258. get_random_bytes(&pktsize, 4);
  10259. pktsize = (pktsize % 1535) + 1; // 1~1535
  10260. } else
  10261. pktsize = ploopback->size;
  10262. pxmitframe = createloopbackpkt(padapter, pktsize);
  10263. if (pxmitframe == NULL) {
  10264. sprintf(ploopback->msg, "loopback FAIL! 3. create Packet FAIL!");
  10265. break;
  10266. }
  10267. ploopback->txsize = TXDESC_SIZE + pxmitframe->attrib.last_txcmdsz;
  10268. _rtw_memcpy(ploopback->txbuf, pxmitframe->buf_addr, ploopback->txsize);
  10269. ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
  10270. cnt++;
  10271. DBG_8192C("%s: wirte port cnt=%d size=%d\n", __func__, cnt, ploopback->txsize);
  10272. pxmitframe->pxmitbuf->pdata = ploopback->txbuf;
  10273. rtw_write_port(padapter, ff_hwaddr, ploopback->txsize, (u8 *)pxmitframe->pxmitbuf);
  10274. // wait for rx pkt
  10275. _rtw_down_sema(&ploopback->sema);
  10276. err = pktcmp(padapter, ploopback->txbuf, ploopback->txsize, ploopback->rxbuf, ploopback->rxsize);
  10277. if (err == _TRUE)
  10278. ok++;
  10279. else
  10280. fail++;
  10281. ploopback->txsize = 0;
  10282. _rtw_memset(ploopback->txbuf, 0, 0x8000);
  10283. ploopback->rxsize = 0;
  10284. _rtw_memset(ploopback->rxbuf, 0, 0x8000);
  10285. freeloopbackpkt(padapter, pxmitframe);
  10286. pxmitframe = NULL;
  10287. if (signal_pending(current)) {
  10288. flush_signals(current);
  10289. }
  10290. if ((ploopback->bstop == _TRUE) ||
  10291. ((ploopback->cnt != 0) && (ploopback->cnt == cnt)))
  10292. {
  10293. u32 ok_rate, fail_rate, all;
  10294. all = cnt;
  10295. ok_rate = (ok*100)/all;
  10296. fail_rate = (fail*100)/all;
  10297. sprintf(ploopback->msg,\
  10298. "loopback result: ok=%d%%(%d/%d),error=%d%%(%d/%d)",\
  10299. ok_rate, ok, all, fail_rate, fail, all);
  10300. break;
  10301. }
  10302. } while (1);
  10303. ploopback->bstop = _TRUE;
  10304. thread_exit();
  10305. }
  10306. static void loopbackTest(PADAPTER padapter, u32 cnt, u32 size, u8* pmsg)
  10307. {
  10308. PLOOPBACKDATA ploopback;
  10309. u32 len;
  10310. s32 err;
  10311. ploopback = padapter->ploopback;
  10312. if (ploopback)
  10313. {
  10314. if (ploopback->bstop == _FALSE) {
  10315. ploopback->bstop = _TRUE;
  10316. _rtw_up_sema(&ploopback->sema);
  10317. }
  10318. len = 0;
  10319. do {
  10320. len = strlen(ploopback->msg);
  10321. if (len) break;
  10322. rtw_msleep_os(1);
  10323. } while (1);
  10324. _rtw_memcpy(pmsg, ploopback->msg, len+1);
  10325. freeLoopback(padapter);
  10326. return;
  10327. }
  10328. // disable dynamic algorithm
  10329. {
  10330. u32 DMFlag = DYNAMIC_FUNC_DISABLE;
  10331. rtw_hal_get_hwreg(padapter, HW_VAR_DM_FLAG, (u8*)&DMFlag);
  10332. }
  10333. // create pseudo ad-hoc connection
  10334. err = initpseudoadhoc(padapter);
  10335. if (err == _FAIL) {
  10336. sprintf(pmsg, "loopback FAIL! 1.1 init ad-hoc FAIL!");
  10337. return;
  10338. }
  10339. err = createpseudoadhoc(padapter);
  10340. if (err == _FAIL) {
  10341. sprintf(pmsg, "loopback FAIL! 1.2 create ad-hoc master FAIL!");
  10342. return;
  10343. }
  10344. err = initLoopback(padapter);
  10345. if (err) {
  10346. sprintf(pmsg, "loopback FAIL! 2. init FAIL! error code=%d", err);
  10347. return;
  10348. }
  10349. ploopback = padapter->ploopback;
  10350. ploopback->bstop = _FALSE;
  10351. ploopback->cnt = cnt;
  10352. ploopback->size = size;
  10353. ploopback->lbkthread = kthread_run(lbk_thread, padapter, "RTW_LBK_THREAD");
  10354. if (IS_ERR(padapter->lbkthread))
  10355. {
  10356. freeLoopback(padapter);
  10357. sprintf(pmsg, "loopback start FAIL! cnt=%d", cnt);
  10358. return;
  10359. }
  10360. sprintf(pmsg, "loopback start! cnt=%d", cnt);
  10361. }
  10362. #endif // CONFIG_MAC_LOOPBACK_DRIVER
  10363. static int rtw_test(
  10364. struct net_device *dev,
  10365. struct iw_request_info *info,
  10366. union iwreq_data *wrqu, char *extra)
  10367. {
  10368. u32 len;
  10369. u8 *pbuf, *pch;
  10370. char *ptmp;
  10371. u8 *delim = ",";
  10372. PADAPTER padapter = rtw_netdev_priv(dev);
  10373. DBG_871X("+%s\n", __func__);
  10374. len = wrqu->data.length;
  10375. pbuf = (u8*)rtw_zmalloc(len);
  10376. if (pbuf == NULL) {
  10377. DBG_871X("%s: no memory!\n", __func__);
  10378. return -ENOMEM;
  10379. }
  10380. if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
  10381. rtw_mfree(pbuf, len);
  10382. DBG_871X("%s: copy from user fail!\n", __func__);
  10383. return -EFAULT;
  10384. }
  10385. DBG_871X("%s: string=\"%s\"\n", __func__, pbuf);
  10386. ptmp = (char*)pbuf;
  10387. pch = strsep(&ptmp, delim);
  10388. if ((pch == NULL) || (strlen(pch) == 0)) {
  10389. rtw_mfree(pbuf, len);
  10390. DBG_871X("%s: parameter error(level 1)!\n", __func__);
  10391. return -EFAULT;
  10392. }
  10393. #ifdef CONFIG_MAC_LOOPBACK_DRIVER
  10394. if (strcmp(pch, "loopback") == 0)
  10395. {
  10396. s32 cnt = 0;
  10397. u32 size = 64;
  10398. pch = strsep(&ptmp, delim);
  10399. if ((pch == NULL) || (strlen(pch) == 0)) {
  10400. rtw_mfree(pbuf, len);
  10401. DBG_871X("%s: parameter error(level 2)!\n", __func__);
  10402. return -EFAULT;
  10403. }
  10404. sscanf(pch, "%d", &cnt);
  10405. DBG_871X("%s: loopback cnt=%d\n", __func__, cnt);
  10406. pch = strsep(&ptmp, delim);
  10407. if ((pch == NULL) || (strlen(pch) == 0)) {
  10408. rtw_mfree(pbuf, len);
  10409. DBG_871X("%s: parameter error(level 2)!\n", __func__);
  10410. return -EFAULT;
  10411. }
  10412. sscanf(pch, "%d", &size);
  10413. DBG_871X("%s: loopback size=%d\n", __func__, size);
  10414. loopbackTest(padapter, cnt, size, extra);
  10415. wrqu->data.length = strlen(extra) + 1;
  10416. rtw_mfree(pbuf, len);
  10417. return 0;
  10418. }
  10419. #endif
  10420. #if (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
  10421. #if 0
  10422. if (strcmp(pch, "poweron") == 0)
  10423. {
  10424. s32 ret;
  10425. ret = _InitPowerOn(padapter);
  10426. DBG_871X("%s: power on %s\n", __func__, (_FAIL==ret) ? "FAIL!":"OK.");
  10427. sprintf(extra, "Power ON %s", (_FAIL==ret) ? "FAIL!":"OK.");
  10428. wrqu->data.length = strlen(extra) + 1;
  10429. rtw_mfree(pbuf, len);
  10430. return 0;
  10431. }
  10432. if (strcmp(pch, "dlfw") == 0)
  10433. {
  10434. s32 ret;
  10435. ret = rtl8723a_FirmwareDownload(padapter);
  10436. DBG_871X("%s: download FW %s\n", __func__, (_FAIL==ret) ? "FAIL!":"OK.");
  10437. sprintf(extra, "download FW %s", (_FAIL==ret) ? "FAIL!":"OK.");
  10438. wrqu->data.length = strlen(extra) + 1;
  10439. rtw_mfree(pbuf, len);
  10440. return 0;
  10441. }
  10442. #endif
  10443. #ifdef CONFIG_BT_COEXIST
  10444. #define GET_BT_INFO(padapter) (&GET_HAL_DATA(padapter)->BtInfo)
  10445. if (strcmp(pch, "btdbg") == 0)
  10446. {
  10447. DBG_8192C("===== BT debug information Start =====\n");
  10448. DBG_8192C("WIFI status=\n");
  10449. DBG_8192C("BT status=\n");
  10450. DBG_8192C("BT profile=\n");
  10451. DBG_8192C("WIFI RSSI=%d\n", GET_HAL_DATA(padapter)->dmpriv.UndecoratedSmoothedPWDB);
  10452. DBG_8192C("BT RSSI=\n");
  10453. DBG_8192C("coex mechanism=\n");
  10454. DBG_8192C("BT counter TX/RX=/\n");
  10455. DBG_8192C("0x880=0x%08x\n", rtw_read32(padapter, 0x880));
  10456. DBG_8192C("0x6c0=0x%08x\n", rtw_read32(padapter, 0x6c0));
  10457. DBG_8192C("0x6c4=0x%08x\n", rtw_read32(padapter, 0x6c4));
  10458. DBG_8192C("0x6c8=0x%08x\n", rtw_read32(padapter, 0x6c8));
  10459. DBG_8192C("0x6cc=0x%08x\n", rtw_read32(padapter, 0x6cc));
  10460. DBG_8192C("0x778=0x%08x\n", rtw_read32(padapter, 0x778));
  10461. DBG_8192C("0xc50=0x%08x\n", rtw_read32(padapter, 0xc50));
  10462. BT_DisplayBtCoexInfo(padapter);
  10463. DBG_8192C("===== BT debug information End =====\n");
  10464. }
  10465. if (strcmp(pch, "bton") == 0)
  10466. {
  10467. PBT30Info pBTInfo = GET_BT_INFO(padapter);
  10468. PBT_MGNT pBtMgnt = &pBTInfo->BtMgnt;
  10469. pBtMgnt->ExtConfig.bManualControl = _FALSE;
  10470. }
  10471. if (strcmp(pch, "btoff") == 0)
  10472. {
  10473. PBT30Info pBTInfo = GET_BT_INFO(padapter);
  10474. PBT_MGNT pBtMgnt = &pBTInfo->BtMgnt;
  10475. pBtMgnt->ExtConfig.bManualControl = _TRUE;
  10476. }
  10477. #endif // CONFIG_BT_COEXIST
  10478. if (strcmp(pch, "h2c") == 0)
  10479. {
  10480. u8 param[6];
  10481. u8 count = 0;
  10482. u32 tmp;
  10483. u8 i;
  10484. u32 pos;
  10485. s32 ret;
  10486. do {
  10487. pch = strsep(&ptmp, delim);
  10488. if ((pch == NULL) || (strlen(pch) == 0))
  10489. break;
  10490. sscanf(pch, "%x", &tmp);
  10491. param[count++] = (u8)tmp;
  10492. } while (count < 6);
  10493. if (count == 0) {
  10494. rtw_mfree(pbuf, len);
  10495. DBG_8192C("%s: parameter error(level 2)!\n", __func__);
  10496. return -EFAULT;
  10497. }
  10498. #ifdef CONFIG_RTL8723A
  10499. ret = FillH2CCmd(padapter, param[0], count-1, &param[1]);
  10500. #elif defined(CONFIG_RTL8723B)
  10501. ret = FillH2CCmd8723B(padapter, param[0], count-1, &param[1]);
  10502. #endif
  10503. pos = sprintf(extra, "H2C ID=%02x content=", param[0]);
  10504. for (i=1; i<count; i++) {
  10505. pos += sprintf(extra+pos, "%02x,", param[i]);
  10506. }
  10507. extra[pos] = 0;
  10508. pos--;
  10509. pos += sprintf(extra+pos, " %s", ret==_FAIL?"FAIL":"OK");
  10510. wrqu->data.length = strlen(extra) + 1;
  10511. }
  10512. #endif // CONFIG_RTL8723A
  10513. rtw_mfree(pbuf, len);
  10514. return 0;
  10515. }
  10516. static iw_handler rtw_handlers[] =
  10517. {
  10518. NULL, /* SIOCSIWCOMMIT */
  10519. rtw_wx_get_name, /* SIOCGIWNAME */
  10520. dummy, /* SIOCSIWNWID */
  10521. dummy, /* SIOCGIWNWID */
  10522. rtw_wx_set_freq, /* SIOCSIWFREQ */
  10523. rtw_wx_get_freq, /* SIOCGIWFREQ */
  10524. rtw_wx_set_mode, /* SIOCSIWMODE */
  10525. rtw_wx_get_mode, /* SIOCGIWMODE */
  10526. dummy, /* SIOCSIWSENS */
  10527. rtw_wx_get_sens, /* SIOCGIWSENS */
  10528. NULL, /* SIOCSIWRANGE */
  10529. rtw_wx_get_range, /* SIOCGIWRANGE */
  10530. rtw_wx_set_priv, /* SIOCSIWPRIV */
  10531. NULL, /* SIOCGIWPRIV */
  10532. NULL, /* SIOCSIWSTATS */
  10533. NULL, /* SIOCGIWSTATS */
  10534. dummy, /* SIOCSIWSPY */
  10535. dummy, /* SIOCGIWSPY */
  10536. NULL, /* SIOCGIWTHRSPY */
  10537. NULL, /* SIOCWIWTHRSPY */
  10538. rtw_wx_set_wap, /* SIOCSIWAP */
  10539. rtw_wx_get_wap, /* SIOCGIWAP */
  10540. rtw_wx_set_mlme, /* request MLME operation; uses struct iw_mlme */
  10541. dummy, /* SIOCGIWAPLIST -- depricated */
  10542. rtw_wx_set_scan, /* SIOCSIWSCAN */
  10543. rtw_wx_get_scan, /* SIOCGIWSCAN */
  10544. rtw_wx_set_essid, /* SIOCSIWESSID */
  10545. rtw_wx_get_essid, /* SIOCGIWESSID */
  10546. dummy, /* SIOCSIWNICKN */
  10547. rtw_wx_get_nick, /* SIOCGIWNICKN */
  10548. NULL, /* -- hole -- */
  10549. NULL, /* -- hole -- */
  10550. rtw_wx_set_rate, /* SIOCSIWRATE */
  10551. rtw_wx_get_rate, /* SIOCGIWRATE */
  10552. rtw_wx_set_rts, /* SIOCSIWRTS */
  10553. rtw_wx_get_rts, /* SIOCGIWRTS */
  10554. rtw_wx_set_frag, /* SIOCSIWFRAG */
  10555. rtw_wx_get_frag, /* SIOCGIWFRAG */
  10556. dummy, /* SIOCSIWTXPOW */
  10557. dummy, /* SIOCGIWTXPOW */
  10558. dummy, /* SIOCSIWRETRY */
  10559. rtw_wx_get_retry, /* SIOCGIWRETRY */
  10560. rtw_wx_set_enc, /* SIOCSIWENCODE */
  10561. rtw_wx_get_enc, /* SIOCGIWENCODE */
  10562. dummy, /* SIOCSIWPOWER */
  10563. rtw_wx_get_power, /* SIOCGIWPOWER */
  10564. NULL, /*---hole---*/
  10565. NULL, /*---hole---*/
  10566. rtw_wx_set_gen_ie, /* SIOCSIWGENIE */
  10567. NULL, /* SIOCGWGENIE */
  10568. rtw_wx_set_auth, /* SIOCSIWAUTH */
  10569. NULL, /* SIOCGIWAUTH */
  10570. rtw_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
  10571. NULL, /* SIOCGIWENCODEEXT */
  10572. rtw_wx_set_pmkid, /* SIOCSIWPMKSA */
  10573. NULL, /*---hole---*/
  10574. };
  10575. #if 0
  10576. //defined(CONFIG_MP_INCLUDED) && defined(CONFIG_MP_IWPRIV_SUPPORT)
  10577. static const struct iw_priv_args rtw_private_args[] =
  10578. {
  10579. { SIOCIWFIRSTPRIV + 0x00, IW_PRIV_TYPE_CHAR | 1024, 0 , ""}, //set
  10580. { SIOCIWFIRSTPRIV + 0x01, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , ""},//get
  10581. /* --- sub-ioctls definitions --- */
  10582. { MP_START , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_start" }, //set
  10583. { MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara" },//get
  10584. { MP_STOP , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_stop" }, //set
  10585. { MP_CHANNEL , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel" },//get
  10586. { MP_BANDWIDTH , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_bandwidth"}, //set
  10587. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },//get
  10588. { MP_RESET_STATS , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_reset_stats"},
  10589. { MP_QUERY , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "mp_query"}, //get
  10590. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10591. { READ_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg" },
  10592. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10593. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  10594. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10595. { READ_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf" },
  10596. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10597. { MP_PSD , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
  10598. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10599. { MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump" },
  10600. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10601. { MP_TXPOWER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
  10602. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10603. { MP_ANT_TX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
  10604. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10605. { MP_ANT_RX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
  10606. { WRITE_REG, IW_PRIV_TYPE_CHAR | 1024, 0,"write_reg"},//set
  10607. { MP_NULL, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "NULL" },
  10608. { WRITE_RF, IW_PRIV_TYPE_CHAR | 1024, 0,"write_rf"},//set
  10609. { MP_NULL, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "NULL" },
  10610. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10611. { MP_CTX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
  10612. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10613. { MP_ARX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
  10614. { MP_NULL, IW_PRIV_TYPE_CHAR | 128, 0,"NULL"},//set
  10615. { MP_THER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
  10616. { EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, 0, "efuse_set" },
  10617. { EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get" },
  10618. { MP_PWRTRK , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_pwrtrk"},
  10619. { MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery" },
  10620. { MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"}, // mp_ioctl
  10621. { MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_setrfpath" },
  10622. #ifdef CONFIG_RTL8723A
  10623. { MP_SetBT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setbt" },
  10624. #endif
  10625. { SIOCIWFIRSTPRIV + 0x02, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "test"},//set
  10626. };
  10627. static iw_handler rtw_private_handler[] =
  10628. {
  10629. rtw_mp_set,
  10630. rtw_mp_get,
  10631. };
  10632. #else // not inlucde MP
  10633. static const struct iw_priv_args rtw_private_args[] = {
  10634. {
  10635. SIOCIWFIRSTPRIV + 0x0,
  10636. IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
  10637. },
  10638. {
  10639. SIOCIWFIRSTPRIV + 0x1,
  10640. IW_PRIV_TYPE_CHAR | 0x7FF,
  10641. IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
  10642. },
  10643. {
  10644. SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
  10645. },
  10646. {
  10647. SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
  10648. },
  10649. {
  10650. SIOCIWFIRSTPRIV + 0x4,
  10651. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
  10652. },
  10653. {
  10654. SIOCIWFIRSTPRIV + 0x5,
  10655. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
  10656. },
  10657. {
  10658. SIOCIWFIRSTPRIV + 0x6,
  10659. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
  10660. },
  10661. //for PLATFORM_MT53XX
  10662. {
  10663. SIOCIWFIRSTPRIV + 0x7,
  10664. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "get_sensitivity"
  10665. },
  10666. {
  10667. SIOCIWFIRSTPRIV + 0x8,
  10668. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_prob_req_ie"
  10669. },
  10670. {
  10671. SIOCIWFIRSTPRIV + 0x9,
  10672. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_assoc_req_ie"
  10673. },
  10674. //for RTK_DMP_PLATFORM
  10675. {
  10676. SIOCIWFIRSTPRIV + 0xA,
  10677. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
  10678. },
  10679. {
  10680. SIOCIWFIRSTPRIV + 0xB,
  10681. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
  10682. },
  10683. {
  10684. SIOCIWFIRSTPRIV + 0xC,
  10685. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
  10686. },
  10687. {
  10688. SIOCIWFIRSTPRIV + 0xD,
  10689. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
  10690. },
  10691. #if 0
  10692. {
  10693. SIOCIWFIRSTPRIV + 0xE,0,0, "wowlan_ctrl"
  10694. },
  10695. #endif
  10696. {
  10697. SIOCIWFIRSTPRIV + 0x10,
  10698. IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, 0, "p2p_set"
  10699. },
  10700. {
  10701. SIOCIWFIRSTPRIV + 0x11,
  10702. IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "p2p_get"
  10703. },
  10704. {
  10705. SIOCIWFIRSTPRIV + 0x12, 0, 0, "NULL"
  10706. },
  10707. {
  10708. SIOCIWFIRSTPRIV + 0x13,
  10709. IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64 , "p2p_get2"
  10710. },
  10711. {
  10712. SIOCIWFIRSTPRIV + 0x14,
  10713. IW_PRIV_TYPE_CHAR | 64, 0, "tdls"
  10714. },
  10715. {
  10716. SIOCIWFIRSTPRIV + 0x15,
  10717. IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | P2P_PRIVATE_IOCTL_SET_LEN , "tdls_get"
  10718. },
  10719. {
  10720. SIOCIWFIRSTPRIV + 0x16,
  10721. IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
  10722. },
  10723. {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ , 0 , "rereg_nd_name"},
  10724. {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "efuse_set"},
  10725. {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
  10726. {
  10727. SIOCIWFIRSTPRIV + 0x1D,
  10728. IW_PRIV_TYPE_CHAR | 40, IW_PRIV_TYPE_CHAR | 0x7FF, "test"
  10729. },
  10730. #ifdef CONFIG_INTEL_WIDI
  10731. {
  10732. SIOCIWFIRSTPRIV + 0x1E,
  10733. IW_PRIV_TYPE_CHAR | 64, 0, "widi_set"
  10734. },
  10735. {
  10736. SIOCIWFIRSTPRIV + 0x1F,
  10737. IW_PRIV_TYPE_CHAR | 128, 0, "widi_prob_req"
  10738. },
  10739. #endif // CONFIG_INTEL_WIDI
  10740. #ifdef CONFIG_MP_INCLUDED
  10741. { SIOCIWFIRSTPRIV + 0x0E, IW_PRIV_TYPE_CHAR | 1024, 0 , ""}, //set
  10742. { SIOCIWFIRSTPRIV + 0x0F, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , ""},//get
  10743. /* --- sub-ioctls definitions --- */
  10744. { MP_START , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_start" }, //set
  10745. { MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara" },//get
  10746. { MP_STOP , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_stop" }, //set
  10747. { MP_CHANNEL , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel" },//get
  10748. { MP_BANDWIDTH , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_bandwidth"}, //set
  10749. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },//get
  10750. { MP_RESET_STATS , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_reset_stats"},
  10751. { MP_QUERY , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "mp_query"}, //get
  10752. { READ_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg" },
  10753. { MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
  10754. { READ_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf" },
  10755. { MP_PSD , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
  10756. { MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump" },
  10757. { MP_TXPOWER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
  10758. { MP_ANT_TX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
  10759. { MP_ANT_RX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
  10760. { WRITE_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_reg" },
  10761. { WRITE_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_rf" },
  10762. { MP_CTX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
  10763. { MP_ARX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
  10764. { MP_THER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
  10765. { EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_set" },
  10766. { EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get" },
  10767. { MP_PWRTRK , IW_PRIV_TYPE_CHAR | 1024, 0, "mp_pwrtrk"},
  10768. { MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery" },
  10769. { MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"}, // mp_ioctl
  10770. { MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_setrfpath" },
  10771. { MP_GET_TXPOWER_INX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_get_txpower" },
  10772. #ifdef CONFIG_RTL8723A
  10773. { MP_SetBT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setbt" },
  10774. #endif
  10775. { CTA_TEST, IW_PRIV_TYPE_CHAR | 1024, 0, "cta_test"},
  10776. #endif
  10777. };
  10778. static iw_handler rtw_private_handler[] =
  10779. {
  10780. rtw_wx_write32, //0x00
  10781. rtw_wx_read32, //0x01
  10782. rtw_drvext_hdl, //0x02
  10783. rtw_mp_ioctl_hdl, //0x03
  10784. // for MM DTV platform
  10785. rtw_get_ap_info, //0x04
  10786. rtw_set_pid, //0x05
  10787. rtw_wps_start, //0x06
  10788. // for PLATFORM_MT53XX
  10789. rtw_wx_get_sensitivity, //0x07
  10790. rtw_wx_set_mtk_wps_probe_ie, //0x08
  10791. rtw_wx_set_mtk_wps_ie, //0x09
  10792. // for RTK_DMP_PLATFORM
  10793. // Set Channel depend on the country code
  10794. rtw_wx_set_channel_plan, //0x0A
  10795. rtw_dbg_port, //0x0B
  10796. rtw_wx_write_rf, //0x0C
  10797. rtw_wx_read_rf, //0x0D
  10798. #ifndef CONFIG_MP_INCLUDED
  10799. rtw_wx_priv_null, //0x0E
  10800. rtw_wx_priv_null, //0x0F
  10801. #else
  10802. rtw_mp_set, //0x0E
  10803. rtw_mp_get, //0x0F
  10804. #endif
  10805. rtw_p2p_set, //0x10
  10806. rtw_p2p_get, //0x11
  10807. NULL, //0x12
  10808. rtw_p2p_get2, //0x13
  10809. rtw_tdls, //0x14
  10810. rtw_tdls_get, //0x15
  10811. rtw_pm_set, //0x16
  10812. rtw_wx_priv_null, //0x17
  10813. rtw_rereg_nd_name, //0x18
  10814. rtw_wx_priv_null, //0x19
  10815. rtw_mp_efuse_set, //0x1A
  10816. rtw_mp_efuse_get, //0x1B
  10817. NULL, // 0x1C is reserved for hostapd
  10818. rtw_test, // 0x1D
  10819. #ifdef CONFIG_INTEL_WIDI
  10820. rtw_widi_set, //0x1E
  10821. rtw_widi_set_probe_request, //0x1F
  10822. #endif // CONFIG_INTEL_WIDI
  10823. };
  10824. #endif // #if defined(CONFIG_MP_INCLUDED) && defined(CONFIG_MP_IWPRIV_SUPPORT)
  10825. #if WIRELESS_EXT >= 17
  10826. static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
  10827. {
  10828. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  10829. struct iw_statistics *piwstats=&padapter->iwstats;
  10830. int tmp_level = 0;
  10831. int tmp_qual = 0;
  10832. int tmp_noise = 0;
  10833. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) != _TRUE)
  10834. {
  10835. piwstats->qual.qual = 0;
  10836. piwstats->qual.level = 0;
  10837. piwstats->qual.noise = 0;
  10838. //DBG_871X("No link level:%d, qual:%d, noise:%d\n", tmp_level, tmp_qual, tmp_noise);
  10839. }
  10840. else{
  10841. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10842. tmp_level = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  10843. #else
  10844. tmp_level = padapter->recvpriv.signal_strength;
  10845. #ifdef CONFIG_BT_COEXIST
  10846. {
  10847. u8 signal = (u8)tmp_level;
  10848. BT_SignalCompensation(padapter, &signal, NULL);
  10849. tmp_level= signal;
  10850. }
  10851. #endif // CONFIG_BT_COEXIST
  10852. #endif
  10853. tmp_qual = padapter->recvpriv.signal_qual;
  10854. tmp_noise =padapter->recvpriv.noise;
  10855. //DBG_871X("level:%d, qual:%d, noise:%d, rssi (%d)\n", tmp_level, tmp_qual, tmp_noise,padapter->recvpriv.rssi);
  10856. piwstats->qual.level = tmp_level;
  10857. piwstats->qual.qual = tmp_qual;
  10858. piwstats->qual.noise = tmp_noise;
  10859. }
  10860. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14))
  10861. piwstats->qual.updated = IW_QUAL_ALL_UPDATED ;//|IW_QUAL_DBM;
  10862. #else
  10863. #ifdef RTK_DMP_PLATFORM
  10864. //IW_QUAL_DBM= 0x8, if driver use this flag, wireless extension will show value of dbm.
  10865. //remove this flag for show percentage 0~100
  10866. piwstats->qual.updated = 0x07;
  10867. #else
  10868. piwstats->qual.updated = 0x0f;
  10869. #endif
  10870. #endif
  10871. #ifdef CONFIG_SIGNAL_DISPLAY_DBM
  10872. piwstats->qual.updated = piwstats->qual.updated | IW_QUAL_DBM;
  10873. #endif
  10874. return &padapter->iwstats;
  10875. }
  10876. #endif
  10877. #ifdef CONFIG_WIRELESS_EXT
  10878. struct iw_handler_def rtw_handlers_def =
  10879. {
  10880. .standard = rtw_handlers,
  10881. .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
  10882. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) || defined(CONFIG_WEXT_PRIV)
  10883. .private = rtw_private_handler,
  10884. .private_args = (struct iw_priv_args *)rtw_private_args,
  10885. .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler),
  10886. .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args),
  10887. #endif
  10888. #if WIRELESS_EXT >= 17
  10889. .get_wireless_stats = rtw_get_wireless_stats,
  10890. #endif
  10891. };
  10892. #endif
  10893. // copy from net/wireless/wext.c start
  10894. /* ---------------------------------------------------------------- */
  10895. /*
  10896. * Calculate size of private arguments
  10897. */
  10898. static const char iw_priv_type_size[] = {
  10899. 0, /* IW_PRIV_TYPE_NONE */
  10900. 1, /* IW_PRIV_TYPE_BYTE */
  10901. 1, /* IW_PRIV_TYPE_CHAR */
  10902. 0, /* Not defined */
  10903. sizeof(__u32), /* IW_PRIV_TYPE_INT */
  10904. sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
  10905. sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
  10906. 0, /* Not defined */
  10907. };
  10908. static int get_priv_size(__u16 args)
  10909. {
  10910. int num = args & IW_PRIV_SIZE_MASK;
  10911. int type = (args & IW_PRIV_TYPE_MASK) >> 12;
  10912. return num * iw_priv_type_size[type];
  10913. }
  10914. // copy from net/wireless/wext.c end
  10915. static int rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_data)
  10916. {
  10917. int err = 0;
  10918. u8 *input = NULL;
  10919. u32 input_len = 0;
  10920. const char delim[] = " ";
  10921. u8 *output = NULL;
  10922. u32 output_len = 0;
  10923. u32 count = 0;
  10924. u8 *buffer= NULL;
  10925. u32 buffer_len = 0;
  10926. char *ptr = NULL;
  10927. u8 cmdname[17] = {0}; // IFNAMSIZ+1
  10928. u32 cmdlen;
  10929. s32 len;
  10930. u8 *extra = NULL;
  10931. u32 extra_size = 0;
  10932. s32 k;
  10933. const iw_handler *priv; /* Private ioctl */
  10934. const struct iw_priv_args *priv_args; /* Private ioctl description */
  10935. u32 num_priv; /* Number of ioctl */
  10936. u32 num_priv_args; /* Number of descriptions */
  10937. iw_handler handler;
  10938. int temp;
  10939. int subcmd = 0; /* sub-ioctl index */
  10940. int offset = 0; /* Space for sub-ioctl index */
  10941. union iwreq_data wdata;
  10942. _rtw_memcpy(&wdata, wrq_data, sizeof(wdata));
  10943. input_len = wdata.data.length;
  10944. input = rtw_zmalloc(input_len);
  10945. if (NULL == input)
  10946. return -ENOMEM;
  10947. if (copy_from_user(input, wdata.data.pointer, input_len)) {
  10948. err = -EFAULT;
  10949. goto exit;
  10950. }
  10951. ptr = input;
  10952. len = input_len;
  10953. sscanf(ptr, "%16s", cmdname);
  10954. cmdlen = strlen(cmdname);
  10955. DBG_8192C("%s: cmd=%s\n", __func__, cmdname);
  10956. // skip command string
  10957. if (cmdlen > 0)
  10958. cmdlen += 1; // skip one space
  10959. ptr += cmdlen;
  10960. len -= cmdlen;
  10961. DBG_8192C("%s: parameters=%s\n", __func__, ptr);
  10962. priv = rtw_private_handler;
  10963. priv_args = rtw_private_args;
  10964. num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler);
  10965. num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args);
  10966. if (num_priv_args == 0) {
  10967. err = -EOPNOTSUPP;
  10968. goto exit;
  10969. }
  10970. /* Search the correct ioctl */
  10971. k = -1;
  10972. while((++k < num_priv_args) && strcmp(priv_args[k].name, cmdname));
  10973. /* If not found... */
  10974. if (k == num_priv_args) {
  10975. err = -EOPNOTSUPP;
  10976. goto exit;
  10977. }
  10978. /* Watch out for sub-ioctls ! */
  10979. if (priv_args[k].cmd < SIOCDEVPRIVATE)
  10980. {
  10981. int j = -1;
  10982. /* Find the matching *real* ioctl */
  10983. while ((++j < num_priv_args) && ((priv_args[j].name[0] != '\0') ||
  10984. (priv_args[j].set_args != priv_args[k].set_args) ||
  10985. (priv_args[j].get_args != priv_args[k].get_args)));
  10986. /* If not found... */
  10987. if (j == num_priv_args) {
  10988. err = -EINVAL;
  10989. goto exit;
  10990. }
  10991. /* Save sub-ioctl number */
  10992. subcmd = priv_args[k].cmd;
  10993. /* Reserve one int (simplify alignment issues) */
  10994. offset = sizeof(__u32);
  10995. /* Use real ioctl definition from now on */
  10996. k = j;
  10997. }
  10998. buffer = rtw_zmalloc(4096);
  10999. if (NULL == buffer) {
  11000. err = -ENOMEM;
  11001. goto exit;
  11002. }
  11003. /* If we have to set some data */
  11004. if ((priv_args[k].set_args & IW_PRIV_TYPE_MASK) &&
  11005. (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  11006. {
  11007. u8 *str;
  11008. switch (priv_args[k].set_args & IW_PRIV_TYPE_MASK)
  11009. {
  11010. case IW_PRIV_TYPE_BYTE:
  11011. /* Fetch args */
  11012. count = 0;
  11013. do {
  11014. str = strsep(&ptr, delim);
  11015. if (NULL == str) break;
  11016. sscanf(str, "%i", &temp);
  11017. buffer[count++] = (u8)temp;
  11018. } while (1);
  11019. buffer_len = count;
  11020. /* Number of args to fetch */
  11021. wdata.data.length = count;
  11022. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  11023. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  11024. break;
  11025. case IW_PRIV_TYPE_INT:
  11026. /* Fetch args */
  11027. count = 0;
  11028. do {
  11029. str = strsep(&ptr, delim);
  11030. if (NULL == str) break;
  11031. sscanf(str, "%i", &temp);
  11032. ((s32*)buffer)[count++] = (s32)temp;
  11033. } while (1);
  11034. buffer_len = count * sizeof(s32);
  11035. /* Number of args to fetch */
  11036. wdata.data.length = count;
  11037. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  11038. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  11039. break;
  11040. case IW_PRIV_TYPE_CHAR:
  11041. if (len > 0)
  11042. {
  11043. /* Size of the string to fetch */
  11044. wdata.data.length = len;
  11045. if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
  11046. wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
  11047. /* Fetch string */
  11048. _rtw_memcpy(buffer, ptr, wdata.data.length);
  11049. }
  11050. else
  11051. {
  11052. wdata.data.length = 1;
  11053. buffer[0] = '\0';
  11054. }
  11055. buffer_len = wdata.data.length;
  11056. break;
  11057. default:
  11058. DBG_8192C("%s: Not yet implemented...\n", __func__);
  11059. err = -1;
  11060. goto exit;
  11061. }
  11062. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  11063. (wdata.data.length != (priv_args[k].set_args & IW_PRIV_SIZE_MASK)))
  11064. {
  11065. DBG_8192C("%s: The command %s needs exactly %d argument(s)...\n",
  11066. __func__, cmdname, priv_args[k].set_args & IW_PRIV_SIZE_MASK);
  11067. err = -EINVAL;
  11068. goto exit;
  11069. }
  11070. } /* if args to set */
  11071. else
  11072. {
  11073. wdata.data.length = 0L;
  11074. }
  11075. /* Those two tests are important. They define how the driver
  11076. * will have to handle the data */
  11077. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  11078. ((get_priv_size(priv_args[k].set_args) + offset) <= IFNAMSIZ))
  11079. {
  11080. /* First case : all SET args fit within wrq */
  11081. if (offset)
  11082. wdata.mode = subcmd;
  11083. _rtw_memcpy(wdata.name + offset, buffer, IFNAMSIZ - offset);
  11084. }
  11085. else
  11086. {
  11087. if ((priv_args[k].set_args == 0) &&
  11088. (priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  11089. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ))
  11090. {
  11091. /* Second case : no SET args, GET args fit within wrq */
  11092. if (offset)
  11093. wdata.mode = subcmd;
  11094. }
  11095. else
  11096. {
  11097. /* Third case : args won't fit in wrq, or variable number of args */
  11098. if (copy_to_user(wdata.data.pointer, buffer, buffer_len)) {
  11099. err = -EFAULT;
  11100. goto exit;
  11101. }
  11102. wdata.data.flags = subcmd;
  11103. }
  11104. }
  11105. rtw_mfree(input, input_len);
  11106. input = NULL;
  11107. extra_size = 0;
  11108. if (IW_IS_SET(priv_args[k].cmd))
  11109. {
  11110. /* Size of set arguments */
  11111. extra_size = get_priv_size(priv_args[k].set_args);
  11112. /* Does it fits in iwr ? */
  11113. if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
  11114. ((extra_size + offset) <= IFNAMSIZ))
  11115. extra_size = 0;
  11116. } else {
  11117. /* Size of get arguments */
  11118. extra_size = get_priv_size(priv_args[k].get_args);
  11119. /* Does it fits in iwr ? */
  11120. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  11121. (extra_size <= IFNAMSIZ))
  11122. extra_size = 0;
  11123. }
  11124. if (extra_size == 0) {
  11125. extra = (u8*)&wdata;
  11126. rtw_mfree(buffer, 4096);
  11127. buffer = NULL;
  11128. } else
  11129. extra = buffer;
  11130. handler = priv[priv_args[k].cmd - SIOCIWFIRSTPRIV];
  11131. err = handler(dev, NULL, &wdata, extra);
  11132. /* If we have to get some data */
  11133. if ((priv_args[k].get_args & IW_PRIV_TYPE_MASK) &&
  11134. (priv_args[k].get_args & IW_PRIV_SIZE_MASK))
  11135. {
  11136. int j;
  11137. int n = 0; /* number of args */
  11138. u8 str[20] = {0};
  11139. /* Check where is the returned data */
  11140. if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
  11141. (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ))
  11142. n = priv_args[k].get_args & IW_PRIV_SIZE_MASK;
  11143. else
  11144. n = wdata.data.length;
  11145. output = rtw_zmalloc(4096);
  11146. if (NULL == output) {
  11147. err = -ENOMEM;
  11148. goto exit;
  11149. }
  11150. switch (priv_args[k].get_args & IW_PRIV_TYPE_MASK)
  11151. {
  11152. case IW_PRIV_TYPE_BYTE:
  11153. /* Display args */
  11154. for (j = 0; j < n; j++)
  11155. {
  11156. sprintf(str, "%d ", extra[j]);
  11157. len = strlen(str);
  11158. output_len = strlen(output);
  11159. if ((output_len + len + 1) > 4096) {
  11160. err = -E2BIG;
  11161. goto exit;
  11162. }
  11163. _rtw_memcpy(output+output_len, str, len);
  11164. }
  11165. break;
  11166. case IW_PRIV_TYPE_INT:
  11167. /* Display args */
  11168. for (j = 0; j < n; j++)
  11169. {
  11170. sprintf(str, "%d ", ((__s32*)extra)[j]);
  11171. len = strlen(str);
  11172. output_len = strlen(output);
  11173. if ((output_len + len + 1) > 4096) {
  11174. err = -E2BIG;
  11175. goto exit;
  11176. }
  11177. _rtw_memcpy(output+output_len, str, len);
  11178. }
  11179. break;
  11180. case IW_PRIV_TYPE_CHAR:
  11181. /* Display args */
  11182. _rtw_memcpy(output, extra, n);
  11183. break;
  11184. default:
  11185. DBG_8192C("%s: Not yet implemented...\n", __func__);
  11186. err = -1;
  11187. goto exit;
  11188. }
  11189. output_len = strlen(output) + 1;
  11190. wrq_data->data.length = output_len;
  11191. if (copy_to_user(wrq_data->data.pointer, output, output_len)) {
  11192. err = -EFAULT;
  11193. goto exit;
  11194. }
  11195. } /* if args to set */
  11196. else
  11197. {
  11198. wrq_data->data.length = 0;
  11199. }
  11200. exit:
  11201. if (input)
  11202. rtw_mfree(input, input_len);
  11203. if (buffer)
  11204. rtw_mfree(buffer, 4096);
  11205. if (output)
  11206. rtw_mfree(output, 4096);
  11207. return err;
  11208. }
  11209. int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  11210. {
  11211. struct iwreq *wrq = (struct iwreq *)rq;
  11212. int ret=0;
  11213. switch (cmd)
  11214. {
  11215. case RTL_IOCTL_WPA_SUPPLICANT:
  11216. ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
  11217. break;
  11218. #ifdef CONFIG_AP_MODE
  11219. case RTL_IOCTL_HOSTAPD:
  11220. ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
  11221. break;
  11222. #ifdef CONFIG_NO_WIRELESS_HANDLERS
  11223. case SIOCSIWMODE:
  11224. ret = rtw_wx_set_mode(dev, NULL, &wrq->u, NULL);
  11225. break;
  11226. #endif
  11227. #endif // CONFIG_AP_MODE
  11228. case SIOCDEVPRIVATE:
  11229. ret = rtw_ioctl_wext_private(dev, &wrq->u);
  11230. break;
  11231. case (SIOCDEVPRIVATE+1):
  11232. ret = rtw_android_priv_cmd(dev, rq, cmd);
  11233. break;
  11234. default:
  11235. ret = -EOPNOTSUPP;
  11236. break;
  11237. }
  11238. return ret;
  11239. }