ioctl_cfg80211.c 289 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #define _IOCTL_CFG80211_C_
  16. #include <drv_types.h>
  17. #include <hal_data.h>
  18. #ifdef CONFIG_IOCTL_CFG80211
  19. #ifndef DBG_RTW_CFG80211_STA_PARAM
  20. #define DBG_RTW_CFG80211_STA_PARAM 0
  21. #endif
  22. #ifndef DBG_RTW_CFG80211_MESH_CONF
  23. #define DBG_RTW_CFG80211_MESH_CONF 0
  24. #endif
  25. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
  26. #define STATION_INFO_INACTIVE_TIME BIT(NL80211_STA_INFO_INACTIVE_TIME)
  27. #define STATION_INFO_LLID BIT(NL80211_STA_INFO_LLID)
  28. #define STATION_INFO_PLID BIT(NL80211_STA_INFO_PLID)
  29. #define STATION_INFO_PLINK_STATE BIT(NL80211_STA_INFO_PLINK_STATE)
  30. #define STATION_INFO_SIGNAL BIT(NL80211_STA_INFO_SIGNAL)
  31. #define STATION_INFO_TX_BITRATE BIT(NL80211_STA_INFO_TX_BITRATE)
  32. #define STATION_INFO_RX_PACKETS BIT(NL80211_STA_INFO_RX_PACKETS)
  33. #define STATION_INFO_TX_PACKETS BIT(NL80211_STA_INFO_TX_PACKETS)
  34. #define STATION_INFO_TX_FAILED BIT(NL80211_STA_INFO_TX_FAILED)
  35. #define STATION_INFO_LOCAL_PM BIT(NL80211_STA_INFO_LOCAL_PM)
  36. #define STATION_INFO_PEER_PM BIT(NL80211_STA_INFO_PEER_PM)
  37. #define STATION_INFO_NONPEER_PM BIT(NL80211_STA_INFO_NONPEER_PM)
  38. #define STATION_INFO_ASSOC_REQ_IES 0
  39. #endif /* Linux kernel >= 4.0.0 */
  40. #include <rtw_wifi_regd.h>
  41. #define RTW_MAX_MGMT_TX_CNT (8)
  42. #define RTW_MAX_MGMT_TX_MS_GAS (500)
  43. #define RTW_SCAN_IE_LEN_MAX 2304
  44. #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */
  45. #define RTW_MAX_NUM_PMKIDS 4
  46. #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
  47. #ifdef CONFIG_WAPI_SUPPORT
  48. #ifndef WLAN_CIPHER_SUITE_SMS4
  49. #define WLAN_CIPHER_SUITE_SMS4 0x00147201
  50. #endif
  51. #ifndef WLAN_AKM_SUITE_WAPI_PSK
  52. #define WLAN_AKM_SUITE_WAPI_PSK 0x000FAC04
  53. #endif
  54. #ifndef WLAN_AKM_SUITE_WAPI_CERT
  55. #define WLAN_AKM_SUITE_WAPI_CERT 0x000FAC12
  56. #endif
  57. #ifndef NL80211_WAPI_VERSION_1
  58. #define NL80211_WAPI_VERSION_1 (1 << 2)
  59. #endif
  60. #endif /* CONFIG_WAPI_SUPPORT */
  61. #ifdef CONFIG_RTW_80211R
  62. #define WLAN_AKM_SUITE_FT_8021X 0x000FAC03
  63. #define WLAN_AKM_SUITE_FT_PSK 0x000FAC04
  64. #endif
  65. /*
  66. * In the current design of Wi-Fi driver, it will return success to the system (e.g. supplicant)
  67. * when Wi-Fi driver decides to abort the scan request in the scan flow by default.
  68. * Defining this flag makes Wi-Fi driver to return -EBUSY to the system if Wi-Fi driver is too busy to do the scan.
  69. */
  70. #ifndef CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  71. #define CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY 0
  72. #endif
  73. static const u32 rtw_cipher_suites[] = {
  74. WLAN_CIPHER_SUITE_WEP40,
  75. WLAN_CIPHER_SUITE_WEP104,
  76. WLAN_CIPHER_SUITE_TKIP,
  77. WLAN_CIPHER_SUITE_CCMP,
  78. #ifdef CONFIG_WAPI_SUPPORT
  79. WLAN_CIPHER_SUITE_SMS4,
  80. #endif /* CONFIG_WAPI_SUPPORT */
  81. #ifdef CONFIG_IEEE80211W
  82. WLAN_CIPHER_SUITE_AES_CMAC,
  83. #endif /* CONFIG_IEEE80211W */
  84. };
  85. #define RATETAB_ENT(_rate, _rateid, _flags) \
  86. { \
  87. .bitrate = (_rate), \
  88. .hw_value = (_rateid), \
  89. .flags = (_flags), \
  90. }
  91. #define CHAN2G(_channel, _freq, _flags) { \
  92. .band = NL80211_BAND_2GHZ, \
  93. .center_freq = (_freq), \
  94. .hw_value = (_channel), \
  95. .flags = (_flags), \
  96. .max_antenna_gain = 0, \
  97. .max_power = 30, \
  98. }
  99. #define CHAN5G(_channel, _flags) { \
  100. .band = NL80211_BAND_5GHZ, \
  101. .center_freq = 5000 + (5 * (_channel)), \
  102. .hw_value = (_channel), \
  103. .flags = (_flags), \
  104. .max_antenna_gain = 0, \
  105. .max_power = 30, \
  106. }
  107. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  108. /* if wowlan is not supported, kernel generate a disconnect at each suspend
  109. * cf: /net/wireless/sysfs.c, so register a stub wowlan.
  110. * Moreover wowlan has to be enabled via a the nl80211_set_wowlan callback.
  111. * (from user space, e.g. iw phy0 wowlan enable)
  112. */
  113. static const struct wiphy_wowlan_support wowlan_stub = {
  114. .flags = WIPHY_WOWLAN_ANY,
  115. .n_patterns = 0,
  116. .pattern_max_len = 0,
  117. .pattern_min_len = 0,
  118. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  119. .max_pkt_offset = 0,
  120. #endif
  121. };
  122. #endif
  123. static struct ieee80211_rate rtw_rates[] = {
  124. RATETAB_ENT(10, 0x1, 0),
  125. RATETAB_ENT(20, 0x2, 0),
  126. RATETAB_ENT(55, 0x4, 0),
  127. RATETAB_ENT(110, 0x8, 0),
  128. RATETAB_ENT(60, 0x10, 0),
  129. RATETAB_ENT(90, 0x20, 0),
  130. RATETAB_ENT(120, 0x40, 0),
  131. RATETAB_ENT(180, 0x80, 0),
  132. RATETAB_ENT(240, 0x100, 0),
  133. RATETAB_ENT(360, 0x200, 0),
  134. RATETAB_ENT(480, 0x400, 0),
  135. RATETAB_ENT(540, 0x800, 0),
  136. };
  137. #define rtw_a_rates (rtw_rates + 4)
  138. #define RTW_A_RATES_NUM 8
  139. #define rtw_g_rates (rtw_rates + 0)
  140. #define RTW_G_RATES_NUM 12
  141. /* from center_ch_2g */
  142. static struct ieee80211_channel rtw_2ghz_channels[MAX_CHANNEL_NUM_2G] = {
  143. CHAN2G(1, 2412, 0),
  144. CHAN2G(2, 2417, 0),
  145. CHAN2G(3, 2422, 0),
  146. CHAN2G(4, 2427, 0),
  147. CHAN2G(5, 2432, 0),
  148. CHAN2G(6, 2437, 0),
  149. CHAN2G(7, 2442, 0),
  150. CHAN2G(8, 2447, 0),
  151. CHAN2G(9, 2452, 0),
  152. CHAN2G(10, 2457, 0),
  153. CHAN2G(11, 2462, 0),
  154. CHAN2G(12, 2467, 0),
  155. CHAN2G(13, 2472, 0),
  156. CHAN2G(14, 2484, 0),
  157. };
  158. /* from center_ch_5g_20m */
  159. static struct ieee80211_channel rtw_5ghz_a_channels[MAX_CHANNEL_NUM_5G] = {
  160. CHAN5G(36, 0), CHAN5G(40, 0), CHAN5G(44, 0), CHAN5G(48, 0),
  161. CHAN5G(52, 0), CHAN5G(56, 0), CHAN5G(60, 0), CHAN5G(64, 0),
  162. CHAN5G(100, 0), CHAN5G(104, 0), CHAN5G(108, 0), CHAN5G(112, 0),
  163. CHAN5G(116, 0), CHAN5G(120, 0), CHAN5G(124, 0), CHAN5G(128, 0),
  164. CHAN5G(132, 0), CHAN5G(136, 0), CHAN5G(140, 0), CHAN5G(144, 0),
  165. CHAN5G(149, 0), CHAN5G(153, 0), CHAN5G(157, 0), CHAN5G(161, 0),
  166. CHAN5G(165, 0), CHAN5G(169, 0), CHAN5G(173, 0), CHAN5G(177, 0),
  167. };
  168. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  169. static const char *nl80211_channel_type_str(enum nl80211_channel_type ctype)
  170. {
  171. switch (ctype) {
  172. case NL80211_CHAN_NO_HT:
  173. return "NO_HT";
  174. case NL80211_CHAN_HT20:
  175. return "HT20";
  176. case NL80211_CHAN_HT40MINUS:
  177. return "HT40-";
  178. case NL80211_CHAN_HT40PLUS:
  179. return "HT40+";
  180. default:
  181. return "INVALID";
  182. };
  183. }
  184. static enum nl80211_channel_type rtw_chbw_to_nl80211_channel_type(u8 ch, u8 bw, u8 offset, u8 ht)
  185. {
  186. rtw_warn_on(!ht && (bw >= CHANNEL_WIDTH_40 || offset != HAL_PRIME_CHNL_OFFSET_DONT_CARE));
  187. if (!ht)
  188. return NL80211_CHAN_NO_HT;
  189. if (bw >= CHANNEL_WIDTH_40) {
  190. if (offset == HAL_PRIME_CHNL_OFFSET_UPPER)
  191. return NL80211_CHAN_HT40MINUS;
  192. else if (offset == HAL_PRIME_CHNL_OFFSET_LOWER)
  193. return NL80211_CHAN_HT40PLUS;
  194. else
  195. rtw_warn_on(1);
  196. }
  197. return NL80211_CHAN_HT20;
  198. }
  199. static void rtw_get_chbw_from_nl80211_channel_type(struct ieee80211_channel *chan, enum nl80211_channel_type ctype, u8 *ht, u8 *ch, u8 *bw, u8 *offset)
  200. {
  201. int pri_freq;
  202. pri_freq = rtw_ch2freq(chan->hw_value);
  203. if (!pri_freq) {
  204. RTW_INFO("invalid channel:%d\n", chan->hw_value);
  205. rtw_warn_on(1);
  206. *ch = 0;
  207. return;
  208. }
  209. *ch = chan->hw_value;
  210. switch (ctype) {
  211. case NL80211_CHAN_NO_HT:
  212. *ht = 0;
  213. *bw = CHANNEL_WIDTH_20;
  214. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  215. break;
  216. case NL80211_CHAN_HT20:
  217. *ht = 1;
  218. *bw = CHANNEL_WIDTH_20;
  219. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  220. break;
  221. case NL80211_CHAN_HT40MINUS:
  222. *ht = 1;
  223. *bw = CHANNEL_WIDTH_40;
  224. *offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  225. break;
  226. case NL80211_CHAN_HT40PLUS:
  227. *ht = 1;
  228. *bw = CHANNEL_WIDTH_40;
  229. *offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  230. break;
  231. default:
  232. *ht = 0;
  233. *bw = CHANNEL_WIDTH_20;
  234. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  235. RTW_INFO("unsupported ctype:%s\n", nl80211_channel_type_str(ctype));
  236. rtw_warn_on(1);
  237. };
  238. }
  239. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)) */
  240. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  241. static const char *nl80211_chan_width_str(enum nl80211_chan_width cwidth)
  242. {
  243. switch (cwidth) {
  244. case NL80211_CHAN_WIDTH_20_NOHT:
  245. return "20_NOHT";
  246. case NL80211_CHAN_WIDTH_20:
  247. return "20";
  248. case NL80211_CHAN_WIDTH_40:
  249. return "40";
  250. case NL80211_CHAN_WIDTH_80:
  251. return "80";
  252. case NL80211_CHAN_WIDTH_80P80:
  253. return "80+80";
  254. case NL80211_CHAN_WIDTH_160:
  255. return "160";
  256. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  257. case NL80211_CHAN_WIDTH_5:
  258. return "5";
  259. case NL80211_CHAN_WIDTH_10:
  260. return "10";
  261. #endif
  262. default:
  263. return "INVALID";
  264. };
  265. }
  266. static u8 rtw_chbw_to_cfg80211_chan_def(struct wiphy *wiphy, struct cfg80211_chan_def *chdef, u8 ch, u8 bw, u8 offset, u8 ht)
  267. {
  268. int freq, cfreq;
  269. struct ieee80211_channel *chan;
  270. u8 ret = _FAIL;
  271. freq = rtw_ch2freq(ch);
  272. if (!freq)
  273. goto exit;
  274. cfreq = rtw_get_center_ch(ch, bw, offset);
  275. if (!cfreq)
  276. goto exit;
  277. cfreq = rtw_ch2freq(cfreq);
  278. if (!cfreq)
  279. goto exit;
  280. chan = ieee80211_get_channel(wiphy, freq);
  281. if (!chan)
  282. goto exit;
  283. if (bw == CHANNEL_WIDTH_20)
  284. chdef->width = ht ? NL80211_CHAN_WIDTH_20 : NL80211_CHAN_WIDTH_20_NOHT;
  285. else if (bw == CHANNEL_WIDTH_40)
  286. chdef->width = NL80211_CHAN_WIDTH_40;
  287. else if (bw == CHANNEL_WIDTH_80)
  288. chdef->width = NL80211_CHAN_WIDTH_80;
  289. else if (bw == CHANNEL_WIDTH_160)
  290. chdef->width = NL80211_CHAN_WIDTH_160;
  291. else {
  292. rtw_warn_on(1);
  293. goto exit;
  294. }
  295. chdef->chan = chan;
  296. chdef->center_freq1 = cfreq;
  297. chdef->center_freq2 = 0;
  298. ret = _SUCCESS;
  299. exit:
  300. return ret;
  301. }
  302. static void rtw_get_chbw_from_cfg80211_chan_def(struct cfg80211_chan_def *chdef, u8 *ht, u8 *ch, u8 *bw, u8 *offset)
  303. {
  304. int pri_freq;
  305. struct ieee80211_channel *chan = chdef->chan;
  306. pri_freq = rtw_ch2freq(chan->hw_value);
  307. if (!pri_freq) {
  308. RTW_INFO("invalid channel:%d\n", chan->hw_value);
  309. rtw_warn_on(1);
  310. *ch = 0;
  311. return;
  312. }
  313. switch (chdef->width) {
  314. case NL80211_CHAN_WIDTH_20_NOHT:
  315. *ht = 0;
  316. *bw = CHANNEL_WIDTH_20;
  317. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  318. *ch = chan->hw_value;
  319. break;
  320. case NL80211_CHAN_WIDTH_20:
  321. *ht = 1;
  322. *bw = CHANNEL_WIDTH_20;
  323. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  324. *ch = chan->hw_value;
  325. break;
  326. case NL80211_CHAN_WIDTH_40:
  327. *ht = 1;
  328. *bw = CHANNEL_WIDTH_40;
  329. *offset = pri_freq > chdef->center_freq1 ? HAL_PRIME_CHNL_OFFSET_UPPER : HAL_PRIME_CHNL_OFFSET_LOWER;
  330. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  331. *ch = chan->hw_value;
  332. break;
  333. case NL80211_CHAN_WIDTH_80:
  334. *ht = 1;
  335. *bw = CHANNEL_WIDTH_80;
  336. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  337. *ch = chan->hw_value;
  338. break;
  339. case NL80211_CHAN_WIDTH_160:
  340. *ht = 1;
  341. *bw = CHANNEL_WIDTH_160;
  342. if (rtw_get_offset_by_chbw(chan->hw_value, *bw, offset))
  343. *ch = chan->hw_value;
  344. break;
  345. case NL80211_CHAN_WIDTH_80P80:
  346. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  347. case NL80211_CHAN_WIDTH_5:
  348. case NL80211_CHAN_WIDTH_10:
  349. #endif
  350. default:
  351. *ht = 0;
  352. *bw = CHANNEL_WIDTH_20;
  353. *offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  354. RTW_INFO("unsupported cwidth:%s\n", nl80211_chan_width_str(chdef->width));
  355. rtw_warn_on(1);
  356. };
  357. }
  358. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) */
  359. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  360. u8 rtw_cfg80211_ch_switch_notify(_adapter *adapter, u8 ch, u8 bw, u8 offset, u8 ht)
  361. {
  362. struct wiphy *wiphy = adapter_to_wiphy(adapter);
  363. u8 ret = _SUCCESS;
  364. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  365. struct cfg80211_chan_def chdef;
  366. ret = rtw_chbw_to_cfg80211_chan_def(wiphy, &chdef, ch, bw, offset, ht);
  367. if (ret != _SUCCESS)
  368. goto exit;
  369. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  370. cfg80211_ch_switch_notify(adapter->pnetdev, &chdef);
  371. #else
  372. cfg80211_ch_switch_notify(adapter->pnetdev, &chdef, 0);
  373. #endif
  374. #else
  375. int freq = rtw_ch2freq(ch);
  376. enum nl80211_channel_type ctype;
  377. if (!freq) {
  378. ret = _FAIL;
  379. goto exit;
  380. }
  381. ctype = rtw_chbw_to_nl80211_channel_type(ch, bw, offset, ht);
  382. cfg80211_ch_switch_notify(adapter->pnetdev, freq, ctype);
  383. #endif
  384. exit:
  385. return ret;
  386. }
  387. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)) */
  388. void rtw_2g_channels_init(struct ieee80211_channel *channels)
  389. {
  390. _rtw_memcpy((void *)channels, (void *)rtw_2ghz_channels, sizeof(rtw_2ghz_channels));
  391. }
  392. void rtw_5g_channels_init(struct ieee80211_channel *channels)
  393. {
  394. _rtw_memcpy((void *)channels, (void *)rtw_5ghz_a_channels, sizeof(rtw_5ghz_a_channels));
  395. }
  396. void rtw_2g_rates_init(struct ieee80211_rate *rates)
  397. {
  398. _rtw_memcpy(rates, rtw_g_rates,
  399. sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM
  400. );
  401. }
  402. void rtw_5g_rates_init(struct ieee80211_rate *rates)
  403. {
  404. _rtw_memcpy(rates, rtw_a_rates,
  405. sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM
  406. );
  407. }
  408. struct ieee80211_supported_band *rtw_spt_band_alloc(BAND_TYPE band)
  409. {
  410. struct ieee80211_supported_band *spt_band = NULL;
  411. int n_channels, n_bitrates;
  412. if (band == BAND_ON_2_4G) {
  413. n_channels = MAX_CHANNEL_NUM_2G;
  414. n_bitrates = RTW_G_RATES_NUM;
  415. } else if (band == BAND_ON_5G) {
  416. n_channels = MAX_CHANNEL_NUM_5G;
  417. n_bitrates = RTW_A_RATES_NUM;
  418. } else
  419. goto exit;
  420. spt_band = (struct ieee80211_supported_band *)rtw_zmalloc(
  421. sizeof(struct ieee80211_supported_band)
  422. + sizeof(struct ieee80211_channel) * n_channels
  423. + sizeof(struct ieee80211_rate) * n_bitrates
  424. );
  425. if (!spt_band)
  426. goto exit;
  427. spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band));
  428. spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels);
  429. spt_band->band = rtw_band_to_nl80211_band(band);
  430. spt_band->n_channels = n_channels;
  431. spt_band->n_bitrates = n_bitrates;
  432. if (band == BAND_ON_2_4G) {
  433. rtw_2g_channels_init(spt_band->channels);
  434. rtw_2g_rates_init(spt_band->bitrates);
  435. } else if (band == BAND_ON_5G) {
  436. rtw_5g_channels_init(spt_band->channels);
  437. rtw_5g_rates_init(spt_band->bitrates);
  438. }
  439. /* spt_band.ht_cap */
  440. exit:
  441. return spt_band;
  442. }
  443. void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
  444. {
  445. u32 size = 0;
  446. if (!spt_band)
  447. return;
  448. if (spt_band->band == NL80211_BAND_2GHZ) {
  449. size = sizeof(struct ieee80211_supported_band)
  450. + sizeof(struct ieee80211_channel) * MAX_CHANNEL_NUM_2G
  451. + sizeof(struct ieee80211_rate) * RTW_G_RATES_NUM;
  452. } else if (spt_band->band == NL80211_BAND_5GHZ) {
  453. size = sizeof(struct ieee80211_supported_band)
  454. + sizeof(struct ieee80211_channel) * MAX_CHANNEL_NUM_5G
  455. + sizeof(struct ieee80211_rate) * RTW_A_RATES_NUM;
  456. } else {
  457. }
  458. rtw_mfree((u8 *)spt_band, size);
  459. }
  460. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  461. static const struct ieee80211_txrx_stypes
  462. rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  463. [NL80211_IFTYPE_ADHOC] = {
  464. .tx = 0xffff,
  465. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  466. },
  467. [NL80211_IFTYPE_STATION] = {
  468. .tx = 0xffff,
  469. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  470. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  471. },
  472. [NL80211_IFTYPE_AP] = {
  473. .tx = 0xffff,
  474. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  475. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  476. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  477. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  478. BIT(IEEE80211_STYPE_AUTH >> 4) |
  479. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  480. BIT(IEEE80211_STYPE_ACTION >> 4)
  481. },
  482. [NL80211_IFTYPE_AP_VLAN] = {
  483. /* copy AP */
  484. .tx = 0xffff,
  485. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  486. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  487. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  488. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  489. BIT(IEEE80211_STYPE_AUTH >> 4) |
  490. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  491. BIT(IEEE80211_STYPE_ACTION >> 4)
  492. },
  493. [NL80211_IFTYPE_P2P_CLIENT] = {
  494. .tx = 0xffff,
  495. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  496. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  497. },
  498. [NL80211_IFTYPE_P2P_GO] = {
  499. .tx = 0xffff,
  500. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  501. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  502. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  503. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  504. BIT(IEEE80211_STYPE_AUTH >> 4) |
  505. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  506. BIT(IEEE80211_STYPE_ACTION >> 4)
  507. },
  508. #if defined(RTW_DEDICATED_P2P_DEVICE)
  509. [NL80211_IFTYPE_P2P_DEVICE] = {
  510. .tx = 0xffff,
  511. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  512. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  513. },
  514. #endif
  515. #if defined(CONFIG_RTW_MESH)
  516. [NL80211_IFTYPE_MESH_POINT] = {
  517. .tx = 0xffff,
  518. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  519. | BIT(IEEE80211_STYPE_AUTH >> 4)
  520. },
  521. #endif
  522. };
  523. #endif
  524. NDIS_802_11_NETWORK_INFRASTRUCTURE nl80211_iftype_to_rtw_network_type(enum nl80211_iftype type)
  525. {
  526. switch (type) {
  527. case NL80211_IFTYPE_ADHOC:
  528. return Ndis802_11IBSS;
  529. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  530. case NL80211_IFTYPE_P2P_CLIENT:
  531. #endif
  532. case NL80211_IFTYPE_STATION:
  533. return Ndis802_11Infrastructure;
  534. #ifdef CONFIG_AP_MODE
  535. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  536. case NL80211_IFTYPE_P2P_GO:
  537. #endif
  538. case NL80211_IFTYPE_AP:
  539. return Ndis802_11APMode;
  540. #endif
  541. #ifdef CONFIG_RTW_MESH
  542. case NL80211_IFTYPE_MESH_POINT:
  543. return Ndis802_11_mesh;
  544. #endif
  545. case NL80211_IFTYPE_MONITOR:
  546. return Ndis802_11Monitor;
  547. default:
  548. return Ndis802_11InfrastructureMax;
  549. }
  550. }
  551. u32 nl80211_iftype_to_rtw_mlme_state(enum nl80211_iftype type)
  552. {
  553. switch (type) {
  554. case NL80211_IFTYPE_ADHOC:
  555. return WIFI_ADHOC_STATE;
  556. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  557. case NL80211_IFTYPE_P2P_CLIENT:
  558. #endif
  559. case NL80211_IFTYPE_STATION:
  560. return WIFI_STATION_STATE;
  561. #ifdef CONFIG_AP_MODE
  562. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  563. case NL80211_IFTYPE_P2P_GO:
  564. #endif
  565. case NL80211_IFTYPE_AP:
  566. return WIFI_AP_STATE;
  567. #endif
  568. #ifdef CONFIG_RTW_MESH
  569. case NL80211_IFTYPE_MESH_POINT:
  570. return WIFI_MESH_STATE;
  571. #endif
  572. case NL80211_IFTYPE_MONITOR:
  573. return WIFI_MONITOR_STATE;
  574. default:
  575. return WIFI_NULL_STATE;
  576. }
  577. }
  578. static int rtw_cfg80211_sync_iftype(_adapter *adapter)
  579. {
  580. struct wireless_dev *rtw_wdev = adapter->rtw_wdev;
  581. if (!(nl80211_iftype_to_rtw_mlme_state(rtw_wdev->iftype) & MLME_STATE(adapter))) {
  582. /* iftype and mlme state is not syc */
  583. NDIS_802_11_NETWORK_INFRASTRUCTURE network_type;
  584. network_type = nl80211_iftype_to_rtw_network_type(rtw_wdev->iftype);
  585. if (network_type != Ndis802_11InfrastructureMax) {
  586. if (rtw_pwr_wakeup(adapter) == _FAIL) {
  587. RTW_WARN(FUNC_ADPT_FMT" call rtw_pwr_wakeup fail\n", FUNC_ADPT_ARG(adapter));
  588. return _FAIL;
  589. }
  590. rtw_set_802_11_infrastructure_mode(adapter, network_type);
  591. rtw_setopmode_cmd(adapter, network_type, RTW_CMDF_WAIT_ACK);
  592. } else {
  593. rtw_warn_on(1);
  594. RTW_WARN(FUNC_ADPT_FMT" iftype:%u is not support\n", FUNC_ADPT_ARG(adapter), rtw_wdev->iftype);
  595. return _FAIL;
  596. }
  597. }
  598. return _SUCCESS;
  599. }
  600. static u64 rtw_get_systime_us(void)
  601. {
  602. return ktime_to_us(ktime_get_boottime());
  603. }
  604. /* Try to remove non target BSS's SR to reduce PBC overlap rate */
  605. static int rtw_cfg80211_clear_wps_sr_of_non_target_bss(_adapter *padapter, struct wlan_network *pnetwork, struct cfg80211_ssid *req_ssid)
  606. {
  607. int ret = 0;
  608. u8 *psr = NULL, sr = 0;
  609. NDIS_802_11_SSID *pssid = &pnetwork->network.Ssid;
  610. u32 wpsielen = 0;
  611. u8 *wpsie = NULL;
  612. if (pssid->SsidLength == req_ssid->ssid_len
  613. && _rtw_memcmp(pssid->Ssid, req_ssid->ssid, req_ssid->ssid_len) == _TRUE)
  614. goto exit;
  615. wpsie = rtw_get_wps_ie(pnetwork->network.IEs + _FIXED_IE_LENGTH_
  616. , pnetwork->network.IELength - _FIXED_IE_LENGTH_, NULL, &wpsielen);
  617. if (wpsie && wpsielen > 0)
  618. psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, &sr, NULL);
  619. if (psr && sr) {
  620. if (0)
  621. RTW_INFO("clear sr of non target bss:%s("MAC_FMT")\n"
  622. , pssid->Ssid, MAC_ARG(pnetwork->network.MacAddress));
  623. *psr = 0; /* clear sr */
  624. ret = 1;
  625. }
  626. exit:
  627. return ret;
  628. }
  629. #define MAX_BSSINFO_LEN 1000
  630. struct cfg80211_bss *rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnetwork)
  631. {
  632. struct ieee80211_channel *notify_channel;
  633. struct cfg80211_bss *bss = NULL;
  634. /* struct ieee80211_supported_band *band; */
  635. u16 channel;
  636. u32 freq;
  637. u64 notify_timestamp;
  638. u16 notify_capability;
  639. u16 notify_interval;
  640. u8 *notify_ie;
  641. size_t notify_ielen;
  642. s32 notify_signal;
  643. /* u8 buf[MAX_BSSINFO_LEN]; */
  644. u8 *pbuf;
  645. size_t buf_size = MAX_BSSINFO_LEN;
  646. size_t len, bssinf_len = 0;
  647. struct rtw_ieee80211_hdr *pwlanhdr;
  648. unsigned short *fctrl;
  649. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  650. struct wireless_dev *wdev = padapter->rtw_wdev;
  651. struct wiphy *wiphy = wdev->wiphy;
  652. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  653. pbuf = rtw_zmalloc(buf_size);
  654. if (pbuf == NULL) {
  655. RTW_INFO("%s pbuf allocate failed !!\n", __FUNCTION__);
  656. return bss;
  657. }
  658. /* RTW_INFO("%s\n", __func__); */
  659. bssinf_len = pnetwork->network.IELength + sizeof(struct rtw_ieee80211_hdr_3addr);
  660. if (bssinf_len > buf_size) {
  661. RTW_INFO("%s IE Length too long > %zu byte\n", __FUNCTION__, buf_size);
  662. goto exit;
  663. }
  664. #ifndef CONFIG_WAPI_SUPPORT
  665. {
  666. u16 wapi_len = 0;
  667. if (rtw_get_wapi_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &wapi_len) > 0) {
  668. if (wapi_len > 0) {
  669. RTW_INFO("%s, no support wapi!\n", __FUNCTION__);
  670. goto exit;
  671. }
  672. }
  673. }
  674. #endif /* !CONFIG_WAPI_SUPPORT */
  675. channel = pnetwork->network.Configuration.DSConfig;
  676. freq = rtw_ch2freq(channel);
  677. notify_channel = ieee80211_get_channel(wiphy, freq);
  678. if (0)
  679. notify_timestamp = le64_to_cpu(*(u64 *)rtw_get_timestampe_from_ie(pnetwork->network.IEs));
  680. else
  681. notify_timestamp = rtw_get_systime_us();
  682. notify_interval = le16_to_cpu(*(u16 *)rtw_get_beacon_interval_from_ie(pnetwork->network.IEs));
  683. notify_capability = le16_to_cpu(*(u16 *)rtw_get_capability_from_ie(pnetwork->network.IEs));
  684. notify_ie = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
  685. notify_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
  686. /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */
  687. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE &&
  688. is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
  689. notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */
  690. } else {
  691. notify_signal = 100 * translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength); /* dbm */
  692. }
  693. #if 0
  694. RTW_INFO("bssid: "MAC_FMT"\n", MAC_ARG(pnetwork->network.MacAddress));
  695. RTW_INFO("Channel: %d(%d)\n", channel, freq);
  696. RTW_INFO("Capability: %X\n", notify_capability);
  697. RTW_INFO("Beacon interval: %d\n", notify_interval);
  698. RTW_INFO("Signal: %d\n", notify_signal);
  699. RTW_INFO("notify_timestamp: %llu\n", notify_timestamp);
  700. #endif
  701. /* pbuf = buf; */
  702. pwlanhdr = (struct rtw_ieee80211_hdr *)pbuf;
  703. fctrl = &(pwlanhdr->frame_ctl);
  704. *(fctrl) = 0;
  705. SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
  706. /* pmlmeext->mgnt_seq++; */
  707. if (pnetwork->network.Reserved[0] == BSS_TYPE_BCN) { /* WIFI_BEACON */
  708. _rtw_memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
  709. set_frame_sub_type(pbuf, WIFI_BEACON);
  710. } else {
  711. _rtw_memcpy(pwlanhdr->addr1, adapter_mac_addr(padapter), ETH_ALEN);
  712. set_frame_sub_type(pbuf, WIFI_PROBERSP);
  713. }
  714. _rtw_memcpy(pwlanhdr->addr2, pnetwork->network.MacAddress, ETH_ALEN);
  715. _rtw_memcpy(pwlanhdr->addr3, pnetwork->network.MacAddress, ETH_ALEN);
  716. /* pbuf += sizeof(struct rtw_ieee80211_hdr_3addr); */
  717. len = sizeof(struct rtw_ieee80211_hdr_3addr);
  718. _rtw_memcpy((pbuf + len), pnetwork->network.IEs, pnetwork->network.IELength);
  719. *((u64 *)(pbuf + len)) = cpu_to_le64(notify_timestamp);
  720. len += pnetwork->network.IELength;
  721. #if defined(CONFIG_P2P) && 0
  722. if(rtw_get_p2p_ie(pnetwork->network.IEs+12, pnetwork->network.IELength-12, NULL, NULL))
  723. RTW_INFO("%s, got p2p_ie\n", __func__);
  724. #endif
  725. #if 1
  726. bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)pbuf,
  727. len, notify_signal, GFP_ATOMIC);
  728. #else
  729. bss = cfg80211_inform_bss(wiphy, notify_channel, (const u8 *)pnetwork->network.MacAddress,
  730. notify_timestamp, notify_capability, notify_interval, notify_ie,
  731. notify_ielen, notify_signal, GFP_ATOMIC/*GFP_KERNEL*/);
  732. #endif
  733. if (unlikely(!bss)) {
  734. RTW_INFO(FUNC_ADPT_FMT" bss NULL\n", FUNC_ADPT_ARG(padapter));
  735. goto exit;
  736. }
  737. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38))
  738. #ifndef COMPAT_KERNEL_RELEASE
  739. /* patch for cfg80211, update beacon ies to information_elements */
  740. if (pnetwork->network.Reserved[0] == BSS_TYPE_BCN) { /* WIFI_BEACON */
  741. if (bss->len_information_elements != bss->len_beacon_ies) {
  742. bss->information_elements = bss->beacon_ies;
  743. bss->len_information_elements = bss->len_beacon_ies;
  744. }
  745. }
  746. #endif /* COMPAT_KERNEL_RELEASE */
  747. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) */
  748. #if 0
  749. {
  750. if (bss->information_elements == bss->proberesp_ies) {
  751. if (bss->len_information_elements != bss->len_proberesp_ies)
  752. RTW_INFO("error!, len_information_elements != bss->len_proberesp_ies\n");
  753. } else if (bss->len_information_elements < bss->len_beacon_ies) {
  754. bss->information_elements = bss->beacon_ies;
  755. bss->len_information_elements = bss->len_beacon_ies;
  756. }
  757. }
  758. #endif
  759. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  760. cfg80211_put_bss(wiphy, bss);
  761. #else
  762. cfg80211_put_bss(bss);
  763. #endif
  764. exit:
  765. if (pbuf)
  766. rtw_mfree(pbuf, buf_size);
  767. return bss;
  768. }
  769. /*
  770. Check the given bss is valid by kernel API cfg80211_get_bss()
  771. @padapter : the given adapter
  772. return _TRUE if bss is valid, _FALSE for not found.
  773. */
  774. int rtw_cfg80211_check_bss(_adapter *padapter)
  775. {
  776. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  777. struct cfg80211_bss *bss = NULL;
  778. struct ieee80211_channel *notify_channel = NULL;
  779. u32 freq;
  780. if (!(pnetwork) || !(padapter->rtw_wdev))
  781. return _FALSE;
  782. freq = rtw_ch2freq(pnetwork->Configuration.DSConfig);
  783. notify_channel = ieee80211_get_channel(padapter->rtw_wdev->wiphy, freq);
  784. bss = cfg80211_get_bss(padapter->rtw_wdev->wiphy, notify_channel,
  785. pnetwork->MacAddress, pnetwork->Ssid.Ssid,
  786. pnetwork->Ssid.SsidLength,
  787. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
  788. pnetwork->InfrastructureMode == Ndis802_11Infrastructure?IEEE80211_BSS_TYPE_ESS:IEEE80211_BSS_TYPE_IBSS,
  789. IEEE80211_PRIVACY(pnetwork->Privacy));
  790. #else
  791. pnetwork->InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS, pnetwork->InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS);
  792. #endif
  793. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  794. cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
  795. #else
  796. cfg80211_put_bss(bss);
  797. #endif
  798. return bss != NULL;
  799. }
  800. void rtw_cfg80211_ibss_indicate_connect(_adapter *padapter)
  801. {
  802. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  803. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  804. struct wireless_dev *pwdev = padapter->rtw_wdev;
  805. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  806. struct wiphy *wiphy = pwdev->wiphy;
  807. int freq = 2412;
  808. struct ieee80211_channel *notify_channel;
  809. #endif
  810. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  811. if (pwdev->iftype != NL80211_IFTYPE_ADHOC)
  812. return;
  813. if (!rtw_cfg80211_check_bss(padapter)) {
  814. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  815. struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
  816. if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) {
  817. _rtw_memcpy(&cur_network->network, pnetwork, sizeof(WLAN_BSSID_EX));
  818. if (cur_network) {
  819. if (!rtw_cfg80211_inform_bss(padapter, cur_network))
  820. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  821. else
  822. RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter));
  823. } else {
  824. RTW_INFO("cur_network is not exist!!!\n");
  825. return ;
  826. }
  827. } else {
  828. if (scanned == NULL)
  829. rtw_warn_on(1);
  830. if (_rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
  831. && _rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
  832. ) {
  833. if (!rtw_cfg80211_inform_bss(padapter, scanned))
  834. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  835. else {
  836. /* RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */
  837. }
  838. } else {
  839. RTW_INFO("scanned & pnetwork compare fail\n");
  840. rtw_warn_on(1);
  841. }
  842. }
  843. if (!rtw_cfg80211_check_bss(padapter))
  844. RTW_PRINT(FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter));
  845. }
  846. /* notify cfg80211 that device joined an IBSS */
  847. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  848. freq = rtw_ch2freq(cur_network->network.Configuration.DSConfig);
  849. if (1)
  850. RTW_INFO("chan: %d, freq: %d\n", cur_network->network.Configuration.DSConfig, freq);
  851. notify_channel = ieee80211_get_channel(wiphy, freq);
  852. cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.MacAddress, notify_channel, GFP_ATOMIC);
  853. #else
  854. cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.MacAddress, GFP_ATOMIC);
  855. #endif
  856. }
  857. void rtw_cfg80211_indicate_connect(_adapter *padapter)
  858. {
  859. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  860. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  861. struct wireless_dev *pwdev = padapter->rtw_wdev;
  862. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  863. _irqL irqL;
  864. #ifdef CONFIG_P2P
  865. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  866. #endif
  867. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
  868. struct cfg80211_roam_info roam_info ={};
  869. #endif
  870. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  871. if (pwdev->iftype != NL80211_IFTYPE_STATION
  872. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  873. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  874. #endif
  875. )
  876. return;
  877. if (!MLME_IS_STA(padapter))
  878. return;
  879. #ifdef CONFIG_P2P
  880. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  881. #if !RTW_P2P_GROUP_INTERFACE
  882. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  883. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  884. rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
  885. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  886. RTW_INFO("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  887. }
  888. #endif
  889. }
  890. #endif /* CONFIG_P2P */
  891. if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE) {
  892. WLAN_BSSID_EX *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network);
  893. struct wlan_network *scanned = pmlmepriv->cur_network_scanned;
  894. /* RTW_INFO(FUNC_ADPT_FMT" BSS not found\n", FUNC_ADPT_ARG(padapter)); */
  895. if (scanned == NULL) {
  896. rtw_warn_on(1);
  897. goto check_bss;
  898. }
  899. if (_rtw_memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) == _TRUE
  900. && _rtw_memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(NDIS_802_11_SSID)) == _TRUE
  901. ) {
  902. if (!rtw_cfg80211_inform_bss(padapter, scanned))
  903. RTW_INFO(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter));
  904. else {
  905. /* RTW_INFO(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */
  906. }
  907. } else {
  908. RTW_INFO("scanned: %s("MAC_FMT"), cur: %s("MAC_FMT")\n",
  909. scanned->network.Ssid.Ssid, MAC_ARG(scanned->network.MacAddress),
  910. pnetwork->Ssid.Ssid, MAC_ARG(pnetwork->MacAddress)
  911. );
  912. rtw_warn_on(1);
  913. }
  914. }
  915. check_bss:
  916. if (!rtw_cfg80211_check_bss(padapter))
  917. RTW_PRINT(FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter));
  918. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  919. if (rtw_to_roam(padapter) > 0) {
  920. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  921. struct wiphy *wiphy = pwdev->wiphy;
  922. struct ieee80211_channel *notify_channel;
  923. u32 freq;
  924. u16 channel = cur_network->network.Configuration.DSConfig;
  925. freq = rtw_ch2freq(channel);
  926. notify_channel = ieee80211_get_channel(wiphy, freq);
  927. #endif
  928. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
  929. #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 0, 0)
  930. roam_info.channel = notify_channel;
  931. roam_info.bssid = cur_network->network.MacAddress;
  932. #else
  933. roam_info.links[0].channel = notify_channel;
  934. roam_info.links[0].bssid = cur_network->network.MacAddress;
  935. #endif
  936. roam_info.req_ie = pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2;
  937. roam_info.req_ie_len = pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2;
  938. roam_info.resp_ie = pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6;
  939. roam_info.resp_ie_len = pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6;
  940. cfg80211_roamed(padapter->pnetdev, &roam_info, GFP_ATOMIC);
  941. #else
  942. cfg80211_roamed(padapter->pnetdev
  943. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39) || defined(COMPAT_KERNEL_RELEASE)
  944. , notify_channel
  945. #endif
  946. , cur_network->network.MacAddress
  947. , pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2
  948. , pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2
  949. , pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6
  950. , pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6
  951. , GFP_ATOMIC);
  952. #endif /*LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)*/
  953. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_roamed\n", FUNC_ADPT_ARG(padapter));
  954. #ifdef CONFIG_RTW_80211R
  955. if (rtw_ft_roam(padapter))
  956. rtw_ft_set_status(padapter, RTW_FT_ASSOCIATED_STA);
  957. #endif
  958. } else {
  959. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  960. RTW_INFO("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  961. #endif
  962. if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE)
  963. rtw_cfg80211_connect_result(pwdev, cur_network->network.MacAddress
  964. , pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2
  965. , pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2
  966. , pmlmepriv->assoc_rsp + sizeof(struct rtw_ieee80211_hdr_3addr) + 6
  967. , pmlmepriv->assoc_rsp_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 6
  968. , WLAN_STATUS_SUCCESS, GFP_ATOMIC);
  969. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  970. RTW_INFO("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  971. #endif
  972. }
  973. rtw_wdev_free_connect_req(pwdev_priv);
  974. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  975. }
  976. void rtw_cfg80211_indicate_disconnect(_adapter *padapter, u16 reason, u8 locally_generated)
  977. {
  978. struct wireless_dev *pwdev = padapter->rtw_wdev;
  979. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  980. _irqL irqL;
  981. #ifdef CONFIG_P2P
  982. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  983. #endif
  984. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  985. /*always replace privated definitions with wifi reserved value 0*/
  986. if (WLAN_REASON_IS_PRIVATE(reason))
  987. reason = 0;
  988. if (pwdev->iftype != NL80211_IFTYPE_STATION
  989. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  990. && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT
  991. #endif
  992. )
  993. return;
  994. if (!MLME_IS_STA(padapter))
  995. return;
  996. #ifdef CONFIG_P2P
  997. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  998. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  999. rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
  1000. #if RTW_P2P_GROUP_INTERFACE
  1001. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1002. if (pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
  1003. #endif
  1004. #endif
  1005. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  1006. RTW_INFO("%s, role=%d, p2p_state=%d, pre_p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo), rtw_p2p_pre_state(pwdinfo));
  1007. }
  1008. }
  1009. #endif /* CONFIG_P2P */
  1010. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  1011. if (padapter->ndev_unregistering || !rtw_wdev_not_indic_disco(pwdev_priv)) {
  1012. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) || defined(COMPAT_KERNEL_RELEASE)
  1013. RTW_INFO("pwdev->sme_state(b)=%d\n", pwdev->sme_state);
  1014. if (pwdev->sme_state == CFG80211_SME_CONNECTING) {
  1015. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_connect_result\n", FUNC_ADPT_ARG(padapter));
  1016. rtw_cfg80211_connect_result(pwdev, NULL, NULL, 0, NULL, 0,
  1017. reason, GFP_ATOMIC);
  1018. } else if (pwdev->sme_state == CFG80211_SME_CONNECTED) {
  1019. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_disconnected\n", FUNC_ADPT_ARG(padapter));
  1020. rtw_cfg80211_disconnected(pwdev, reason, NULL, 0, locally_generated, GFP_ATOMIC);
  1021. }
  1022. RTW_INFO("pwdev->sme_state(a)=%d\n", pwdev->sme_state);
  1023. #else
  1024. if (pwdev_priv->connect_req) {
  1025. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_connect_result\n", FUNC_ADPT_ARG(padapter));
  1026. rtw_cfg80211_connect_result(pwdev, NULL, NULL, 0, NULL, 0,
  1027. reason, GFP_ATOMIC);
  1028. } else {
  1029. RTW_INFO(FUNC_ADPT_FMT" call cfg80211_disconnected\n", FUNC_ADPT_ARG(padapter));
  1030. rtw_cfg80211_disconnected(pwdev, reason, NULL, 0, locally_generated, GFP_ATOMIC);
  1031. }
  1032. #endif
  1033. }
  1034. rtw_wdev_free_connect_req(pwdev_priv);
  1035. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  1036. }
  1037. #ifdef CONFIG_AP_MODE
  1038. static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param)
  1039. {
  1040. int ret = 0;
  1041. u32 wep_key_idx, wep_key_len;
  1042. struct sta_info *psta = NULL, *pbcmc_sta = NULL;
  1043. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1044. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1045. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  1046. struct sta_priv *pstapriv = &padapter->stapriv;
  1047. RTW_INFO("%s\n", __FUNCTION__);
  1048. param->u.crypt.err = 0;
  1049. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  1050. if (is_broadcast_mac_addr(param->sta_addr)) {
  1051. if (param->u.crypt.idx >= WEP_KEYS
  1052. #ifdef CONFIG_IEEE80211W
  1053. && param->u.crypt.idx > BIP_MAX_KEYID
  1054. #endif
  1055. ) {
  1056. ret = -EINVAL;
  1057. goto exit;
  1058. }
  1059. } else {
  1060. psta = rtw_get_stainfo(pstapriv, param->sta_addr);
  1061. if (!psta) {
  1062. ret = -EINVAL;
  1063. RTW_INFO(FUNC_ADPT_FMT", sta "MAC_FMT" not found\n"
  1064. , FUNC_ADPT_ARG(padapter), MAC_ARG(param->sta_addr));
  1065. goto exit;
  1066. }
  1067. }
  1068. if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) {
  1069. /* todo:clear default encryption keys */
  1070. RTW_INFO("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
  1071. goto exit;
  1072. }
  1073. if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) {
  1074. RTW_INFO("r871x_set_encryption, crypt.alg = WEP\n");
  1075. wep_key_idx = param->u.crypt.idx;
  1076. wep_key_len = param->u.crypt.key_len;
  1077. RTW_INFO("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
  1078. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  1079. ret = -EINVAL;
  1080. goto exit;
  1081. }
  1082. if (wep_key_len > 0)
  1083. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  1084. if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
  1085. /* wep default key has not been set, so use this key index as default key. */
  1086. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  1087. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1088. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1089. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1090. if (wep_key_len == 13) {
  1091. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1092. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1093. }
  1094. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  1095. }
  1096. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  1097. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  1098. rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1);
  1099. goto exit;
  1100. }
  1101. if (!psta) { /* group key */
  1102. if (param->u.crypt.set_tx == 0) { /* group key, TX only */
  1103. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1104. RTW_INFO(FUNC_ADPT_FMT" set WEP TX GTK idx:%u, len:%u\n"
  1105. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1106. _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));
  1107. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1108. if (param->u.crypt.key_len == 13)
  1109. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1110. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  1111. RTW_INFO(FUNC_ADPT_FMT" set TKIP TX GTK idx:%u, len:%u\n"
  1112. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1113. psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
  1114. _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));
  1115. /* set mic key */
  1116. _rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  1117. _rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  1118. psecuritypriv->busetkipkey = _TRUE;
  1119. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1120. RTW_INFO(FUNC_ADPT_FMT" set CCMP TX GTK idx:%u, len:%u\n"
  1121. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1122. psecuritypriv->dot118021XGrpPrivacy = _AES_;
  1123. _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));
  1124. #ifdef CONFIG_IEEE80211W
  1125. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1126. RTW_INFO(FUNC_ADPT_FMT" set TX IGTK idx:%u, len:%u\n"
  1127. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1128. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1129. padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx;
  1130. psecuritypriv->dot11wBIPtxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1131. padapter->securitypriv.binstallBIPkey = _TRUE;
  1132. goto exit;
  1133. #endif /* CONFIG_IEEE80211W */
  1134. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1135. RTW_INFO(FUNC_ADPT_FMT" clear group key, idx:%u\n"
  1136. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx);
  1137. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  1138. } else {
  1139. RTW_WARN(FUNC_ADPT_FMT" set group key, not support\n"
  1140. , FUNC_ADPT_ARG(padapter));
  1141. goto exit;
  1142. }
  1143. psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
  1144. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  1145. if (pbcmc_sta) {
  1146. pbcmc_sta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1147. pbcmc_sta->ieee8021x_blocked = _FALSE;
  1148. pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy; /* rx will use bmc_sta's dot118021XPrivacy */
  1149. }
  1150. psecuritypriv->binstallGrpkey = _TRUE;
  1151. psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* !!! */
  1152. rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
  1153. }
  1154. goto exit;
  1155. }
  1156. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
  1157. if (param->u.crypt.set_tx == 1) {
  1158. /* pairwise key */
  1159. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1160. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1161. RTW_INFO(FUNC_ADPT_FMT" set WEP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1162. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1163. , param->u.crypt.idx, param->u.crypt.key_len);
  1164. psta->dot118021XPrivacy = _WEP40_;
  1165. if (param->u.crypt.key_len == 13)
  1166. psta->dot118021XPrivacy = _WEP104_;
  1167. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  1168. RTW_INFO(FUNC_ADPT_FMT" set TKIP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1169. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1170. , param->u.crypt.idx, param->u.crypt.key_len);
  1171. psta->dot118021XPrivacy = _TKIP_;
  1172. /* set mic key */
  1173. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  1174. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  1175. psecuritypriv->busetkipkey = _TRUE;
  1176. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1177. RTW_INFO(FUNC_ADPT_FMT" set CCMP PTK of "MAC_FMT" idx:%u, len:%u\n"
  1178. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1179. , param->u.crypt.idx, param->u.crypt.key_len);
  1180. psta->dot118021XPrivacy = _AES_;
  1181. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1182. RTW_INFO(FUNC_ADPT_FMT" clear pairwise key of "MAC_FMT" idx:%u\n"
  1183. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1184. , param->u.crypt.idx);
  1185. psta->dot118021XPrivacy = _NO_PRIVACY_;
  1186. } else {
  1187. RTW_WARN(FUNC_ADPT_FMT" set pairwise key of "MAC_FMT", not support\n"
  1188. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  1189. goto exit;
  1190. }
  1191. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1192. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1193. psta->ieee8021x_blocked = _FALSE;
  1194. if (psta->dot118021XPrivacy != _NO_PRIVACY_) {
  1195. psta->bpairwise_key_installed = _TRUE;
  1196. /* WPA2 key-handshake has completed */
  1197. if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK)
  1198. psta->state &= (~WIFI_UNDER_KEY_HANDSHAKE);
  1199. }
  1200. rtw_ap_set_pairwise_key(padapter, psta);
  1201. } else {
  1202. /* peer's group key, RX only */
  1203. #ifdef CONFIG_RTW_MESH
  1204. if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1205. RTW_INFO(FUNC_ADPT_FMT" set CCMP GTK of "MAC_FMT", idx:%u, len:%u\n"
  1206. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1207. , param->u.crypt.idx, param->u.crypt.key_len);
  1208. psta->group_privacy = _AES_;
  1209. _rtw_memcpy(psta->gtk.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1210. psta->gtk_bmp |= BIT(param->u.crypt.idx);
  1211. psta->gtk_pn.val = RTW_GET_LE64(param->u.crypt.seq);
  1212. #ifdef CONFIG_IEEE80211W
  1213. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1214. RTW_INFO(FUNC_ADPT_FMT" set IGTK of "MAC_FMT", idx:%u, len:%u\n"
  1215. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1216. , param->u.crypt.idx, param->u.crypt.key_len);
  1217. _rtw_memcpy(psta->igtk.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1218. psta->igtk_bmp |= BIT(param->u.crypt.idx);
  1219. psta->igtk_id = param->u.crypt.idx;
  1220. psta->igtk_pn.val = RTW_GET_LE64(param->u.crypt.seq);
  1221. goto exit;
  1222. #endif /* CONFIG_IEEE80211W */
  1223. } else if (strcmp(param->u.crypt.alg, "none") == 0) {
  1224. RTW_INFO(FUNC_ADPT_FMT" clear group key of "MAC_FMT", idx:%u\n"
  1225. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
  1226. , param->u.crypt.idx);
  1227. psta->group_privacy = _NO_PRIVACY_;
  1228. psta->gtk_bmp &= ~BIT(param->u.crypt.idx);
  1229. } else
  1230. #endif /* CONFIG_RTW_MESH */
  1231. {
  1232. RTW_WARN(FUNC_ADPT_FMT" set group key of "MAC_FMT", not support\n"
  1233. , FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
  1234. goto exit;
  1235. }
  1236. #ifdef CONFIG_RTW_MESH
  1237. rtw_ap_set_sta_key(padapter, psta->cmn.mac_addr, psta->group_privacy
  1238. , param->u.crypt.key, param->u.crypt.idx, 1);
  1239. #endif
  1240. }
  1241. }
  1242. exit:
  1243. return ret;
  1244. }
  1245. #endif /* CONFIG_AP_MODE */
  1246. static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param)
  1247. {
  1248. int ret = 0;
  1249. u32 wep_key_idx, wep_key_len;
  1250. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  1251. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1252. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1253. #ifdef CONFIG_P2P
  1254. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  1255. #endif /* CONFIG_P2P */
  1256. RTW_INFO("%s\n", __func__);
  1257. param->u.crypt.err = 0;
  1258. param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
  1259. if (is_broadcast_mac_addr(param->sta_addr)) {
  1260. if (param->u.crypt.idx >= WEP_KEYS
  1261. #ifdef CONFIG_IEEE80211W
  1262. && param->u.crypt.idx > BIP_MAX_KEYID
  1263. #endif
  1264. ) {
  1265. ret = -EINVAL;
  1266. goto exit;
  1267. }
  1268. } else {
  1269. #ifdef CONFIG_WAPI_SUPPORT
  1270. if (strcmp(param->u.crypt.alg, "SMS4"))
  1271. #endif
  1272. {
  1273. ret = -EINVAL;
  1274. goto exit;
  1275. }
  1276. }
  1277. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  1278. RTW_INFO("wpa_set_encryption, crypt.alg = WEP\n");
  1279. wep_key_idx = param->u.crypt.idx;
  1280. wep_key_len = param->u.crypt.key_len;
  1281. if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
  1282. ret = -EINVAL;
  1283. goto exit;
  1284. }
  1285. if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
  1286. /* wep default key has not been set, so use this key index as default key. */
  1287. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  1288. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1289. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1290. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1291. if (wep_key_len == 13) {
  1292. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1293. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1294. }
  1295. psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
  1296. }
  1297. _rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
  1298. psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
  1299. rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, _TRUE);
  1300. goto exit;
  1301. }
  1302. if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
  1303. struct sta_info *psta, *pbcmc_sta;
  1304. struct sta_priv *pstapriv = &padapter->stapriv;
  1305. /* RTW_INFO("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X\n", __func__); */
  1306. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) { /* sta mode */
  1307. #ifdef CONFIG_RTW_80211R
  1308. if (rtw_ft_roam(padapter))
  1309. psta = rtw_get_stainfo(pstapriv, pmlmepriv->assoc_bssid);
  1310. else
  1311. #endif
  1312. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  1313. if (psta == NULL) {
  1314. /* DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail\n")); */
  1315. RTW_INFO("%s, : Obtain Sta_info fail\n", __func__);
  1316. } else {
  1317. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  1318. if (strcmp(param->u.crypt.alg, "none") != 0)
  1319. psta->ieee8021x_blocked = _FALSE;
  1320. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  1321. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  1322. psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  1323. if (param->u.crypt.set_tx == 1) { /* pairwise key */
  1324. RTW_INFO(FUNC_ADPT_FMT" set %s PTK idx:%u, len:%u\n"
  1325. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  1326. _rtw_memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1327. if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
  1328. _rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
  1329. _rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
  1330. padapter->securitypriv.busetkipkey = _FALSE;
  1331. }
  1332. psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1333. psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1334. psta->bpairwise_key_installed = _TRUE;
  1335. #ifdef CONFIG_RTW_80211R
  1336. psta->ft_pairwise_key_installed = _TRUE;
  1337. #endif
  1338. rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _TRUE);
  1339. } else { /* group key */
  1340. if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) {
  1341. RTW_INFO(FUNC_ADPT_FMT" set %s GTK idx:%u, len:%u\n"
  1342. , FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
  1343. _rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key,
  1344. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1345. _rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
  1346. _rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
  1347. padapter->securitypriv.binstallGrpkey = _TRUE;
  1348. if (param->u.crypt.idx < 4)
  1349. _rtw_memcpy(padapter->securitypriv.iv_seq[param->u.crypt.idx], param->u.crypt.seq, 8);
  1350. padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
  1351. rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, _TRUE);
  1352. #ifdef CONFIG_IEEE80211W
  1353. } else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
  1354. RTW_INFO(FUNC_ADPT_FMT" set IGTK idx:%u, len:%u\n"
  1355. , FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
  1356. _rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key,
  1357. (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
  1358. psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
  1359. psecuritypriv->dot11wBIPrxpn.val = RTW_GET_LE64(param->u.crypt.seq);
  1360. psecuritypriv->binstallBIPkey = _TRUE;
  1361. #endif /* CONFIG_IEEE80211W */
  1362. }
  1363. #ifdef CONFIG_P2P
  1364. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  1365. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
  1366. rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
  1367. }
  1368. #endif /* CONFIG_P2P */
  1369. /* WPA/WPA2 key-handshake has completed */
  1370. clr_fwstate(pmlmepriv, WIFI_UNDER_KEY_HANDSHAKE);
  1371. }
  1372. }
  1373. pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
  1374. if (pbcmc_sta == NULL) {
  1375. /* DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */
  1376. } else {
  1377. /* Jeff: don't disable ieee8021x_blocked while clearing key */
  1378. if (strcmp(param->u.crypt.alg, "none") != 0)
  1379. pbcmc_sta->ieee8021x_blocked = _FALSE;
  1380. if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
  1381. (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
  1382. pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
  1383. }
  1384. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
  1385. }
  1386. }
  1387. #ifdef CONFIG_WAPI_SUPPORT
  1388. if (strcmp(param->u.crypt.alg, "SMS4") == 0)
  1389. rtw_wapi_set_set_encryption(padapter, param);
  1390. #endif
  1391. exit:
  1392. RTW_INFO("%s, ret=%d\n", __func__, ret);
  1393. return ret;
  1394. }
  1395. static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev
  1396. , u8 key_index
  1397. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1398. , bool pairwise
  1399. #endif
  1400. , const u8 *mac_addr, struct key_params *params)
  1401. {
  1402. char *alg_name;
  1403. u32 param_len;
  1404. struct ieee_param *param = NULL;
  1405. int ret = 0;
  1406. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1407. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  1408. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1409. #ifdef CONFIG_TDLS
  1410. struct sta_info *ptdls_sta;
  1411. #endif /* CONFIG_TDLS */
  1412. if (mac_addr)
  1413. RTW_INFO(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr);
  1414. RTW_INFO(FUNC_NDEV_FMT" cipher=0x%x\n", FUNC_NDEV_ARG(ndev), params->cipher);
  1415. RTW_INFO(FUNC_NDEV_FMT" key_len=%d, key_index=%d\n", FUNC_NDEV_ARG(ndev), params->key_len, key_index);
  1416. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1417. RTW_INFO(FUNC_NDEV_FMT" pairwise=%d\n", FUNC_NDEV_ARG(ndev), pairwise);
  1418. #endif
  1419. if (rtw_cfg80211_sync_iftype(padapter) != _SUCCESS) {
  1420. ret = -ENOTSUPP;
  1421. goto addkey_end;
  1422. }
  1423. param_len = sizeof(struct ieee_param) + params->key_len;
  1424. param = rtw_malloc(param_len);
  1425. if (param == NULL)
  1426. return -1;
  1427. _rtw_memset(param, 0, param_len);
  1428. param->cmd = IEEE_CMD_SET_ENCRYPTION;
  1429. _rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
  1430. switch (params->cipher) {
  1431. case IW_AUTH_CIPHER_NONE:
  1432. /* todo: remove key */
  1433. /* remove = 1; */
  1434. alg_name = "none";
  1435. break;
  1436. case WLAN_CIPHER_SUITE_WEP40:
  1437. case WLAN_CIPHER_SUITE_WEP104:
  1438. alg_name = "WEP";
  1439. break;
  1440. case WLAN_CIPHER_SUITE_TKIP:
  1441. alg_name = "TKIP";
  1442. break;
  1443. case WLAN_CIPHER_SUITE_CCMP:
  1444. alg_name = "CCMP";
  1445. break;
  1446. #ifdef CONFIG_IEEE80211W
  1447. case WLAN_CIPHER_SUITE_AES_CMAC:
  1448. alg_name = "BIP";
  1449. break;
  1450. #endif /* CONFIG_IEEE80211W */
  1451. #ifdef CONFIG_WAPI_SUPPORT
  1452. case WLAN_CIPHER_SUITE_SMS4:
  1453. alg_name = "SMS4";
  1454. if (pairwise == NL80211_KEYTYPE_PAIRWISE) {
  1455. if (key_index != 0 && key_index != 1) {
  1456. ret = -ENOTSUPP;
  1457. goto addkey_end;
  1458. }
  1459. _rtw_memcpy((void *)param->sta_addr, (void *)mac_addr, ETH_ALEN);
  1460. } else
  1461. RTW_INFO("mac_addr is null\n");
  1462. RTW_INFO("rtw_wx_set_enc_ext: SMS4 case\n");
  1463. break;
  1464. #endif
  1465. default:
  1466. ret = -ENOTSUPP;
  1467. goto addkey_end;
  1468. }
  1469. strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
  1470. if (!mac_addr || is_broadcast_ether_addr(mac_addr)
  1471. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1472. || !pairwise
  1473. #endif
  1474. ) {
  1475. param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */
  1476. } else {
  1477. param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */
  1478. }
  1479. param->u.crypt.idx = key_index;
  1480. if (params->seq_len && params->seq) {
  1481. _rtw_memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len);
  1482. RTW_INFO(FUNC_NDEV_FMT" seq_len:%u, seq:0x%llx\n", FUNC_NDEV_ARG(ndev)
  1483. , params->seq_len, RTW_GET_LE64(param->u.crypt.seq));
  1484. }
  1485. if (params->key_len && params->key) {
  1486. param->u.crypt.key_len = params->key_len;
  1487. _rtw_memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len);
  1488. }
  1489. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE) {
  1490. #ifdef CONFIG_TDLS
  1491. if (rtw_tdls_is_driver_setup(padapter) == _FALSE && mac_addr) {
  1492. ptdls_sta = rtw_get_stainfo(&padapter->stapriv, (void *)mac_addr);
  1493. if (ptdls_sta != NULL && ptdls_sta->tdls_sta_state) {
  1494. _rtw_memcpy(ptdls_sta->tpk.tk, params->key, params->key_len);
  1495. rtw_tdls_set_key(padapter, ptdls_sta);
  1496. goto addkey_end;
  1497. }
  1498. }
  1499. #endif /* CONFIG_TDLS */
  1500. ret = rtw_cfg80211_set_encryption(ndev, param);
  1501. } else if (MLME_IS_AP(padapter) || MLME_IS_MESH(padapter)) {
  1502. #ifdef CONFIG_AP_MODE
  1503. if (mac_addr)
  1504. _rtw_memcpy(param->sta_addr, (void *)mac_addr, ETH_ALEN);
  1505. ret = rtw_cfg80211_ap_set_encryption(ndev, param);
  1506. #endif
  1507. } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE
  1508. || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE
  1509. ) {
  1510. /* RTW_INFO("@@@@@@@@@@ fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype); */
  1511. ret = rtw_cfg80211_set_encryption(ndev, param);
  1512. } else
  1513. RTW_INFO("error! fw_state=0x%x, iftype=%d\n", pmlmepriv->fw_state, rtw_wdev->iftype);
  1514. addkey_end:
  1515. if (param)
  1516. rtw_mfree(param, param_len);
  1517. return ret;
  1518. }
  1519. static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev
  1520. , u8 keyid
  1521. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1522. , bool pairwise
  1523. #endif
  1524. , const u8 *mac_addr, void *cookie
  1525. , void (*callback)(void *cookie, struct key_params *))
  1526. {
  1527. #define GET_KEY_PARAM_FMT_S " keyid=%d"
  1528. #define GET_KEY_PARAM_ARG_S , keyid
  1529. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1530. #define GET_KEY_PARAM_FMT_2_6_37 ", pairwise=%d"
  1531. #define GET_KEY_PARAM_ARG_2_6_37 , pairwise
  1532. #else
  1533. #define GET_KEY_PARAM_FMT_2_6_37 ""
  1534. #define GET_KEY_PARAM_ARG_2_6_37
  1535. #endif
  1536. #define GET_KEY_PARAM_FMT_E ", addr=%pM"
  1537. #define GET_KEY_PARAM_ARG_E , mac_addr
  1538. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  1539. struct security_priv *sec = &adapter->securitypriv;
  1540. struct sta_priv *stapriv = &adapter->stapriv;
  1541. struct sta_info *sta = NULL;
  1542. u32 cipher = _NO_PRIVACY_;
  1543. union Keytype *key = NULL;
  1544. u8 key_len = 0;
  1545. u64 *pn = NULL;
  1546. u8 pn_len = 0;
  1547. u8 pn_val[8] = {0};
  1548. struct key_params params;
  1549. int ret = -ENOENT;
  1550. if (keyid >= WEP_KEYS
  1551. #ifdef CONFIG_IEEE80211W
  1552. && keyid > BIP_MAX_KEYID
  1553. #endif
  1554. )
  1555. goto exit;
  1556. if (!mac_addr || is_broadcast_ether_addr(mac_addr)
  1557. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1558. || (MLME_IS_STA(adapter) && !pairwise)
  1559. #endif
  1560. ) {
  1561. /* WEP key, TX GTK/IGTK, RX GTK/IGTK(for STA mode) */
  1562. if (is_wep_enc(sec->dot118021XGrpPrivacy)) {
  1563. if (keyid >= WEP_KEYS)
  1564. goto exit;
  1565. if (!(sec->key_mask & BIT(keyid)))
  1566. goto exit;
  1567. cipher = sec->dot118021XGrpPrivacy;
  1568. key = &sec->dot11DefKey[keyid];
  1569. } else {
  1570. if (keyid < WEP_KEYS) {
  1571. if (sec->binstallGrpkey != _TRUE)
  1572. goto exit;
  1573. cipher = sec->dot118021XGrpPrivacy;
  1574. key = &sec->dot118021XGrpKey[keyid];
  1575. sta = rtw_get_bcmc_stainfo(adapter);
  1576. if (sta)
  1577. pn = &sta->dot11txpn.val;
  1578. #ifdef CONFIG_IEEE80211W
  1579. } else if (keyid < BIP_MAX_KEYID) {
  1580. if (SEC_IS_BIP_KEY_INSTALLED(sec) != _TRUE)
  1581. goto exit;
  1582. cipher = _BIP_;
  1583. key = &sec->dot11wBIPKey[keyid];
  1584. pn = &sec->dot11wBIPtxpn.val;
  1585. #endif
  1586. }
  1587. }
  1588. } else {
  1589. /* Pairwise key, RX GTK/IGTK for specific peer */
  1590. sta = rtw_get_stainfo(stapriv, mac_addr);
  1591. if (!sta)
  1592. goto exit;
  1593. if (keyid < WEP_KEYS && pairwise) {
  1594. if (sta->bpairwise_key_installed != _TRUE)
  1595. goto exit;
  1596. cipher = sta->dot118021XPrivacy;
  1597. key = &sta->dot118021x_UncstKey;
  1598. #ifdef CONFIG_RTW_MESH
  1599. } else if (keyid < WEP_KEYS && !pairwise) {
  1600. if (!(sta->gtk_bmp & BIT(keyid)))
  1601. goto exit;
  1602. cipher = sta->group_privacy;
  1603. key = &sta->gtk;
  1604. #ifdef CONFIG_IEEE80211W
  1605. } else if (keyid < BIP_MAX_KEYID && !pairwise) {
  1606. if (!(sta->igtk_bmp & BIT(keyid)))
  1607. goto exit;
  1608. cipher = _BIP_;
  1609. key = &sta->igtk;
  1610. pn = &sta->igtk_pn.val;
  1611. #endif
  1612. #endif /* CONFIG_RTW_MESH */
  1613. }
  1614. }
  1615. if (!key)
  1616. goto exit;
  1617. if (cipher == _WEP40_) {
  1618. cipher = WLAN_CIPHER_SUITE_WEP40;
  1619. key_len = sec->dot11DefKeylen[keyid];
  1620. } else if (cipher == _WEP104_) {
  1621. cipher = WLAN_CIPHER_SUITE_WEP104;
  1622. key_len = sec->dot11DefKeylen[keyid];
  1623. } else if (cipher == _TKIP_) {
  1624. cipher = WLAN_CIPHER_SUITE_TKIP;
  1625. key_len = 16;
  1626. } else if (cipher == _AES_) {
  1627. cipher = WLAN_CIPHER_SUITE_CCMP;
  1628. key_len = 16;
  1629. #ifdef CONFIG_IEEE80211W
  1630. } else if (cipher == _BIP_) {
  1631. cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  1632. key_len = 16;
  1633. #endif
  1634. } else {
  1635. RTW_WARN(FUNC_NDEV_FMT" unknown cipher:%u\n", FUNC_NDEV_ARG(ndev), cipher);
  1636. rtw_warn_on(1);
  1637. goto exit;
  1638. }
  1639. if (pn) {
  1640. *((u64 *)pn_val) = cpu_to_le64(*pn);
  1641. pn_len = 6;
  1642. }
  1643. ret = 0;
  1644. exit:
  1645. RTW_INFO(FUNC_NDEV_FMT
  1646. GET_KEY_PARAM_FMT_S
  1647. GET_KEY_PARAM_FMT_2_6_37
  1648. GET_KEY_PARAM_FMT_E
  1649. " ret %d\n", FUNC_NDEV_ARG(ndev)
  1650. GET_KEY_PARAM_ARG_S
  1651. GET_KEY_PARAM_ARG_2_6_37
  1652. GET_KEY_PARAM_ARG_E
  1653. , ret);
  1654. if (pn)
  1655. RTW_INFO(FUNC_NDEV_FMT " seq:0x%llx\n", FUNC_NDEV_ARG(ndev), *pn);
  1656. if (ret == 0) {
  1657. _rtw_memset(&params, 0, sizeof(params));
  1658. params.cipher = cipher;
  1659. params.key = key->skey;
  1660. params.key_len = key_len;
  1661. if (pn) {
  1662. params.seq = pn_val;
  1663. params.seq_len = pn_len;
  1664. }
  1665. callback(cookie, &params);
  1666. }
  1667. return ret;
  1668. }
  1669. static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1670. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  1671. u8 key_index, bool pairwise, const u8 *mac_addr)
  1672. #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) */
  1673. u8 key_index, const u8 *mac_addr)
  1674. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) */
  1675. {
  1676. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1677. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1678. RTW_INFO(FUNC_NDEV_FMT" key_index=%d, addr=%pM\n", FUNC_NDEV_ARG(ndev), key_index, mac_addr);
  1679. if (key_index == psecuritypriv->dot11PrivacyKeyIndex) {
  1680. /* clear the flag of wep default key set. */
  1681. psecuritypriv->bWepDefaultKeyIdxSet = 0;
  1682. }
  1683. return 0;
  1684. }
  1685. static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
  1686. struct net_device *ndev, u8 key_index
  1687. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  1688. , bool unicast, bool multicast
  1689. #endif
  1690. )
  1691. {
  1692. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1693. struct security_priv *psecuritypriv = &padapter->securitypriv;
  1694. #define SET_DEF_KEY_PARAM_FMT " key_index=%d"
  1695. #define SET_DEF_KEY_PARAM_ARG , key_index
  1696. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  1697. #define SET_DEF_KEY_PARAM_FMT_2_6_38 ", unicast=%d, multicast=%d"
  1698. #define SET_DEF_KEY_PARAM_ARG_2_6_38 , unicast, multicast
  1699. #else
  1700. #define SET_DEF_KEY_PARAM_FMT_2_6_38 ""
  1701. #define SET_DEF_KEY_PARAM_ARG_2_6_38
  1702. #endif
  1703. RTW_INFO(FUNC_NDEV_FMT
  1704. SET_DEF_KEY_PARAM_FMT
  1705. SET_DEF_KEY_PARAM_FMT_2_6_38
  1706. "\n", FUNC_NDEV_ARG(ndev)
  1707. SET_DEF_KEY_PARAM_ARG
  1708. SET_DEF_KEY_PARAM_ARG_2_6_38
  1709. );
  1710. if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) { /* set wep default key */
  1711. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  1712. psecuritypriv->dot11PrivacyKeyIndex = key_index;
  1713. psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
  1714. psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
  1715. if (psecuritypriv->dot11DefKeylen[key_index] == 13) {
  1716. psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
  1717. psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
  1718. }
  1719. psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */
  1720. }
  1721. return 0;
  1722. }
  1723. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
  1724. int cfg80211_rtw_set_default_mgmt_key(struct wiphy *wiphy,
  1725. struct net_device *ndev, u8 key_index)
  1726. {
  1727. #define SET_DEF_KEY_PARAM_FMT " key_index=%d"
  1728. #define SET_DEF_KEY_PARAM_ARG , key_index
  1729. RTW_INFO(FUNC_NDEV_FMT
  1730. SET_DEF_KEY_PARAM_FMT
  1731. "\n", FUNC_NDEV_ARG(ndev)
  1732. SET_DEF_KEY_PARAM_ARG
  1733. );
  1734. return 0;
  1735. }
  1736. #endif
  1737. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
  1738. static int cfg80211_rtw_set_rekey_data(struct wiphy *wiphy,
  1739. struct net_device *ndev,
  1740. struct cfg80211_gtk_rekey_data *data)
  1741. {
  1742. /*int i;*/
  1743. struct sta_info *psta;
  1744. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1745. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1746. struct sta_priv *pstapriv = &padapter->stapriv;
  1747. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  1748. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  1749. if (psta == NULL) {
  1750. RTW_INFO("%s, : Obtain Sta_info fail\n", __func__);
  1751. return -1;
  1752. }
  1753. _rtw_memcpy(psta->kek, data->kek, NL80211_KEK_LEN);
  1754. /*printk("\ncfg80211_rtw_set_rekey_data KEK:");
  1755. for(i=0;i<NL80211_KEK_LEN; i++)
  1756. printk(" %02x ", psta->kek[i]);*/
  1757. _rtw_memcpy(psta->kck, data->kck, NL80211_KCK_LEN);
  1758. /*printk("\ncfg80211_rtw_set_rekey_data KCK:");
  1759. for(i=0;i<NL80211_KCK_LEN; i++)
  1760. printk(" %02x ", psta->kck[i]);*/
  1761. _rtw_memcpy(psta->replay_ctr, data->replay_ctr, NL80211_REPLAY_CTR_LEN);
  1762. psecuritypriv->binstallKCK_KEK = _TRUE;
  1763. /*printk("\nREPLAY_CTR: ");
  1764. for(i=0;i<RTW_REPLAY_CTR_LEN; i++)
  1765. printk(" %02x ", psta->replay_ctr[i]);*/
  1766. return 0;
  1767. }
  1768. #endif /*CONFIG_GTK_OL*/
  1769. #ifdef CONFIG_RTW_MESH
  1770. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  1771. static enum nl80211_mesh_power_mode rtw_mesh_ps_to_nl80211_mesh_power_mode(u8 ps)
  1772. {
  1773. if (ps == RTW_MESH_PS_UNKNOWN)
  1774. return NL80211_MESH_POWER_UNKNOWN;
  1775. if (ps == RTW_MESH_PS_ACTIVE)
  1776. return NL80211_MESH_POWER_ACTIVE;
  1777. if (ps == RTW_MESH_PS_LSLEEP)
  1778. return NL80211_MESH_POWER_LIGHT_SLEEP;
  1779. if (ps == RTW_MESH_PS_DSLEEP)
  1780. return NL80211_MESH_POWER_DEEP_SLEEP;
  1781. rtw_warn_on(1);
  1782. return NL80211_MESH_POWER_UNKNOWN;
  1783. }
  1784. #endif
  1785. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1786. enum nl80211_plink_state rtw_plink_state_to_nl80211_plink_state(u8 plink_state)
  1787. {
  1788. if (plink_state == RTW_MESH_PLINK_UNKNOWN)
  1789. return NUM_NL80211_PLINK_STATES;
  1790. if (plink_state == RTW_MESH_PLINK_LISTEN)
  1791. return NL80211_PLINK_LISTEN;
  1792. if (plink_state == RTW_MESH_PLINK_OPN_SNT)
  1793. return NL80211_PLINK_OPN_SNT;
  1794. if (plink_state == RTW_MESH_PLINK_OPN_RCVD)
  1795. return NL80211_PLINK_OPN_RCVD;
  1796. if (plink_state == RTW_MESH_PLINK_CNF_RCVD)
  1797. return NL80211_PLINK_CNF_RCVD;
  1798. if (plink_state == RTW_MESH_PLINK_ESTAB)
  1799. return NL80211_PLINK_ESTAB;
  1800. if (plink_state == RTW_MESH_PLINK_HOLDING)
  1801. return NL80211_PLINK_HOLDING;
  1802. if (plink_state == RTW_MESH_PLINK_BLOCKED)
  1803. return NL80211_PLINK_BLOCKED;
  1804. rtw_warn_on(1);
  1805. return NUM_NL80211_PLINK_STATES;
  1806. }
  1807. u8 nl80211_plink_state_to_rtw_plink_state(enum nl80211_plink_state plink_state)
  1808. {
  1809. if (plink_state == NL80211_PLINK_LISTEN)
  1810. return RTW_MESH_PLINK_LISTEN;
  1811. if (plink_state == NL80211_PLINK_OPN_SNT)
  1812. return RTW_MESH_PLINK_OPN_SNT;
  1813. if (plink_state == NL80211_PLINK_OPN_RCVD)
  1814. return RTW_MESH_PLINK_OPN_RCVD;
  1815. if (plink_state == NL80211_PLINK_CNF_RCVD)
  1816. return RTW_MESH_PLINK_CNF_RCVD;
  1817. if (plink_state == NL80211_PLINK_ESTAB)
  1818. return RTW_MESH_PLINK_ESTAB;
  1819. if (plink_state == NL80211_PLINK_HOLDING)
  1820. return RTW_MESH_PLINK_HOLDING;
  1821. if (plink_state == NL80211_PLINK_BLOCKED)
  1822. return RTW_MESH_PLINK_BLOCKED;
  1823. rtw_warn_on(1);
  1824. return RTW_MESH_PLINK_UNKNOWN;
  1825. }
  1826. #endif
  1827. static void rtw_cfg80211_fill_mesh_only_sta_info(struct mesh_plink_ent *plink, struct sta_info *sta, struct station_info *sinfo)
  1828. {
  1829. sinfo->filled |= STATION_INFO_LLID;
  1830. sinfo->llid = plink->llid;
  1831. sinfo->filled |= STATION_INFO_PLID;
  1832. sinfo->plid = plink->plid;
  1833. sinfo->filled |= STATION_INFO_PLINK_STATE;
  1834. sinfo->plink_state = rtw_plink_state_to_nl80211_plink_state(plink->plink_state);
  1835. if (!sta && plink->scanned) {
  1836. sinfo->filled |= STATION_INFO_SIGNAL;
  1837. sinfo->signal = translate_percentage_to_dbm(plink->scanned->network.PhyInfo.SignalStrength);
  1838. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  1839. if (plink->plink_state == RTW_MESH_PLINK_UNKNOWN)
  1840. sinfo->inactive_time = 0 - 1;
  1841. else
  1842. sinfo->inactive_time = rtw_get_passing_time_ms(plink->scanned->last_scanned);
  1843. }
  1844. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  1845. if (sta) {
  1846. sinfo->filled |= STATION_INFO_LOCAL_PM;
  1847. sinfo->local_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->local_mps);
  1848. sinfo->filled |= STATION_INFO_PEER_PM;
  1849. sinfo->peer_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->peer_mps);
  1850. sinfo->filled |= STATION_INFO_NONPEER_PM;
  1851. sinfo->nonpeer_pm = rtw_mesh_ps_to_nl80211_mesh_power_mode(sta->nonpeer_mps);
  1852. }
  1853. #endif
  1854. }
  1855. #endif /* CONFIG_RTW_MESH */
  1856. static int cfg80211_rtw_get_station(struct wiphy *wiphy,
  1857. struct net_device *ndev,
  1858. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  1859. u8 *mac,
  1860. #else
  1861. const u8 *mac,
  1862. #endif
  1863. struct station_info *sinfo)
  1864. {
  1865. int ret = 0;
  1866. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1867. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  1868. struct sta_info *psta = NULL;
  1869. struct sta_priv *pstapriv = &padapter->stapriv;
  1870. #ifdef CONFIG_RTW_MESH
  1871. struct mesh_plink_ent *plink = NULL;
  1872. #endif
  1873. sinfo->filled = 0;
  1874. if (!mac) {
  1875. RTW_INFO(FUNC_NDEV_FMT" mac==%p\n", FUNC_NDEV_ARG(ndev), mac);
  1876. ret = -ENOENT;
  1877. goto exit;
  1878. }
  1879. psta = rtw_get_stainfo(pstapriv, mac);
  1880. #ifdef CONFIG_RTW_MESH
  1881. if (MLME_IS_MESH(padapter)) {
  1882. if (psta)
  1883. plink = psta->plink;
  1884. if (!plink)
  1885. plink = rtw_mesh_plink_get(padapter, mac);
  1886. }
  1887. #endif /* CONFIG_RTW_MESH */
  1888. if ((!MLME_IS_MESH(padapter) && !psta)
  1889. #ifdef CONFIG_RTW_MESH
  1890. || (MLME_IS_MESH(padapter) && !plink)
  1891. #endif
  1892. ) {
  1893. RTW_INFO(FUNC_NDEV_FMT" no sta info for mac="MAC_FMT"\n"
  1894. , FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  1895. ret = -ENOENT;
  1896. goto exit;
  1897. }
  1898. #ifdef CONFIG_DEBUG_CFG80211
  1899. RTW_INFO(FUNC_NDEV_FMT" mac="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  1900. #endif
  1901. /* for infra./P2PClient mode */
  1902. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
  1903. && check_fwstate(pmlmepriv, _FW_LINKED)
  1904. ) {
  1905. struct wlan_network *cur_network = &(pmlmepriv->cur_network);
  1906. if (_rtw_memcmp((u8 *)mac, cur_network->network.MacAddress, ETH_ALEN) == _FALSE) {
  1907. RTW_INFO("%s, mismatch bssid="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress));
  1908. ret = -ENOENT;
  1909. goto exit;
  1910. }
  1911. sinfo->filled |= STATION_INFO_SIGNAL;
  1912. sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
  1913. sinfo->filled |= STATION_INFO_TX_BITRATE;
  1914. sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter);
  1915. }
  1916. if (psta) {
  1917. if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _FALSE
  1918. || check_fwstate(pmlmepriv, _FW_LINKED) == _FALSE
  1919. ) {
  1920. sinfo->filled |= STATION_INFO_SIGNAL;
  1921. sinfo->signal = translate_percentage_to_dbm(psta->cmn.rssi_stat.rssi);
  1922. }
  1923. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  1924. sinfo->inactive_time = rtw_get_passing_time_ms(psta->sta_stats.last_rx_time);
  1925. sinfo->filled |= STATION_INFO_RX_PACKETS;
  1926. sinfo->rx_packets = sta_rx_data_pkts(psta);
  1927. sinfo->filled |= STATION_INFO_TX_PACKETS;
  1928. sinfo->tx_packets = psta->sta_stats.tx_pkts;
  1929. sinfo->filled |= STATION_INFO_TX_FAILED;
  1930. sinfo->tx_failed = psta->sta_stats.tx_fail_cnt;
  1931. }
  1932. #ifdef CONFIG_RTW_MESH
  1933. if (MLME_IS_MESH(padapter))
  1934. rtw_cfg80211_fill_mesh_only_sta_info(plink, psta, sinfo);
  1935. #endif
  1936. exit:
  1937. return ret;
  1938. }
  1939. extern int netdev_open(struct net_device *pnetdev);
  1940. #if 0
  1941. enum nl80211_iftype {
  1942. NL80211_IFTYPE_UNSPECIFIED,
  1943. NL80211_IFTYPE_ADHOC, /* 1 */
  1944. NL80211_IFTYPE_STATION, /* 2 */
  1945. NL80211_IFTYPE_AP, /* 3 */
  1946. NL80211_IFTYPE_AP_VLAN,
  1947. NL80211_IFTYPE_WDS,
  1948. NL80211_IFTYPE_MONITOR, /* 6 */
  1949. NL80211_IFTYPE_MESH_POINT,
  1950. NL80211_IFTYPE_P2P_CLIENT, /* 8 */
  1951. NL80211_IFTYPE_P2P_GO, /* 9 */
  1952. /* keep last */
  1953. NUM_NL80211_IFTYPES,
  1954. NL80211_IFTYPE_MAX = NUM_NL80211_IFTYPES - 1
  1955. };
  1956. #endif
  1957. static int cfg80211_rtw_change_iface(struct wiphy *wiphy,
  1958. struct net_device *ndev,
  1959. enum nl80211_iftype type,
  1960. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  1961. u32 *flags,
  1962. #endif
  1963. struct vif_params *params)
  1964. {
  1965. enum nl80211_iftype old_type;
  1966. NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
  1967. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  1968. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  1969. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  1970. #ifdef CONFIG_P2P
  1971. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  1972. u8 is_p2p = _FALSE;
  1973. #endif
  1974. int ret = 0;
  1975. u8 change = _FALSE;
  1976. RTW_INFO(FUNC_NDEV_FMT" type=%d, hw_port:%d\n", FUNC_NDEV_ARG(ndev), type, padapter->hw_port);
  1977. if (adapter_to_dvobj(padapter)->processing_dev_remove == _TRUE) {
  1978. ret = -EPERM;
  1979. goto exit;
  1980. }
  1981. RTW_INFO(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev));
  1982. if (netdev_open(ndev) != 0) {
  1983. RTW_INFO(FUNC_NDEV_FMT" call netdev_open fail\n", FUNC_NDEV_ARG(ndev));
  1984. ret = -EPERM;
  1985. goto exit;
  1986. }
  1987. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  1988. RTW_INFO(FUNC_NDEV_FMT" call rtw_pwr_wakeup fail\n", FUNC_NDEV_ARG(ndev));
  1989. ret = -EPERM;
  1990. goto exit;
  1991. }
  1992. old_type = rtw_wdev->iftype;
  1993. RTW_INFO(FUNC_NDEV_FMT" old_iftype=%d, new_iftype=%d\n",
  1994. FUNC_NDEV_ARG(ndev), old_type, type);
  1995. if (old_type != type) {
  1996. change = _TRUE;
  1997. pmlmeext->action_public_rxseq = 0xffff;
  1998. pmlmeext->action_public_dialog_token = 0xff;
  1999. }
  2000. /* initial default type */
  2001. ndev->type = ARPHRD_ETHER;
  2002. /*
  2003. * Disable Power Save in moniter mode,
  2004. * and enable it after leaving moniter mode.
  2005. */
  2006. if (type == NL80211_IFTYPE_MONITOR) {
  2007. rtw_ps_deny(padapter, PS_DENY_MONITOR_MODE);
  2008. LeaveAllPowerSaveMode(padapter);
  2009. } else if (old_type == NL80211_IFTYPE_MONITOR) {
  2010. /* driver in moniter mode in last time */
  2011. rtw_ps_deny_cancel(padapter, PS_DENY_MONITOR_MODE);
  2012. }
  2013. switch (type) {
  2014. case NL80211_IFTYPE_ADHOC:
  2015. networkType = Ndis802_11IBSS;
  2016. break;
  2017. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  2018. case NL80211_IFTYPE_P2P_CLIENT:
  2019. is_p2p = _TRUE;
  2020. __attribute__((__fallthrough__));
  2021. #endif
  2022. case NL80211_IFTYPE_STATION:
  2023. networkType = Ndis802_11Infrastructure;
  2024. #ifdef CONFIG_P2P
  2025. if (change && pwdinfo->driver_interface == DRIVER_CFG80211) {
  2026. if (is_p2p == _TRUE)
  2027. rtw_p2p_enable(padapter, P2P_ROLE_CLIENT);
  2028. #if !RTW_P2P_GROUP_INTERFACE
  2029. else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)
  2030. || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)
  2031. ) {
  2032. /* it means remove GC/GO and change mode from GC/GO to station(P2P DEVICE) */
  2033. rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
  2034. }
  2035. #endif
  2036. }
  2037. #endif /* CONFIG_P2P */
  2038. break;
  2039. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  2040. case NL80211_IFTYPE_P2P_GO:
  2041. is_p2p = _TRUE;
  2042. __attribute__((__fallthrough__));
  2043. #endif
  2044. case NL80211_IFTYPE_AP:
  2045. networkType = Ndis802_11APMode;
  2046. #ifdef CONFIG_P2P
  2047. if (change && pwdinfo->driver_interface == DRIVER_CFG80211) {
  2048. if (is_p2p == _TRUE)
  2049. rtw_p2p_enable(padapter, P2P_ROLE_GO);
  2050. #if !RTW_P2P_GROUP_INTERFACE
  2051. else if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  2052. /* it means P2P Group created, we will be GO and change mode from P2P DEVICE to AP(GO) */
  2053. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  2054. }
  2055. #endif
  2056. }
  2057. #endif /* CONFIG_P2P */
  2058. break;
  2059. #ifdef CONFIG_RTW_MESH
  2060. case NL80211_IFTYPE_MESH_POINT:
  2061. networkType = Ndis802_11_mesh;
  2062. break;
  2063. #endif
  2064. case NL80211_IFTYPE_MONITOR:
  2065. networkType = Ndis802_11Monitor;
  2066. #if 0
  2067. ndev->type = ARPHRD_IEEE80211; /* IEEE 802.11 : 801 */
  2068. #endif
  2069. ndev->type = ARPHRD_IEEE80211_RADIOTAP; /* IEEE 802.11 + radiotap header : 803 */
  2070. break;
  2071. default:
  2072. ret = -EOPNOTSUPP;
  2073. goto exit;
  2074. }
  2075. rtw_wdev->iftype = type;
  2076. if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == _FALSE) {
  2077. rtw_wdev->iftype = old_type;
  2078. ret = -EPERM;
  2079. goto exit;
  2080. }
  2081. rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
  2082. exit:
  2083. RTW_INFO(FUNC_NDEV_FMT" ret:%d\n", FUNC_NDEV_ARG(ndev), ret);
  2084. return ret;
  2085. }
  2086. void rtw_cfg80211_indicate_scan_done(_adapter *adapter, bool aborted)
  2087. {
  2088. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  2089. _irqL irqL;
  2090. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2091. struct cfg80211_scan_info info;
  2092. memset(&info, 0, sizeof(info));
  2093. info.aborted = aborted;
  2094. #endif
  2095. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2096. if (pwdev_priv->scan_request != NULL) {
  2097. #ifdef CONFIG_DEBUG_CFG80211
  2098. RTW_INFO("%s with scan req\n", __FUNCTION__);
  2099. #endif
  2100. /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */
  2101. if (pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy)
  2102. RTW_INFO("error wiphy compare\n");
  2103. else
  2104. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2105. cfg80211_scan_done(pwdev_priv->scan_request, &info);
  2106. #else
  2107. cfg80211_scan_done(pwdev_priv->scan_request, aborted);
  2108. #endif
  2109. pwdev_priv->scan_request = NULL;
  2110. } else {
  2111. #ifdef CONFIG_DEBUG_CFG80211
  2112. RTW_INFO("%s without scan req\n", __FUNCTION__);
  2113. #endif
  2114. }
  2115. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2116. }
  2117. u32 rtw_cfg80211_wait_scan_req_empty(_adapter *adapter, u32 timeout_ms)
  2118. {
  2119. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  2120. u8 empty = _FALSE;
  2121. systime start;
  2122. u32 pass_ms;
  2123. start = rtw_get_current_time();
  2124. while (rtw_get_passing_time_ms(start) <= timeout_ms) {
  2125. if (RTW_CANNOT_RUN(adapter))
  2126. break;
  2127. if (!wdev_priv->scan_request) {
  2128. empty = _TRUE;
  2129. break;
  2130. }
  2131. rtw_msleep_os(10);
  2132. }
  2133. pass_ms = rtw_get_passing_time_ms(start);
  2134. if (empty == _FALSE && pass_ms > timeout_ms)
  2135. RTW_PRINT(FUNC_ADPT_FMT" pass_ms:%u, timeout\n"
  2136. , FUNC_ADPT_ARG(adapter), pass_ms);
  2137. return pass_ms;
  2138. }
  2139. void rtw_cfg80211_unlink_bss(_adapter *padapter, struct wlan_network *pnetwork)
  2140. {
  2141. struct wireless_dev *pwdev = padapter->rtw_wdev;
  2142. struct wiphy *wiphy = pwdev->wiphy;
  2143. struct cfg80211_bss *bss = NULL;
  2144. WLAN_BSSID_EX select_network = pnetwork->network;
  2145. bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/,
  2146. select_network.MacAddress, select_network.Ssid.Ssid,
  2147. select_network.Ssid.SsidLength,
  2148. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
  2149. select_network.InfrastructureMode == Ndis802_11Infrastructure?IEEE80211_BSS_TYPE_ESS:IEEE80211_BSS_TYPE_IBSS,
  2150. IEEE80211_PRIVACY(select_network.Privacy));
  2151. #else
  2152. select_network.InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS,
  2153. select_network.InfrastructureMode == Ndis802_11Infrastructure?WLAN_CAPABILITY_ESS:WLAN_CAPABILITY_IBSS);
  2154. #endif
  2155. if (bss) {
  2156. cfg80211_unlink_bss(wiphy, bss);
  2157. RTW_INFO("%s(): cfg80211_unlink %s!!\n", __func__, select_network.Ssid.Ssid);
  2158. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
  2159. cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss);
  2160. #else
  2161. cfg80211_put_bss(bss);
  2162. #endif
  2163. }
  2164. return;
  2165. }
  2166. /* if target wps scan ongoing, target_ssid is filled */
  2167. int rtw_cfg80211_is_target_wps_scan(struct cfg80211_scan_request *scan_req, struct cfg80211_ssid *target_ssid)
  2168. {
  2169. int ret = 0;
  2170. if (scan_req->n_ssids != 1
  2171. || scan_req->ssids[0].ssid_len == 0
  2172. || scan_req->n_channels != 1
  2173. )
  2174. goto exit;
  2175. /* under target WPS scan */
  2176. _rtw_memcpy(target_ssid, scan_req->ssids, sizeof(struct cfg80211_ssid));
  2177. ret = 1;
  2178. exit:
  2179. return ret;
  2180. }
  2181. static void _rtw_cfg80211_surveydone_event_callback(_adapter *padapter, struct cfg80211_scan_request *scan_req)
  2182. {
  2183. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  2184. RT_CHANNEL_INFO *chset = rfctl->channel_set;
  2185. _irqL irqL;
  2186. _list *plist, *phead;
  2187. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2188. _queue *queue = &(pmlmepriv->scanned_queue);
  2189. struct wlan_network *pnetwork = NULL;
  2190. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  2191. struct cfg80211_ssid target_ssid;
  2192. u8 target_wps_scan = 0;
  2193. u8 ch;
  2194. #ifdef CONFIG_DEBUG_CFG80211
  2195. RTW_INFO("%s\n", __func__);
  2196. #endif
  2197. if (scan_req)
  2198. target_wps_scan = rtw_cfg80211_is_target_wps_scan(scan_req, &target_ssid);
  2199. else {
  2200. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2201. if (pwdev_priv->scan_request != NULL)
  2202. target_wps_scan = rtw_cfg80211_is_target_wps_scan(pwdev_priv->scan_request, &target_ssid);
  2203. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2204. }
  2205. _enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2206. phead = get_list_head(queue);
  2207. plist = get_next(phead);
  2208. while (1) {
  2209. if (rtw_end_of_queue_search(phead, plist) == _TRUE)
  2210. break;
  2211. pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
  2212. ch = pnetwork->network.Configuration.DSConfig;
  2213. /* report network only if the current channel set contains the channel to which this network belongs */
  2214. if (rtw_chset_search_ch(chset, ch) >= 0
  2215. && rtw_mlme_band_check(padapter, ch) == _TRUE
  2216. && _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
  2217. && (!IS_DFS_SLAVE_WITH_RD(rfctl)
  2218. || rtw_odm_dfs_domain_unknown(rfctl_to_dvobj(rfctl))
  2219. || !rtw_chset_is_ch_non_ocp(chset, ch))
  2220. ) {
  2221. if (target_wps_scan)
  2222. rtw_cfg80211_clear_wps_sr_of_non_target_bss(padapter, pnetwork, &target_ssid);
  2223. rtw_cfg80211_inform_bss(padapter, pnetwork);
  2224. }
  2225. #if 0
  2226. /* check ralink testbed RSN IE length */
  2227. {
  2228. if (_rtw_memcmp(pnetwork->network.Ssid.Ssid, "Ralink_11n_AP", 13)) {
  2229. uint ie_len = 0;
  2230. u8 *p = NULL;
  2231. p = rtw_get_ie(pnetwork->network.IEs + _BEACON_IE_OFFSET_, _RSN_IE_2_, &ie_len, (pnetwork->network.IELength - _BEACON_IE_OFFSET_));
  2232. RTW_INFO("ie_len=%d\n", ie_len);
  2233. }
  2234. }
  2235. #endif
  2236. plist = get_next(plist);
  2237. }
  2238. _exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
  2239. }
  2240. inline void rtw_cfg80211_surveydone_event_callback(_adapter *padapter)
  2241. {
  2242. _rtw_cfg80211_surveydone_event_callback(padapter, NULL);
  2243. }
  2244. static int rtw_cfg80211_set_probe_req_wpsp2pie(_adapter *padapter, char *buf, int len)
  2245. {
  2246. int ret = 0;
  2247. uint wps_ielen = 0;
  2248. u8 *wps_ie;
  2249. u32 p2p_ielen = 0;
  2250. u8 *p2p_ie;
  2251. u32 wfd_ielen = 0;
  2252. u8 *wfd_ie;
  2253. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2254. #ifdef CONFIG_DEBUG_CFG80211
  2255. RTW_INFO("%s, ielen=%d\n", __func__, len);
  2256. #endif
  2257. if (len > 0) {
  2258. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  2259. if (wps_ie) {
  2260. #ifdef CONFIG_DEBUG_CFG80211
  2261. RTW_INFO("probe_req_wps_ielen=%d\n", wps_ielen);
  2262. #endif
  2263. if (pmlmepriv->wps_probe_req_ie) {
  2264. u32 free_len = pmlmepriv->wps_probe_req_ie_len;
  2265. pmlmepriv->wps_probe_req_ie_len = 0;
  2266. rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
  2267. pmlmepriv->wps_probe_req_ie = NULL;
  2268. }
  2269. pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen);
  2270. if (pmlmepriv->wps_probe_req_ie == NULL) {
  2271. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  2272. return -EINVAL;
  2273. }
  2274. _rtw_memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen);
  2275. pmlmepriv->wps_probe_req_ie_len = wps_ielen;
  2276. }
  2277. /* buf += wps_ielen; */
  2278. /* len -= wps_ielen; */
  2279. #ifdef CONFIG_P2P
  2280. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  2281. if (p2p_ie) {
  2282. struct wifidirect_info *wdinfo = &padapter->wdinfo;
  2283. u32 attr_contentlen = 0;
  2284. u8 listen_ch_attr[5];
  2285. #ifdef CONFIG_DEBUG_CFG80211
  2286. RTW_INFO("probe_req_p2p_ielen=%d\n", p2p_ielen);
  2287. #endif
  2288. if (pmlmepriv->p2p_probe_req_ie) {
  2289. u32 free_len = pmlmepriv->p2p_probe_req_ie_len;
  2290. pmlmepriv->p2p_probe_req_ie_len = 0;
  2291. rtw_mfree(pmlmepriv->p2p_probe_req_ie, free_len);
  2292. pmlmepriv->p2p_probe_req_ie = NULL;
  2293. }
  2294. pmlmepriv->p2p_probe_req_ie = rtw_malloc(p2p_ielen);
  2295. if (pmlmepriv->p2p_probe_req_ie == NULL) {
  2296. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  2297. return -EINVAL;
  2298. }
  2299. _rtw_memcpy(pmlmepriv->p2p_probe_req_ie, p2p_ie, p2p_ielen);
  2300. pmlmepriv->p2p_probe_req_ie_len = p2p_ielen;
  2301. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_LISTEN_CH, (u8 *)listen_ch_attr, (uint *) &attr_contentlen)
  2302. && attr_contentlen == 5) {
  2303. if (wdinfo->listen_channel != listen_ch_attr[4]) {
  2304. RTW_INFO(FUNC_ADPT_FMT" listen channel - country:%c%c%c, class:%u, ch:%u\n",
  2305. FUNC_ADPT_ARG(padapter), listen_ch_attr[0], listen_ch_attr[1], listen_ch_attr[2],
  2306. listen_ch_attr[3], listen_ch_attr[4]);
  2307. wdinfo->listen_channel = listen_ch_attr[4];
  2308. }
  2309. }
  2310. }
  2311. #endif /* CONFIG_P2P */
  2312. #ifdef CONFIG_WFD
  2313. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  2314. if (wfd_ie) {
  2315. #ifdef CONFIG_DEBUG_CFG80211
  2316. RTW_INFO("probe_req_wfd_ielen=%d\n", wfd_ielen);
  2317. #endif
  2318. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_PROBE_REQ_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  2319. return -EINVAL;
  2320. }
  2321. #endif /* CONFIG_WFD */
  2322. }
  2323. return ret;
  2324. }
  2325. #ifdef CONFIG_CONCURRENT_MODE
  2326. u8 rtw_cfg80211_scan_via_buddy(_adapter *padapter, struct cfg80211_scan_request *request)
  2327. {
  2328. int i;
  2329. u8 ret = _FALSE;
  2330. _adapter *iface = NULL;
  2331. _irqL irqL;
  2332. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2333. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  2334. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  2335. for (i = 0; i < dvobj->iface_nums; i++) {
  2336. struct mlme_priv *buddy_mlmepriv;
  2337. struct rtw_wdev_priv *buddy_wdev_priv;
  2338. iface = dvobj->padapters[i];
  2339. if (iface == NULL)
  2340. continue;
  2341. if (iface == padapter)
  2342. continue;
  2343. if (rtw_is_adapter_up(iface) == _FALSE)
  2344. continue;
  2345. buddy_mlmepriv = &iface->mlmepriv;
  2346. if (!check_fwstate(buddy_mlmepriv, _FW_UNDER_SURVEY))
  2347. continue;
  2348. buddy_wdev_priv = adapter_wdev_data(iface);
  2349. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2350. _enter_critical_bh(&buddy_wdev_priv->scan_req_lock, &irqL);
  2351. if (buddy_wdev_priv->scan_request) {
  2352. pmlmepriv->scanning_via_buddy_intf = _TRUE;
  2353. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2354. set_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
  2355. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2356. pwdev_priv->scan_request = request;
  2357. ret = _TRUE;
  2358. }
  2359. _exit_critical_bh(&buddy_wdev_priv->scan_req_lock, &irqL);
  2360. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2361. if (ret == _TRUE)
  2362. goto exit;
  2363. }
  2364. exit:
  2365. return ret;
  2366. }
  2367. void rtw_cfg80211_indicate_scan_done_for_buddy(_adapter *padapter, bool bscan_aborted)
  2368. {
  2369. int i;
  2370. u8 ret = 0;
  2371. _adapter *iface = NULL;
  2372. _irqL irqL;
  2373. struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
  2374. struct mlme_priv *mlmepriv;
  2375. struct rtw_wdev_priv *wdev_priv;
  2376. bool indicate_buddy_scan;
  2377. for (i = 0; i < dvobj->iface_nums; i++) {
  2378. iface = dvobj->padapters[i];
  2379. if ((iface) && rtw_is_adapter_up(iface)) {
  2380. if (iface == padapter)
  2381. continue;
  2382. mlmepriv = &(iface->mlmepriv);
  2383. wdev_priv = adapter_wdev_data(iface);
  2384. indicate_buddy_scan = _FALSE;
  2385. _enter_critical_bh(&wdev_priv->scan_req_lock, &irqL);
  2386. if (mlmepriv->scanning_via_buddy_intf == _TRUE) {
  2387. mlmepriv->scanning_via_buddy_intf = _FALSE;
  2388. clr_fwstate(mlmepriv, _FW_UNDER_SURVEY);
  2389. if (wdev_priv->scan_request)
  2390. indicate_buddy_scan = _TRUE;
  2391. }
  2392. _exit_critical_bh(&wdev_priv->scan_req_lock, &irqL);
  2393. if (indicate_buddy_scan == _TRUE) {
  2394. rtw_cfg80211_surveydone_event_callback(iface);
  2395. rtw_indicate_scan_done(iface, bscan_aborted);
  2396. }
  2397. }
  2398. }
  2399. }
  2400. #endif /* CONFIG_CONCURRENT_MODE */
  2401. static int cfg80211_rtw_scan(struct wiphy *wiphy
  2402. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  2403. , struct net_device *ndev
  2404. #endif
  2405. , struct cfg80211_scan_request *request)
  2406. {
  2407. int i;
  2408. u8 _status = _FALSE;
  2409. int ret = 0;
  2410. struct sitesurvey_parm parm;
  2411. _irqL irqL;
  2412. u8 survey_times = 3;
  2413. u8 survey_times_for_one_ch = 6;
  2414. struct cfg80211_ssid *ssids = request->ssids;
  2415. int social_channel = 0, j = 0;
  2416. bool need_indicate_scan_done = _FALSE;
  2417. bool ps_denied = _FALSE;
  2418. u8 ssc_chk;
  2419. _adapter *padapter;
  2420. struct wireless_dev *wdev;
  2421. struct rtw_wdev_priv *pwdev_priv;
  2422. struct mlme_priv *pmlmepriv;
  2423. #ifdef CONFIG_P2P
  2424. struct wifidirect_info *pwdinfo;
  2425. #endif /* CONFIG_P2P */
  2426. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  2427. wdev = request->wdev;
  2428. #if defined(RTW_DEDICATED_P2P_DEVICE)
  2429. if (wdev == wiphy_to_pd_wdev(wiphy))
  2430. padapter = wiphy_to_adapter(wiphy);
  2431. else
  2432. #endif
  2433. if (wdev_to_ndev(wdev))
  2434. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  2435. else {
  2436. ret = -EINVAL;
  2437. goto exit;
  2438. }
  2439. #else
  2440. if (ndev == NULL) {
  2441. ret = -EINVAL;
  2442. goto exit;
  2443. }
  2444. padapter = (_adapter *)rtw_netdev_priv(ndev);
  2445. wdev = ndev_to_wdev(ndev);
  2446. #endif
  2447. pwdev_priv = adapter_wdev_data(padapter);
  2448. pmlmepriv = &padapter->mlmepriv;
  2449. #ifdef CONFIG_P2P
  2450. pwdinfo = &(padapter->wdinfo);
  2451. #endif /* CONFIG_P2P */
  2452. RTW_INFO(FUNC_ADPT_FMT"%s\n", FUNC_ADPT_ARG(padapter)
  2453. , wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : "");
  2454. #if 1
  2455. ssc_chk = rtw_sitesurvey_condition_check(padapter, _TRUE);
  2456. if (ssc_chk == SS_DENY_MP_MODE)
  2457. goto bypass_p2p_chk;
  2458. #ifdef DBG_LA_MODE
  2459. if (ssc_chk == SS_DENY_LA_MODE)
  2460. goto bypass_p2p_chk;
  2461. #endif
  2462. #ifdef CONFIG_P2P
  2463. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  2464. if (ssids->ssid != NULL
  2465. && _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
  2466. && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
  2467. ) {
  2468. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2469. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  2470. else {
  2471. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  2472. #ifdef CONFIG_DEBUG_CFG80211
  2473. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  2474. #endif
  2475. }
  2476. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  2477. if (request->n_channels == 3 &&
  2478. request->channels[0]->hw_value == 1 &&
  2479. request->channels[1]->hw_value == 6 &&
  2480. request->channels[2]->hw_value == 11
  2481. )
  2482. social_channel = 1;
  2483. }
  2484. }
  2485. #endif /*CONFIG_P2P*/
  2486. if (request->ie && request->ie_len > 0)
  2487. rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len);
  2488. bypass_p2p_chk:
  2489. switch (ssc_chk) {
  2490. case SS_ALLOW :
  2491. break;
  2492. case SS_DENY_MP_MODE:
  2493. ret = -EPERM;
  2494. goto exit;
  2495. #ifdef DBG_LA_MODE
  2496. case SS_DENY_LA_MODE:
  2497. ret = -EPERM;
  2498. goto exit;
  2499. #endif
  2500. #ifdef CONFIG_RTW_REPEATER_SON
  2501. case SS_DENY_RSON_SCANING :
  2502. #endif
  2503. case SS_DENY_BLOCK_SCAN :
  2504. case SS_DENY_SELF_AP_UNDER_WPS :
  2505. case SS_DENY_SELF_AP_UNDER_LINKING :
  2506. case SS_DENY_SELF_AP_UNDER_SURVEY :
  2507. case SS_DENY_SELF_STA_UNDER_SURVEY :
  2508. #ifdef CONFIG_CONCURRENT_MODE
  2509. case SS_DENY_BUDDY_UNDER_LINK_WPS :
  2510. #endif
  2511. case SS_DENY_BUSY_TRAFFIC :
  2512. need_indicate_scan_done = _TRUE;
  2513. goto check_need_indicate_scan_done;
  2514. case SS_DENY_BY_DRV :
  2515. #if CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  2516. ret = -EBUSY;
  2517. goto exit;
  2518. #else
  2519. need_indicate_scan_done = _TRUE;
  2520. goto check_need_indicate_scan_done;
  2521. #endif
  2522. break;
  2523. case SS_DENY_SELF_STA_UNDER_LINKING :
  2524. ret = -EBUSY;
  2525. goto check_need_indicate_scan_done;
  2526. #ifdef CONFIG_CONCURRENT_MODE
  2527. case SS_DENY_BUDDY_UNDER_SURVEY :
  2528. {
  2529. bool scan_via_buddy = rtw_cfg80211_scan_via_buddy(padapter, request);
  2530. if (scan_via_buddy == _FALSE)
  2531. need_indicate_scan_done = _TRUE;
  2532. goto check_need_indicate_scan_done;
  2533. }
  2534. #endif
  2535. default :
  2536. RTW_ERR("site survey check code (%d) unknown\n", ssc_chk);
  2537. need_indicate_scan_done = _TRUE;
  2538. goto check_need_indicate_scan_done;
  2539. }
  2540. rtw_ps_deny(padapter, PS_DENY_SCAN);
  2541. ps_denied = _TRUE;
  2542. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  2543. need_indicate_scan_done = _TRUE;
  2544. goto check_need_indicate_scan_done;
  2545. }
  2546. #else
  2547. #ifdef CONFIG_MP_INCLUDED
  2548. if (rtw_mp_mode_check(padapter)) {
  2549. RTW_INFO("MP mode block Scan request\n");
  2550. ret = -EPERM;
  2551. goto exit;
  2552. }
  2553. #endif
  2554. #ifdef CONFIG_P2P
  2555. if (pwdinfo->driver_interface == DRIVER_CFG80211) {
  2556. if (ssids->ssid != NULL
  2557. && _rtw_memcmp(ssids->ssid, "DIRECT-", 7)
  2558. && rtw_get_p2p_ie((u8 *)request->ie, request->ie_len, NULL, NULL)
  2559. ) {
  2560. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  2561. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  2562. else {
  2563. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  2564. #ifdef CONFIG_DEBUG_CFG80211
  2565. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  2566. #endif
  2567. }
  2568. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  2569. if (request->n_channels == 3 &&
  2570. request->channels[0]->hw_value == 1 &&
  2571. request->channels[1]->hw_value == 6 &&
  2572. request->channels[2]->hw_value == 11
  2573. )
  2574. social_channel = 1;
  2575. }
  2576. }
  2577. #endif /*CONFIG_P2P*/
  2578. if (request->ie && request->ie_len > 0)
  2579. rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len);
  2580. #ifdef CONFIG_RTW_REPEATER_SON
  2581. if (padapter->rtw_rson_scanstage == RSON_SCAN_PROCESS) {
  2582. RTW_INFO(FUNC_ADPT_FMT" blocking scan for under rson scanning process\n", FUNC_ADPT_ARG(padapter));
  2583. need_indicate_scan_done = _TRUE;
  2584. goto check_need_indicate_scan_done;
  2585. }
  2586. #endif
  2587. if (adapter_wdev_data(padapter)->block_scan == _TRUE) {
  2588. RTW_INFO(FUNC_ADPT_FMT" wdev_priv.block_scan is set\n", FUNC_ADPT_ARG(padapter));
  2589. need_indicate_scan_done = _TRUE;
  2590. goto check_need_indicate_scan_done;
  2591. }
  2592. rtw_ps_deny(padapter, PS_DENY_SCAN);
  2593. ps_denied = _TRUE;
  2594. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  2595. need_indicate_scan_done = _TRUE;
  2596. goto check_need_indicate_scan_done;
  2597. }
  2598. if (rtw_is_scan_deny(padapter)) {
  2599. RTW_INFO(FUNC_ADPT_FMT ": scan deny\n", FUNC_ADPT_ARG(padapter));
  2600. #if CONFIG_NOTIFY_SCAN_ABORT_WITH_BUSY
  2601. ret = -EBUSY;
  2602. goto exit;
  2603. #else
  2604. need_indicate_scan_done = _TRUE;
  2605. goto check_need_indicate_scan_done;
  2606. #endif
  2607. }
  2608. /* check fw state*/
  2609. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
  2610. #ifdef CONFIG_DEBUG_CFG80211
  2611. RTW_INFO(FUNC_ADPT_FMT" under WIFI_AP_STATE\n", FUNC_ADPT_ARG(padapter));
  2612. #endif
  2613. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS | _FW_UNDER_SURVEY | _FW_UNDER_LINKING) == _TRUE) {
  2614. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2615. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS))
  2616. RTW_INFO("AP mode process WPS\n");
  2617. need_indicate_scan_done = _TRUE;
  2618. goto check_need_indicate_scan_done;
  2619. }
  2620. }
  2621. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE) {
  2622. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2623. need_indicate_scan_done = _TRUE;
  2624. goto check_need_indicate_scan_done;
  2625. } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  2626. RTW_INFO("%s, fwstate=0x%x\n", __func__, pmlmepriv->fw_state);
  2627. ret = -EBUSY;
  2628. goto check_need_indicate_scan_done;
  2629. }
  2630. #ifdef CONFIG_CONCURRENT_MODE
  2631. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING | WIFI_UNDER_WPS)) {
  2632. RTW_INFO("%s exit due to buddy_intf's mlme state under linking or wps\n", __func__);
  2633. need_indicate_scan_done = _TRUE;
  2634. goto check_need_indicate_scan_done;
  2635. } else if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_SURVEY)) {
  2636. bool scan_via_buddy = rtw_cfg80211_scan_via_buddy(padapter, request);
  2637. if (scan_via_buddy == _FALSE)
  2638. need_indicate_scan_done = _TRUE;
  2639. goto check_need_indicate_scan_done;
  2640. }
  2641. #endif /* CONFIG_CONCURRENT_MODE */
  2642. /* busy traffic check*/
  2643. if (rtw_mi_busy_traffic_check(padapter, _TRUE)) {
  2644. need_indicate_scan_done = _TRUE;
  2645. goto check_need_indicate_scan_done;
  2646. }
  2647. #endif
  2648. #ifdef CONFIG_P2P
  2649. if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
  2650. rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  2651. if (social_channel == 0)
  2652. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
  2653. else
  2654. rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_SOCIAL_LAST);
  2655. }
  2656. #endif /* CONFIG_P2P */
  2657. rtw_init_sitesurvey_parm(padapter, &parm);
  2658. /* parsing request ssids, n_ssids */
  2659. for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) {
  2660. #ifdef CONFIG_DEBUG_CFG80211
  2661. RTW_INFO("ssid=%s, len=%d\n", ssids[i].ssid, ssids[i].ssid_len);
  2662. #endif
  2663. _rtw_memcpy(&parm.ssid[i].Ssid, ssids[i].ssid, ssids[i].ssid_len);
  2664. parm.ssid[i].SsidLength = ssids[i].ssid_len;
  2665. }
  2666. parm.ssid_num = i;
  2667. /* parsing channels, n_channels */
  2668. for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
  2669. #ifdef CONFIG_DEBUG_CFG80211
  2670. RTW_INFO(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i]));
  2671. #endif
  2672. parm.ch[i].hw_value = request->channels[i]->hw_value;
  2673. parm.ch[i].flags = request->channels[i]->flags;
  2674. }
  2675. parm.ch_num = i;
  2676. if (request->n_channels == 1) {
  2677. for (i = 1; i < survey_times_for_one_ch; i++)
  2678. _rtw_memcpy(&parm.ch[i], &parm.ch[0], sizeof(struct rtw_ieee80211_channel));
  2679. parm.ch_num = survey_times_for_one_ch;
  2680. } else if (request->n_channels <= 4) {
  2681. for (j = request->n_channels - 1; j >= 0; j--)
  2682. for (i = 0; i < survey_times; i++)
  2683. _rtw_memcpy(&parm.ch[j * survey_times + i], &parm.ch[j], sizeof(struct rtw_ieee80211_channel));
  2684. parm.ch_num = survey_times * request->n_channels;
  2685. }
  2686. _enter_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2687. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  2688. _status = rtw_sitesurvey_cmd(padapter, &parm);
  2689. if (_status == _SUCCESS)
  2690. pwdev_priv->scan_request = request;
  2691. else
  2692. ret = -1;
  2693. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  2694. _exit_critical_bh(&pwdev_priv->scan_req_lock, &irqL);
  2695. check_need_indicate_scan_done:
  2696. if (_TRUE == need_indicate_scan_done) {
  2697. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2698. struct cfg80211_scan_info info;
  2699. memset(&info, 0, sizeof(info));
  2700. info.aborted = 0;
  2701. #endif
  2702. _rtw_cfg80211_surveydone_event_callback(padapter, request);
  2703. #if (KERNEL_VERSION(4, 7, 0) <= LINUX_VERSION_CODE)
  2704. cfg80211_scan_done(request, &info);
  2705. #else
  2706. cfg80211_scan_done(request, 0);
  2707. #endif
  2708. }
  2709. cancel_ps_deny:
  2710. if (ps_denied == _TRUE)
  2711. rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
  2712. exit:
  2713. return ret;
  2714. }
  2715. static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  2716. {
  2717. #if 0
  2718. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  2719. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  2720. (iwm->conf.rts_threshold != wiphy->rts_threshold)) {
  2721. int ret;
  2722. iwm->conf.rts_threshold = wiphy->rts_threshold;
  2723. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  2724. CFG_RTS_THRESHOLD,
  2725. iwm->conf.rts_threshold);
  2726. if (ret < 0)
  2727. return ret;
  2728. }
  2729. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  2730. (iwm->conf.frag_threshold != wiphy->frag_threshold)) {
  2731. int ret;
  2732. iwm->conf.frag_threshold = wiphy->frag_threshold;
  2733. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_FA_CFG_FIX,
  2734. CFG_FRAG_THRESHOLD,
  2735. iwm->conf.frag_threshold);
  2736. if (ret < 0)
  2737. return ret;
  2738. }
  2739. #endif
  2740. RTW_INFO("%s\n", __func__);
  2741. return 0;
  2742. }
  2743. static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version)
  2744. {
  2745. RTW_INFO("%s, wpa_version=%d\n", __func__, wpa_version);
  2746. if (!wpa_version) {
  2747. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  2748. return 0;
  2749. }
  2750. if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
  2751. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK;
  2752. #if 0
  2753. if (wpa_version & NL80211_WPA_VERSION_2)
  2754. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  2755. #endif
  2756. #ifdef CONFIG_WAPI_SUPPORT
  2757. if (wpa_version & NL80211_WAPI_VERSION_1)
  2758. psecuritypriv->ndisauthtype = Ndis802_11AuthModeWAPI;
  2759. #endif
  2760. return 0;
  2761. }
  2762. static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv,
  2763. enum nl80211_auth_type sme_auth_type)
  2764. {
  2765. RTW_INFO("%s, nl80211_auth_type=%d\n", __func__, sme_auth_type);
  2766. switch (sme_auth_type) {
  2767. case NL80211_AUTHTYPE_AUTOMATIC:
  2768. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
  2769. break;
  2770. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  2771. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  2772. if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA)
  2773. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2774. #ifdef CONFIG_WAPI_SUPPORT
  2775. if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWAPI)
  2776. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2777. #endif
  2778. break;
  2779. case NL80211_AUTHTYPE_SHARED_KEY:
  2780. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
  2781. psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2782. break;
  2783. default:
  2784. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
  2785. /* return -ENOTSUPP; */
  2786. }
  2787. return 0;
  2788. }
  2789. static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast)
  2790. {
  2791. u32 ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2792. u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm :
  2793. &psecuritypriv->dot118021XGrpPrivacy;
  2794. RTW_INFO("%s, ucast=%d, cipher=0x%x\n", __func__, ucast, cipher);
  2795. if (!cipher) {
  2796. *profile_cipher = _NO_PRIVACY_;
  2797. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  2798. return 0;
  2799. }
  2800. switch (cipher) {
  2801. case IW_AUTH_CIPHER_NONE:
  2802. *profile_cipher = _NO_PRIVACY_;
  2803. ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2804. #ifdef CONFIG_WAPI_SUPPORT
  2805. if (psecuritypriv->dot11PrivacyAlgrthm == _SMS4_)
  2806. *profile_cipher = _SMS4_;
  2807. #endif
  2808. break;
  2809. case WLAN_CIPHER_SUITE_WEP40:
  2810. *profile_cipher = _WEP40_;
  2811. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2812. break;
  2813. case WLAN_CIPHER_SUITE_WEP104:
  2814. *profile_cipher = _WEP104_;
  2815. ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2816. break;
  2817. case WLAN_CIPHER_SUITE_TKIP:
  2818. *profile_cipher = _TKIP_;
  2819. ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2820. break;
  2821. case WLAN_CIPHER_SUITE_CCMP:
  2822. *profile_cipher = _AES_;
  2823. ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2824. break;
  2825. #ifdef CONFIG_WAPI_SUPPORT
  2826. case WLAN_CIPHER_SUITE_SMS4:
  2827. *profile_cipher = _SMS4_;
  2828. ndisencryptstatus = Ndis802_11_EncrypteionWAPI;
  2829. break;
  2830. #endif
  2831. default:
  2832. RTW_INFO("Unsupported cipher: 0x%x\n", cipher);
  2833. return -ENOTSUPP;
  2834. }
  2835. if (ucast) {
  2836. psecuritypriv->ndisencryptstatus = ndisencryptstatus;
  2837. /* if(psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */
  2838. /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */
  2839. }
  2840. return 0;
  2841. }
  2842. static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt)
  2843. {
  2844. RTW_INFO("%s, key_mgt=0x%x\n", __func__, key_mgt);
  2845. if (key_mgt == WLAN_AKM_SUITE_8021X) {
  2846. /* *auth_type = UMAC_AUTH_TYPE_8021X; */
  2847. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2848. psecuritypriv->rsn_akm_suite_type = 1;
  2849. } else if (key_mgt == WLAN_AKM_SUITE_PSK) {
  2850. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2851. psecuritypriv->rsn_akm_suite_type = 2;
  2852. }
  2853. #ifdef CONFIG_WAPI_SUPPORT
  2854. else if (key_mgt == WLAN_AKM_SUITE_WAPI_PSK)
  2855. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2856. else if (key_mgt == WLAN_AKM_SUITE_WAPI_CERT)
  2857. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
  2858. #endif
  2859. #ifdef CONFIG_RTW_80211R
  2860. else if (key_mgt == WLAN_AKM_SUITE_FT_8021X) {
  2861. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2862. psecuritypriv->rsn_akm_suite_type = 3;
  2863. } else if (key_mgt == WLAN_AKM_SUITE_FT_PSK) {
  2864. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2865. psecuritypriv->rsn_akm_suite_type = 4;
  2866. }
  2867. #endif
  2868. else {
  2869. RTW_INFO("Invalid key mgt: 0x%x\n", key_mgt);
  2870. /* return -EINVAL; */
  2871. }
  2872. return 0;
  2873. }
  2874. static int rtw_cfg80211_set_wpa_ie(_adapter *padapter, u8 *pie, size_t ielen)
  2875. {
  2876. u8 *buf = NULL, *pos = NULL;
  2877. int group_cipher = 0, pairwise_cipher = 0;
  2878. u8 mfp_opt = MFP_NO;
  2879. int ret = 0;
  2880. int wpa_ielen = 0;
  2881. int wpa2_ielen = 0;
  2882. u8 *pwpa, *pwpa2;
  2883. u8 null_addr[] = {0, 0, 0, 0, 0, 0};
  2884. if (pie == NULL || !ielen) {
  2885. /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */
  2886. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  2887. goto exit;
  2888. }
  2889. if (ielen > MAX_WPA_IE_LEN + MAX_WPS_IE_LEN + MAX_P2P_IE_LEN) {
  2890. ret = -EINVAL;
  2891. goto exit;
  2892. }
  2893. buf = rtw_zmalloc(ielen);
  2894. if (buf == NULL) {
  2895. ret = -ENOMEM;
  2896. goto exit;
  2897. }
  2898. _rtw_memcpy(buf, pie , ielen);
  2899. RTW_INFO("set wpa_ie(length:%zu):\n", ielen);
  2900. RTW_INFO_DUMP(NULL, buf, ielen);
  2901. pos = buf;
  2902. if (ielen < RSN_HEADER_LEN) {
  2903. ret = -1;
  2904. goto exit;
  2905. }
  2906. pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen);
  2907. if (pwpa && wpa_ielen > 0) {
  2908. if (rtw_parse_wpa_ie(pwpa, wpa_ielen + 2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
  2909. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2910. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
  2911. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen + 2);
  2912. RTW_INFO("got wpa_ie, wpa_ielen:%u\n", wpa_ielen);
  2913. }
  2914. }
  2915. pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen);
  2916. if (pwpa2 && wpa2_ielen > 0) {
  2917. if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen + 2, &group_cipher, &pairwise_cipher, NULL, &mfp_opt) == _SUCCESS) {
  2918. padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
  2919. padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
  2920. _rtw_memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen + 2);
  2921. RTW_INFO("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen);
  2922. }
  2923. }
  2924. if (group_cipher == 0)
  2925. group_cipher = WPA_CIPHER_NONE;
  2926. if (pairwise_cipher == 0)
  2927. pairwise_cipher = WPA_CIPHER_NONE;
  2928. switch (group_cipher) {
  2929. case WPA_CIPHER_NONE:
  2930. padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
  2931. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2932. break;
  2933. case WPA_CIPHER_WEP40:
  2934. padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
  2935. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2936. break;
  2937. case WPA_CIPHER_TKIP:
  2938. padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
  2939. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2940. break;
  2941. case WPA_CIPHER_CCMP:
  2942. padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
  2943. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2944. break;
  2945. case WPA_CIPHER_WEP104:
  2946. padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
  2947. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2948. break;
  2949. }
  2950. switch (pairwise_cipher) {
  2951. case WPA_CIPHER_NONE:
  2952. padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
  2953. padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
  2954. break;
  2955. case WPA_CIPHER_WEP40:
  2956. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
  2957. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2958. break;
  2959. case WPA_CIPHER_TKIP:
  2960. padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
  2961. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
  2962. break;
  2963. case WPA_CIPHER_CCMP:
  2964. padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
  2965. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
  2966. break;
  2967. case WPA_CIPHER_WEP104:
  2968. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  2969. padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
  2970. break;
  2971. }
  2972. if (mfp_opt == MFP_INVALID) {
  2973. RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
  2974. ret = -EINVAL;
  2975. goto exit;
  2976. }
  2977. padapter->securitypriv.mfp_opt = mfp_opt;
  2978. {/* handle wps_ie */
  2979. uint wps_ielen;
  2980. u8 *wps_ie;
  2981. wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen);
  2982. if (wps_ie && wps_ielen > 0) {
  2983. RTW_INFO("got wps_ie, wps_ielen:%u\n", wps_ielen);
  2984. padapter->securitypriv.wps_ie_len = wps_ielen < MAX_WPS_IE_LEN ? wps_ielen : MAX_WPS_IE_LEN;
  2985. _rtw_memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len);
  2986. set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
  2987. } else
  2988. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  2989. }
  2990. #ifdef CONFIG_P2P
  2991. {/* check p2p_ie for assoc req; */
  2992. uint p2p_ielen = 0;
  2993. u8 *p2p_ie;
  2994. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  2995. p2p_ie = rtw_get_p2p_ie(buf, ielen, NULL, &p2p_ielen);
  2996. if (p2p_ie) {
  2997. #ifdef CONFIG_DEBUG_CFG80211
  2998. RTW_INFO("%s p2p_assoc_req_ielen=%d\n", __FUNCTION__, p2p_ielen);
  2999. #endif
  3000. if (pmlmepriv->p2p_assoc_req_ie) {
  3001. u32 free_len = pmlmepriv->p2p_assoc_req_ie_len;
  3002. pmlmepriv->p2p_assoc_req_ie_len = 0;
  3003. rtw_mfree(pmlmepriv->p2p_assoc_req_ie, free_len);
  3004. pmlmepriv->p2p_assoc_req_ie = NULL;
  3005. }
  3006. pmlmepriv->p2p_assoc_req_ie = rtw_malloc(p2p_ielen);
  3007. if (pmlmepriv->p2p_assoc_req_ie == NULL) {
  3008. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  3009. goto exit;
  3010. }
  3011. _rtw_memcpy(pmlmepriv->p2p_assoc_req_ie, p2p_ie, p2p_ielen);
  3012. pmlmepriv->p2p_assoc_req_ie_len = p2p_ielen;
  3013. }
  3014. }
  3015. #endif /* CONFIG_P2P */
  3016. #ifdef CONFIG_WFD
  3017. {
  3018. uint wfd_ielen = 0;
  3019. u8 *wfd_ie;
  3020. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3021. wfd_ie = rtw_get_wfd_ie(buf, ielen, NULL, &wfd_ielen);
  3022. if (wfd_ie) {
  3023. #ifdef CONFIG_DEBUG_CFG80211
  3024. RTW_INFO("%s wfd_assoc_req_ielen=%d\n", __FUNCTION__, wfd_ielen);
  3025. #endif
  3026. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_ASSOC_REQ_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  3027. goto exit;
  3028. }
  3029. }
  3030. #endif /* CONFIG_WFD */
  3031. /* TKIP and AES disallow multicast packets until installing group key */
  3032. if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
  3033. || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
  3034. || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
  3035. /* WPS open need to enable multicast */
  3036. /* || check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE) */
  3037. rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
  3038. exit:
  3039. if (buf)
  3040. rtw_mfree(buf, ielen);
  3041. if (ret)
  3042. _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
  3043. return ret;
  3044. }
  3045. static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
  3046. struct cfg80211_ibss_params *params)
  3047. {
  3048. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3049. NDIS_802_11_SSID ndis_ssid;
  3050. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3051. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  3052. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3053. struct cfg80211_chan_def *pch_def;
  3054. #endif
  3055. struct ieee80211_channel *pch;
  3056. int ret = 0;
  3057. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3058. pch_def = (struct cfg80211_chan_def *)(&params->chandef);
  3059. pch = (struct ieee80211_channel *) pch_def->chan;
  3060. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
  3061. pch = (struct ieee80211_channel *)(params->channel);
  3062. #endif
  3063. if (!params->ssid || !params->ssid_len) {
  3064. ret = -EINVAL;
  3065. goto exit;
  3066. }
  3067. if (params->ssid_len > IW_ESSID_MAX_SIZE) {
  3068. ret = -E2BIG;
  3069. goto exit;
  3070. }
  3071. rtw_ps_deny(padapter, PS_DENY_JOIN);
  3072. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  3073. ret = -EPERM;
  3074. goto cancel_ps_deny;
  3075. }
  3076. #ifdef CONFIG_CONCURRENT_MODE
  3077. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING)) {
  3078. RTW_INFO("%s, but buddy_intf is under linking\n", __FUNCTION__);
  3079. ret = -EINVAL;
  3080. goto cancel_ps_deny;
  3081. }
  3082. rtw_mi_buddy_scan_abort(padapter, _TRUE); /* OR rtw_mi_scan_abort(padapter, _TRUE);*/
  3083. #endif /*CONFIG_CONCURRENT_MODE*/
  3084. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  3085. ndis_ssid.SsidLength = params->ssid_len;
  3086. _rtw_memcpy(ndis_ssid.Ssid, (u8 *)params->ssid, params->ssid_len);
  3087. /* RTW_INFO("ssid=%s, len=%zu\n", ndis_ssid.Ssid, params->ssid_len); */
  3088. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  3089. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  3090. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  3091. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  3092. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  3093. ret = rtw_cfg80211_set_auth_type(psecuritypriv, NL80211_AUTHTYPE_OPEN_SYSTEM);
  3094. rtw_set_802_11_authentication_mode(padapter, psecuritypriv->ndisauthtype);
  3095. RTW_INFO("%s: center_freq = %d\n", __func__, pch->center_freq);
  3096. pmlmeext->cur_channel = rtw_freq2ch(pch->center_freq);
  3097. if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
  3098. ret = -1;
  3099. goto cancel_ps_deny;
  3100. }
  3101. cancel_ps_deny:
  3102. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  3103. exit:
  3104. return ret;
  3105. }
  3106. static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
  3107. {
  3108. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3109. struct wireless_dev *rtw_wdev = padapter->rtw_wdev;
  3110. enum nl80211_iftype old_type;
  3111. int ret = 0;
  3112. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3113. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3114. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 1);
  3115. #endif
  3116. old_type = rtw_wdev->iftype;
  3117. rtw_set_to_roam(padapter, 0);
  3118. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  3119. rtw_scan_abort(padapter);
  3120. LeaveAllPowerSaveMode(padapter);
  3121. rtw_wdev->iftype = NL80211_IFTYPE_STATION;
  3122. if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) == _FALSE) {
  3123. rtw_wdev->iftype = old_type;
  3124. ret = -EPERM;
  3125. goto leave_ibss;
  3126. }
  3127. rtw_setopmode_cmd(padapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  3128. }
  3129. leave_ibss:
  3130. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3131. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 0);
  3132. #endif
  3133. return 0;
  3134. }
  3135. bool rtw_cfg80211_is_connect_requested(_adapter *adapter)
  3136. {
  3137. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  3138. _irqL irqL;
  3139. bool requested;
  3140. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3141. requested = pwdev_priv->connect_req ? 1 : 0;
  3142. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3143. return requested;
  3144. }
  3145. static int _rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev)
  3146. {
  3147. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3148. /* if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)) */
  3149. {
  3150. rtw_scan_abort(padapter);
  3151. rtw_join_abort_timeout(padapter, 300);
  3152. LeaveAllPowerSaveMode(padapter);
  3153. rtw_disassoc_cmd(padapter, 500, RTW_CMDF_WAIT_ACK);
  3154. #ifdef CONFIG_RTW_REPEATER_SON
  3155. rtw_rson_do_disconnect(padapter);
  3156. #endif
  3157. RTW_INFO("%s...call rtw_indicate_disconnect\n", __func__);
  3158. rtw_free_assoc_resources_cmd(padapter, _TRUE, RTW_CMDF_WAIT_ACK);
  3159. /* indicate locally_generated = 0 when suspend */
  3160. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0))
  3161. rtw_indicate_disconnect(padapter, 0, wiphy->dev.power.is_prepared ? _FALSE : _TRUE);
  3162. #else
  3163. /*
  3164. * for kernel < 4.2, DISCONNECT event is hardcoded with
  3165. * NL80211_ATTR_DISCONNECTED_BY_AP=1 in NL80211 layer
  3166. * no need to judge if under suspend
  3167. */
  3168. rtw_indicate_disconnect(padapter, 0, _TRUE);
  3169. #endif
  3170. rtw_pwr_wakeup(padapter);
  3171. }
  3172. return 0;
  3173. }
  3174. static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
  3175. struct cfg80211_connect_params *sme)
  3176. {
  3177. int ret = 0;
  3178. NDIS_802_11_AUTHENTICATION_MODE authmode;
  3179. NDIS_802_11_SSID ndis_ssid;
  3180. /* u8 matched_by_bssid=_FALSE; */
  3181. /* u8 matched_by_ssid=_FALSE; */
  3182. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3183. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3184. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  3185. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  3186. _irqL irqL;
  3187. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT)
  3188. rtw_wdev_set_not_indic_disco(pwdev_priv, 1);
  3189. #endif
  3190. RTW_INFO("=>"FUNC_NDEV_FMT" - Start to Connection\n", FUNC_NDEV_ARG(ndev));
  3191. RTW_INFO("privacy=%d, key=%p, key_len=%d, key_idx=%d, auth_type=%d\n",
  3192. sme->privacy, sme->key, sme->key_len, sme->key_idx, sme->auth_type);
  3193. if (pwdev_priv->block == _TRUE) {
  3194. ret = -EBUSY;
  3195. RTW_INFO("%s wdev_priv.block is set\n", __FUNCTION__);
  3196. goto exit;
  3197. }
  3198. if (check_fwstate(pmlmepriv, _FW_LINKED | _FW_UNDER_LINKING) == _TRUE) {
  3199. _rtw_disconnect(wiphy, ndev);
  3200. RTW_INFO("%s disconnect before connecting! fw_state=0x%x\n",
  3201. __FUNCTION__, pmlmepriv->fw_state);
  3202. }
  3203. #ifdef CONFIG_PLATFORM_MSTAR_SCAN_BEFORE_CONNECT
  3204. printk("MStar Android!\n");
  3205. if (pwdev_priv->bandroid_scan == _FALSE) {
  3206. #ifdef CONFIG_P2P
  3207. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  3208. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
  3209. #endif /* CONFIG_P2P */
  3210. {
  3211. ret = -EBUSY;
  3212. printk("Android hasn't attached yet!\n");
  3213. goto exit;
  3214. }
  3215. }
  3216. #endif
  3217. if (!sme->ssid || !sme->ssid_len) {
  3218. ret = -EINVAL;
  3219. goto exit;
  3220. }
  3221. if (sme->ssid_len > IW_ESSID_MAX_SIZE) {
  3222. ret = -E2BIG;
  3223. goto exit;
  3224. }
  3225. rtw_ps_deny(padapter, PS_DENY_JOIN);
  3226. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  3227. ret = -EPERM;
  3228. goto cancel_ps_deny;
  3229. }
  3230. rtw_mi_scan_abort(padapter, _TRUE);
  3231. rtw_join_abort_timeout(padapter, 300);
  3232. #ifdef CONFIG_CONCURRENT_MODE
  3233. if (rtw_mi_buddy_check_fwstate(padapter, _FW_UNDER_LINKING)) {
  3234. ret = -EINVAL;
  3235. goto cancel_ps_deny;
  3236. }
  3237. #endif
  3238. _rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
  3239. ndis_ssid.SsidLength = sme->ssid_len;
  3240. _rtw_memcpy(ndis_ssid.Ssid, (u8 *)sme->ssid, sme->ssid_len);
  3241. RTW_INFO("ssid=%s, len=%zu\n", ndis_ssid.Ssid, sme->ssid_len);
  3242. if (sme->bssid)
  3243. RTW_INFO("bssid="MAC_FMT"\n", MAC_ARG(sme->bssid));
  3244. psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
  3245. psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
  3246. psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
  3247. psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
  3248. psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
  3249. #ifdef CONFIG_WAPI_SUPPORT
  3250. padapter->wapiInfo.bWapiEnable = false;
  3251. #endif
  3252. ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions);
  3253. if (ret < 0)
  3254. goto cancel_ps_deny;
  3255. #ifdef CONFIG_WAPI_SUPPORT
  3256. if (sme->crypto.wpa_versions & NL80211_WAPI_VERSION_1) {
  3257. padapter->wapiInfo.bWapiEnable = true;
  3258. padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
  3259. padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
  3260. }
  3261. #endif
  3262. ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type);
  3263. #ifdef CONFIG_WAPI_SUPPORT
  3264. if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_WAPI)
  3265. padapter->mlmeextpriv.mlmext_info.auth_algo = psecuritypriv->dot11AuthAlgrthm;
  3266. #endif
  3267. if (ret < 0)
  3268. goto cancel_ps_deny;
  3269. RTW_INFO("%s, ie_len=%zu\n", __func__, sme->ie_len);
  3270. ret = rtw_cfg80211_set_wpa_ie(padapter, (u8 *)sme->ie, sme->ie_len);
  3271. if (ret < 0)
  3272. goto cancel_ps_deny;
  3273. if (sme->crypto.n_ciphers_pairwise) {
  3274. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], _TRUE);
  3275. if (ret < 0)
  3276. goto cancel_ps_deny;
  3277. }
  3278. /* For WEP Shared auth */
  3279. if (sme->key_len > 0 && sme->key) {
  3280. u32 wep_key_idx, wep_key_len, wep_total_len;
  3281. NDIS_802_11_WEP *pwep = NULL;
  3282. RTW_INFO("%s(): Shared/Auto WEP\n", __FUNCTION__);
  3283. wep_key_idx = sme->key_idx;
  3284. wep_key_len = sme->key_len;
  3285. if (sme->key_idx > WEP_KEYS) {
  3286. ret = -EINVAL;
  3287. goto cancel_ps_deny;
  3288. }
  3289. if (wep_key_len > 0) {
  3290. wep_key_len = wep_key_len <= 5 ? 5 : 13;
  3291. wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
  3292. pwep = (NDIS_802_11_WEP *) rtw_malloc(wep_total_len);
  3293. if (pwep == NULL) {
  3294. RTW_INFO(" wpa_set_encryption: pwep allocate fail !!!\n");
  3295. ret = -ENOMEM;
  3296. goto cancel_ps_deny;
  3297. }
  3298. _rtw_memset(pwep, 0, wep_total_len);
  3299. pwep->KeyLength = wep_key_len;
  3300. pwep->Length = wep_total_len;
  3301. if (wep_key_len == 13) {
  3302. padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
  3303. padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
  3304. }
  3305. } else {
  3306. ret = -EINVAL;
  3307. goto cancel_ps_deny;
  3308. }
  3309. pwep->KeyIndex = wep_key_idx;
  3310. pwep->KeyIndex |= 0x80000000;
  3311. _rtw_memcpy(pwep->KeyMaterial, (void *)sme->key, pwep->KeyLength);
  3312. if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
  3313. ret = -EOPNOTSUPP ;
  3314. if (pwep)
  3315. rtw_mfree((u8 *)pwep, wep_total_len);
  3316. if (ret < 0)
  3317. goto cancel_ps_deny;
  3318. }
  3319. ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, _FALSE);
  3320. if (ret < 0)
  3321. return ret;
  3322. if (sme->crypto.n_akm_suites) {
  3323. ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]);
  3324. if (ret < 0)
  3325. goto cancel_ps_deny;
  3326. }
  3327. #ifdef CONFIG_8011R
  3328. else {
  3329. /*It could be a connection without RSN IEs*/
  3330. psecuritypriv->rsn_akm_suite_type = 0;
  3331. }
  3332. #endif
  3333. #ifdef CONFIG_WAPI_SUPPORT
  3334. if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_PSK)
  3335. padapter->wapiInfo.bWapiPSK = true;
  3336. else if (sme->crypto.akm_suites[0] == WLAN_AKM_SUITE_WAPI_CERT)
  3337. padapter->wapiInfo.bWapiPSK = false;
  3338. #endif
  3339. authmode = psecuritypriv->ndisauthtype;
  3340. rtw_set_802_11_authentication_mode(padapter, authmode);
  3341. /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
  3342. if (rtw_set_802_11_connect(padapter, (u8 *)sme->bssid, &ndis_ssid) == _FALSE) {
  3343. ret = -1;
  3344. goto cancel_ps_deny;
  3345. }
  3346. _enter_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3347. if (pwdev_priv->connect_req) {
  3348. rtw_wdev_free_connect_req(pwdev_priv);
  3349. RTW_INFO(FUNC_NDEV_FMT" free existing connect_req\n", FUNC_NDEV_ARG(ndev));
  3350. }
  3351. pwdev_priv->connect_req = (struct cfg80211_connect_params *)rtw_malloc(sizeof(*pwdev_priv->connect_req));
  3352. if (pwdev_priv->connect_req)
  3353. _rtw_memcpy(pwdev_priv->connect_req, sme, sizeof(*pwdev_priv->connect_req));
  3354. else
  3355. RTW_WARN(FUNC_NDEV_FMT" alloc connect_req fail\n", FUNC_NDEV_ARG(ndev));
  3356. _exit_critical_bh(&pwdev_priv->connect_req_lock, &irqL);
  3357. RTW_INFO("set ssid:dot11AuthAlgrthm=%d, dot11PrivacyAlgrthm=%d, dot118021XGrpPrivacy=%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
  3358. psecuritypriv->dot118021XGrpPrivacy);
  3359. cancel_ps_deny:
  3360. rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
  3361. exit:
  3362. RTW_INFO("<=%s, ret %d\n", __FUNCTION__, ret);
  3363. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT)
  3364. rtw_wdev_set_not_indic_disco(pwdev_priv, 0);
  3365. #endif
  3366. return ret;
  3367. }
  3368. static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev,
  3369. u16 reason_code)
  3370. {
  3371. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3372. RTW_INFO(FUNC_NDEV_FMT" - Start to Disconnect\n", FUNC_NDEV_ARG(ndev));
  3373. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3374. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  3375. if (!wiphy->dev.power.is_prepared)
  3376. #endif
  3377. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 1);
  3378. #endif
  3379. rtw_set_to_roam(padapter, 0);
  3380. /* if(check_fwstate(&padapter->mlmepriv, _FW_LINKED)) */
  3381. {
  3382. _rtw_disconnect(wiphy, ndev);
  3383. }
  3384. #if (RTW_CFG80211_BLOCK_STA_DISCON_EVENT & RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
  3385. rtw_wdev_set_not_indic_disco(adapter_wdev_data(padapter), 0);
  3386. #endif
  3387. RTW_INFO(FUNC_NDEV_FMT" return 0\n", FUNC_NDEV_ARG(ndev));
  3388. return 0;
  3389. }
  3390. static int cfg80211_rtw_set_txpower(struct wiphy *wiphy,
  3391. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3392. struct wireless_dev *wdev,
  3393. #endif
  3394. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) || defined(COMPAT_KERNEL_RELEASE)
  3395. enum nl80211_tx_power_setting type, int mbm)
  3396. #else
  3397. enum tx_power_setting type, int dbm)
  3398. #endif
  3399. {
  3400. #if 0
  3401. struct iwm_priv *iwm = wiphy_to_iwm(wiphy);
  3402. int ret;
  3403. switch (type) {
  3404. case NL80211_TX_POWER_AUTOMATIC:
  3405. return 0;
  3406. case NL80211_TX_POWER_FIXED:
  3407. if (mbm < 0 || (mbm % 100))
  3408. return -EOPNOTSUPP;
  3409. if (!test_bit(IWM_STATUS_READY, &iwm->status))
  3410. return 0;
  3411. ret = iwm_umac_set_config_fix(iwm, UMAC_PARAM_TBL_CFG_FIX,
  3412. CFG_TX_PWR_LIMIT_USR,
  3413. MBM_TO_DBM(mbm) * 2);
  3414. if (ret < 0)
  3415. return ret;
  3416. return iwm_tx_power_trigger(iwm);
  3417. default:
  3418. IWM_ERR(iwm, "Unsupported power type: %d\n", type);
  3419. return -EOPNOTSUPP;
  3420. }
  3421. #endif
  3422. RTW_INFO("%s\n", __func__);
  3423. return 0;
  3424. }
  3425. static int cfg80211_rtw_get_txpower(struct wiphy *wiphy,
  3426. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  3427. struct wireless_dev *wdev,
  3428. #endif
  3429. int *dbm)
  3430. {
  3431. RTW_INFO("%s\n", __func__);
  3432. *dbm = (12);
  3433. return 0;
  3434. }
  3435. inline bool rtw_cfg80211_pwr_mgmt(_adapter *adapter)
  3436. {
  3437. struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter);
  3438. return rtw_wdev_priv->power_mgmt;
  3439. }
  3440. static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy,
  3441. struct net_device *ndev,
  3442. bool enabled, int timeout)
  3443. {
  3444. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3445. struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter);
  3446. RTW_INFO(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev),
  3447. enabled, timeout);
  3448. rtw_wdev_priv->power_mgmt = enabled;
  3449. #ifdef CONFIG_LPS
  3450. if (!enabled)
  3451. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE_CFG80211_PWRMGMT, 1);
  3452. #endif
  3453. return 0;
  3454. }
  3455. static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy,
  3456. struct net_device *ndev,
  3457. struct cfg80211_pmksa *pmksa)
  3458. {
  3459. u8 index, blInserted = _FALSE;
  3460. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3461. struct mlme_priv *mlme = &padapter->mlmepriv;
  3462. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3463. u8 strZeroMacAddress[ETH_ALEN] = { 0x00 };
  3464. RTW_INFO(FUNC_NDEV_FMT" "MAC_FMT" "KEY_FMT"\n", FUNC_NDEV_ARG(ndev)
  3465. , MAC_ARG(pmksa->bssid), KEY_ARG(pmksa->pmkid));
  3466. if (_rtw_memcmp((u8 *)pmksa->bssid, strZeroMacAddress, ETH_ALEN) == _TRUE)
  3467. return -EINVAL;
  3468. if (check_fwstate(mlme, _FW_LINKED) == _FALSE) {
  3469. RTW_INFO(FUNC_NDEV_FMT" not set pmksa cause not in linked state\n", FUNC_NDEV_ARG(ndev));
  3470. return -EINVAL;
  3471. }
  3472. blInserted = _FALSE;
  3473. /* overwrite PMKID */
  3474. for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
  3475. if (_rtw_memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN) == _TRUE) {
  3476. /* BSSID is matched, the same AP => rewrite with new PMKID. */
  3477. RTW_INFO(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(ndev));
  3478. _rtw_memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
  3479. psecuritypriv->PMKIDList[index].bUsed = _TRUE;
  3480. psecuritypriv->PMKIDIndex = index + 1;
  3481. blInserted = _TRUE;
  3482. break;
  3483. }
  3484. }
  3485. if (!blInserted) {
  3486. /* Find a new entry */
  3487. RTW_INFO(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n",
  3488. FUNC_NDEV_ARG(ndev), psecuritypriv->PMKIDIndex);
  3489. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN);
  3490. _rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN);
  3491. psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
  3492. psecuritypriv->PMKIDIndex++ ;
  3493. if (psecuritypriv->PMKIDIndex == 16)
  3494. psecuritypriv->PMKIDIndex = 0;
  3495. }
  3496. return 0;
  3497. }
  3498. static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy,
  3499. struct net_device *ndev,
  3500. struct cfg80211_pmksa *pmksa)
  3501. {
  3502. u8 index, bMatched = _FALSE;
  3503. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3504. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3505. RTW_INFO(FUNC_NDEV_FMT" "MAC_FMT" "KEY_FMT"\n", FUNC_NDEV_ARG(ndev)
  3506. , MAC_ARG(pmksa->bssid), KEY_ARG(pmksa->pmkid));
  3507. for (index = 0 ; index < NUM_PMKID_CACHE; index++) {
  3508. if (_rtw_memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN) == _TRUE) {
  3509. /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
  3510. _rtw_memset(psecuritypriv->PMKIDList[index].Bssid, 0x00, ETH_ALEN);
  3511. _rtw_memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN);
  3512. psecuritypriv->PMKIDList[index].bUsed = _FALSE;
  3513. bMatched = _TRUE;
  3514. RTW_INFO(FUNC_NDEV_FMT" clear id:%hhu\n", FUNC_NDEV_ARG(ndev), index);
  3515. break;
  3516. }
  3517. }
  3518. if (_FALSE == bMatched) {
  3519. RTW_INFO(FUNC_NDEV_FMT" do not have matched BSSID\n"
  3520. , FUNC_NDEV_ARG(ndev));
  3521. return -EINVAL;
  3522. }
  3523. return 0;
  3524. }
  3525. static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy,
  3526. struct net_device *ndev)
  3527. {
  3528. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3529. struct security_priv *psecuritypriv = &padapter->securitypriv;
  3530. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3531. _rtw_memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
  3532. psecuritypriv->PMKIDIndex = 0;
  3533. return 0;
  3534. }
  3535. #ifdef CONFIG_AP_MODE
  3536. void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint frame_len)
  3537. {
  3538. #if !defined(RTW_USE_CFG80211_STA_EVENT) && !defined(COMPAT_KERNEL_RELEASE)
  3539. s32 freq;
  3540. int channel;
  3541. struct wireless_dev *pwdev = padapter->rtw_wdev;
  3542. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3543. #endif
  3544. struct net_device *ndev = padapter->pnetdev;
  3545. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  3546. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  3547. {
  3548. struct station_info sinfo;
  3549. u8 ie_offset;
  3550. if (get_frame_sub_type(pmgmt_frame) == WIFI_ASSOCREQ)
  3551. ie_offset = _ASOCREQ_IE_OFFSET_;
  3552. else /* WIFI_REASSOCREQ */
  3553. ie_offset = _REASOCREQ_IE_OFFSET_;
  3554. memset(&sinfo, 0, sizeof(sinfo));
  3555. sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
  3556. sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset;
  3557. sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset;
  3558. cfg80211_new_sta(ndev, get_addr2_ptr(pmgmt_frame), &sinfo, GFP_ATOMIC);
  3559. }
  3560. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3561. channel = pmlmeext->cur_channel;
  3562. freq = rtw_ch2freq(channel);
  3563. #ifdef COMPAT_KERNEL_RELEASE
  3564. rtw_cfg80211_rx_mgmt(pwdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3565. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  3566. rtw_cfg80211_rx_mgmt(pwdev, freq, 0, pmgmt_frame, frame_len, GFP_ATOMIC);
  3567. #else /* COMPAT_KERNEL_RELEASE */
  3568. {
  3569. /* to avoid WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION) when calling cfg80211_send_rx_assoc() */
  3570. #ifndef CONFIG_PLATFORM_MSTAR
  3571. pwdev->iftype = NL80211_IFTYPE_STATION;
  3572. #endif /* CONFIG_PLATFORM_MSTAR */
  3573. RTW_INFO("iftype=%d before call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  3574. rtw_cfg80211_send_rx_assoc(padapter, NULL, pmgmt_frame, frame_len);
  3575. RTW_INFO("iftype=%d after call cfg80211_send_rx_assoc()\n", pwdev->iftype);
  3576. pwdev->iftype = NL80211_IFTYPE_AP;
  3577. /* cfg80211_rx_action(padapter->pnetdev, freq, pmgmt_frame, frame_len, GFP_ATOMIC); */
  3578. }
  3579. #endif /* COMPAT_KERNEL_RELEASE */
  3580. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3581. }
  3582. void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, const u8 *da, unsigned short reason)
  3583. {
  3584. #if !defined(RTW_USE_CFG80211_STA_EVENT) && !defined(COMPAT_KERNEL_RELEASE)
  3585. s32 freq;
  3586. int channel;
  3587. u8 *pmgmt_frame;
  3588. uint frame_len;
  3589. struct rtw_ieee80211_hdr *pwlanhdr;
  3590. unsigned short *fctrl;
  3591. u8 mgmt_buf[128] = {0};
  3592. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3593. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  3594. struct wireless_dev *wdev = padapter->rtw_wdev;
  3595. #endif
  3596. struct net_device *ndev = padapter->pnetdev;
  3597. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
  3598. #if defined(RTW_USE_CFG80211_STA_EVENT) || defined(COMPAT_KERNEL_RELEASE)
  3599. cfg80211_del_sta(ndev, da, GFP_ATOMIC);
  3600. #else /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3601. channel = pmlmeext->cur_channel;
  3602. freq = rtw_ch2freq(channel);
  3603. pmgmt_frame = mgmt_buf;
  3604. pwlanhdr = (struct rtw_ieee80211_hdr *)pmgmt_frame;
  3605. fctrl = &(pwlanhdr->frame_ctl);
  3606. *(fctrl) = 0;
  3607. _rtw_memcpy(pwlanhdr->addr1, adapter_mac_addr(padapter), ETH_ALEN);
  3608. _rtw_memcpy(pwlanhdr->addr2, da, ETH_ALEN);
  3609. _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
  3610. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  3611. pmlmeext->mgnt_seq++;
  3612. set_frame_sub_type(pmgmt_frame, WIFI_DEAUTH);
  3613. pmgmt_frame += sizeof(struct rtw_ieee80211_hdr_3addr);
  3614. frame_len = sizeof(struct rtw_ieee80211_hdr_3addr);
  3615. reason = cpu_to_le16(reason);
  3616. pmgmt_frame = rtw_set_fixed_ie(pmgmt_frame, _RSON_CODE_ , (unsigned char *)&reason, &frame_len);
  3617. #ifdef COMPAT_KERNEL_RELEASE
  3618. rtw_cfg80211_rx_mgmt(wdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  3619. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && !defined(CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER)
  3620. rtw_cfg80211_rx_mgmt(wdev, freq, 0, mgmt_buf, frame_len, GFP_ATOMIC);
  3621. #else /* COMPAT_KERNEL_RELEASE */
  3622. cfg80211_send_disassoc(padapter->pnetdev, mgmt_buf, frame_len);
  3623. /* cfg80211_rx_action(padapter->pnetdev, freq, mgmt_buf, frame_len, GFP_ATOMIC); */
  3624. #endif /* COMPAT_KERNEL_RELEASE */
  3625. #endif /* defined(RTW_USE_CFG80211_STA_EVENT) */
  3626. }
  3627. static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
  3628. {
  3629. int ret = 0;
  3630. RTW_INFO("%s\n", __func__);
  3631. return ret;
  3632. }
  3633. static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
  3634. {
  3635. int ret = 0;
  3636. RTW_INFO("%s\n", __func__);
  3637. return ret;
  3638. }
  3639. static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev)
  3640. {
  3641. int ret = 0;
  3642. int rtap_len;
  3643. int qos_len = 0;
  3644. int dot11_hdr_len = 24;
  3645. int snap_len = 6;
  3646. unsigned char *pdata;
  3647. u16 frame_ctl;
  3648. unsigned char src_mac_addr[ETH_ALEN];
  3649. unsigned char dst_mac_addr[ETH_ALEN];
  3650. struct rtw_ieee80211_hdr *dot11_hdr;
  3651. struct ieee80211_radiotap_header *rtap_hdr;
  3652. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  3653. #ifdef CONFIG_DFS_MASTER
  3654. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  3655. #endif
  3656. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  3657. if (skb)
  3658. rtw_mstat_update(MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, skb->truesize);
  3659. if (IS_CH_WAITING(rfctl)) {
  3660. #ifdef CONFIG_DFS_MASTER
  3661. if (rtw_rfctl_overlap_radar_detect_ch(rfctl))
  3662. goto fail;
  3663. #endif
  3664. }
  3665. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  3666. goto fail;
  3667. rtap_hdr = (struct ieee80211_radiotap_header *)skb->data;
  3668. if (unlikely(rtap_hdr->it_version))
  3669. goto fail;
  3670. rtap_len = ieee80211_get_radiotap_len(skb->data);
  3671. if (unlikely(skb->len < rtap_len))
  3672. goto fail;
  3673. if (rtap_len != 14) {
  3674. RTW_INFO("radiotap len (should be 14): %d\n", rtap_len);
  3675. goto fail;
  3676. }
  3677. /* Skip the ratio tap header */
  3678. skb_pull(skb, rtap_len);
  3679. dot11_hdr = (struct rtw_ieee80211_hdr *)skb->data;
  3680. frame_ctl = le16_to_cpu(dot11_hdr->frame_ctl);
  3681. /* Check if the QoS bit is set */
  3682. if ((frame_ctl & RTW_IEEE80211_FCTL_FTYPE) == RTW_IEEE80211_FTYPE_DATA) {
  3683. /* Check if this ia a Wireless Distribution System (WDS) frame
  3684. * which has 4 MAC addresses
  3685. */
  3686. if (dot11_hdr->frame_ctl & 0x0080)
  3687. qos_len = 2;
  3688. if ((dot11_hdr->frame_ctl & 0x0300) == 0x0300)
  3689. dot11_hdr_len += 6;
  3690. memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr));
  3691. memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr));
  3692. /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for
  3693. * for two MAC addresses
  3694. */
  3695. skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2);
  3696. pdata = (unsigned char *)skb->data;
  3697. memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr));
  3698. memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr));
  3699. RTW_INFO("should be eapol packet\n");
  3700. /* Use the real net device to transmit the packet */
  3701. ret = _rtw_xmit_entry(skb, padapter->pnetdev);
  3702. return ret;
  3703. } else if ((frame_ctl & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE))
  3704. == (RTW_IEEE80211_FTYPE_MGMT | RTW_IEEE80211_STYPE_ACTION)
  3705. ) {
  3706. /* only for action frames */
  3707. struct xmit_frame *pmgntframe;
  3708. struct pkt_attrib *pattrib;
  3709. unsigned char *pframe;
  3710. /* u8 category, action, OUI_Subtype, dialogToken=0; */
  3711. /* unsigned char *frame_body; */
  3712. struct rtw_ieee80211_hdr *pwlanhdr;
  3713. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  3714. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  3715. u8 *buf = skb->data;
  3716. u32 len = skb->len;
  3717. u8 category, action;
  3718. int type = -1;
  3719. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  3720. RTW_INFO(FUNC_NDEV_FMT" frame_control:0x%x\n", FUNC_NDEV_ARG(ndev),
  3721. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  3722. goto fail;
  3723. }
  3724. RTW_INFO("RTW_Tx:da="MAC_FMT" via "FUNC_NDEV_FMT"\n",
  3725. MAC_ARG(GetAddr1Ptr(buf)), FUNC_NDEV_ARG(ndev));
  3726. #ifdef CONFIG_P2P
  3727. type = rtw_p2p_check_frames(padapter, buf, len, _TRUE);
  3728. if (type >= 0)
  3729. goto dump;
  3730. #endif
  3731. if (category == RTW_WLAN_CATEGORY_PUBLIC)
  3732. RTW_INFO("RTW_Tx:%s\n", action_public_str(action));
  3733. else
  3734. RTW_INFO("RTW_Tx:category(%u), action(%u)\n", category, action);
  3735. dump:
  3736. /* starting alloc mgmt frame to dump it */
  3737. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  3738. if (pmgntframe == NULL)
  3739. goto fail;
  3740. /* update attribute */
  3741. pattrib = &pmgntframe->attrib;
  3742. update_mgntframe_attrib(padapter, pattrib);
  3743. pattrib->retry_ctrl = _FALSE;
  3744. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  3745. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  3746. _rtw_memcpy(pframe, (void *)buf, len);
  3747. pattrib->pktlen = len;
  3748. #ifdef CONFIG_P2P
  3749. if (type >= 0)
  3750. rtw_xframe_chk_wfd_ie(pmgntframe);
  3751. #endif /* CONFIG_P2P */
  3752. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  3753. /* update seq number */
  3754. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  3755. pattrib->seqnum = pmlmeext->mgnt_seq;
  3756. pmlmeext->mgnt_seq++;
  3757. pattrib->last_txcmdsz = pattrib->pktlen;
  3758. dump_mgntframe(padapter, pmgntframe);
  3759. } else
  3760. RTW_INFO("frame_ctl=0x%x\n", frame_ctl & (RTW_IEEE80211_FCTL_FTYPE | RTW_IEEE80211_FCTL_STYPE));
  3761. fail:
  3762. rtw_skb_free(skb);
  3763. return 0;
  3764. }
  3765. static void rtw_cfg80211_monitor_if_set_multicast_list(struct net_device *ndev)
  3766. {
  3767. RTW_INFO("%s\n", __func__);
  3768. }
  3769. static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
  3770. {
  3771. int ret = 0;
  3772. RTW_INFO("%s\n", __func__);
  3773. return ret;
  3774. }
  3775. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  3776. static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
  3777. .ndo_open = rtw_cfg80211_monitor_if_open,
  3778. .ndo_stop = rtw_cfg80211_monitor_if_close,
  3779. .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry,
  3780. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
  3781. .ndo_set_multicast_list = rtw_cfg80211_monitor_if_set_multicast_list,
  3782. #endif
  3783. .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address,
  3784. };
  3785. #endif
  3786. static int rtw_cfg80211_add_monitor_if(_adapter *padapter, char *name, struct net_device **ndev)
  3787. {
  3788. int ret = 0;
  3789. struct net_device *mon_ndev = NULL;
  3790. struct wireless_dev *mon_wdev = NULL;
  3791. struct rtw_netdev_priv_indicator *pnpi;
  3792. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  3793. if (!name) {
  3794. RTW_INFO(FUNC_ADPT_FMT" without specific name\n", FUNC_ADPT_ARG(padapter));
  3795. ret = -EINVAL;
  3796. goto out;
  3797. }
  3798. if (pwdev_priv->pmon_ndev) {
  3799. RTW_INFO(FUNC_ADPT_FMT" monitor interface exist: "NDEV_FMT"\n",
  3800. FUNC_ADPT_ARG(padapter), NDEV_ARG(pwdev_priv->pmon_ndev));
  3801. ret = -EBUSY;
  3802. goto out;
  3803. }
  3804. mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator));
  3805. if (!mon_ndev) {
  3806. RTW_INFO(FUNC_ADPT_FMT" allocate ndev fail\n", FUNC_ADPT_ARG(padapter));
  3807. ret = -ENOMEM;
  3808. goto out;
  3809. }
  3810. mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP;
  3811. strncpy(mon_ndev->name, name, IFNAMSIZ);
  3812. mon_ndev->name[IFNAMSIZ - 1] = 0;
  3813. #if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 11, 8))
  3814. mon_ndev->priv_destructor = rtw_ndev_destructor;
  3815. #else
  3816. mon_ndev->destructor = rtw_ndev_destructor;
  3817. #endif
  3818. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  3819. mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops;
  3820. #else
  3821. mon_ndev->open = rtw_cfg80211_monitor_if_open;
  3822. mon_ndev->stop = rtw_cfg80211_monitor_if_close;
  3823. mon_ndev->hard_start_xmit = rtw_cfg80211_monitor_if_xmit_entry;
  3824. mon_ndev->set_mac_address = rtw_cfg80211_monitor_if_set_mac_address;
  3825. #endif
  3826. pnpi = netdev_priv(mon_ndev);
  3827. pnpi->priv = padapter;
  3828. pnpi->sizeof_priv = sizeof(_adapter);
  3829. /* wdev */
  3830. mon_wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  3831. if (!mon_wdev) {
  3832. RTW_INFO(FUNC_ADPT_FMT" allocate mon_wdev fail\n", FUNC_ADPT_ARG(padapter));
  3833. ret = -ENOMEM;
  3834. goto out;
  3835. }
  3836. mon_wdev->wiphy = padapter->rtw_wdev->wiphy;
  3837. mon_wdev->netdev = mon_ndev;
  3838. mon_wdev->iftype = NL80211_IFTYPE_MONITOR;
  3839. mon_ndev->ieee80211_ptr = mon_wdev;
  3840. ret = register_netdevice(mon_ndev);
  3841. if (ret)
  3842. goto out;
  3843. *ndev = pwdev_priv->pmon_ndev = mon_ndev;
  3844. _rtw_memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ + 1);
  3845. out:
  3846. if (ret && mon_wdev) {
  3847. rtw_mfree((u8 *)mon_wdev, sizeof(struct wireless_dev));
  3848. mon_wdev = NULL;
  3849. }
  3850. if (ret && mon_ndev) {
  3851. free_netdev(mon_ndev);
  3852. *ndev = mon_ndev = NULL;
  3853. }
  3854. return ret;
  3855. }
  3856. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3857. static struct wireless_dev *
  3858. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  3859. static struct net_device *
  3860. #else
  3861. static int
  3862. #endif
  3863. cfg80211_rtw_add_virtual_intf(
  3864. struct wiphy *wiphy,
  3865. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
  3866. const char *name,
  3867. #else
  3868. char *name,
  3869. #endif
  3870. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0))
  3871. unsigned char name_assign_type,
  3872. #endif
  3873. enum nl80211_iftype type,
  3874. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  3875. u32 *flags,
  3876. #endif
  3877. struct vif_params *params)
  3878. {
  3879. int ret = 0;
  3880. struct wireless_dev *wdev = NULL;
  3881. struct net_device *ndev = NULL;
  3882. _adapter *padapter;
  3883. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  3884. rtw_set_rtnl_lock_holder(dvobj, current);
  3885. RTW_INFO(FUNC_WIPHY_FMT" name:%s, type:%d\n", FUNC_WIPHY_ARG(wiphy), name, type);
  3886. switch (type) {
  3887. case NL80211_IFTYPE_MONITOR:
  3888. padapter = wiphy_to_adapter(wiphy); /* TODO: get ap iface ? */
  3889. ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev);
  3890. if (ret == 0)
  3891. wdev = ndev->ieee80211_ptr;
  3892. break;
  3893. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  3894. case NL80211_IFTYPE_P2P_CLIENT:
  3895. case NL80211_IFTYPE_P2P_GO:
  3896. #endif
  3897. case NL80211_IFTYPE_STATION:
  3898. case NL80211_IFTYPE_AP:
  3899. #ifdef CONFIG_RTW_MESH
  3900. case NL80211_IFTYPE_MESH_POINT:
  3901. #endif
  3902. padapter = dvobj_get_unregisterd_adapter(dvobj);
  3903. if (!padapter) {
  3904. RTW_WARN("adapter pool empty!\n");
  3905. ret = -ENODEV;
  3906. break;
  3907. }
  3908. if (rtw_os_ndev_init(padapter, name) != _SUCCESS) {
  3909. RTW_WARN("ndev init fail!\n");
  3910. ret = -ENODEV;
  3911. break;
  3912. }
  3913. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  3914. if (type == NL80211_IFTYPE_P2P_CLIENT || type == NL80211_IFTYPE_P2P_GO)
  3915. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  3916. #endif
  3917. ndev = padapter->pnetdev;
  3918. wdev = ndev->ieee80211_ptr;
  3919. break;
  3920. #if defined(CONFIG_P2P) && defined(RTW_DEDICATED_P2P_DEVICE)
  3921. case NL80211_IFTYPE_P2P_DEVICE:
  3922. ret = rtw_pd_iface_alloc(wiphy, name, &wdev);
  3923. break;
  3924. #endif
  3925. case NL80211_IFTYPE_ADHOC:
  3926. case NL80211_IFTYPE_AP_VLAN:
  3927. case NL80211_IFTYPE_WDS:
  3928. default:
  3929. ret = -ENODEV;
  3930. RTW_INFO("Unsupported interface type\n");
  3931. break;
  3932. }
  3933. if (ndev)
  3934. RTW_INFO(FUNC_WIPHY_FMT" ndev:%p, ret:%d\n", FUNC_WIPHY_ARG(wiphy), ndev, ret);
  3935. else
  3936. RTW_INFO(FUNC_WIPHY_FMT" wdev:%p, ret:%d\n", FUNC_WIPHY_ARG(wiphy), wdev, ret);
  3937. rtw_set_rtnl_lock_holder(dvobj, NULL);
  3938. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3939. return wdev ? wdev : ERR_PTR(ret);
  3940. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  3941. return ndev ? ndev : ERR_PTR(ret);
  3942. #else
  3943. return ret;
  3944. #endif
  3945. }
  3946. static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy,
  3947. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3948. struct wireless_dev *wdev
  3949. #else
  3950. struct net_device *ndev
  3951. #endif
  3952. )
  3953. {
  3954. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  3955. struct net_device *ndev = wdev_to_ndev(wdev);
  3956. #endif
  3957. int ret = 0;
  3958. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  3959. _adapter *adapter;
  3960. struct rtw_wdev_priv *pwdev_priv;
  3961. rtw_set_rtnl_lock_holder(dvobj, current);
  3962. if (ndev) {
  3963. adapter = (_adapter *)rtw_netdev_priv(ndev);
  3964. pwdev_priv = adapter_wdev_data(adapter);
  3965. if (ndev == pwdev_priv->pmon_ndev) {
  3966. unregister_netdevice(ndev);
  3967. pwdev_priv->pmon_ndev = NULL;
  3968. pwdev_priv->ifname_mon[0] = '\0';
  3969. RTW_INFO(FUNC_NDEV_FMT" remove monitor ndev\n", FUNC_NDEV_ARG(ndev));
  3970. } else {
  3971. RTW_INFO(FUNC_NDEV_FMT" unregister ndev\n", FUNC_NDEV_ARG(ndev));
  3972. rtw_os_ndev_unregister(adapter);
  3973. }
  3974. } else
  3975. #if defined(CONFIG_P2P) && defined(RTW_DEDICATED_P2P_DEVICE)
  3976. if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE) {
  3977. if (wdev == wiphy_to_pd_wdev(wiphy))
  3978. rtw_pd_iface_free(wiphy);
  3979. else {
  3980. RTW_ERR(FUNC_WIPHY_FMT" unknown P2P Device wdev:%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  3981. rtw_warn_on(1);
  3982. }
  3983. } else
  3984. #endif
  3985. {
  3986. ret = -EINVAL;
  3987. goto exit;
  3988. }
  3989. exit:
  3990. rtw_set_rtnl_lock_holder(dvobj, NULL);
  3991. return ret;
  3992. }
  3993. static int rtw_add_beacon(_adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len)
  3994. {
  3995. int ret = 0;
  3996. u8 *pbuf = NULL;
  3997. uint len, wps_ielen = 0;
  3998. uint p2p_ielen = 0;
  3999. u8 got_p2p_ie = _FALSE;
  4000. struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
  4001. /* struct sta_priv *pstapriv = &padapter->stapriv; */
  4002. RTW_INFO("%s beacon_head_len=%zu, beacon_tail_len=%zu\n", __FUNCTION__, head_len, tail_len);
  4003. if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
  4004. return -EINVAL;
  4005. if (head_len < 24)
  4006. return -EINVAL;
  4007. #ifdef CONFIG_FW_HANDLE_TXBCN
  4008. if (!rtw_ap_nums_check(adapter)) {
  4009. RTW_ERR(FUNC_ADPT_FMT"failed, con't support over %d BCN\n", FUNC_ADPT_ARG(adapter), CONFIG_LIMITED_AP_NUM);
  4010. return -EINVAL;
  4011. }
  4012. #endif /*CONFIG_FW_HANDLE_TXBCN*/
  4013. pbuf = rtw_zmalloc(head_len + tail_len);
  4014. if (!pbuf)
  4015. return -ENOMEM;
  4016. /* _rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2); */
  4017. /* if((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<=0)) */
  4018. /* pstapriv->max_num_sta = NUM_STA; */
  4019. _rtw_memcpy(pbuf, (void *)head + 24, head_len - 24); /* 24=beacon header len. */
  4020. _rtw_memcpy(pbuf + head_len - 24, (void *)tail, tail_len);
  4021. len = head_len + tail_len - 24;
  4022. /* check wps ie if inclued */
  4023. if (rtw_get_wps_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &wps_ielen))
  4024. RTW_INFO("add bcn, wps_ielen=%d\n", wps_ielen);
  4025. #ifdef CONFIG_P2P
  4026. if (adapter->wdinfo.driver_interface == DRIVER_CFG80211) {
  4027. /* check p2p if enable */
  4028. if (rtw_get_p2p_ie(pbuf + _FIXED_IE_LENGTH_, len - _FIXED_IE_LENGTH_, NULL, &p2p_ielen)) {
  4029. struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
  4030. RTW_INFO("got p2p_ie, len=%d\n", p2p_ielen);
  4031. got_p2p_ie = _TRUE;
  4032. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  4033. RTW_INFO("Enable P2P function for the first time\n");
  4034. rtw_p2p_enable(adapter, P2P_ROLE_GO);
  4035. adapter->stapriv.expire_to = 3; /* 3x2 = 6 sec in p2p mode */
  4036. } else {
  4037. RTW_INFO("enter GO Mode, p2p_ielen=%d\n", p2p_ielen);
  4038. rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
  4039. rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_OK);
  4040. pwdinfo->intent = 15;
  4041. }
  4042. }
  4043. }
  4044. #endif /* CONFIG_P2P */
  4045. /* pbss_network->IEs will not include p2p_ie, wfd ie */
  4046. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, P2P_OUI, 4);
  4047. rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, WFD_OUI, 4);
  4048. if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS) {
  4049. #ifdef CONFIG_P2P
  4050. /* check p2p if enable */
  4051. if (got_p2p_ie == _TRUE) {
  4052. struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
  4053. struct wifidirect_info *pwdinfo = &(adapter->wdinfo);
  4054. pwdinfo->operating_channel = pmlmeext->cur_channel;
  4055. }
  4056. #endif /* CONFIG_P2P */
  4057. ret = 0;
  4058. } else
  4059. ret = -EINVAL;
  4060. rtw_mfree(pbuf, head_len + tail_len);
  4061. return ret;
  4062. }
  4063. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
  4064. static int cfg80211_rtw_add_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4065. struct beacon_parameters *info)
  4066. {
  4067. int ret = 0;
  4068. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4069. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4070. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  4071. ret = -ENOTSUPP;
  4072. goto exit;
  4073. }
  4074. rtw_mi_scan_abort(adapter, _TRUE);
  4075. rtw_mi_buddy_set_scan_deny(adapter, 300);
  4076. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  4077. exit:
  4078. return ret;
  4079. }
  4080. static int cfg80211_rtw_set_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4081. struct beacon_parameters *info)
  4082. {
  4083. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4084. struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
  4085. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4086. pmlmeext->bstart_bss = _TRUE;
  4087. cfg80211_rtw_add_beacon(wiphy, ndev, info);
  4088. return 0;
  4089. }
  4090. static int cfg80211_rtw_del_beacon(struct wiphy *wiphy, struct net_device *ndev)
  4091. {
  4092. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4093. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4094. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  4095. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  4096. return 0;
  4097. }
  4098. #else
  4099. static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev,
  4100. struct cfg80211_ap_settings *settings)
  4101. {
  4102. int ret = 0;
  4103. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4104. RTW_INFO(FUNC_NDEV_FMT" hidden_ssid:%d, auth_type:%d\n", FUNC_NDEV_ARG(ndev),
  4105. settings->hidden_ssid, settings->auth_type);
  4106. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  4107. ret = -ENOTSUPP;
  4108. goto exit;
  4109. }
  4110. rtw_mi_scan_abort(adapter, _TRUE);
  4111. rtw_mi_buddy_set_scan_deny(adapter, 300);
  4112. ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len,
  4113. settings->beacon.tail, settings->beacon.tail_len);
  4114. adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid;
  4115. if (settings->ssid && settings->ssid_len) {
  4116. WLAN_BSSID_EX *pbss_network = &adapter->mlmepriv.cur_network.network;
  4117. WLAN_BSSID_EX *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network;
  4118. if (0)
  4119. RTW_INFO(FUNC_ADPT_FMT" ssid:(%s,%zu), from ie:(%s,%d)\n", FUNC_ADPT_ARG(adapter),
  4120. settings->ssid, settings->ssid_len,
  4121. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength);
  4122. _rtw_memcpy(pbss_network->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  4123. pbss_network->Ssid.SsidLength = settings->ssid_len;
  4124. _rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len);
  4125. pbss_network_ext->Ssid.SsidLength = settings->ssid_len;
  4126. if (0)
  4127. RTW_INFO(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
  4128. pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
  4129. pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
  4130. }
  4131. exit:
  4132. return ret;
  4133. }
  4134. static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
  4135. struct cfg80211_beacon_data *info)
  4136. {
  4137. int ret = 0;
  4138. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4139. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4140. ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
  4141. return ret;
  4142. }
  4143. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  4144. static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
  4145. #else
  4146. static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev, unsigned int link_id)
  4147. #endif
  4148. {
  4149. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4150. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4151. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  4152. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  4153. return 0;
  4154. }
  4155. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) */
  4156. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4157. static int cfg80211_rtw_set_mac_acl(struct wiphy *wiphy, struct net_device *ndev,
  4158. const struct cfg80211_acl_data *params)
  4159. {
  4160. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4161. u8 acl_mode = RTW_ACL_MODE_DISABLED;
  4162. int ret = -1;
  4163. int i;
  4164. if (!params) {
  4165. RTW_WARN(FUNC_ADPT_FMT" params NULL\n", FUNC_ADPT_ARG(adapter));
  4166. rtw_macaddr_acl_clear(adapter, RTW_ACL_PERIOD_BSS);
  4167. goto exit;
  4168. }
  4169. RTW_INFO(FUNC_ADPT_FMT" acl_policy:%d, entry_num:%d\n"
  4170. , FUNC_ADPT_ARG(adapter), params->acl_policy, params->n_acl_entries);
  4171. if (params->acl_policy == NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED)
  4172. acl_mode = RTW_ACL_MODE_ACCEPT_UNLESS_LISTED;
  4173. else if (params->acl_policy == NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
  4174. acl_mode = RTW_ACL_MODE_DENY_UNLESS_LISTED;
  4175. rtw_macaddr_acl_clear(adapter, RTW_ACL_PERIOD_BSS);
  4176. rtw_set_macaddr_acl(adapter, RTW_ACL_PERIOD_BSS, acl_mode);
  4177. for (i = 0; i < params->n_acl_entries; i++)
  4178. rtw_acl_add_sta(adapter, RTW_ACL_PERIOD_BSS, params->mac_addrs[i].addr);
  4179. ret = 0;
  4180. exit:
  4181. return ret;
  4182. }
  4183. #endif /* CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)) */
  4184. const char *_nl80211_sta_flags_str[] = {
  4185. "INVALID",
  4186. "AUTHORIZED",
  4187. "SHORT_PREAMBLE",
  4188. "WME",
  4189. "MFP",
  4190. "AUTHENTICATED",
  4191. "TDLS_PEER",
  4192. "ASSOCIATED",
  4193. };
  4194. #define nl80211_sta_flags_str(_f) ((_f <= NL80211_STA_FLAG_MAX) ? _nl80211_sta_flags_str[_f] : _nl80211_sta_flags_str[0])
  4195. const char *_nl80211_plink_state_str[] = {
  4196. "LISTEN",
  4197. "OPN_SNT",
  4198. "OPN_RCVD",
  4199. "CNF_RCVD",
  4200. "ESTAB",
  4201. "HOLDING",
  4202. "BLOCKED",
  4203. "UNKNOWN",
  4204. };
  4205. #define nl80211_plink_state_str(_s) ((_s < NUM_NL80211_PLINK_STATES) ? _nl80211_plink_state_str[_s] : _nl80211_plink_state_str[NUM_NL80211_PLINK_STATES])
  4206. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
  4207. #define NL80211_PLINK_ACTION_NO_ACTION PLINK_ACTION_INVALID
  4208. #define NL80211_PLINK_ACTION_OPEN PLINK_ACTION_OPEN
  4209. #define NL80211_PLINK_ACTION_BLOCK PLINK_ACTION_BLOCK
  4210. #define NUM_NL80211_PLINK_ACTIONS 3
  4211. #endif
  4212. const char *_nl80211_plink_actions_str[] = {
  4213. "NO_ACTION",
  4214. "OPEN",
  4215. "BLOCK",
  4216. "UNKNOWN",
  4217. };
  4218. #define nl80211_plink_actions_str(_a) ((_a < NUM_NL80211_PLINK_ACTIONS) ? _nl80211_plink_actions_str[_a] : _nl80211_plink_actions_str[NUM_NL80211_PLINK_ACTIONS])
  4219. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4220. const char *_nl80211_mesh_power_mode_str[] = {
  4221. "UNKNOWN",
  4222. "ACTIVE",
  4223. "LIGHT_SLEEP",
  4224. "DEEP_SLEEP",
  4225. };
  4226. #define nl80211_mesh_power_mode_str(_p) ((_p <= NL80211_MESH_POWER_MAX) ? _nl80211_mesh_power_mode_str[_p] : _nl80211_mesh_power_mode_str[0])
  4227. #endif
  4228. void dump_station_parameters(void *sel, struct wiphy *wiphy, const struct station_parameters *params)
  4229. {
  4230. #if DBG_RTW_CFG80211_STA_PARAM
  4231. if (params->supported_rates_len) {
  4232. #define SUPP_RATES_BUF_LEN (3 * RTW_G_RATES_NUM + 1)
  4233. int i;
  4234. char supp_rates_buf[SUPP_RATES_BUF_LEN] = {0};
  4235. u8 cnt = 0;
  4236. rtw_warn_on(params->supported_rates_len > RTW_G_RATES_NUM);
  4237. for (i = 0; i < params->supported_rates_len; i++) {
  4238. if (i >= RTW_G_RATES_NUM)
  4239. break;
  4240. cnt += snprintf(supp_rates_buf + cnt, SUPP_RATES_BUF_LEN - cnt -1
  4241. , "%02X ", params->supported_rates[i]);
  4242. if (cnt >= SUPP_RATES_BUF_LEN - 1)
  4243. break;
  4244. }
  4245. RTW_PRINT_SEL(sel, "supported_rates:%s\n", supp_rates_buf);
  4246. }
  4247. if (params->vlan)
  4248. RTW_PRINT_SEL(sel, "vlan:"NDEV_FMT"\n", NDEV_ARG(params->vlan));
  4249. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
  4250. if (params->sta_flags_mask) {
  4251. #define STA_FLAGS_BUF_LEN 128
  4252. int i = 0;
  4253. char sta_flags_buf[STA_FLAGS_BUF_LEN] = {0};
  4254. u8 cnt = 0;
  4255. for (i = 1; i <= NL80211_STA_FLAG_MAX; i++) {
  4256. if (params->sta_flags_mask & BIT(i)) {
  4257. cnt += snprintf(sta_flags_buf + cnt, STA_FLAGS_BUF_LEN - cnt -1, "%s=%u "
  4258. , nl80211_sta_flags_str(i), (params->sta_flags_set & BIT(i)) ? 1 : 0);
  4259. if (cnt >= STA_FLAGS_BUF_LEN - 1)
  4260. break;
  4261. }
  4262. }
  4263. RTW_PRINT_SEL(sel, "sta_flags:%s\n", sta_flags_buf);
  4264. }
  4265. #else
  4266. u32 station_flags;
  4267. #error "TBD\n"
  4268. #endif
  4269. if (params->listen_interval != -1)
  4270. RTW_PRINT_SEL(sel, "listen_interval:%d\n", params->listen_interval);
  4271. if (params->aid)
  4272. RTW_PRINT_SEL(sel, "aid:%u\n", params->aid);
  4273. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  4274. if (params->peer_aid)
  4275. RTW_PRINT_SEL(sel, "peer_aid:%u\n", params->peer_aid);
  4276. #endif
  4277. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26))
  4278. if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
  4279. RTW_PRINT_SEL(sel, "plink_action:%s\n", nl80211_plink_actions_str(params->plink_action));
  4280. #endif
  4281. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  4282. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4283. if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4284. #endif
  4285. RTW_PRINT_SEL(sel, "plink_state:%s\n"
  4286. , nl80211_plink_state_str(params->plink_state));
  4287. #endif
  4288. #if 0 /* TODO */
  4289. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
  4290. const struct ieee80211_ht_cap *ht_capa;
  4291. #endif
  4292. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4293. const struct ieee80211_vht_cap *vht_capa;
  4294. #endif
  4295. #endif
  4296. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4297. if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
  4298. RTW_PRINT_SEL(sel, "uapsd_queues:0x%02x\n", params->uapsd_queues);
  4299. if (params->max_sp)
  4300. RTW_PRINT_SEL(sel, "max_sp:%u\n", params->max_sp);
  4301. #endif
  4302. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  4303. if (params->local_pm != NL80211_MESH_POWER_UNKNOWN) {
  4304. RTW_PRINT_SEL(sel, "local_pm:%s\n"
  4305. , nl80211_mesh_power_mode_str(params->local_pm));
  4306. }
  4307. if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
  4308. RTW_PRINT_SEL(sel, "capability:0x%04x\n", params->capability);
  4309. #if 0 /* TODO */
  4310. const u8 *ext_capab;
  4311. u8 ext_capab_len;
  4312. #endif
  4313. #endif
  4314. #if 0 /* TODO */
  4315. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
  4316. const u8 *supported_channels;
  4317. u8 supported_channels_len;
  4318. const u8 *supported_oper_classes;
  4319. u8 supported_oper_classes_len;
  4320. #endif
  4321. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
  4322. u8 opmode_notif;
  4323. bool opmode_notif_used;
  4324. #endif
  4325. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
  4326. int support_p2p_ps;
  4327. #endif
  4328. #endif
  4329. #endif /* DBG_RTW_CFG80211_STA_PARAM */
  4330. }
  4331. static int cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev,
  4332. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4333. u8 *mac,
  4334. #else
  4335. const u8 *mac,
  4336. #endif
  4337. struct station_parameters *params)
  4338. {
  4339. int ret = 0;
  4340. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4341. #if defined(CONFIG_TDLS) || defined(CONFIG_RTW_MESH)
  4342. struct sta_priv *pstapriv = &padapter->stapriv;
  4343. #endif
  4344. #ifdef CONFIG_TDLS
  4345. struct sta_info *psta;
  4346. #endif /* CONFIG_TDLS */
  4347. RTW_INFO(FUNC_NDEV_FMT" mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  4348. #if CONFIG_RTW_MACADDR_ACL
  4349. if (rtw_access_ctrl(padapter, mac) == _FALSE) {
  4350. RTW_INFO(FUNC_NDEV_FMT" deny by macaddr ACL\n", FUNC_NDEV_ARG(ndev));
  4351. ret = -EINVAL;
  4352. goto exit;
  4353. }
  4354. #endif
  4355. dump_station_parameters(RTW_DBGDUMP, wiphy, params);
  4356. #ifdef CONFIG_RTW_MESH
  4357. if (MLME_IS_MESH(padapter)) {
  4358. struct rtw_mesh_cfg *mcfg = &padapter->mesh_cfg;
  4359. struct rtw_mesh_info *minfo = &padapter->mesh_info;
  4360. struct mesh_plink_pool *plink_ctl = &minfo->plink_ctl;
  4361. struct mesh_plink_ent *plink = NULL;
  4362. struct wlan_network *scanned = NULL;
  4363. bool acnode = 0;
  4364. u8 add_new_sta = 0, probe_req = 0;
  4365. _irqL irqL;
  4366. if (params->plink_state != NL80211_PLINK_LISTEN) {
  4367. RTW_WARN(FUNC_NDEV_FMT" %s\n", FUNC_NDEV_ARG(ndev), nl80211_plink_state_str(params->plink_state));
  4368. rtw_warn_on(1);
  4369. }
  4370. if (!params->aid || params->aid > pstapriv->max_aid) {
  4371. RTW_WARN(FUNC_NDEV_FMT" invalid aid:%u\n", FUNC_NDEV_ARG(ndev), params->aid);
  4372. rtw_warn_on(1);
  4373. ret = -EINVAL;
  4374. goto exit;
  4375. }
  4376. _enter_critical_bh(&(plink_ctl->lock), &irqL);
  4377. plink = _rtw_mesh_plink_get(padapter, mac);
  4378. if (plink)
  4379. goto release_plink_ctl;
  4380. #if CONFIG_RTW_MESH_PEER_BLACKLIST
  4381. if (rtw_mesh_peer_blacklist_search(padapter, mac)) {
  4382. RTW_INFO(FUNC_NDEV_FMT" deny by peer blacklist\n"
  4383. , FUNC_NDEV_ARG(ndev));
  4384. ret = -EINVAL;
  4385. goto release_plink_ctl;
  4386. }
  4387. #endif
  4388. scanned = rtw_find_network(&padapter->mlmepriv.scanned_queue, mac);
  4389. if (!scanned
  4390. || rtw_get_passing_time_ms(scanned->last_scanned) >= mcfg->peer_sel_policy.scanr_exp_ms
  4391. ) {
  4392. if (!scanned)
  4393. RTW_INFO(FUNC_NDEV_FMT" corresponding network not found\n", FUNC_NDEV_ARG(ndev));
  4394. else
  4395. RTW_INFO(FUNC_NDEV_FMT" corresponding network too old\n", FUNC_NDEV_ARG(ndev));
  4396. if (adapter_to_rfctl(padapter)->offch_state == OFFCHS_NONE)
  4397. probe_req = 1;
  4398. ret = -EINVAL;
  4399. goto release_plink_ctl;
  4400. }
  4401. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4402. if (plink_ctl->acnode_rsvd)
  4403. acnode = rtw_mesh_scanned_is_acnode_confirmed(padapter, scanned);
  4404. #endif
  4405. /* wpa_supplicant's auto peer will initiate peering when candidate peer is reported without max_peer_links consideration */
  4406. if (plink_ctl->num >= mcfg->max_peer_links + acnode ? 1 : 0) {
  4407. RTW_INFO(FUNC_NDEV_FMT" exceed max_peer_links:%u%s\n"
  4408. , FUNC_NDEV_ARG(ndev), mcfg->max_peer_links, acnode ? " acn" : "");
  4409. ret = -EINVAL;
  4410. goto release_plink_ctl;
  4411. }
  4412. if (!rtw_bss_is_candidate_mesh_peer(&padapter->mlmepriv.cur_network.network, &scanned->network, 1, 1)) {
  4413. RTW_WARN(FUNC_NDEV_FMT" corresponding network is not candidate with same ch\n"
  4414. , FUNC_NDEV_ARG(ndev));
  4415. ret = -EINVAL;
  4416. goto release_plink_ctl;
  4417. }
  4418. #if CONFIG_RTW_MESH_CTO_MGATE_BLACKLIST
  4419. if (!rtw_mesh_cto_mgate_network_filter(padapter, scanned)) {
  4420. RTW_INFO(FUNC_NDEV_FMT" peer filtered out by cto_mgate check\n"
  4421. , FUNC_NDEV_ARG(ndev));
  4422. ret = -EINVAL;
  4423. goto release_plink_ctl;
  4424. }
  4425. #endif
  4426. if (_rtw_mesh_plink_add(padapter, mac) == _SUCCESS) {
  4427. /* hook corresponding network in scan queue */
  4428. plink = _rtw_mesh_plink_get(padapter, mac);
  4429. plink->aid = params->aid;
  4430. plink->scanned = scanned;
  4431. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4432. if (acnode) {
  4433. RTW_INFO(FUNC_ADPT_FMT" acnode "MAC_FMT"\n"
  4434. , FUNC_ADPT_ARG(padapter), MAC_ARG(scanned->network.MacAddress));
  4435. }
  4436. #endif
  4437. add_new_sta = 1;
  4438. } else {
  4439. RTW_WARN(FUNC_NDEV_FMT" rtw_mesh_plink_add not success\n"
  4440. , FUNC_NDEV_ARG(ndev));
  4441. ret = -EINVAL;
  4442. }
  4443. release_plink_ctl:
  4444. _exit_critical_bh(&(plink_ctl->lock), &irqL);
  4445. if (probe_req)
  4446. issue_probereq(padapter, &padapter->mlmepriv.cur_network.network.mesh_id, mac);
  4447. if (add_new_sta) {
  4448. struct station_info sinfo;
  4449. #ifdef CONFIG_DFS_MASTER
  4450. if (IS_UNDER_CAC(adapter_to_rfctl(padapter)))
  4451. rtw_force_stop_cac(adapter_to_rfctl(padapter), 300);
  4452. #endif
  4453. /* indicate new sta */
  4454. _rtw_memset(&sinfo, 0, sizeof(sinfo));
  4455. cfg80211_new_sta(ndev, mac, &sinfo, GFP_ATOMIC);
  4456. }
  4457. goto exit;
  4458. }
  4459. #endif /* CONFIG_RTW_MESH */
  4460. #ifdef CONFIG_TDLS
  4461. psta = rtw_get_stainfo(pstapriv, (u8 *)mac);
  4462. if (psta == NULL) {
  4463. psta = rtw_alloc_stainfo(pstapriv, (u8 *)mac);
  4464. if (psta == NULL) {
  4465. RTW_INFO("[%s] Alloc station for "MAC_FMT" fail\n", __FUNCTION__, MAC_ARG(mac));
  4466. ret = -EOPNOTSUPP;
  4467. goto exit;
  4468. }
  4469. }
  4470. #endif /* CONFIG_TDLS */
  4471. exit:
  4472. return ret;
  4473. }
  4474. static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev,
  4475. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4476. u8 *mac
  4477. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0))
  4478. const u8 *mac
  4479. #else
  4480. struct station_del_parameters *params
  4481. #endif
  4482. )
  4483. {
  4484. int ret = 0;
  4485. _irqL irqL;
  4486. _list *phead, *plist;
  4487. u8 updated = _FALSE;
  4488. const u8 *target_mac;
  4489. struct sta_info *psta = NULL;
  4490. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4491. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  4492. struct sta_priv *pstapriv = &padapter->stapriv;
  4493. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0))
  4494. target_mac = mac;
  4495. #else
  4496. target_mac = params->mac;
  4497. #endif
  4498. RTW_INFO("+"FUNC_NDEV_FMT" mac=%pM\n", FUNC_NDEV_ARG(ndev), target_mac);
  4499. if (check_fwstate(pmlmepriv, (_FW_LINKED | WIFI_AP_STATE | WIFI_MESH_STATE)) != _TRUE) {
  4500. RTW_INFO("%s, fw_state != FW_LINKED|WIFI_AP_STATE|WIFI_MESH_STATE\n", __func__);
  4501. return -EINVAL;
  4502. }
  4503. if (!target_mac) {
  4504. RTW_INFO("flush all sta, and cam_entry\n");
  4505. flush_all_cam_entry(padapter); /* clear CAM */
  4506. #ifdef CONFIG_AP_MODE
  4507. ret = rtw_sta_flush(padapter, _TRUE);
  4508. #endif
  4509. return ret;
  4510. }
  4511. RTW_INFO("free sta macaddr =" MAC_FMT "\n", MAC_ARG(target_mac));
  4512. if (target_mac[0] == 0xff && target_mac[1] == 0xff &&
  4513. target_mac[2] == 0xff && target_mac[3] == 0xff &&
  4514. target_mac[4] == 0xff && target_mac[5] == 0xff)
  4515. return -EINVAL;
  4516. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4517. phead = &pstapriv->asoc_list;
  4518. plist = get_next(phead);
  4519. /* check asoc_queue */
  4520. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  4521. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  4522. plist = get_next(plist);
  4523. if (_rtw_memcmp((u8 *)target_mac, psta->cmn.mac_addr, ETH_ALEN)) {
  4524. if (psta->dot8021xalg == 1 && psta->bpairwise_key_installed == _FALSE)
  4525. RTW_INFO("%s, sta's dot8021xalg = 1 and key_installed = _FALSE\n", __func__);
  4526. else {
  4527. RTW_INFO("free psta=%p, aid=%d\n", psta, psta->cmn.aid);
  4528. rtw_list_delete(&psta->asoc_list);
  4529. pstapriv->asoc_list_cnt--;
  4530. STA_SET_MESH_PLINK(psta, NULL);
  4531. /* _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  4532. if (MLME_IS_AP(padapter))
  4533. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_PREV_AUTH_NOT_VALID, _TRUE);
  4534. else
  4535. updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
  4536. /* _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL); */
  4537. psta = NULL;
  4538. break;
  4539. }
  4540. }
  4541. }
  4542. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4543. associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
  4544. #ifdef CONFIG_RTW_MESH
  4545. if (MLME_IS_MESH(padapter))
  4546. rtw_mesh_plink_del(padapter, target_mac);
  4547. #endif
  4548. RTW_INFO("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4549. return ret;
  4550. }
  4551. static int cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev,
  4552. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0))
  4553. u8 *mac,
  4554. #else
  4555. const u8 *mac,
  4556. #endif
  4557. struct station_parameters *params)
  4558. {
  4559. #ifdef CONFIG_RTW_MESH
  4560. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  4561. struct sta_priv *stapriv = &adapter->stapriv;
  4562. struct sta_info *sta = NULL;
  4563. _irqL irqL;
  4564. #endif
  4565. int ret = 0;
  4566. RTW_INFO(FUNC_NDEV_FMT" mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac));
  4567. dump_station_parameters(RTW_DBGDUMP, wiphy, params);
  4568. #ifdef CONFIG_RTW_MESH
  4569. if (MLME_IS_MESH(adapter)) {
  4570. enum cfg80211_station_type sta_type = CFG80211_STA_MESH_PEER_USER;
  4571. struct rtw_mesh_info *minfo = &adapter->mesh_info;
  4572. struct mesh_plink_pool *plink_ctl = &minfo->plink_ctl;
  4573. struct mesh_plink_ent *plink = NULL;
  4574. _irqL irqL2;
  4575. struct sta_info *del_sta = NULL;
  4576. ret = cfg80211_check_station_change(wiphy, params, sta_type);
  4577. if (ret) {
  4578. RTW_INFO("cfg80211_check_station_change return %d\n", ret);
  4579. goto exit;
  4580. }
  4581. _enter_critical_bh(&(plink_ctl->lock), &irqL2);
  4582. plink = _rtw_mesh_plink_get(adapter, mac);
  4583. if (!plink) {
  4584. ret = -ENOENT;
  4585. goto release_plink_ctl;
  4586. }
  4587. plink->plink_state = nl80211_plink_state_to_rtw_plink_state(params->plink_state);
  4588. #if CONFIG_RTW_MESH_ACNODE_PREVENT
  4589. if (params->plink_state == NL80211_PLINK_OPN_SNT
  4590. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4591. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4592. #endif
  4593. ) {
  4594. if (rtw_mesh_scanned_is_acnode_confirmed(adapter, plink->scanned)
  4595. && rtw_mesh_acnode_prevent_allow_sacrifice(adapter)
  4596. ) {
  4597. struct sta_info *sac = rtw_mesh_acnode_prevent_pick_sacrifice(adapter);
  4598. if (sac) {
  4599. del_sta = sac;
  4600. _enter_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4601. if (!rtw_is_list_empty(&del_sta->asoc_list)) {
  4602. rtw_list_delete(&del_sta->asoc_list);
  4603. stapriv->asoc_list_cnt--;
  4604. STA_SET_MESH_PLINK(del_sta, NULL);
  4605. }
  4606. _exit_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4607. RTW_INFO(FUNC_ADPT_FMT" sacrifice "MAC_FMT" for acnode\n"
  4608. , FUNC_ADPT_ARG(adapter), MAC_ARG(del_sta->cmn.mac_addr));
  4609. }
  4610. }
  4611. } else
  4612. #endif
  4613. if ((params->plink_state == NL80211_PLINK_OPN_RCVD
  4614. || params->plink_state == NL80211_PLINK_CNF_RCVD
  4615. || params->plink_state == NL80211_PLINK_ESTAB)
  4616. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4617. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4618. #endif
  4619. ) {
  4620. sta = rtw_get_stainfo(stapriv, mac);
  4621. if (!sta) {
  4622. sta = rtw_alloc_stainfo(stapriv, mac);
  4623. if (!sta)
  4624. goto release_plink_ctl;
  4625. }
  4626. if (params->plink_state == NL80211_PLINK_ESTAB) {
  4627. if (rtw_mesh_peer_establish(adapter, plink, sta) != _SUCCESS) {
  4628. rtw_free_stainfo(adapter, sta);
  4629. ret = -ENOENT;
  4630. goto release_plink_ctl;
  4631. }
  4632. }
  4633. }
  4634. else if (params->plink_state == NL80211_PLINK_HOLDING
  4635. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  4636. && (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
  4637. #endif
  4638. ) {
  4639. del_sta = rtw_get_stainfo(stapriv, mac);
  4640. if (!del_sta)
  4641. goto release_plink_ctl;
  4642. _enter_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4643. if (!rtw_is_list_empty(&del_sta->asoc_list)) {
  4644. rtw_list_delete(&del_sta->asoc_list);
  4645. stapriv->asoc_list_cnt--;
  4646. STA_SET_MESH_PLINK(del_sta, NULL);
  4647. }
  4648. _exit_critical_bh(&stapriv->asoc_list_lock, &irqL);
  4649. }
  4650. release_plink_ctl:
  4651. _exit_critical_bh(&(plink_ctl->lock), &irqL2);
  4652. if (del_sta) {
  4653. u8 sta_addr[ETH_ALEN];
  4654. u8 updated = _FALSE;
  4655. _rtw_memcpy(sta_addr, del_sta->cmn.mac_addr, ETH_ALEN);
  4656. updated = ap_free_sta(adapter, del_sta, 0, 0, 1);
  4657. rtw_mesh_expire_peer(stapriv->padapter, sta_addr);
  4658. associated_clients_update(adapter, updated, STA_INFO_UPDATE_ALL);
  4659. }
  4660. }
  4661. #endif /* CONFIG_RTW_MESH */
  4662. exit:
  4663. return ret;
  4664. }
  4665. struct sta_info *rtw_sta_info_get_by_idx(struct sta_priv *pstapriv, const int idx, u8 *asoc_list_num)
  4666. {
  4667. _list *phead, *plist;
  4668. struct sta_info *psta = NULL;
  4669. int i = 0;
  4670. phead = &pstapriv->asoc_list;
  4671. plist = get_next(phead);
  4672. /* check asoc_queue */
  4673. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  4674. if (idx == i)
  4675. psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
  4676. plist = get_next(plist);
  4677. i++;
  4678. }
  4679. if (asoc_list_num)
  4680. *asoc_list_num = i;
  4681. return psta;
  4682. }
  4683. static int cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev,
  4684. int idx, u8 *mac, struct station_info *sinfo)
  4685. {
  4686. #define DBG_DUMP_STATION 0
  4687. int ret = 0;
  4688. _irqL irqL;
  4689. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4690. struct sta_priv *pstapriv = &padapter->stapriv;
  4691. struct sta_info *psta = NULL;
  4692. #ifdef CONFIG_RTW_MESH
  4693. struct mesh_plink_ent *plink = NULL;
  4694. #endif
  4695. u8 asoc_list_num;
  4696. if (DBG_DUMP_STATION)
  4697. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4698. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4699. psta = rtw_sta_info_get_by_idx(pstapriv, idx, &asoc_list_num);
  4700. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
  4701. #ifdef CONFIG_RTW_MESH
  4702. if (MLME_IS_MESH(padapter)) {
  4703. if (psta)
  4704. plink = psta->plink;
  4705. if (!plink)
  4706. plink = rtw_mesh_plink_get_no_estab_by_idx(padapter, idx - asoc_list_num);
  4707. }
  4708. #endif /* CONFIG_RTW_MESH */
  4709. if ((!MLME_IS_MESH(padapter) && !psta)
  4710. #ifdef CONFIG_RTW_MESH
  4711. || (MLME_IS_MESH(padapter) && !plink)
  4712. #endif
  4713. ) {
  4714. if (DBG_DUMP_STATION)
  4715. RTW_INFO(FUNC_NDEV_FMT" end with idx:%d\n", FUNC_NDEV_ARG(ndev), idx);
  4716. ret = -ENOENT;
  4717. goto exit;
  4718. }
  4719. if (psta)
  4720. _rtw_memcpy(mac, psta->cmn.mac_addr, ETH_ALEN);
  4721. #ifdef CONFIG_RTW_MESH
  4722. else
  4723. _rtw_memcpy(mac, plink->addr, ETH_ALEN);
  4724. #endif
  4725. sinfo->filled = 0;
  4726. if (psta) {
  4727. sinfo->filled |= STATION_INFO_SIGNAL;
  4728. sinfo->signal = translate_percentage_to_dbm(psta->cmn.rssi_stat.rssi);
  4729. sinfo->filled |= STATION_INFO_INACTIVE_TIME;
  4730. sinfo->inactive_time = rtw_get_passing_time_ms(psta->sta_stats.last_rx_time);
  4731. }
  4732. #ifdef CONFIG_RTW_MESH
  4733. if (MLME_IS_MESH(padapter))
  4734. rtw_cfg80211_fill_mesh_only_sta_info(plink, psta, sinfo);
  4735. #endif
  4736. exit:
  4737. return ret;
  4738. }
  4739. static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev,
  4740. struct bss_parameters *params)
  4741. {
  4742. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4743. /*
  4744. RTW_INFO("use_cts_prot=%d\n", params->use_cts_prot);
  4745. RTW_INFO("use_short_preamble=%d\n", params->use_short_preamble);
  4746. RTW_INFO("use_short_slot_time=%d\n", params->use_short_slot_time);
  4747. RTW_INFO("ap_isolate=%d\n", params->ap_isolate);
  4748. RTW_INFO("basic_rates_len=%d\n", params->basic_rates_len);
  4749. for(i = 0; i < params->basic_rates_len; i++)
  4750. RTW_INFO("basic_rates=%d\n", params->basic_rates[i]);
  4751. */
  4752. return 0;
  4753. }
  4754. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  4755. static int cfg80211_rtw_set_txq_params(struct wiphy *wiphy
  4756. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4757. , struct net_device *ndev
  4758. #endif
  4759. , struct ieee80211_txq_params *params)
  4760. {
  4761. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  4762. _adapter *padapter = rtw_netdev_priv(ndev);
  4763. #else
  4764. _adapter *padapter = wiphy_to_adapter(wiphy);
  4765. #endif
  4766. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  4767. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  4768. u8 ac, AIFS, ECWMin, ECWMax, aSifsTime;
  4769. u16 TXOP;
  4770. u8 shift_count = 0;
  4771. u32 acParm;
  4772. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  4773. ac = params->ac;
  4774. #else
  4775. ac = params->queue;
  4776. #endif
  4777. #if 0
  4778. RTW_INFO("ac=%d\n", ac);
  4779. RTW_INFO("txop=%u\n", params->txop);
  4780. RTW_INFO("cwmin=%u\n", params->cwmin);
  4781. RTW_INFO("cwmax=%u\n", params->cwmax);
  4782. RTW_INFO("aifs=%u\n", params->aifs);
  4783. #endif
  4784. if (is_supported_5g(pmlmeext->cur_wireless_mode) ||
  4785. (pmlmeext->cur_wireless_mode & WIRELESS_11_24N))
  4786. aSifsTime = 16;
  4787. else
  4788. aSifsTime = 10;
  4789. AIFS = params->aifs * pmlmeinfo->slotTime + aSifsTime;
  4790. while ((params->cwmin + 1) >> shift_count != 1) {
  4791. shift_count++;
  4792. if (shift_count == 15)
  4793. break;
  4794. }
  4795. ECWMin = shift_count;
  4796. shift_count = 0;
  4797. while ((params->cwmax + 1) >> shift_count != 1) {
  4798. shift_count++;
  4799. if (shift_count == 15)
  4800. break;
  4801. }
  4802. ECWMax = shift_count;
  4803. TXOP = le16_to_cpu(params->txop);
  4804. acParm = AIFS | (ECWMin << 8) | (ECWMax << 12) | (TXOP << 16);
  4805. switch (ac) {
  4806. case NL80211_TXQ_Q_VO:
  4807. RTW_INFO(FUNC_NDEV_FMT" AC_VO = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4808. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acParm));
  4809. break;
  4810. case NL80211_TXQ_Q_VI:
  4811. RTW_INFO(FUNC_NDEV_FMT" AC_VI = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4812. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acParm));
  4813. break;
  4814. case NL80211_TXQ_Q_BE:
  4815. RTW_INFO(FUNC_NDEV_FMT" AC_BE = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4816. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acParm));
  4817. break;
  4818. case NL80211_TXQ_Q_BK:
  4819. RTW_INFO(FUNC_NDEV_FMT" AC_BK = 0x%08x\n", FUNC_ADPT_ARG(padapter), acParm);
  4820. rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acParm));
  4821. break;
  4822. default:
  4823. break;
  4824. }
  4825. return 0;
  4826. }
  4827. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)) */
  4828. static int cfg80211_rtw_set_channel(struct wiphy *wiphy
  4829. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4830. , struct net_device *ndev
  4831. #endif
  4832. , struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
  4833. {
  4834. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4835. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  4836. #else
  4837. _adapter *padapter = wiphy_to_adapter(wiphy);
  4838. #endif
  4839. int chan_target = (u8) ieee80211_frequency_to_channel(chan->center_freq);
  4840. int chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4841. int chan_width = CHANNEL_WIDTH_20;
  4842. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  4843. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4844. #endif
  4845. switch (channel_type) {
  4846. case NL80211_CHAN_NO_HT:
  4847. case NL80211_CHAN_HT20:
  4848. chan_width = CHANNEL_WIDTH_20;
  4849. chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4850. break;
  4851. case NL80211_CHAN_HT40MINUS:
  4852. chan_width = CHANNEL_WIDTH_40;
  4853. chan_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4854. break;
  4855. case NL80211_CHAN_HT40PLUS:
  4856. chan_width = CHANNEL_WIDTH_40;
  4857. chan_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4858. break;
  4859. default:
  4860. chan_width = CHANNEL_WIDTH_20;
  4861. chan_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4862. break;
  4863. }
  4864. RTW_INFO(FUNC_ADPT_FMT" ch:%d bw:%d, offset:%d\n"
  4865. , FUNC_ADPT_ARG(padapter), chan_target, chan_width, chan_offset);
  4866. rtw_set_chbw_cmd(padapter, chan_target, chan_width, chan_offset, RTW_CMDF_WAIT_ACK);
  4867. return 0;
  4868. }
  4869. static int cfg80211_rtw_set_monitor_channel(struct wiphy *wiphy
  4870. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4871. , struct cfg80211_chan_def *chandef
  4872. #else
  4873. , struct ieee80211_channel *chan
  4874. , enum nl80211_channel_type channel_type
  4875. #endif
  4876. )
  4877. {
  4878. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4879. struct ieee80211_channel *chan = chandef->chan;
  4880. #endif
  4881. _adapter *padapter = wiphy_to_adapter(wiphy);
  4882. int target_channal = chan->hw_value;
  4883. int target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4884. int target_width = CHANNEL_WIDTH_20;
  4885. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  4886. #ifdef CONFIG_DEBUG_CFG80211
  4887. RTW_INFO("center_freq %u Mhz ch %u width %u freq1 %u freq2 %u\n"
  4888. , chan->center_freq
  4889. , chan->hw_value
  4890. , chandef->width
  4891. , chandef->center_freq1
  4892. , chandef->center_freq2);
  4893. #endif /* CONFIG_DEBUG_CFG80211 */
  4894. switch (chandef->width) {
  4895. case NL80211_CHAN_WIDTH_20_NOHT:
  4896. case NL80211_CHAN_WIDTH_20:
  4897. target_width = CHANNEL_WIDTH_20;
  4898. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4899. break;
  4900. case NL80211_CHAN_WIDTH_40:
  4901. target_width = CHANNEL_WIDTH_40;
  4902. if (chandef->center_freq1 > chan->center_freq)
  4903. target_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4904. else
  4905. target_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4906. break;
  4907. case NL80211_CHAN_WIDTH_80:
  4908. target_width = CHANNEL_WIDTH_80;
  4909. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4910. break;
  4911. case NL80211_CHAN_WIDTH_80P80:
  4912. target_width = CHANNEL_WIDTH_80_80;
  4913. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4914. break;
  4915. case NL80211_CHAN_WIDTH_160:
  4916. target_width = CHANNEL_WIDTH_160;
  4917. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4918. break;
  4919. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  4920. case NL80211_CHAN_WIDTH_5:
  4921. case NL80211_CHAN_WIDTH_10:
  4922. #endif
  4923. default:
  4924. target_width = CHANNEL_WIDTH_20;
  4925. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4926. break;
  4927. }
  4928. #else
  4929. #ifdef CONFIG_DEBUG_CFG80211
  4930. RTW_INFO("center_freq %u Mhz ch %u channel_type %u\n"
  4931. , chan->center_freq
  4932. , chan->hw_value
  4933. , channel_type);
  4934. #endif /* CONFIG_DEBUG_CFG80211 */
  4935. switch (channel_type) {
  4936. case NL80211_CHAN_NO_HT:
  4937. case NL80211_CHAN_HT20:
  4938. target_width = CHANNEL_WIDTH_20;
  4939. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4940. break;
  4941. case NL80211_CHAN_HT40MINUS:
  4942. target_width = CHANNEL_WIDTH_40;
  4943. target_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
  4944. break;
  4945. case NL80211_CHAN_HT40PLUS:
  4946. target_width = CHANNEL_WIDTH_40;
  4947. target_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
  4948. break;
  4949. default:
  4950. target_width = CHANNEL_WIDTH_20;
  4951. target_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  4952. break;
  4953. }
  4954. #endif
  4955. RTW_INFO(FUNC_ADPT_FMT" ch:%d bw:%d, offset:%d\n"
  4956. , FUNC_ADPT_ARG(padapter), target_channal, target_width, target_offset);
  4957. rtw_set_chbw_cmd(padapter, target_channal, target_width, target_offset, RTW_CMDF_WAIT_ACK);
  4958. return 0;
  4959. }
  4960. static int cfg80211_rtw_auth(struct wiphy *wiphy, struct net_device *ndev,
  4961. struct cfg80211_auth_request *req)
  4962. {
  4963. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4964. return 0;
  4965. }
  4966. static int cfg80211_rtw_assoc(struct wiphy *wiphy, struct net_device *ndev,
  4967. struct cfg80211_assoc_request *req)
  4968. {
  4969. RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));
  4970. return 0;
  4971. }
  4972. #endif /* CONFIG_AP_MODE */
  4973. void rtw_cfg80211_rx_probe_request(_adapter *adapter, union recv_frame *rframe)
  4974. {
  4975. struct wireless_dev *wdev = adapter->rtw_wdev;
  4976. u8 *frame = get_recvframe_data(rframe);
  4977. uint frame_len = rframe->u.hdr.len;
  4978. s32 freq;
  4979. u8 ch, sch = rtw_get_oper_ch(adapter);
  4980. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  4981. freq = rtw_ch2freq(ch);
  4982. #ifdef CONFIG_DEBUG_CFG80211
  4983. RTW_INFO("RTW_Rx: probe request, ch=%d(%d), ta="MAC_FMT"\n"
  4984. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  4985. #endif
  4986. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) || defined(COMPAT_KERNEL_RELEASE)
  4987. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  4988. #else
  4989. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  4990. #endif
  4991. }
  4992. void rtw_cfg80211_rx_action_p2p(_adapter *adapter, union recv_frame *rframe)
  4993. {
  4994. struct wireless_dev *wdev = adapter->rtw_wdev;
  4995. u8 *frame = get_recvframe_data(rframe);
  4996. uint frame_len = rframe->u.hdr.len;
  4997. s32 freq;
  4998. u8 ch, sch = rtw_get_oper_ch(adapter);
  4999. u8 category, action;
  5000. int type;
  5001. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5002. freq = rtw_ch2freq(ch);
  5003. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5004. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5005. #ifdef CONFIG_P2P
  5006. type = rtw_p2p_check_frames(adapter, frame, frame_len, _FALSE);
  5007. if (type >= 0)
  5008. goto indicate;
  5009. #endif
  5010. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5011. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5012. indicate:
  5013. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5014. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5015. #else
  5016. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5017. #endif
  5018. }
  5019. void rtw_cfg80211_rx_p2p_action_public(_adapter *adapter, union recv_frame *rframe)
  5020. {
  5021. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  5022. struct wireless_dev *wdev = adapter->rtw_wdev;
  5023. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter);
  5024. u8 *frame = get_recvframe_data(rframe);
  5025. uint frame_len = rframe->u.hdr.len;
  5026. s32 freq;
  5027. u8 ch, sch = rtw_get_oper_ch(adapter);
  5028. u8 category, action;
  5029. int type;
  5030. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5031. freq = rtw_ch2freq(ch);
  5032. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5033. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5034. #ifdef CONFIG_P2P
  5035. type = rtw_p2p_check_frames(adapter, frame, frame_len, _FALSE);
  5036. if (type >= 0) {
  5037. switch (type) {
  5038. case P2P_GO_NEGO_CONF:
  5039. if (0) {
  5040. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. state=%u, status=%u, iaddr="MAC_FMT"\n"
  5041. , FUNC_ADPT_ARG(adapter), pwdev_priv->nego_info.state, pwdev_priv->nego_info.status
  5042. , MAC_ARG(pwdev_priv->nego_info.iface_addr));
  5043. }
  5044. if (pwdev_priv->nego_info.state == 2
  5045. && pwdev_priv->nego_info.status == 0
  5046. && rtw_check_invalid_mac_address(pwdev_priv->nego_info.iface_addr, _FALSE) == _FALSE
  5047. ) {
  5048. _adapter *intended_iface = dvobj_get_adapter_by_addr(dvobj, pwdev_priv->nego_info.iface_addr);
  5049. if (intended_iface) {
  5050. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. Allow only "ADPT_FMT" to scan for 2000 ms\n"
  5051. , FUNC_ADPT_ARG(adapter), ADPT_ARG(intended_iface));
  5052. /* allow only intended_iface to do scan for 2000 ms */
  5053. rtw_mi_set_scan_deny(adapter, 2000);
  5054. rtw_clear_scan_deny(intended_iface);
  5055. }
  5056. }
  5057. break;
  5058. case P2P_PROVISION_DISC_RESP:
  5059. case P2P_INVIT_RESP:
  5060. rtw_clear_scan_deny(adapter);
  5061. #if !RTW_P2P_GROUP_INTERFACE
  5062. rtw_mi_buddy_set_scan_deny(adapter, 2000);
  5063. #endif
  5064. break;
  5065. }
  5066. goto indicate;
  5067. }
  5068. #endif
  5069. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5070. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5071. indicate:
  5072. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5073. if (rtw_cfg80211_redirect_pd_wdev(dvobj_to_wiphy(dvobj), get_ra(frame), &wdev))
  5074. if (0)
  5075. RTW_INFO("redirect to pd_wdev:%p\n", wdev);
  5076. #endif
  5077. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5078. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5079. #else
  5080. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5081. #endif
  5082. }
  5083. void rtw_cfg80211_rx_action(_adapter *adapter, union recv_frame *rframe, const char *msg)
  5084. {
  5085. struct wireless_dev *wdev = adapter->rtw_wdev;
  5086. u8 *frame = get_recvframe_data(rframe);
  5087. uint frame_len = rframe->u.hdr.len;
  5088. s32 freq;
  5089. u8 ch, sch = rtw_get_oper_ch(adapter);
  5090. u8 category, action;
  5091. int type = -1;
  5092. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5093. freq = rtw_ch2freq(ch);
  5094. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5095. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5096. #ifdef CONFIG_RTW_MESH
  5097. if (MLME_IS_MESH(adapter)) {
  5098. type = rtw_mesh_check_frames_rx(adapter, frame, frame_len);
  5099. if (type >= 0)
  5100. goto indicate;
  5101. }
  5102. #endif
  5103. rtw_action_frame_parse(frame, frame_len, &category, &action);
  5104. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  5105. if (action == ACT_PUBLIC_GAS_INITIAL_REQ) {
  5106. rtw_mi_set_scan_deny(adapter, 200);
  5107. rtw_mi_scan_abort(adapter, _FALSE); /*rtw_scan_abort_no_wait*/
  5108. }
  5109. }
  5110. indicate:
  5111. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5112. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5113. #else
  5114. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5115. #endif
  5116. if (type == -1) {
  5117. if (msg)
  5118. RTW_INFO("RTW_Rx:%s\n", msg);
  5119. else
  5120. RTW_INFO("RTW_Rx:category(%u), action(%u)\n", category, action);
  5121. }
  5122. }
  5123. #ifdef CONFIG_RTW_80211K
  5124. void rtw_cfg80211_rx_rrm_action(_adapter *adapter, union recv_frame *rframe)
  5125. {
  5126. struct wireless_dev *wdev = adapter->rtw_wdev;
  5127. u8 *frame = get_recvframe_data(rframe);
  5128. uint frame_len = rframe->u.hdr.len;
  5129. s32 freq;
  5130. u8 ch, sch = rtw_get_oper_ch(adapter);
  5131. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5132. freq = rtw_ch2freq(ch);
  5133. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5134. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5135. #else
  5136. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5137. #endif
  5138. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n"
  5139. , ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5140. }
  5141. #endif /* CONFIG_RTW_80211K */
  5142. void rtw_cfg80211_rx_mframe(_adapter *adapter, union recv_frame *rframe, const char *msg)
  5143. {
  5144. struct wireless_dev *wdev = adapter->rtw_wdev;
  5145. u8 *frame = get_recvframe_data(rframe);
  5146. uint frame_len = rframe->u.hdr.len;
  5147. s32 freq;
  5148. u8 ch, sch = rtw_get_oper_ch(adapter);
  5149. ch = rframe->u.hdr.attrib.ch ? rframe->u.hdr.attrib.ch : sch;
  5150. freq = rtw_ch2freq(ch);
  5151. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5152. rtw_cfg80211_rx_mgmt(wdev, freq, 0, frame, frame_len, GFP_ATOMIC);
  5153. #else
  5154. cfg80211_rx_action(adapter->pnetdev, freq, frame, frame_len, GFP_ATOMIC);
  5155. #endif
  5156. RTW_INFO("RTW_Rx:ch=%d(%d), ta="MAC_FMT"\n", ch, sch, MAC_ARG(get_addr2_ptr(frame)));
  5157. #ifdef CONFIG_RTW_MESH
  5158. if (!rtw_sae_check_frames(adapter, frame, frame_len, _FALSE))
  5159. #endif
  5160. {
  5161. if (msg)
  5162. RTW_INFO("RTW_Rx:%s\n", msg);
  5163. else
  5164. RTW_INFO("RTW_Rx:frame_control:0x%02x\n", le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)rframe)->frame_ctl));
  5165. }
  5166. }
  5167. #ifdef CONFIG_P2P
  5168. void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf, size_t len)
  5169. {
  5170. u16 wps_devicepassword_id = 0x0000;
  5171. uint wps_devicepassword_id_len = 0;
  5172. u8 wpsie[255] = { 0x00 }, p2p_ie[255] = { 0x00 };
  5173. uint p2p_ielen = 0;
  5174. uint wpsielen = 0;
  5175. u32 devinfo_contentlen = 0;
  5176. u8 devinfo_content[64] = { 0x00 };
  5177. u16 capability = 0;
  5178. uint capability_len = 0;
  5179. unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
  5180. u8 action = P2P_PUB_ACTION_ACTION;
  5181. u8 dialogToken = 1;
  5182. u32 p2poui = cpu_to_be32(P2POUI);
  5183. u8 oui_subtype = P2P_PROVISION_DISC_REQ;
  5184. u32 p2pielen = 0;
  5185. #ifdef CONFIG_WFD
  5186. u32 wfdielen = 0;
  5187. #endif
  5188. struct xmit_frame *pmgntframe;
  5189. struct pkt_attrib *pattrib;
  5190. unsigned char *pframe;
  5191. struct rtw_ieee80211_hdr *pwlanhdr;
  5192. unsigned short *fctrl;
  5193. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  5194. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5195. struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
  5196. u8 *frame_body = (unsigned char *)(buf + sizeof(struct rtw_ieee80211_hdr_3addr));
  5197. size_t frame_body_len = len - sizeof(struct rtw_ieee80211_hdr_3addr);
  5198. RTW_INFO("[%s] In\n", __FUNCTION__);
  5199. /* prepare for building provision_request frame */
  5200. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr1Ptr(buf), ETH_ALEN);
  5201. _rtw_memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, GetAddr1Ptr(buf), ETH_ALEN);
  5202. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  5203. rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
  5204. rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *) &wps_devicepassword_id, &wps_devicepassword_id_len);
  5205. wps_devicepassword_id = be16_to_cpu(wps_devicepassword_id);
  5206. switch (wps_devicepassword_id) {
  5207. case WPS_DPID_PIN:
  5208. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
  5209. break;
  5210. case WPS_DPID_USER_SPEC:
  5211. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
  5212. break;
  5213. case WPS_DPID_MACHINE_SPEC:
  5214. break;
  5215. case WPS_DPID_REKEY:
  5216. break;
  5217. case WPS_DPID_PBC:
  5218. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
  5219. break;
  5220. case WPS_DPID_REGISTRAR_SPEC:
  5221. pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
  5222. break;
  5223. default:
  5224. break;
  5225. }
  5226. if (rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, frame_body_len - _PUBLIC_ACTION_IE_OFFSET_, p2p_ie, &p2p_ielen)) {
  5227. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_DEVICE_INFO, devinfo_content, &devinfo_contentlen);
  5228. rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&capability, &capability_len);
  5229. }
  5230. /* start to build provision_request frame */
  5231. _rtw_memset(wpsie, 0, sizeof(wpsie));
  5232. _rtw_memset(p2p_ie, 0, sizeof(p2p_ie));
  5233. p2p_ielen = 0;
  5234. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  5235. if (pmgntframe == NULL)
  5236. return;
  5237. /* update attribute */
  5238. pattrib = &pmgntframe->attrib;
  5239. update_mgntframe_attrib(padapter, pattrib);
  5240. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  5241. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  5242. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  5243. fctrl = &(pwlanhdr->frame_ctl);
  5244. *(fctrl) = 0;
  5245. _rtw_memcpy(pwlanhdr->addr1, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  5246. _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
  5247. _rtw_memcpy(pwlanhdr->addr3, pwdinfo->tx_prov_disc_info.peerDevAddr, ETH_ALEN);
  5248. SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
  5249. pmlmeext->mgnt_seq++;
  5250. set_frame_sub_type(pframe, WIFI_ACTION);
  5251. pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
  5252. pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
  5253. pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
  5254. pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
  5255. pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
  5256. pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
  5257. pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
  5258. /* build_prov_disc_request_p2p_ie */
  5259. /* P2P OUI */
  5260. p2pielen = 0;
  5261. p2p_ie[p2pielen++] = 0x50;
  5262. p2p_ie[p2pielen++] = 0x6F;
  5263. p2p_ie[p2pielen++] = 0x9A;
  5264. p2p_ie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
  5265. /* Commented by Albert 20110301 */
  5266. /* According to the P2P Specification, the provision discovery request frame should contain 3 P2P attributes */
  5267. /* 1. P2P Capability */
  5268. /* 2. Device Info */
  5269. /* 3. Group ID ( When joining an operating P2P Group ) */
  5270. /* P2P Capability ATTR */
  5271. /* Type: */
  5272. p2p_ie[p2pielen++] = P2P_ATTR_CAPABILITY;
  5273. /* Length: */
  5274. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 0x0002 ); */
  5275. RTW_PUT_LE16(p2p_ie + p2pielen, 0x0002);
  5276. p2pielen += 2;
  5277. /* Value: */
  5278. /* Device Capability Bitmap, 1 byte */
  5279. /* Group Capability Bitmap, 1 byte */
  5280. _rtw_memcpy(p2p_ie + p2pielen, &capability, 2);
  5281. p2pielen += 2;
  5282. /* Device Info ATTR */
  5283. /* Type: */
  5284. p2p_ie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
  5285. /* Length: */
  5286. /* 21->P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
  5287. /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
  5288. /* *(u16*) ( p2pie + p2pielen ) = cpu_to_le16( 21 + pwdinfo->device_name_len ); */
  5289. RTW_PUT_LE16(p2p_ie + p2pielen, devinfo_contentlen);
  5290. p2pielen += 2;
  5291. /* Value: */
  5292. _rtw_memcpy(p2p_ie + p2pielen, devinfo_content, devinfo_contentlen);
  5293. p2pielen += devinfo_contentlen;
  5294. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2p_ie, &p2p_ielen);
  5295. /* p2pielen = build_prov_disc_request_p2p_ie( pwdinfo, pframe, NULL, 0, pwdinfo->tx_prov_disc_info.peerDevAddr); */
  5296. /* pframe += p2pielen; */
  5297. pattrib->pktlen += p2p_ielen;
  5298. wpsielen = 0;
  5299. /* WPS OUI */
  5300. *(u32 *)(wpsie) = cpu_to_be32(WPSOUI);
  5301. wpsielen += 4;
  5302. /* WPS version */
  5303. /* Type: */
  5304. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
  5305. wpsielen += 2;
  5306. /* Length: */
  5307. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
  5308. wpsielen += 2;
  5309. /* Value: */
  5310. wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
  5311. /* Config Method */
  5312. /* Type: */
  5313. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
  5314. wpsielen += 2;
  5315. /* Length: */
  5316. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
  5317. wpsielen += 2;
  5318. /* Value: */
  5319. *(u16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
  5320. wpsielen += 2;
  5321. pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen);
  5322. #ifdef CONFIG_WFD
  5323. wfdielen = build_provdisc_req_wfd_ie(pwdinfo, pframe);
  5324. pframe += wfdielen;
  5325. pattrib->pktlen += wfdielen;
  5326. #endif
  5327. pattrib->last_txcmdsz = pattrib->pktlen;
  5328. /* dump_mgntframe(padapter, pmgntframe); */
  5329. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS)
  5330. RTW_INFO("%s, ack to\n", __func__);
  5331. #if 0
  5332. if(wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC) {
  5333. RTW_INFO("waiting for p2p peer key-in PIN CODE\n");
  5334. rtw_msleep_os(15000); /* 15 sec for key in PIN CODE, workaround for GS2 before issuing Nego Req. */
  5335. }
  5336. #endif
  5337. }
  5338. #ifdef CONFIG_RTW_80211R
  5339. static s32 cfg80211_rtw_update_ft_ies(struct wiphy *wiphy,
  5340. struct net_device *ndev,
  5341. struct cfg80211_update_ft_ies_params *ftie)
  5342. {
  5343. _adapter *padapter = NULL;
  5344. struct mlme_priv *pmlmepriv = NULL;
  5345. struct ft_roam_info *pft_roam = NULL;
  5346. _irqL irqL;
  5347. u8 *p;
  5348. u8 *pie = NULL;
  5349. u32 ie_len = 0;
  5350. if (ndev == NULL)
  5351. return -EINVAL;
  5352. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5353. pmlmepriv = &(padapter->mlmepriv);
  5354. pft_roam = &(pmlmepriv->ft_roam);
  5355. p = (u8 *)ftie->ie;
  5356. if (ftie->ie_len <= sizeof(pft_roam->updated_ft_ies)) {
  5357. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  5358. _rtw_memcpy(pft_roam->updated_ft_ies, ftie->ie, ftie->ie_len);
  5359. pft_roam->updated_ft_ies_len = ftie->ie_len;
  5360. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  5361. } else {
  5362. RTW_ERR("FTIEs parsing fail!\n");
  5363. return -EINVAL;
  5364. }
  5365. if (rtw_ft_roam_status(padapter, RTW_FT_AUTHENTICATED_STA)) {
  5366. RTW_PRINT("auth success, start reassoc\n");
  5367. rtw_ft_lock_set_status(padapter, RTW_FT_ASSOCIATING_STA, &irqL);
  5368. start_clnt_assoc(padapter);
  5369. }
  5370. return 0;
  5371. }
  5372. #endif
  5373. inline void rtw_cfg80211_set_is_roch(_adapter *adapter, bool val)
  5374. {
  5375. adapter->cfg80211_wdinfo.is_ro_ch = val;
  5376. rtw_mi_update_iface_status(&(adapter->mlmepriv), 0);
  5377. }
  5378. inline bool rtw_cfg80211_get_is_roch(_adapter *adapter)
  5379. {
  5380. return adapter->cfg80211_wdinfo.is_ro_ch;
  5381. }
  5382. inline bool rtw_cfg80211_is_ro_ch_once(_adapter *adapter)
  5383. {
  5384. return adapter->cfg80211_wdinfo.last_ro_ch_time ? 1 : 0;
  5385. }
  5386. inline void rtw_cfg80211_set_last_ro_ch_time(_adapter *adapter)
  5387. {
  5388. adapter->cfg80211_wdinfo.last_ro_ch_time = rtw_get_current_time();
  5389. if (!adapter->cfg80211_wdinfo.last_ro_ch_time)
  5390. adapter->cfg80211_wdinfo.last_ro_ch_time++;
  5391. }
  5392. inline s32 rtw_cfg80211_get_last_ro_ch_passing_ms(_adapter *adapter)
  5393. {
  5394. return rtw_get_passing_time_ms(adapter->cfg80211_wdinfo.last_ro_ch_time);
  5395. }
  5396. static s32 cfg80211_rtw_remain_on_channel(struct wiphy *wiphy,
  5397. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5398. struct wireless_dev *wdev,
  5399. #else
  5400. struct net_device *ndev,
  5401. #endif
  5402. struct ieee80211_channel *channel,
  5403. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5404. enum nl80211_channel_type channel_type,
  5405. #endif
  5406. unsigned int duration, u64 *cookie)
  5407. {
  5408. s32 err = 0;
  5409. u8 remain_ch = (u8) ieee80211_frequency_to_channel(channel->center_freq);
  5410. _adapter *padapter = NULL;
  5411. struct rtw_wdev_priv *pwdev_priv;
  5412. struct wifidirect_info *pwdinfo;
  5413. struct cfg80211_wifidirect_info *pcfg80211_wdinfo;
  5414. #ifdef CONFIG_CONCURRENT_MODE
  5415. u8 is_p2p_find = _FALSE;
  5416. #endif
  5417. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5418. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5419. if (wdev == wiphy_to_pd_wdev(wiphy))
  5420. padapter = wiphy_to_adapter(wiphy);
  5421. else
  5422. #endif
  5423. if (wdev_to_ndev(wdev))
  5424. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5425. else {
  5426. err = -EINVAL;
  5427. goto exit;
  5428. }
  5429. #else
  5430. struct wireless_dev *wdev;
  5431. if (ndev == NULL) {
  5432. err = -EINVAL;
  5433. goto exit;
  5434. }
  5435. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5436. wdev = ndev_to_wdev(ndev);
  5437. #endif
  5438. pwdev_priv = adapter_wdev_data(padapter);
  5439. pwdinfo = &padapter->wdinfo;
  5440. pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5441. #ifdef CONFIG_CONCURRENT_MODE
  5442. is_p2p_find = (duration < (pwdinfo->ext_listen_interval)) ? _TRUE : _FALSE;
  5443. #endif
  5444. *cookie = ATOMIC_INC_RETURN(&pcfg80211_wdinfo->ro_ch_cookie_gen);
  5445. RTW_INFO(FUNC_ADPT_FMT"%s ch:%u duration:%d, cookie:0x%llx\n"
  5446. , FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  5447. , remain_ch, duration, *cookie);
  5448. if (rtw_chset_search_ch(adapter_to_chset(padapter), remain_ch) < 0) {
  5449. RTW_WARN(FUNC_ADPT_FMT" invalid ch:%u\n", FUNC_ADPT_ARG(padapter), remain_ch);
  5450. err = -EFAULT;
  5451. goto exit;
  5452. }
  5453. #ifdef CONFIG_MP_INCLUDED
  5454. if (rtw_mp_mode_check(padapter)) {
  5455. RTW_INFO("MP mode block remain_on_channel request\n");
  5456. err = -EFAULT;
  5457. goto exit;
  5458. }
  5459. #endif
  5460. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  5461. err = -EFAULT;
  5462. goto exit;
  5463. }
  5464. rtw_scan_abort(padapter);
  5465. #ifdef CONFIG_CONCURRENT_MODE
  5466. /*don't scan_abort during p2p_listen.*/
  5467. if (is_p2p_find)
  5468. rtw_mi_buddy_scan_abort(padapter, _TRUE);
  5469. #endif /*CONFIG_CONCURRENT_MODE*/
  5470. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5471. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  5472. p2p_cancel_roch_cmd(padapter, 0, NULL, RTW_CMDF_WAIT_ACK);
  5473. }
  5474. /* if(!rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) && !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) */
  5475. if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
  5476. rtw_p2p_enable(padapter, P2P_ROLE_DEVICE);
  5477. padapter->wdinfo.listen_channel = remain_ch;
  5478. RTW_INFO(FUNC_ADPT_FMT" init listen_channel %u\n"
  5479. , FUNC_ADPT_ARG(padapter), padapter->wdinfo.listen_channel);
  5480. } else if (rtw_p2p_chk_state(pwdinfo , P2P_STATE_LISTEN)
  5481. && (time_after_eq(rtw_get_current_time(), pwdev_priv->probe_resp_ie_update_time)
  5482. && rtw_get_passing_time_ms(pwdev_priv->probe_resp_ie_update_time) < 50)
  5483. ) {
  5484. if (padapter->wdinfo.listen_channel != remain_ch) {
  5485. padapter->wdinfo.listen_channel = remain_ch;
  5486. RTW_INFO(FUNC_ADPT_FMT" update listen_channel %u\n"
  5487. , FUNC_ADPT_ARG(padapter), padapter->wdinfo.listen_channel);
  5488. }
  5489. } else {
  5490. rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
  5491. #ifdef CONFIG_DEBUG_CFG80211
  5492. RTW_INFO("%s, role=%d, p2p_state=%d\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo));
  5493. #endif
  5494. }
  5495. rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
  5496. #ifdef RTW_ROCH_DURATION_ENLARGE
  5497. if (duration < 400)
  5498. duration = duration * 3; /* extend from exper */
  5499. #endif
  5500. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_CONCURRENT_MODE)
  5501. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  5502. if (is_p2p_find) /* p2p_find , duration<1000 */
  5503. duration = duration + pwdinfo->ext_listen_interval;
  5504. else /* p2p_listen, duration=5000 */
  5505. duration = pwdinfo->ext_listen_interval + (pwdinfo->ext_listen_interval / 4);
  5506. }
  5507. #endif /*defined (RTW_ROCH_BACK_OP) && defined(CONFIG_CONCURRENT_MODE) */
  5508. rtw_cfg80211_set_is_roch(padapter, _TRUE);
  5509. pcfg80211_wdinfo->ro_ch_wdev = wdev;
  5510. pcfg80211_wdinfo->remain_on_ch_cookie = *cookie;
  5511. rtw_cfg80211_set_last_ro_ch_time(padapter);
  5512. _rtw_memcpy(&pcfg80211_wdinfo->remain_on_ch_channel, channel, sizeof(struct ieee80211_channel));
  5513. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5514. pcfg80211_wdinfo->remain_on_ch_type = channel_type;
  5515. #endif
  5516. pcfg80211_wdinfo->restore_channel = rtw_get_oper_ch(padapter);
  5517. p2p_roch_cmd(padapter, *cookie, wdev, channel, pcfg80211_wdinfo->remain_on_ch_type,
  5518. duration, RTW_CMDF_WAIT_ACK);
  5519. rtw_cfg80211_ready_on_channel(wdev, *cookie, channel, channel_type, duration, GFP_KERNEL);
  5520. exit:
  5521. return err;
  5522. }
  5523. static s32 cfg80211_rtw_cancel_remain_on_channel(struct wiphy *wiphy,
  5524. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5525. struct wireless_dev *wdev,
  5526. #else
  5527. struct net_device *ndev,
  5528. #endif
  5529. u64 cookie)
  5530. {
  5531. s32 err = 0;
  5532. _adapter *padapter;
  5533. struct rtw_wdev_priv *pwdev_priv;
  5534. struct wifidirect_info *pwdinfo;
  5535. struct cfg80211_wifidirect_info *pcfg80211_wdinfo;
  5536. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5537. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5538. if (wdev == wiphy_to_pd_wdev(wiphy))
  5539. padapter = wiphy_to_adapter(wiphy);
  5540. else
  5541. #endif
  5542. if (wdev_to_ndev(wdev))
  5543. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5544. else {
  5545. err = -EINVAL;
  5546. goto exit;
  5547. }
  5548. #else
  5549. struct wireless_dev *wdev;
  5550. if (ndev == NULL) {
  5551. err = -EINVAL;
  5552. goto exit;
  5553. }
  5554. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5555. wdev = ndev_to_wdev(ndev);
  5556. #endif
  5557. pwdev_priv = adapter_wdev_data(padapter);
  5558. pwdinfo = &padapter->wdinfo;
  5559. pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5560. RTW_INFO(FUNC_ADPT_FMT"%s cookie:0x%llx\n"
  5561. , FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  5562. , cookie);
  5563. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5564. _cancel_timer_ex(&padapter->cfg80211_wdinfo.remain_on_ch_timer);
  5565. p2p_cancel_roch_cmd(padapter, cookie, wdev, RTW_CMDF_WAIT_ACK);
  5566. }
  5567. exit:
  5568. return err;
  5569. }
  5570. inline int rtw_cfg80211_iface_has_p2p_group_cap(_adapter *adapter)
  5571. {
  5572. #if RTW_P2P_GROUP_INTERFACE
  5573. if (is_primary_adapter(adapter))
  5574. return 0;
  5575. #endif
  5576. return 1;
  5577. }
  5578. inline int rtw_cfg80211_is_p2p_scan(_adapter *adapter)
  5579. {
  5580. #if RTW_P2P_GROUP_INTERFACE
  5581. if (rtw_cfg80211_iface_has_p2p_group_cap(adapter))
  5582. #endif
  5583. {
  5584. struct wifidirect_info *wdinfo = &adapter->wdinfo;
  5585. return rtw_p2p_chk_state(wdinfo, P2P_STATE_SCAN)
  5586. || rtw_p2p_chk_state(wdinfo, P2P_STATE_FIND_PHASE_SEARCH);
  5587. }
  5588. #if RTW_P2P_GROUP_INTERFACE
  5589. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5590. if (wiphy_to_pd_wdev(adapter_to_wiphy(adapter))) /* pd_wdev exist */
  5591. return rtw_cfg80211_is_scan_by_pd_wdev(adapter);
  5592. #endif
  5593. {
  5594. /*
  5595. * For 2 RTW_P2P_GROUP_INTERFACE cases:
  5596. * 1. RTW_DEDICATED_P2P_DEVICE defined but upper layer don't use pd_wdev or
  5597. * 2. RTW_DEDICATED_P2P_DEVICE not defined
  5598. */
  5599. struct rtw_wdev_priv *wdev_data = adapter_wdev_data(adapter);
  5600. _irqL irqL;
  5601. int is_p2p_scan = 0;
  5602. _enter_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5603. if (wdev_data->scan_request
  5604. && wdev_data->scan_request->ssids
  5605. && wdev_data->scan_request->ie
  5606. ) {
  5607. if (_rtw_memcmp(wdev_data->scan_request->ssids->ssid, "DIRECT-", 7)
  5608. && rtw_get_p2p_ie((u8 *)wdev_data->scan_request->ie, wdev_data->scan_request->ie_len, NULL, NULL))
  5609. is_p2p_scan = 1;
  5610. }
  5611. _exit_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5612. return is_p2p_scan;
  5613. }
  5614. #endif
  5615. }
  5616. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5617. int rtw_pd_iface_alloc(struct wiphy *wiphy, const char *name, struct wireless_dev **pd_wdev)
  5618. {
  5619. struct rtw_wiphy_data *wiphy_data = rtw_wiphy_priv(wiphy);
  5620. struct wireless_dev *wdev = NULL;
  5621. struct rtw_netdev_priv_indicator *npi;
  5622. _adapter *primary_adpt = wiphy_to_adapter(wiphy);
  5623. int ret = 0;
  5624. if (wiphy_data->pd_wdev) {
  5625. RTW_WARN(FUNC_WIPHY_FMT" pd_wdev already exists\n", FUNC_WIPHY_ARG(wiphy));
  5626. ret = -EBUSY;
  5627. goto exit;
  5628. }
  5629. wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  5630. if (!wdev) {
  5631. RTW_WARN(FUNC_WIPHY_FMT" allocate wdev fail\n", FUNC_WIPHY_ARG(wiphy));
  5632. ret = -ENOMEM;
  5633. goto exit;
  5634. }
  5635. wdev->wiphy = wiphy;
  5636. wdev->iftype = NL80211_IFTYPE_P2P_DEVICE;
  5637. _rtw_memcpy(wdev->address, adapter_mac_addr(primary_adpt), ETH_ALEN);
  5638. wiphy_data->pd_wdev = wdev;
  5639. *pd_wdev = wdev;
  5640. RTW_INFO(FUNC_WIPHY_FMT" pd_wdev:%p, addr="MAC_FMT" added\n"
  5641. , FUNC_WIPHY_ARG(wiphy), wdev, MAC_ARG(wdev_address(wdev)));
  5642. exit:
  5643. if (ret && wdev) {
  5644. rtw_mfree((u8 *)wdev, sizeof(struct wireless_dev));
  5645. wdev = NULL;
  5646. }
  5647. return ret;
  5648. }
  5649. void rtw_pd_iface_free(struct wiphy *wiphy)
  5650. {
  5651. struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
  5652. struct rtw_wiphy_data *wiphy_data = rtw_wiphy_priv(wiphy);
  5653. u8 rtnl_lock_needed;
  5654. if (!wiphy_data->pd_wdev)
  5655. goto exit;
  5656. RTW_INFO(FUNC_WIPHY_FMT" pd_wdev:%p, addr="MAC_FMT"\n"
  5657. , FUNC_WIPHY_ARG(wiphy), wiphy_data->pd_wdev
  5658. , MAC_ARG(wdev_address(wiphy_data->pd_wdev)));
  5659. rtnl_lock_needed = rtw_rtnl_lock_needed(dvobj);
  5660. if (rtnl_lock_needed)
  5661. rtnl_lock();
  5662. cfg80211_unregister_wdev(wiphy_data->pd_wdev);
  5663. if (rtnl_lock_needed)
  5664. rtnl_unlock();
  5665. rtw_mfree((u8 *)wiphy_data->pd_wdev, sizeof(struct wireless_dev));
  5666. wiphy_data->pd_wdev = NULL;
  5667. exit:
  5668. return;
  5669. }
  5670. static int cfg80211_rtw_start_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev)
  5671. {
  5672. _adapter *adapter = wiphy_to_adapter(wiphy);
  5673. RTW_INFO(FUNC_WIPHY_FMT" wdev=%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  5674. rtw_p2p_enable(adapter, P2P_ROLE_DEVICE);
  5675. return 0;
  5676. }
  5677. static void cfg80211_rtw_stop_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev)
  5678. {
  5679. _adapter *adapter = wiphy_to_adapter(wiphy);
  5680. RTW_INFO(FUNC_WIPHY_FMT" wdev=%p\n", FUNC_WIPHY_ARG(wiphy), wdev);
  5681. if (rtw_cfg80211_is_p2p_scan(adapter))
  5682. rtw_scan_abort(adapter);
  5683. rtw_p2p_enable(adapter, P2P_ROLE_DISABLE);
  5684. }
  5685. inline int rtw_cfg80211_redirect_pd_wdev(struct wiphy *wiphy, u8 *ra, struct wireless_dev **wdev)
  5686. {
  5687. struct wireless_dev *pd_wdev = wiphy_to_pd_wdev(wiphy);
  5688. if (pd_wdev && pd_wdev != *wdev
  5689. && _rtw_memcmp(wdev_address(pd_wdev), ra, ETH_ALEN) == _TRUE
  5690. ) {
  5691. *wdev = pd_wdev;
  5692. return 1;
  5693. }
  5694. return 0;
  5695. }
  5696. inline int rtw_cfg80211_is_scan_by_pd_wdev(_adapter *adapter)
  5697. {
  5698. struct wiphy *wiphy = adapter_to_wiphy(adapter);
  5699. struct rtw_wdev_priv *wdev_data = adapter_wdev_data(adapter);
  5700. struct wireless_dev *wdev = NULL;
  5701. _irqL irqL;
  5702. _enter_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5703. if (wdev_data->scan_request)
  5704. wdev = wdev_data->scan_request->wdev;
  5705. _exit_critical_bh(&wdev_data->scan_req_lock, &irqL);
  5706. if (wdev && wdev == wiphy_to_pd_wdev(wiphy))
  5707. return 1;
  5708. return 0;
  5709. }
  5710. #endif /* RTW_DEDICATED_P2P_DEVICE */
  5711. #endif /* CONFIG_P2P */
  5712. inline void rtw_cfg80211_set_is_mgmt_tx(_adapter *adapter, u8 val)
  5713. {
  5714. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  5715. wdev_priv->is_mgmt_tx = val;
  5716. rtw_mi_update_iface_status(&(adapter->mlmepriv), 0);
  5717. }
  5718. inline u8 rtw_cfg80211_get_is_mgmt_tx(_adapter *adapter)
  5719. {
  5720. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  5721. return wdev_priv->is_mgmt_tx;
  5722. }
  5723. static int _cfg80211_rtw_mgmt_tx(_adapter *padapter, u8 tx_ch, u8 no_cck, const u8 *buf, size_t len, int wait_ack)
  5724. {
  5725. struct xmit_frame *pmgntframe;
  5726. struct pkt_attrib *pattrib;
  5727. unsigned char *pframe;
  5728. int ret = _FAIL;
  5729. bool ack = _TRUE;
  5730. struct rtw_ieee80211_hdr *pwlanhdr;
  5731. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_P2P) && defined(CONFIG_CONCURRENT_MODE)
  5732. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  5733. #endif
  5734. struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
  5735. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  5736. u8 u_ch = rtw_mi_get_union_chan(padapter);
  5737. u8 leave_op = 0;
  5738. #ifdef CONFIG_P2P
  5739. struct cfg80211_wifidirect_info *pcfg80211_wdinfo = &padapter->cfg80211_wdinfo;
  5740. #ifdef CONFIG_CONCURRENT_MODE
  5741. struct wifidirect_info *pwdinfo = &padapter->wdinfo;
  5742. #endif
  5743. #endif
  5744. rtw_cfg80211_set_is_mgmt_tx(padapter, 1);
  5745. #ifdef CONFIG_BT_COEXIST
  5746. rtw_btcoex_ScanNotify(padapter, _TRUE);
  5747. #endif
  5748. #ifdef CONFIG_P2P
  5749. if (rtw_cfg80211_get_is_roch(padapter) == _TRUE) {
  5750. #ifdef CONFIG_CONCURRENT_MODE
  5751. if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
  5752. RTW_INFO("%s, extend ro ch time\n", __func__);
  5753. _set_timer(&padapter->cfg80211_wdinfo.remain_on_ch_timer, pwdinfo->ext_listen_period);
  5754. }
  5755. #endif /* CONFIG_CONCURRENT_MODE */
  5756. }
  5757. #endif /* CONFIG_P2P */
  5758. #ifdef CONFIG_MCC_MODE
  5759. if (MCC_EN(padapter)) {
  5760. if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))
  5761. /* don't set channel, issue frame directly */
  5762. goto issue_mgmt_frame;
  5763. }
  5764. #endif /* CONFIG_MCC_MODE */
  5765. if (rtw_mi_check_status(padapter, MI_LINKED)
  5766. && tx_ch != u_ch
  5767. ) {
  5768. rtw_leave_opch(padapter);
  5769. leave_op = 1;
  5770. #if defined(RTW_ROCH_BACK_OP) && defined(CONFIG_P2P) && defined(CONFIG_CONCURRENT_MODE)
  5771. if (rtw_cfg80211_get_is_roch(padapter)
  5772. && ATOMIC_READ(&pwdev_priv->switch_ch_to) == 1
  5773. ) {
  5774. u16 ext_listen_period;
  5775. if (check_fwstate(&padapter->mlmepriv, _FW_LINKED))
  5776. ext_listen_period = 500;
  5777. else
  5778. ext_listen_period = pwdinfo->ext_listen_period;
  5779. ATOMIC_SET(&pwdev_priv->switch_ch_to, 0);
  5780. _set_timer(&pwdinfo->ap_p2p_switch_timer, ext_listen_period);
  5781. RTW_INFO("%s, set switch ch timer, period=%d\n", __func__, ext_listen_period);
  5782. }
  5783. #endif /* RTW_ROCH_BACK_OP && CONFIG_P2P && CONFIG_CONCURRENT_MODE */
  5784. }
  5785. if (tx_ch != rtw_get_oper_ch(padapter))
  5786. set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  5787. issue_mgmt_frame:
  5788. /* starting alloc mgmt frame to dump it */
  5789. pmgntframe = alloc_mgtxmitframe(pxmitpriv);
  5790. if (pmgntframe == NULL) {
  5791. /* ret = -ENOMEM; */
  5792. ret = _FAIL;
  5793. goto exit;
  5794. }
  5795. /* update attribute */
  5796. pattrib = &pmgntframe->attrib;
  5797. update_mgntframe_attrib(padapter, pattrib);
  5798. if (no_cck && IS_CCK_RATE(pattrib->rate)) {
  5799. /* force OFDM 6M rate*/
  5800. pattrib->rate = MGN_6M;
  5801. pattrib->raid = rtw_get_mgntframe_raid(padapter, WIRELESS_11G);
  5802. }
  5803. pattrib->retry_ctrl = _FALSE;
  5804. _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
  5805. pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
  5806. _rtw_memcpy(pframe, (void *)buf, len);
  5807. pattrib->pktlen = len;
  5808. pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
  5809. /* update seq number */
  5810. pmlmeext->mgnt_seq = GetSequence(pwlanhdr);
  5811. pattrib->seqnum = pmlmeext->mgnt_seq;
  5812. pmlmeext->mgnt_seq++;
  5813. #ifdef CONFIG_P2P
  5814. rtw_xframe_chk_wfd_ie(pmgntframe);
  5815. #endif /* CONFIG_P2P */
  5816. pattrib->last_txcmdsz = pattrib->pktlen;
  5817. if (wait_ack) {
  5818. if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) {
  5819. ack = _FALSE;
  5820. ret = _FAIL;
  5821. #ifdef CONFIG_DEBUG_CFG80211
  5822. RTW_INFO("%s, ack == _FAIL\n", __func__);
  5823. #endif
  5824. } else {
  5825. #ifdef CONFIG_XMIT_ACK
  5826. if (!MLME_IS_MESH(padapter)) /* TODO: remove this sleep for all mode */
  5827. rtw_msleep_os(50);
  5828. #endif
  5829. #ifdef CONFIG_DEBUG_CFG80211
  5830. RTW_INFO("%s, ack=%d, ok!\n", __func__, ack);
  5831. #endif
  5832. ret = _SUCCESS;
  5833. }
  5834. } else {
  5835. dump_mgntframe(padapter, pmgntframe);
  5836. ret = _SUCCESS;
  5837. }
  5838. exit:
  5839. #ifdef CONFIG_P2P
  5840. if (rtw_cfg80211_get_is_roch(padapter)
  5841. && !roch_stay_in_cur_chan(padapter)
  5842. && pcfg80211_wdinfo->remain_on_ch_channel.hw_value != u_ch
  5843. ) {
  5844. /* roch is ongoing, switch back to rch */
  5845. if (pcfg80211_wdinfo->remain_on_ch_channel.hw_value != tx_ch)
  5846. set_channel_bwmode(padapter, pcfg80211_wdinfo->remain_on_ch_channel.hw_value
  5847. , HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
  5848. } else
  5849. #endif
  5850. if (leave_op) {
  5851. if (rtw_mi_check_status(padapter, MI_LINKED)) {
  5852. u8 u_bw = rtw_mi_get_union_bw(padapter);
  5853. u8 u_offset = rtw_mi_get_union_offset(padapter);
  5854. set_channel_bwmode(padapter, u_ch, u_offset, u_bw);
  5855. }
  5856. rtw_back_opch(padapter);
  5857. }
  5858. rtw_cfg80211_set_is_mgmt_tx(padapter, 0);
  5859. #ifdef CONFIG_BT_COEXIST
  5860. rtw_btcoex_ScanNotify(padapter, _FALSE);
  5861. #endif
  5862. #ifdef CONFIG_DEBUG_CFG80211
  5863. RTW_INFO("%s, ret=%d\n", __func__, ret);
  5864. #endif
  5865. return ret;
  5866. }
  5867. u8 rtw_mgnt_tx_handler(_adapter *adapter, u8 *buf)
  5868. {
  5869. u8 rst = H2C_CMD_FAIL;
  5870. struct mgnt_tx_parm *mgnt_parm = (struct mgnt_tx_parm *)buf;
  5871. if (_cfg80211_rtw_mgmt_tx(adapter, mgnt_parm->tx_ch, mgnt_parm->no_cck,
  5872. mgnt_parm->buf, mgnt_parm->len, mgnt_parm->wait_ack) == _SUCCESS)
  5873. rst = H2C_SUCCESS;
  5874. return rst;
  5875. }
  5876. static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy,
  5877. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5878. struct wireless_dev *wdev,
  5879. #else
  5880. struct net_device *ndev,
  5881. #endif
  5882. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)) || defined(COMPAT_KERNEL_RELEASE)
  5883. struct ieee80211_channel *chan,
  5884. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  5885. bool offchan,
  5886. #endif
  5887. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5888. enum nl80211_channel_type channel_type,
  5889. #endif
  5890. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5891. bool channel_type_valid,
  5892. #endif
  5893. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  5894. unsigned int wait,
  5895. #endif
  5896. const u8 *buf, size_t len,
  5897. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  5898. bool no_cck,
  5899. #endif
  5900. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  5901. bool dont_wait_for_ack,
  5902. #endif
  5903. #else
  5904. struct cfg80211_mgmt_tx_params *params,
  5905. #endif
  5906. u64 *cookie)
  5907. {
  5908. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(COMPAT_KERNEL_RELEASE)
  5909. struct ieee80211_channel *chan = params->chan;
  5910. const u8 *buf = params->buf;
  5911. size_t len = params->len;
  5912. bool no_cck = params->no_cck;
  5913. #endif
  5914. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
  5915. bool no_cck = 0;
  5916. #endif
  5917. int ret = 0;
  5918. u8 tx_ret;
  5919. int wait_ack = 1;
  5920. const u8 *dump_buf = buf;
  5921. size_t dump_len = len;
  5922. u32 dump_limit = RTW_MAX_MGMT_TX_CNT;
  5923. u32 dump_cnt = 0;
  5924. u32 sleep_ms = 0;
  5925. u32 retry_guarantee_ms = 0;
  5926. bool ack = _TRUE;
  5927. u8 tx_ch;
  5928. u8 category, action;
  5929. u8 frame_styp;
  5930. #ifdef CONFIG_P2P
  5931. u8 is_p2p = 0;
  5932. #endif
  5933. int type = (-1);
  5934. systime start = rtw_get_current_time();
  5935. _adapter *padapter;
  5936. struct dvobj_priv *dvobj;
  5937. struct rtw_wdev_priv *pwdev_priv;
  5938. struct rf_ctl_t *rfctl;
  5939. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  5940. #if defined(RTW_DEDICATED_P2P_DEVICE)
  5941. if (wdev == wiphy_to_pd_wdev(wiphy))
  5942. padapter = wiphy_to_adapter(wiphy);
  5943. else
  5944. #endif
  5945. if (wdev_to_ndev(wdev))
  5946. padapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  5947. else {
  5948. ret = -EINVAL;
  5949. goto exit;
  5950. }
  5951. #else
  5952. struct wireless_dev *wdev;
  5953. if (ndev == NULL) {
  5954. ret = -EINVAL;
  5955. goto exit;
  5956. }
  5957. padapter = (_adapter *)rtw_netdev_priv(ndev);
  5958. wdev = ndev_to_wdev(ndev);
  5959. #endif
  5960. if (chan == NULL) {
  5961. ret = -EINVAL;
  5962. goto exit;
  5963. }
  5964. rfctl = adapter_to_rfctl(padapter);
  5965. tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq);
  5966. if (IS_CH_WAITING(rfctl)) {
  5967. #ifdef CONFIG_DFS_MASTER
  5968. if (_rtw_rfctl_overlap_radar_detect_ch(rfctl, tx_ch, CHANNEL_WIDTH_20, HAL_PRIME_CHNL_OFFSET_DONT_CARE)) {
  5969. ret = -EINVAL;
  5970. goto exit;
  5971. }
  5972. #endif
  5973. }
  5974. dvobj = adapter_to_dvobj(padapter);
  5975. pwdev_priv = adapter_wdev_data(padapter);
  5976. /* cookie generation */
  5977. *cookie = pwdev_priv->mgmt_tx_cookie++;
  5978. #ifdef CONFIG_DEBUG_CFG80211
  5979. RTW_INFO(FUNC_ADPT_FMT"%s len=%zu, ch=%d"
  5980. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5981. ", ch_type=%d"
  5982. #endif
  5983. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5984. ", channel_type_valid=%d"
  5985. #endif
  5986. "\n", FUNC_ADPT_ARG(padapter), wdev == wiphy_to_pd_wdev(wiphy) ? " PD" : ""
  5987. , len, tx_ch
  5988. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5989. , channel_type
  5990. #endif
  5991. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
  5992. , channel_type_valid
  5993. #endif
  5994. );
  5995. #endif /* CONFIG_DEBUG_CFG80211 */
  5996. /* indicate ack before issue frame to avoid racing with rsp frame */
  5997. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  5998. rtw_cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack, GFP_KERNEL);
  5999. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 36))
  6000. cfg80211_action_tx_status(ndev, *cookie, buf, len, ack, GFP_KERNEL);
  6001. #endif
  6002. frame_styp = le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl) & IEEE80211_FCTL_STYPE;
  6003. if (IEEE80211_STYPE_PROBE_RESP == frame_styp) {
  6004. #ifdef CONFIG_DEBUG_CFG80211
  6005. RTW_INFO("RTW_Tx: probe_resp tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6006. #endif /* CONFIG_DEBUG_CFG80211 */
  6007. wait_ack = 0;
  6008. goto dump;
  6009. }
  6010. #ifdef CONFIG_RTW_MESH
  6011. else if (frame_styp == RTW_IEEE80211_STYPE_AUTH) {
  6012. RTW_INFO("RTW_Tx:tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6013. if (!rtw_sae_check_frames(padapter, buf, len, _TRUE))
  6014. RTW_INFO("RTW_Tx:AUTH\n");
  6015. dump_limit = 1;
  6016. goto dump;
  6017. }
  6018. #endif
  6019. if (rtw_action_frame_parse(buf, len, &category, &action) == _FALSE) {
  6020. RTW_INFO(FUNC_ADPT_FMT" frame_control:0x%02x\n", FUNC_ADPT_ARG(padapter),
  6021. le16_to_cpu(((struct rtw_ieee80211_hdr_3addr *)buf)->frame_ctl));
  6022. goto exit;
  6023. }
  6024. RTW_INFO("RTW_Tx:tx_ch=%d, no_cck=%u, da="MAC_FMT"\n", tx_ch, no_cck, MAC_ARG(GetAddr1Ptr(buf)));
  6025. #ifdef CONFIG_P2P
  6026. type = rtw_p2p_check_frames(padapter, buf, len, _TRUE);
  6027. if (type >= 0) {
  6028. is_p2p = 1;
  6029. no_cck = 1; /* force no CCK for P2P frames */
  6030. goto dump;
  6031. }
  6032. #endif
  6033. #ifdef CONFIG_RTW_MESH
  6034. if (MLME_IS_MESH(padapter)) {
  6035. type = rtw_mesh_check_frames_tx(padapter, &dump_buf, &dump_len);
  6036. if (type >= 0) {
  6037. dump_limit = 1;
  6038. goto dump;
  6039. }
  6040. }
  6041. #endif
  6042. if (category == RTW_WLAN_CATEGORY_PUBLIC) {
  6043. RTW_INFO("RTW_Tx:%s\n", action_public_str(action));
  6044. switch (action) {
  6045. case ACT_PUBLIC_GAS_INITIAL_REQ:
  6046. case ACT_PUBLIC_GAS_INITIAL_RSP:
  6047. sleep_ms = 50;
  6048. retry_guarantee_ms = RTW_MAX_MGMT_TX_MS_GAS;
  6049. break;
  6050. }
  6051. }
  6052. #ifdef CONFIG_RTW_80211K
  6053. else if (category == RTW_WLAN_CATEGORY_RADIO_MEAS)
  6054. RTW_INFO("RTW_Tx: RRM Action\n");
  6055. #endif
  6056. else
  6057. RTW_INFO("RTW_Tx:category(%u), action(%u)\n", category, action);
  6058. dump:
  6059. rtw_ps_deny(padapter, PS_DENY_MGNT_TX);
  6060. if (_FAIL == rtw_pwr_wakeup(padapter)) {
  6061. ret = -EFAULT;
  6062. goto cancel_ps_deny;
  6063. }
  6064. while (1) {
  6065. dump_cnt++;
  6066. rtw_mi_set_scan_deny(padapter, 1000);
  6067. rtw_mi_scan_abort(padapter, _TRUE);
  6068. tx_ret = rtw_mgnt_tx_cmd(padapter, tx_ch, no_cck, dump_buf, dump_len, wait_ack, RTW_CMDF_WAIT_ACK);
  6069. if (tx_ret == _SUCCESS
  6070. || (dump_cnt >= dump_limit && rtw_get_passing_time_ms(start) >= retry_guarantee_ms))
  6071. break;
  6072. if (sleep_ms > 0)
  6073. rtw_msleep_os(sleep_ms);
  6074. }
  6075. if (tx_ret != _SUCCESS || dump_cnt > 1) {
  6076. RTW_INFO(FUNC_ADPT_FMT" %s (%d/%d) in %d ms\n", FUNC_ADPT_ARG(padapter),
  6077. tx_ret == _SUCCESS ? "OK" : "FAIL", dump_cnt, dump_limit, rtw_get_passing_time_ms(start));
  6078. }
  6079. #ifdef CONFIG_P2P
  6080. if (is_p2p) {
  6081. switch (type) {
  6082. case P2P_GO_NEGO_CONF:
  6083. if (0) {
  6084. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. state=%u, status=%u, iaddr="MAC_FMT"\n"
  6085. , FUNC_ADPT_ARG(padapter), pwdev_priv->nego_info.state, pwdev_priv->nego_info.status
  6086. , MAC_ARG(pwdev_priv->nego_info.iface_addr));
  6087. }
  6088. if (pwdev_priv->nego_info.state == 2
  6089. && pwdev_priv->nego_info.status == 0
  6090. && rtw_check_invalid_mac_address(pwdev_priv->nego_info.iface_addr, _FALSE) == _FALSE
  6091. ) {
  6092. _adapter *intended_iface = dvobj_get_adapter_by_addr(dvobj, pwdev_priv->nego_info.iface_addr);
  6093. if (intended_iface) {
  6094. RTW_INFO(FUNC_ADPT_FMT" Nego confirm. Allow only "ADPT_FMT" to scan for 2000 ms\n"
  6095. , FUNC_ADPT_ARG(padapter), ADPT_ARG(intended_iface));
  6096. /* allow only intended_iface to do scan for 2000 ms */
  6097. rtw_mi_set_scan_deny(padapter, 2000);
  6098. rtw_clear_scan_deny(intended_iface);
  6099. }
  6100. }
  6101. break;
  6102. case P2P_INVIT_RESP:
  6103. if (pwdev_priv->invit_info.flags & BIT(0)
  6104. && pwdev_priv->invit_info.status == 0
  6105. ) {
  6106. rtw_clear_scan_deny(padapter);
  6107. RTW_INFO(FUNC_ADPT_FMT" agree with invitation of persistent group\n",
  6108. FUNC_ADPT_ARG(padapter));
  6109. #if !RTW_P2P_GROUP_INTERFACE
  6110. rtw_mi_buddy_set_scan_deny(padapter, 5000);
  6111. #endif
  6112. rtw_pwr_wakeup_ex(padapter, 5000);
  6113. }
  6114. break;
  6115. }
  6116. }
  6117. #endif /* CONFIG_P2P */
  6118. cancel_ps_deny:
  6119. rtw_ps_deny_cancel(padapter, PS_DENY_MGNT_TX);
  6120. if (dump_buf != buf)
  6121. rtw_mfree((u8 *)dump_buf, dump_len);
  6122. exit:
  6123. return ret;
  6124. }
  6125. static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy,
  6126. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6127. struct wireless_dev *wdev,
  6128. #else
  6129. struct net_device *ndev,
  6130. #endif
  6131. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6132. struct mgmt_frame_regs *upd)
  6133. #else
  6134. u16 frame_type, bool reg)
  6135. #endif
  6136. {
  6137. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6138. struct net_device *ndev = wdev_to_ndev(wdev);
  6139. #endif
  6140. /* hardcoded always true, to make it pass compilation */
  6141. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6142. bool reg = true;
  6143. #endif
  6144. _adapter *adapter;
  6145. struct rtw_wdev_priv *pwdev_priv;
  6146. if (ndev == NULL)
  6147. goto exit;
  6148. adapter = (_adapter *)rtw_netdev_priv(ndev);
  6149. pwdev_priv = adapter_wdev_data(adapter);
  6150. #ifdef CONFIG_DEBUG_CFG80211
  6151. RTW_INFO(FUNC_ADPT_FMT" frame_type:%x, reg:%d\n", FUNC_ADPT_ARG(adapter),
  6152. frame_type, reg);
  6153. #endif
  6154. /* Wait QC Verify */
  6155. return;
  6156. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  6157. switch (upd->interface_stypes) {
  6158. #else
  6159. switch (frame_type) {
  6160. #endif
  6161. case IEEE80211_STYPE_PROBE_REQ: /* 0x0040 */
  6162. SET_CFG80211_REPORT_MGMT(pwdev_priv, IEEE80211_STYPE_PROBE_REQ, reg);
  6163. break;
  6164. case IEEE80211_STYPE_ACTION: /* 0x00D0 */
  6165. SET_CFG80211_REPORT_MGMT(pwdev_priv, IEEE80211_STYPE_ACTION, reg);
  6166. break;
  6167. default:
  6168. break;
  6169. }
  6170. exit:
  6171. return;
  6172. }
  6173. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6174. static int cfg80211_rtw_tdls_mgmt(struct wiphy *wiphy,
  6175. struct net_device *ndev,
  6176. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  6177. const u8 *peer,
  6178. #else
  6179. u8 *peer,
  6180. #endif
  6181. u8 action_code,
  6182. u8 dialog_token,
  6183. u16 status_code,
  6184. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 15, 0))
  6185. u32 peer_capability,
  6186. #endif
  6187. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0))
  6188. bool initiator,
  6189. #endif
  6190. const u8 *buf,
  6191. size_t len)
  6192. {
  6193. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  6194. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  6195. struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
  6196. int ret = 0;
  6197. struct tdls_txmgmt txmgmt;
  6198. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  6199. RTW_INFO("Discard tdls action:%d, since hal doesn't support tdls\n", action_code);
  6200. goto discard;
  6201. }
  6202. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  6203. RTW_INFO("TDLS is not enabled\n");
  6204. goto discard;
  6205. }
  6206. if (rtw_tdls_is_driver_setup(padapter)) {
  6207. RTW_INFO("Discard tdls action:%d, let driver to set up direct link\n", action_code);
  6208. goto discard;
  6209. }
  6210. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  6211. _rtw_memcpy(txmgmt.peer, peer, ETH_ALEN);
  6212. txmgmt.action_code = action_code;
  6213. txmgmt.dialog_token = dialog_token;
  6214. txmgmt.status_code = status_code;
  6215. txmgmt.len = len;
  6216. txmgmt.buf = (u8 *)rtw_malloc(txmgmt.len);
  6217. if (txmgmt.buf == NULL) {
  6218. ret = -ENOMEM;
  6219. goto bad;
  6220. }
  6221. _rtw_memcpy(txmgmt.buf, (void *)buf, txmgmt.len);
  6222. /* Debug purpose */
  6223. #if 1
  6224. RTW_INFO("%s %d\n", __FUNCTION__, __LINE__);
  6225. RTW_INFO("peer:"MAC_FMT", action code:%d, dialog:%d, status code:%d\n",
  6226. MAC_ARG(txmgmt.peer), txmgmt.action_code,
  6227. txmgmt.dialog_token, txmgmt.status_code);
  6228. if (txmgmt.len > 0) {
  6229. int i = 0;
  6230. for (; i < len; i++)
  6231. printk("%02x ", *(txmgmt.buf + i));
  6232. RTW_INFO("len:%d\n", (u32)txmgmt.len);
  6233. }
  6234. #endif
  6235. switch (txmgmt.action_code) {
  6236. case TDLS_SETUP_REQUEST:
  6237. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6238. break;
  6239. case TDLS_SETUP_RESPONSE:
  6240. issue_tdls_setup_rsp(padapter, &txmgmt);
  6241. break;
  6242. case TDLS_SETUP_CONFIRM:
  6243. issue_tdls_setup_cfm(padapter, &txmgmt);
  6244. break;
  6245. case TDLS_TEARDOWN:
  6246. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  6247. break;
  6248. case TDLS_DISCOVERY_REQUEST:
  6249. issue_tdls_dis_req(padapter, &txmgmt);
  6250. break;
  6251. case TDLS_DISCOVERY_RESPONSE:
  6252. issue_tdls_dis_rsp(padapter, &txmgmt, pmlmeinfo->enc_algo ? _TRUE : _FALSE);
  6253. break;
  6254. }
  6255. bad:
  6256. if (txmgmt.buf)
  6257. rtw_mfree(txmgmt.buf, txmgmt.len);
  6258. discard:
  6259. return ret;
  6260. }
  6261. static int cfg80211_rtw_tdls_oper(struct wiphy *wiphy,
  6262. struct net_device *ndev,
  6263. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  6264. const u8 *peer,
  6265. #else
  6266. u8 *peer,
  6267. #endif
  6268. enum nl80211_tdls_operation oper)
  6269. {
  6270. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  6271. struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
  6272. struct tdls_txmgmt txmgmt;
  6273. struct sta_info *ptdls_sta = NULL;
  6274. RTW_INFO(FUNC_NDEV_FMT", nl80211_tdls_operation:%d\n", FUNC_NDEV_ARG(ndev), oper);
  6275. if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
  6276. RTW_INFO("Discard tdls oper:%d, since hal doesn't support tdls\n", oper);
  6277. return 0;
  6278. }
  6279. if (rtw_is_tdls_enabled(padapter) == _FALSE) {
  6280. RTW_INFO("TDLS is not enabled\n");
  6281. return 0;
  6282. }
  6283. #ifdef CONFIG_LPS
  6284. rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 1);
  6285. #endif /* CONFIG_LPS */
  6286. _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
  6287. if (peer)
  6288. _rtw_memcpy(txmgmt.peer, peer, ETH_ALEN);
  6289. if (rtw_tdls_is_driver_setup(padapter)) {
  6290. /* these two cases are done by driver itself */
  6291. if (oper == NL80211_TDLS_ENABLE_LINK || oper == NL80211_TDLS_DISABLE_LINK)
  6292. return 0;
  6293. }
  6294. switch (oper) {
  6295. case NL80211_TDLS_DISCOVERY_REQ:
  6296. issue_tdls_dis_req(padapter, &txmgmt);
  6297. break;
  6298. case NL80211_TDLS_SETUP:
  6299. #ifdef CONFIG_WFD
  6300. if (_AES_ != padapter->securitypriv.dot11PrivacyAlgrthm) {
  6301. if (padapter->wdinfo.wfd_tdls_weaksec == _TRUE)
  6302. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6303. else
  6304. RTW_INFO("[%s] Current link is not AES, SKIP sending the tdls setup request!!\n", __FUNCTION__);
  6305. } else
  6306. #endif /* CONFIG_WFD */
  6307. {
  6308. issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
  6309. }
  6310. break;
  6311. case NL80211_TDLS_TEARDOWN:
  6312. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), txmgmt.peer);
  6313. if (ptdls_sta != NULL) {
  6314. txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
  6315. issue_tdls_teardown(padapter, &txmgmt, _TRUE);
  6316. } else
  6317. RTW_INFO("TDLS peer not found\n");
  6318. break;
  6319. case NL80211_TDLS_ENABLE_LINK:
  6320. RTW_INFO(FUNC_NDEV_FMT", NL80211_TDLS_ENABLE_LINK;mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(peer));
  6321. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), (u8 *)peer);
  6322. if (ptdls_sta != NULL) {
  6323. rtw_tdls_set_link_established(padapter, _TRUE);
  6324. ptdls_sta->tdls_sta_state |= TDLS_LINKED_STATE;
  6325. ptdls_sta->state |= _FW_LINKED;
  6326. rtw_tdls_cmd(padapter, txmgmt.peer, TDLS_ESTABLISHED);
  6327. }
  6328. break;
  6329. case NL80211_TDLS_DISABLE_LINK:
  6330. RTW_INFO(FUNC_NDEV_FMT", NL80211_TDLS_DISABLE_LINK;mac:"MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(peer));
  6331. ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), (u8 *)peer);
  6332. if (ptdls_sta != NULL) {
  6333. rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
  6334. rtw_tdls_cmd(padapter, (u8 *)peer, TDLS_TEARDOWN_STA_LOCALLY_POST);
  6335. }
  6336. break;
  6337. }
  6338. return 0;
  6339. }
  6340. #endif /* CONFIG_TDLS */
  6341. #if defined(CONFIG_RTW_MESH) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
  6342. #if DBG_RTW_CFG80211_MESH_CONF
  6343. #define LEGACY_RATES_STR_LEN (RTW_G_RATES_NUM * 5 + 1)
  6344. int get_legacy_rates_str(struct wiphy *wiphy, enum nl80211_band band, u32 mask, char *buf)
  6345. {
  6346. int i;
  6347. int cnt = 0;
  6348. for (i = 0; i < wiphy->bands[band]->n_bitrates; i++) {
  6349. if (mask & BIT(i)) {
  6350. cnt += snprintf(buf + cnt, LEGACY_RATES_STR_LEN - cnt -1, "%d.%d "
  6351. , wiphy->bands[band]->bitrates[i].bitrate / 10
  6352. , wiphy->bands[band]->bitrates[i].bitrate % 10);
  6353. if (cnt >= LEGACY_RATES_STR_LEN - 1)
  6354. break;
  6355. }
  6356. }
  6357. return cnt;
  6358. }
  6359. void dump_mesh_setup(void *sel, struct wiphy *wiphy, const struct mesh_setup *setup)
  6360. {
  6361. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6362. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6363. struct cfg80211_chan_def *chdef = (struct cfg80211_chan_def *)(&setup->chandef);
  6364. #endif
  6365. struct ieee80211_channel *chan;
  6366. #endif
  6367. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6368. chan = (struct ieee80211_channel *)chdef->chan;
  6369. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6370. chan = (struct ieee80211_channel *)setup->channel;
  6371. #endif
  6372. RTW_PRINT_SEL(sel, "mesh_id:\"%s\", len:%u\n", setup->mesh_id, setup->mesh_id_len);
  6373. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6374. RTW_PRINT_SEL(sel, "sync_method:%u\n", setup->sync_method);
  6375. #endif
  6376. RTW_PRINT_SEL(sel, "path_sel_proto:%u, path_metric:%u\n", setup->path_sel_proto, setup->path_metric);
  6377. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6378. RTW_PRINT_SEL(sel, "auth_id:%u\n", setup->auth_id);
  6379. #endif
  6380. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  6381. if (setup->ie && setup->ie_len) {
  6382. RTW_PRINT_SEL(sel, "ie:%p, len:%u\n", setup->ie, setup->ie_len);
  6383. dump_ies(RTW_DBGDUMP, setup->ie, setup->ie_len);
  6384. }
  6385. #else
  6386. if (setup->vendor_ie && setup->vendor_ie_len) {
  6387. RTW_PRINT_SEL(sel, "ie:%p, len:%u\n", setup->vendor_ie, setup->vendor_ie_len);
  6388. dump_ies(RTW_DBGDUMP, setup->vendor_ie, setup->vendor_ie_len);
  6389. }
  6390. #endif
  6391. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  6392. RTW_PRINT_SEL(sel, "is_authenticated:%d, is_secure:%d\n", setup->is_authenticated, setup->is_secure);
  6393. #endif
  6394. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  6395. RTW_PRINT_SEL(sel, "user_mpm:%d\n", setup->user_mpm);
  6396. #endif
  6397. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6398. RTW_PRINT_SEL(sel, "dtim_period:%u, beacon_interval:%u\n", setup->dtim_period, setup->beacon_interval);
  6399. #endif
  6400. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6401. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6402. RTW_PRINT_SEL(sel, "center_freq:%u, ch:%u, width:%s, cfreq1:%u, cfreq2:%u\n"
  6403. , chan->center_freq, chan->hw_value, nl80211_chan_width_str(chdef->width), chdef->center_freq1, chdef->center_freq2);
  6404. #else
  6405. RTW_PRINT_SEL(sel, "center_freq:%u, ch:%u, channel_type:%s\n"
  6406. , chan->center_freq, chan->hw_value, nl80211_channel_type_str(setup->channel_type));
  6407. #endif
  6408. #endif
  6409. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6410. if (setup->mcast_rate[chan->band]) {
  6411. RTW_PRINT_SEL(sel, "mcast_rate:%d.%d\n"
  6412. , wiphy->bands[chan->band]->bitrates[setup->mcast_rate[chan->band] - 1].bitrate / 10
  6413. , wiphy->bands[chan->band]->bitrates[setup->mcast_rate[chan->band] - 1].bitrate % 10
  6414. );
  6415. }
  6416. #endif
  6417. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6418. if (setup->basic_rates) {
  6419. char buf[LEGACY_RATES_STR_LEN] = {0};
  6420. get_legacy_rates_str(wiphy, chan->band, setup->basic_rates, buf);
  6421. RTW_PRINT_SEL(sel, "basic_rates:%s\n", buf);
  6422. }
  6423. #endif
  6424. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
  6425. if (setup->beacon_rate.control[chan->band].legacy) {
  6426. char buf[LEGACY_RATES_STR_LEN] = {0};
  6427. get_legacy_rates_str(wiphy, chan->band, setup->beacon_rate.control[chan->band].legacy, buf);
  6428. RTW_PRINT_SEL(sel, "beacon_rate.legacy:%s\n", buf);
  6429. }
  6430. if (*((u32 *)&(setup->beacon_rate.control[chan->band].ht_mcs[0]))
  6431. || *((u32 *)&(setup->beacon_rate.control[chan->band].ht_mcs[4]))
  6432. || *((u16 *)&(setup->beacon_rate.control[chan->band].ht_mcs[8]))
  6433. ) {
  6434. RTW_PRINT_SEL(sel, "beacon_rate.ht_mcs:"HT_RX_MCS_BMP_FMT"\n"
  6435. , HT_RX_MCS_BMP_ARG(setup->beacon_rate.control[chan->band].ht_mcs));
  6436. }
  6437. if (setup->beacon_rate.control[chan->band].vht_mcs[0]
  6438. || setup->beacon_rate.control[chan->band].vht_mcs[1]
  6439. || setup->beacon_rate.control[chan->band].vht_mcs[2]
  6440. || setup->beacon_rate.control[chan->band].vht_mcs[3]
  6441. ) {
  6442. int i;
  6443. for (i = 0; i < 4; i++) {/* parsing up to 4SS */
  6444. u16 mcs_mask = setup->beacon_rate.control[chan->band].vht_mcs[i];
  6445. RTW_PRINT_SEL(sel, "beacon_rate.vht_mcs[%d]:%s\n", i
  6446. , mcs_mask == 0x00FF ? "0~7" : mcs_mask == 0x01FF ? "0~8" : mcs_mask == 0x03FF ? "0~9" : "invalid");
  6447. }
  6448. }
  6449. if (setup->beacon_rate.control[chan->band].gi) {
  6450. RTW_PRINT_SEL(sel, "beacon_rate.gi:%s\n"
  6451. , setup->beacon_rate.control[chan->band].gi == NL80211_TXRATE_FORCE_SGI ? "SGI" :
  6452. setup->beacon_rate.control[chan->band].gi == NL80211_TXRATE_FORCE_LGI ? "LGI" : "invalid"
  6453. );
  6454. }
  6455. #endif
  6456. }
  6457. void dump_mesh_config(void *sel, const struct mesh_config *conf)
  6458. {
  6459. RTW_PRINT_SEL(sel, "dot11MeshRetryTimeout:%u\n", conf->dot11MeshRetryTimeout);
  6460. RTW_PRINT_SEL(sel, "dot11MeshConfirmTimeout:%u\n", conf->dot11MeshConfirmTimeout);
  6461. RTW_PRINT_SEL(sel, "dot11MeshHoldingTimeout:%u\n", conf->dot11MeshHoldingTimeout);
  6462. RTW_PRINT_SEL(sel, "dot11MeshMaxPeerLinks:%u\n", conf->dot11MeshMaxPeerLinks);
  6463. RTW_PRINT_SEL(sel, "dot11MeshMaxRetries:%u\n", conf->dot11MeshMaxRetries);
  6464. RTW_PRINT_SEL(sel, "dot11MeshTTL:%u\n", conf->dot11MeshTTL);
  6465. RTW_PRINT_SEL(sel, "element_ttl:%u\n", conf->element_ttl);
  6466. RTW_PRINT_SEL(sel, "auto_open_plinks:%d\n", conf->auto_open_plinks);
  6467. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6468. RTW_PRINT_SEL(sel, "dot11MeshNbrOffsetMaxNeighbor:%u\n", conf->dot11MeshNbrOffsetMaxNeighbor);
  6469. #endif
  6470. RTW_PRINT_SEL(sel, "dot11MeshHWMPmaxPREQretries:%u\n", conf->dot11MeshHWMPmaxPREQretries);
  6471. RTW_PRINT_SEL(sel, "path_refresh_time:%u\n", conf->path_refresh_time);
  6472. RTW_PRINT_SEL(sel, "min_discovery_timeout:%u\n", conf->min_discovery_timeout);
  6473. RTW_PRINT_SEL(sel, "dot11MeshHWMPactivePathTimeout:%u\n", conf->dot11MeshHWMPactivePathTimeout);
  6474. RTW_PRINT_SEL(sel, "dot11MeshHWMPpreqMinInterval:%u\n", conf->dot11MeshHWMPpreqMinInterval);
  6475. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6476. RTW_PRINT_SEL(sel, "dot11MeshHWMPperrMinInterval:%u\n", conf->dot11MeshHWMPperrMinInterval);
  6477. #endif
  6478. RTW_PRINT_SEL(sel, "dot11MeshHWMPnetDiameterTraversalTime:%u\n", conf->dot11MeshHWMPnetDiameterTraversalTime);
  6479. RTW_PRINT_SEL(sel, "dot11MeshHWMPRootMode:%u\n", conf->dot11MeshHWMPRootMode);
  6480. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6481. RTW_PRINT_SEL(sel, "dot11MeshHWMPRannInterval:%u\n", conf->dot11MeshHWMPRannInterval);
  6482. RTW_PRINT_SEL(sel, "dot11MeshGateAnnouncementProtocol:%d\n", conf->dot11MeshGateAnnouncementProtocol);
  6483. #endif
  6484. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6485. RTW_PRINT_SEL(sel, "dot11MeshForwarding:%d\n", conf->dot11MeshForwarding);
  6486. RTW_PRINT_SEL(sel, "rssi_threshold:%d\n", conf->rssi_threshold);
  6487. #endif
  6488. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6489. RTW_PRINT_SEL(sel, "ht_opmode:0x%04x\n", conf->ht_opmode);
  6490. #endif
  6491. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6492. RTW_PRINT_SEL(sel, "dot11MeshHWMPactivePathToRootTimeout:%u\n", conf->dot11MeshHWMPactivePathToRootTimeout);
  6493. RTW_PRINT_SEL(sel, "dot11MeshHWMProotInterval:%u\n", conf->dot11MeshHWMProotInterval);
  6494. RTW_PRINT_SEL(sel, "dot11MeshHWMPconfirmationInterval:%u\n", conf->dot11MeshHWMPconfirmationInterval);
  6495. #endif
  6496. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6497. RTW_PRINT_SEL(sel, "power_mode:%s\n", nl80211_mesh_power_mode_str(conf->power_mode));
  6498. RTW_PRINT_SEL(sel, "dot11MeshAwakeWindowDuration:%u\n", conf->dot11MeshAwakeWindowDuration);
  6499. #endif
  6500. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6501. RTW_PRINT_SEL(sel, "plink_timeout:%u\n", conf->plink_timeout);
  6502. #endif
  6503. }
  6504. #endif /* DBG_RTW_CFG80211_MESH_CONF */
  6505. static void rtw_cfg80211_mesh_info_set_profile(struct rtw_mesh_info *minfo, const struct mesh_setup *setup)
  6506. {
  6507. _rtw_memcpy(minfo->mesh_id, setup->mesh_id, setup->mesh_id_len);
  6508. minfo->mesh_id_len = setup->mesh_id_len;
  6509. minfo->mesh_pp_id = setup->path_sel_proto;
  6510. minfo->mesh_pm_id = setup->path_metric;
  6511. minfo->mesh_cc_id = 0;
  6512. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6513. minfo->mesh_sp_id = setup->sync_method;
  6514. #endif
  6515. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6516. minfo->mesh_auth_id = setup->auth_id;
  6517. #else
  6518. if (setup->is_authenticated) {
  6519. u8 *rsn_ie;
  6520. sint rsn_ie_len;
  6521. struct rsne_info info;
  6522. u8 *akm;
  6523. u8 AKM_SUITE_SAE[4] = {0x00, 0x0F, 0xAC, 0x08};
  6524. rsn_ie = rtw_get_ie(setup->ie, WLAN_EID_RSN, &rsn_ie_len, setup->ie_len);
  6525. if (!rsn_ie || !rsn_ie_len) {
  6526. rtw_warn_on(1);
  6527. return;
  6528. }
  6529. if (rtw_rsne_info_parse(rsn_ie, rsn_ie_len + 2, &info) != _SUCCESS) {
  6530. rtw_warn_on(1);
  6531. return;
  6532. }
  6533. if (!info.akm_list || !info.akm_cnt) {
  6534. rtw_warn_on(1);
  6535. return;
  6536. }
  6537. akm = info.akm_list;
  6538. while (akm < info.akm_list + info.akm_cnt * 4) {
  6539. if (_rtw_memcmp(akm, AKM_SUITE_SAE, 4) == _TRUE) {
  6540. minfo->mesh_auth_id = 0x01;
  6541. break;
  6542. }
  6543. }
  6544. if (!minfo->mesh_auth_id) {
  6545. rtw_warn_on(1);
  6546. return;
  6547. }
  6548. }
  6549. #endif
  6550. }
  6551. static inline bool chk_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
  6552. {
  6553. return (mask >> (parm - 1)) & 0x1;
  6554. }
  6555. static void rtw_cfg80211_mesh_cfg_set(_adapter *adapter, const struct mesh_config *conf, u32 mask)
  6556. {
  6557. struct rtw_mesh_cfg *mcfg = &adapter->mesh_cfg;
  6558. #if 0 /* driver MPM */
  6559. if (chk_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask));
  6560. if (chk_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask));
  6561. if (chk_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask));
  6562. if (chk_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask));
  6563. if (chk_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask));
  6564. #endif
  6565. if (chk_mesh_attr(NL80211_MESHCONF_TTL, mask))
  6566. mcfg->dot11MeshTTL = conf->dot11MeshTTL;
  6567. if (chk_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
  6568. mcfg->element_ttl = conf->element_ttl;
  6569. #if 0 /* driver MPM */
  6570. if (chk_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask));
  6571. #endif
  6572. #if 0 /* TBD: synchronization */
  6573. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6574. if (chk_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask));
  6575. #endif
  6576. #endif
  6577. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
  6578. mcfg->dot11MeshHWMPmaxPREQretries = conf->dot11MeshHWMPmaxPREQretries;
  6579. if (chk_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
  6580. mcfg->path_refresh_time = conf->path_refresh_time;
  6581. if (chk_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
  6582. mcfg->min_discovery_timeout = conf->min_discovery_timeout;
  6583. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
  6584. mcfg->dot11MeshHWMPactivePathTimeout = conf->dot11MeshHWMPactivePathTimeout;
  6585. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
  6586. mcfg->dot11MeshHWMPpreqMinInterval = conf->dot11MeshHWMPpreqMinInterval;
  6587. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6588. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
  6589. mcfg->dot11MeshHWMPperrMinInterval = conf->dot11MeshHWMPperrMinInterval;
  6590. #endif
  6591. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, mask))
  6592. mcfg->dot11MeshHWMPnetDiameterTraversalTime = conf->dot11MeshHWMPnetDiameterTraversalTime;
  6593. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask))
  6594. mcfg->dot11MeshHWMPRootMode = conf->dot11MeshHWMPRootMode;
  6595. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6596. if (chk_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask))
  6597. mcfg->dot11MeshGateAnnouncementProtocol = conf->dot11MeshGateAnnouncementProtocol;
  6598. /* our current gate annc implementation rides on root annc with gate annc bit in PREQ flags */
  6599. if (mcfg->dot11MeshGateAnnouncementProtocol
  6600. && mcfg->dot11MeshHWMPRootMode <= RTW_IEEE80211_ROOTMODE_ROOT
  6601. ) {
  6602. mcfg->dot11MeshHWMPRootMode = RTW_IEEE80211_PROACTIVE_RANN;
  6603. RTW_INFO(ADPT_FMT" enable PROACTIVE_RANN becaue gate annc is needed\n", ADPT_ARG(adapter));
  6604. }
  6605. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
  6606. mcfg->dot11MeshHWMPRannInterval = conf->dot11MeshHWMPRannInterval;
  6607. #endif
  6608. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6609. if (chk_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
  6610. mcfg->dot11MeshForwarding = conf->dot11MeshForwarding;
  6611. if (chk_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask))
  6612. mcfg->rssi_threshold = conf->rssi_threshold;
  6613. #endif
  6614. #if 0 /* controlled by driver */
  6615. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6616. if (chk_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask));
  6617. #endif
  6618. #endif
  6619. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6620. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
  6621. mcfg->dot11MeshHWMPactivePathToRootTimeout = conf->dot11MeshHWMPactivePathToRootTimeout;
  6622. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
  6623. mcfg->dot11MeshHWMProotInterval = conf->dot11MeshHWMProotInterval;
  6624. if (chk_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
  6625. mcfg->dot11MeshHWMPconfirmationInterval = conf->dot11MeshHWMPconfirmationInterval;
  6626. #endif
  6627. #if 0 /* TBD */
  6628. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6629. if (chk_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask));
  6630. if (chk_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask));
  6631. #endif
  6632. #endif
  6633. #if 0 /* driver MPM */
  6634. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6635. if (chk_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask));
  6636. #endif
  6637. #endif
  6638. }
  6639. u8 *rtw_cfg80211_construct_mesh_beacon_ies(struct wiphy *wiphy, _adapter *adapter
  6640. , const struct mesh_config *conf, const struct mesh_setup *setup
  6641. , uint *ies_len)
  6642. {
  6643. struct rtw_mesh_info *minfo = &adapter->mesh_info;
  6644. struct rtw_mesh_cfg *mcfg = &adapter->mesh_cfg;
  6645. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6646. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6647. struct cfg80211_chan_def *chdef = (struct cfg80211_chan_def *)(&setup->chandef);
  6648. #endif
  6649. struct ieee80211_channel *chan;
  6650. u8 ch, bw, offset;
  6651. #endif
  6652. uint len;
  6653. u8 n_bitrates;
  6654. u8 ht = 0;
  6655. u8 vht = 0;
  6656. u8 *rsn_ie = NULL;
  6657. sint rsn_ie_len = 0;
  6658. u8 *ies = NULL, *c;
  6659. u8 supported_rates[RTW_G_RATES_NUM] = {0};
  6660. int i;
  6661. *ies_len = 0;
  6662. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6663. chan = (struct ieee80211_channel *)chdef->chan;
  6664. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6665. chan = (struct ieee80211_channel *)setup->channel;
  6666. #endif
  6667. n_bitrates = wiphy->bands[chan->band]->n_bitrates;
  6668. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6669. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
  6670. rtw_get_chbw_from_cfg80211_chan_def(chdef, &ht, &ch, &bw, &offset);
  6671. #else
  6672. rtw_get_chbw_from_nl80211_channel_type(chan, setup->channel_type, &ht, &ch, &bw, &offset);
  6673. #endif
  6674. if (!ch)
  6675. goto exit;
  6676. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6677. vht = ht && ch > 14 && bw >= CHANNEL_WIDTH_80; /* VHT40/VHT20? */
  6678. #endif
  6679. RTW_INFO(FUNC_ADPT_FMT" => ch:%u,%u,%u, ht:%u, vht:%u\n"
  6680. , FUNC_ADPT_ARG(adapter), ch, bw, offset, ht, vht);
  6681. #endif
  6682. rsn_ie = rtw_get_ie(setup->ie, WLAN_EID_RSN, &rsn_ie_len, setup->ie_len);
  6683. if (rsn_ie && !rsn_ie_len) {
  6684. rtw_warn_on(1);
  6685. rsn_ie = NULL;
  6686. }
  6687. len = _BEACON_IE_OFFSET_
  6688. + 2 /* 0-length SSID */
  6689. + (n_bitrates >= 8 ? 8 : n_bitrates) + 2 /* Supported Rates */
  6690. + 3 /* DS parameter set */
  6691. + 6 /* TIM */
  6692. + (n_bitrates > 8 ? n_bitrates - 8 + 2 : 0) /* Extended Supported Rates */
  6693. + (rsn_ie ? rsn_ie_len + 2 : 0) /* RSN */
  6694. #if defined(CONFIG_80211N_HT)
  6695. + (ht ? HT_CAP_IE_LEN + 2 + HT_OP_IE_LEN + 2 : 0) /* HT */
  6696. #endif
  6697. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6698. + (vht ? VHT_CAP_IE_LEN + 2 + VHT_OP_IE_LEN + 2 : 0) /* VHT */
  6699. #endif
  6700. + minfo->mesh_id_len + 2 /* Mesh ID */
  6701. + 9 /* Mesh configuration */
  6702. ;
  6703. ies = rtw_zmalloc(len);
  6704. if (!ies)
  6705. goto exit;
  6706. /* timestamp */
  6707. c = ies + 8;
  6708. /* beacon interval */
  6709. RTW_PUT_LE16(c , setup->beacon_interval);
  6710. c += 2;
  6711. /* capability */
  6712. if (rsn_ie)
  6713. *((u16 *)c) |= cpu_to_le16(cap_Privacy);
  6714. c += 2;
  6715. /* SSID */
  6716. c = rtw_set_ie(c, WLAN_EID_SSID, 0, NULL, NULL);
  6717. /* Supported Rates */
  6718. for (i = 0; i < n_bitrates; i++) {
  6719. supported_rates[i] = wiphy->bands[chan->band]->bitrates[i].bitrate / 5;
  6720. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6721. if (setup->basic_rates & BIT(i))
  6722. #else
  6723. if (rtw_is_basic_rate_mix(supported_rates[i]))
  6724. #endif
  6725. supported_rates[i] |= IEEE80211_BASIC_RATE_MASK;
  6726. }
  6727. c = rtw_set_ie(c, WLAN_EID_SUPP_RATES, (n_bitrates >= 8 ? 8 : n_bitrates), supported_rates, NULL);
  6728. /* DS parameter set */
  6729. c = rtw_set_ie(c, WLAN_EID_DS_PARAMS, 1, &ch, NULL);
  6730. /* TIM */
  6731. *c = WLAN_EID_TIM;
  6732. *(c + 1) = 4;
  6733. c += 6;
  6734. //c = rtw_set_ie(c, _TIM_IE_, 4, NULL, NULL);
  6735. /* Extended Supported Rates */
  6736. if (n_bitrates > 8)
  6737. c = rtw_set_ie(c, WLAN_EID_EXT_SUPP_RATES, n_bitrates - 8, supported_rates + 8, NULL);
  6738. /* RSN */
  6739. if (rsn_ie)
  6740. c = rtw_set_ie(c, WLAN_EID_RSN, rsn_ie_len, rsn_ie + 2, NULL);
  6741. #if defined(CONFIG_80211N_HT)
  6742. if (ht) {
  6743. struct ieee80211_sta_ht_cap *sta_ht_cap = &wiphy->bands[chan->band]->ht_cap;
  6744. u8 ht_cap[HT_CAP_IE_LEN];
  6745. u8 ht_op[HT_OP_IE_LEN];
  6746. _rtw_memset(ht_cap, 0, HT_CAP_IE_LEN);
  6747. _rtw_memset(ht_op, 0, HT_OP_IE_LEN);
  6748. /* WLAN_EID_HT_CAP */
  6749. RTW_PUT_LE16(HT_CAP_ELE_CAP_INFO(ht_cap), sta_ht_cap->cap);
  6750. SET_HT_CAP_ELE_MAX_AMPDU_LEN_EXP(ht_cap, sta_ht_cap->ampdu_factor);
  6751. SET_HT_CAP_ELE_MIN_MPDU_S_SPACE(ht_cap, sta_ht_cap->ampdu_density);
  6752. _rtw_memcpy(HT_CAP_ELE_SUP_MCS_SET(ht_cap), &sta_ht_cap->mcs, 16);
  6753. c = rtw_set_ie(c, WLAN_EID_HT_CAP, HT_CAP_IE_LEN, ht_cap, NULL);
  6754. /* WLAN_EID_HT_OPERATION */
  6755. SET_HT_OP_ELE_PRI_CHL(ht_op, ch);
  6756. switch (offset) {
  6757. case HAL_PRIME_CHNL_OFFSET_LOWER:
  6758. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCA);
  6759. break;
  6760. case HAL_PRIME_CHNL_OFFSET_UPPER:
  6761. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCB);
  6762. break;
  6763. case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
  6764. default:
  6765. SET_HT_OP_ELE_2ND_CHL_OFFSET(ht_op, SCN);
  6766. break;
  6767. }
  6768. if (bw >= CHANNEL_WIDTH_40)
  6769. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op, 1);
  6770. else
  6771. SET_HT_OP_ELE_STA_CHL_WIDTH(ht_op, 0);
  6772. c = rtw_set_ie(c, WLAN_EID_HT_OPERATION, HT_OP_IE_LEN, ht_op, NULL);
  6773. }
  6774. #endif /* defined(CONFIG_80211N_HT) */
  6775. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6776. if (vht) {
  6777. struct ieee80211_sta_vht_cap *sta_vht_cap = &wiphy->bands[chan->band]->vht_cap;
  6778. u8 vht_cap[VHT_CAP_IE_LEN];
  6779. u8 vht_op[VHT_OP_IE_LEN];
  6780. u8 cch = rtw_get_center_ch(ch, bw, offset);
  6781. _rtw_memset(vht_op, 0, VHT_OP_IE_LEN);
  6782. /* WLAN_EID_VHT_CAPABILITY */
  6783. _rtw_memcpy(vht_cap, &sta_vht_cap->cap, 4);
  6784. _rtw_memcpy(vht_cap + 4, &sta_vht_cap->vht_mcs, 8);
  6785. c = rtw_set_ie(c, WLAN_EID_VHT_CAPABILITY, VHT_CAP_IE_LEN, vht_cap, NULL);
  6786. /* WLAN_EID_VHT_OPERATION */
  6787. if (bw < CHANNEL_WIDTH_80) {
  6788. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op, 0);
  6789. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op, 0);
  6790. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op, 0);
  6791. } else if (bw == CHANNEL_WIDTH_80) {
  6792. SET_VHT_OPERATION_ELE_CHL_WIDTH(vht_op, 1);
  6793. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ1(vht_op, cch);
  6794. SET_VHT_OPERATION_ELE_CHL_CENTER_FREQ2(vht_op, 0);
  6795. } else {
  6796. RTW_ERR(FUNC_ADPT_FMT" unsupported BW:%u\n", FUNC_ADPT_ARG(adapter), bw);
  6797. rtw_warn_on(1);
  6798. rtw_mfree(ies, len);
  6799. goto exit;
  6800. }
  6801. /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
  6802. vht_op[3] = 0xfc;
  6803. vht_op[4] = 0xff;
  6804. c = rtw_set_ie(c, WLAN_EID_VHT_OPERATION, VHT_OP_IE_LEN, vht_op, NULL);
  6805. }
  6806. #endif /* defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) */
  6807. /* Mesh ID */
  6808. c = rtw_set_ie_mesh_id(c, NULL, minfo->mesh_id, minfo->mesh_id_len);
  6809. /* Mesh configuration */
  6810. c = rtw_set_ie_mesh_config(c, NULL
  6811. , minfo->mesh_pp_id
  6812. , minfo->mesh_pm_id
  6813. , minfo->mesh_cc_id
  6814. , minfo->mesh_sp_id
  6815. , minfo->mesh_auth_id
  6816. , 0, 0, 0
  6817. , 1
  6818. , 0, 0
  6819. , mcfg->dot11MeshForwarding
  6820. , 0, 0, 0
  6821. );
  6822. #if DBG_RTW_CFG80211_MESH_CONF
  6823. RTW_INFO(FUNC_ADPT_FMT" ies_len:%u\n", FUNC_ADPT_ARG(adapter), len);
  6824. dump_ies(RTW_DBGDUMP, ies + _BEACON_IE_OFFSET_, len - _BEACON_IE_OFFSET_);
  6825. #endif
  6826. exit:
  6827. if (ies)
  6828. *ies_len = len;
  6829. return ies;
  6830. }
  6831. static int cfg80211_rtw_get_mesh_config(struct wiphy *wiphy, struct net_device *dev
  6832. , struct mesh_config *conf)
  6833. {
  6834. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6835. struct rtw_mesh_cfg *mesh_cfg = &adapter->mesh_cfg;
  6836. int ret = 0;
  6837. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6838. /* driver MPM */
  6839. conf->dot11MeshRetryTimeout = 0;
  6840. conf->dot11MeshConfirmTimeout = 0;
  6841. conf->dot11MeshHoldingTimeout = 0;
  6842. conf->dot11MeshMaxPeerLinks = mesh_cfg->max_peer_links;
  6843. conf->dot11MeshMaxRetries = 0;
  6844. conf->dot11MeshTTL = mesh_cfg->dot11MeshTTL;
  6845. conf->element_ttl = mesh_cfg->element_ttl;
  6846. /* driver MPM */
  6847. conf->auto_open_plinks = 0;
  6848. /* TBD: synchronization */
  6849. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6850. conf->dot11MeshNbrOffsetMaxNeighbor = 0;
  6851. #endif
  6852. conf->dot11MeshHWMPmaxPREQretries = mesh_cfg->dot11MeshHWMPmaxPREQretries;
  6853. conf->path_refresh_time = mesh_cfg->path_refresh_time;
  6854. conf->min_discovery_timeout = mesh_cfg->min_discovery_timeout;
  6855. conf->dot11MeshHWMPactivePathTimeout = mesh_cfg->dot11MeshHWMPactivePathTimeout;
  6856. conf->dot11MeshHWMPpreqMinInterval = mesh_cfg->dot11MeshHWMPpreqMinInterval;
  6857. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  6858. conf->dot11MeshHWMPperrMinInterval = mesh_cfg->dot11MeshHWMPperrMinInterval;
  6859. #endif
  6860. conf->dot11MeshHWMPnetDiameterTraversalTime = mesh_cfg->dot11MeshHWMPnetDiameterTraversalTime;
  6861. conf->dot11MeshHWMPRootMode = mesh_cfg->dot11MeshHWMPRootMode;
  6862. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  6863. conf->dot11MeshHWMPRannInterval = mesh_cfg->dot11MeshHWMPRannInterval;
  6864. #endif
  6865. conf->dot11MeshGateAnnouncementProtocol = mesh_cfg->dot11MeshGateAnnouncementProtocol;
  6866. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
  6867. conf->dot11MeshForwarding = mesh_cfg->dot11MeshForwarding;
  6868. conf->rssi_threshold = mesh_cfg->rssi_threshold;
  6869. #endif
  6870. /* TBD */
  6871. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
  6872. conf->ht_opmode = 0xffff;
  6873. #endif
  6874. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  6875. conf->dot11MeshHWMPactivePathToRootTimeout = mesh_cfg->dot11MeshHWMPactivePathToRootTimeout;
  6876. conf->dot11MeshHWMProotInterval = mesh_cfg->dot11MeshHWMProotInterval;
  6877. conf->dot11MeshHWMPconfirmationInterval = mesh_cfg->dot11MeshHWMPconfirmationInterval;
  6878. #endif
  6879. /* TBD: power save */
  6880. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  6881. conf->power_mode = NL80211_MESH_POWER_ACTIVE;
  6882. conf->dot11MeshAwakeWindowDuration = 0;
  6883. #endif
  6884. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6885. conf->plink_timeout = mesh_cfg->plink_timeout;
  6886. #endif
  6887. return ret;
  6888. }
  6889. static void rtw_mbss_info_change_notify(_adapter *adapter, bool minfo_changed, bool need_work)
  6890. {
  6891. if (need_work)
  6892. rtw_mesh_work(&adapter->mesh_work);
  6893. }
  6894. static int cfg80211_rtw_update_mesh_config(struct wiphy *wiphy, struct net_device *dev
  6895. , u32 mask, const struct mesh_config *nconf)
  6896. {
  6897. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6898. int ret = 0;
  6899. bool minfo_changed = _FALSE, need_work = _FALSE;
  6900. RTW_INFO(FUNC_ADPT_FMT" mask:0x%08x\n", FUNC_ADPT_ARG(adapter), mask);
  6901. rtw_cfg80211_mesh_cfg_set(adapter, nconf, mask);
  6902. update_beacon(adapter, WLAN_EID_MESH_CONFIG, NULL, _TRUE);
  6903. #if CONFIG_RTW_MESH_CTO_MGATE_CARRIER
  6904. if (rtw_mesh_cto_mgate_required(adapter))
  6905. rtw_netif_carrier_off(adapter->pnetdev);
  6906. else
  6907. rtw_netif_carrier_on(adapter->pnetdev);
  6908. #endif
  6909. need_work = rtw_ieee80211_mesh_root_setup(adapter);
  6910. rtw_mbss_info_change_notify(adapter, minfo_changed, need_work);
  6911. return ret;
  6912. }
  6913. static int cfg80211_rtw_join_mesh(struct wiphy *wiphy, struct net_device *dev,
  6914. const struct mesh_config *conf, const struct mesh_setup *setup)
  6915. {
  6916. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6917. u8 *ies = NULL;
  6918. uint ies_len;
  6919. int ret = 0;
  6920. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6921. #if DBG_RTW_CFG80211_MESH_CONF
  6922. RTW_INFO(FUNC_ADPT_FMT" mesh_setup:\n", FUNC_ADPT_ARG(adapter));
  6923. dump_mesh_setup(RTW_DBGDUMP, wiphy, setup);
  6924. RTW_INFO(FUNC_ADPT_FMT" mesh_config:\n", FUNC_ADPT_ARG(adapter));
  6925. dump_mesh_config(RTW_DBGDUMP, conf);
  6926. #endif
  6927. if (rtw_cfg80211_sync_iftype(adapter) != _SUCCESS) {
  6928. ret = -ENOTSUPP;
  6929. goto exit;
  6930. }
  6931. /* initialization */
  6932. rtw_mesh_init_mesh_info(adapter);
  6933. /* apply cfg80211 settings*/
  6934. rtw_cfg80211_mesh_info_set_profile(&adapter->mesh_info, setup);
  6935. rtw_cfg80211_mesh_cfg_set(adapter, conf, 0xFFFFFFFF);
  6936. /* apply cfg80211 settings (join only) */
  6937. rtw_mesh_cfg_init_max_peer_links(adapter, conf->dot11MeshMaxPeerLinks);
  6938. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
  6939. rtw_mesh_cfg_init_plink_timeout(adapter, conf->plink_timeout);
  6940. #endif
  6941. rtw_ieee80211_mesh_root_setup(adapter);
  6942. ies = rtw_cfg80211_construct_mesh_beacon_ies(wiphy, adapter, conf, setup, &ies_len);
  6943. if (!ies) {
  6944. ret = -EINVAL;
  6945. goto exit;
  6946. }
  6947. /* start mbss */
  6948. if (rtw_check_beacon_data(adapter, ies, ies_len) != _SUCCESS) {
  6949. ret = -EINVAL;
  6950. goto exit;
  6951. }
  6952. rtw_mesh_work(&adapter->mesh_work);
  6953. exit:
  6954. if (ies)
  6955. rtw_mfree(ies, ies_len);
  6956. if (ret)
  6957. rtw_mesh_deinit_mesh_info(adapter);
  6958. return ret;
  6959. }
  6960. static int cfg80211_rtw_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
  6961. {
  6962. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6963. int ret = 0;
  6964. RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(adapter));
  6965. rtw_mesh_deinit_mesh_info(adapter);
  6966. rtw_set_802_11_infrastructure_mode(adapter, Ndis802_11Infrastructure);
  6967. rtw_setopmode_cmd(adapter, Ndis802_11Infrastructure, RTW_CMDF_WAIT_ACK);
  6968. return ret;
  6969. }
  6970. static int cfg80211_rtw_add_mpath(struct wiphy *wiphy, struct net_device *dev
  6971. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  6972. , const u8 *dst, const u8 *next_hop
  6973. #else
  6974. , u8 *dst, u8 *next_hop
  6975. #endif
  6976. )
  6977. {
  6978. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  6979. struct sta_priv *stapriv = &adapter->stapriv;
  6980. struct sta_info *sta;
  6981. struct rtw_mesh_path *mpath;
  6982. int ret = 0;
  6983. rtw_rcu_read_lock();
  6984. sta = rtw_get_stainfo(stapriv, next_hop);
  6985. if (!sta) {
  6986. ret = -ENOENT;
  6987. goto exit;
  6988. }
  6989. mpath = rtw_mesh_path_add(adapter, dst);
  6990. if (!mpath) {
  6991. ret = -ENOENT;
  6992. goto exit;
  6993. }
  6994. rtw_mesh_path_fix_nexthop(mpath, sta);
  6995. exit:
  6996. rtw_rcu_read_unlock();
  6997. return ret;
  6998. }
  6999. static int cfg80211_rtw_del_mpath(struct wiphy *wiphy, struct net_device *dev
  7000. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  7001. , const u8 *dst
  7002. #else
  7003. , u8 *dst
  7004. #endif
  7005. )
  7006. {
  7007. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7008. int ret = 0;
  7009. if (dst) {
  7010. if (rtw_mesh_path_del(adapter, dst)) {
  7011. ret = -ENOENT;
  7012. goto exit;
  7013. }
  7014. } else {
  7015. rtw_mesh_path_flush_by_iface(adapter);
  7016. }
  7017. exit:
  7018. return ret;
  7019. }
  7020. static int cfg80211_rtw_change_mpath(struct wiphy *wiphy, struct net_device *dev
  7021. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  7022. , const u8 *dst, const u8 *next_hop
  7023. #else
  7024. , u8 *dst, u8 *next_hop
  7025. #endif
  7026. )
  7027. {
  7028. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7029. struct sta_priv *stapriv = &adapter->stapriv;
  7030. struct sta_info *sta;
  7031. struct rtw_mesh_path *mpath;
  7032. int ret = 0;
  7033. rtw_rcu_read_lock();
  7034. sta = rtw_get_stainfo(stapriv, next_hop);
  7035. if (!sta) {
  7036. ret = -ENOENT;
  7037. goto exit;
  7038. }
  7039. mpath = rtw_mesh_path_lookup(adapter, dst);
  7040. if (!mpath) {
  7041. ret = -ENOENT;
  7042. goto exit;
  7043. }
  7044. rtw_mesh_path_fix_nexthop(mpath, sta);
  7045. exit:
  7046. rtw_rcu_read_unlock();
  7047. return ret;
  7048. }
  7049. static void rtw_cfg80211_mpath_set_pinfo(struct rtw_mesh_path *mpath, u8 *next_hop, struct mpath_info *pinfo)
  7050. {
  7051. struct sta_info *next_hop_sta = rtw_rcu_dereference(mpath->next_hop);
  7052. if (next_hop_sta)
  7053. _rtw_memcpy(next_hop, next_hop_sta->cmn.mac_addr, ETH_ALEN);
  7054. else
  7055. _rtw_memset(next_hop, 0, ETH_ALEN);
  7056. _rtw_memset(pinfo, 0, sizeof(*pinfo));
  7057. pinfo->generation = mpath->adapter->mesh_info.mesh_paths_generation;
  7058. pinfo->filled = 0
  7059. | MPATH_INFO_FRAME_QLEN
  7060. | MPATH_INFO_SN
  7061. | MPATH_INFO_METRIC
  7062. | MPATH_INFO_EXPTIME
  7063. | MPATH_INFO_DISCOVERY_TIMEOUT
  7064. | MPATH_INFO_DISCOVERY_RETRIES
  7065. | MPATH_INFO_FLAGS
  7066. ;
  7067. pinfo->frame_qlen = mpath->frame_queue_len;
  7068. pinfo->sn = mpath->sn;
  7069. pinfo->metric = mpath->metric;
  7070. if (rtw_time_after(mpath->exp_time, rtw_get_current_time()))
  7071. pinfo->exptime = rtw_get_remaining_time_ms(mpath->exp_time);
  7072. pinfo->discovery_timeout = rtw_systime_to_ms(mpath->discovery_timeout);
  7073. pinfo->discovery_retries = mpath->discovery_retries;
  7074. if (mpath->flags & RTW_MESH_PATH_ACTIVE)
  7075. pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
  7076. if (mpath->flags & RTW_MESH_PATH_RESOLVING)
  7077. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
  7078. if (mpath->flags & RTW_MESH_PATH_SN_VALID)
  7079. pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
  7080. if (mpath->flags & RTW_MESH_PATH_FIXED)
  7081. pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
  7082. if (mpath->flags & RTW_MESH_PATH_RESOLVED)
  7083. pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
  7084. }
  7085. static int cfg80211_rtw_get_mpath(struct wiphy *wiphy, struct net_device *dev, u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  7086. {
  7087. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7088. struct rtw_mesh_path *mpath;
  7089. int ret = 0;
  7090. rtw_rcu_read_lock();
  7091. mpath = rtw_mesh_path_lookup(adapter, dst);
  7092. if (!mpath) {
  7093. ret = -ENOENT;
  7094. goto exit;
  7095. }
  7096. rtw_cfg80211_mpath_set_pinfo(mpath, next_hop, pinfo);
  7097. exit:
  7098. rtw_rcu_read_unlock();
  7099. return ret;
  7100. }
  7101. static int cfg80211_rtw_dump_mpath(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
  7102. {
  7103. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7104. struct rtw_mesh_path *mpath;
  7105. int ret = 0;
  7106. rtw_rcu_read_lock();
  7107. mpath = rtw_mesh_path_lookup_by_idx(adapter, idx);
  7108. if (!mpath) {
  7109. ret = -ENOENT;
  7110. goto exit;
  7111. }
  7112. _rtw_memcpy(dst, mpath->dst, ETH_ALEN);
  7113. rtw_cfg80211_mpath_set_pinfo(mpath, next_hop, pinfo);
  7114. exit:
  7115. rtw_rcu_read_unlock();
  7116. return ret;
  7117. }
  7118. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
  7119. static void rtw_cfg80211_mpp_set_pinfo(struct rtw_mesh_path *mpath, u8 *mpp, struct mpath_info *pinfo)
  7120. {
  7121. _rtw_memcpy(mpp, mpath->mpp, ETH_ALEN);
  7122. _rtw_memset(pinfo, 0, sizeof(*pinfo));
  7123. pinfo->generation = mpath->adapter->mesh_info.mpp_paths_generation;
  7124. }
  7125. static int cfg80211_rtw_get_mpp(struct wiphy *wiphy, struct net_device *dev, u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  7126. {
  7127. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7128. struct rtw_mesh_path *mpath;
  7129. int ret = 0;
  7130. rtw_rcu_read_lock();
  7131. mpath = rtw_mpp_path_lookup(adapter, dst);
  7132. if (!mpath) {
  7133. ret = -ENOENT;
  7134. goto exit;
  7135. }
  7136. rtw_cfg80211_mpp_set_pinfo(mpath, mpp, pinfo);
  7137. exit:
  7138. rtw_rcu_read_unlock();
  7139. return ret;
  7140. }
  7141. static int cfg80211_rtw_dump_mpp(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *dst, u8 *mpp, struct mpath_info *pinfo)
  7142. {
  7143. _adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
  7144. struct rtw_mesh_path *mpath;
  7145. int ret = 0;
  7146. rtw_rcu_read_lock();
  7147. mpath = rtw_mpp_path_lookup_by_idx(adapter, idx);
  7148. if (!mpath) {
  7149. ret = -ENOENT;
  7150. goto exit;
  7151. }
  7152. _rtw_memcpy(dst, mpath->dst, ETH_ALEN);
  7153. rtw_cfg80211_mpp_set_pinfo(mpath, mpp, pinfo);
  7154. exit:
  7155. rtw_rcu_read_unlock();
  7156. return ret;
  7157. }
  7158. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) */
  7159. #endif /* defined(CONFIG_RTW_MESH) */
  7160. #if defined(CONFIG_PNO_SUPPORT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7161. static int cfg80211_rtw_sched_scan_start(struct wiphy *wiphy,
  7162. struct net_device *dev,
  7163. struct cfg80211_sched_scan_request *request)
  7164. {
  7165. _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
  7166. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7167. struct cfg80211_ssid *ssids;
  7168. int n_ssids = 0;
  7169. int interval = 0;
  7170. int i = 0;
  7171. u8 ret;
  7172. if (padapter->bup == _FALSE) {
  7173. RTW_INFO("%s: net device is down.\n", __func__);
  7174. return -EIO;
  7175. }
  7176. if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _TRUE ||
  7177. check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE ||
  7178. check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) {
  7179. RTW_INFO("%s: device is busy.\n", __func__);
  7180. rtw_scan_abort(padapter);
  7181. }
  7182. if (request == NULL) {
  7183. RTW_INFO("%s: invalid cfg80211_requests parameters.\n", __func__);
  7184. return -EINVAL;
  7185. }
  7186. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
  7187. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
  7188. interval = request->scan_plans->interval;
  7189. #else
  7190. interval = request->interval;
  7191. #endif
  7192. n_ssids = request->n_match_sets;
  7193. ssids = (struct cfg80211_ssid *)rtw_zmalloc(n_ssids * sizeof(struct cfg80211_ssid));
  7194. if(ssids == NULL) {
  7195. RTW_ERR("Fail to allocate ssids for PNO\n");
  7196. return -ENOMEM;
  7197. }
  7198. for (i=0;i<request->n_match_sets;i++) {
  7199. ssids[i].ssid_len = request->match_sets[i].ssid.ssid_len;
  7200. memcpy(ssids[i].ssid, request->match_sets[i].ssid.ssid,
  7201. request->match_sets[i].ssid.ssid_len);
  7202. }
  7203. #else
  7204. interval = request->interval;
  7205. n_ssids = request->n_ssids;
  7206. ssids = request->ssids;
  7207. #endif
  7208. ret = rtw_android_cfg80211_pno_setup(dev, ssids,
  7209. n_ssids, interval);
  7210. if (ret < 0) {
  7211. RTW_INFO("%s ret: %d\n", __func__, ret);
  7212. goto exit;
  7213. }
  7214. ret = rtw_android_pno_enable(dev, _TRUE);
  7215. if (ret < 0) {
  7216. RTW_INFO("%s ret: %d\n", __func__, ret);
  7217. goto exit;
  7218. }
  7219. exit:
  7220. return ret;
  7221. }
  7222. static int cfg80211_rtw_sched_scan_stop(struct wiphy *wiphy,
  7223. struct net_device *dev)
  7224. {
  7225. return rtw_android_pno_enable(dev, _FALSE);
  7226. }
  7227. int cfg80211_rtw_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wow) {
  7228. RTW_DBG("==> %s\n",__func__);
  7229. RTW_DBG("<== %s\n",__func__);
  7230. return 0;
  7231. }
  7232. int cfg80211_rtw_resume(struct wiphy *wiphy) {
  7233. _adapter *padapter;
  7234. struct pwrctrl_priv *pwrpriv;
  7235. struct mlme_priv *pmlmepriv;
  7236. padapter = wiphy_to_adapter(wiphy);
  7237. pwrpriv = adapter_to_pwrctl(padapter);
  7238. pmlmepriv = &padapter->mlmepriv;
  7239. struct sitesurvey_parm parm;
  7240. int i, len;
  7241. RTW_DBG("==> %s\n",__func__);
  7242. if (pwrpriv->wowlan_last_wake_reason == RX_PNO) {
  7243. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  7244. _irqL irqL;
  7245. int PNOWakeupScanWaitCnt = 0;
  7246. rtw_cfg80211_disconnected(padapter->rtw_wdev, 0, NULL, 0, 1, GFP_ATOMIC);
  7247. rtw_init_sitesurvey_parm(padapter, &parm);
  7248. for (i=0;i<pwrpriv->pnlo_info->ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
  7249. len = pwrpriv->pno_ssid_list->node[i].SSID_len;
  7250. _rtw_memcpy(&parm.ssid[i].Ssid, pwrpriv->pno_ssid_list->node[i].SSID, len);
  7251. parm.ssid[i].SsidLength = len;
  7252. }
  7253. parm.ssid_num = pwrpriv->pnlo_info->ssid_num;
  7254. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  7255. //This modification fix PNO wakeup reconnect issue with hidden SSID AP.
  7256. //rtw_sitesurvey_cmd(padapter, NULL);
  7257. rtw_sitesurvey_cmd(padapter, &parm);
  7258. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  7259. for (PNOWakeupScanWaitCnt = 0; PNOWakeupScanWaitCnt < 10; PNOWakeupScanWaitCnt++) {
  7260. if(check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == _FALSE)
  7261. break;
  7262. rtw_msleep_os(1000);
  7263. }
  7264. _enter_critical_bh(&pmlmepriv->lock, &irqL);
  7265. cfg80211_sched_scan_results(padapter->rtw_wdev->wiphy);
  7266. _exit_critical_bh(&pmlmepriv->lock, &irqL);
  7267. }
  7268. RTW_DBG("<== %s\n",__func__);
  7269. return 0;
  7270. }
  7271. #endif /* CONFIG_PNO_SUPPORT */
  7272. static int rtw_cfg80211_set_beacon_wpsp2pie(struct net_device *ndev, char *buf, int len)
  7273. {
  7274. int ret = 0;
  7275. uint wps_ielen = 0;
  7276. u8 *wps_ie;
  7277. u32 p2p_ielen = 0;
  7278. u8 wps_oui[8] = {0x0, 0x50, 0xf2, 0x04};
  7279. u8 *p2p_ie;
  7280. u32 wfd_ielen = 0;
  7281. u8 *wfd_ie;
  7282. _adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
  7283. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7284. struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
  7285. RTW_INFO(FUNC_NDEV_FMT" ielen=%d\n", FUNC_NDEV_ARG(ndev), len);
  7286. if (len > 0) {
  7287. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  7288. if (wps_ie) {
  7289. #ifdef CONFIG_DEBUG_CFG80211
  7290. RTW_INFO("bcn_wps_ielen=%d\n", wps_ielen);
  7291. #endif
  7292. if (pmlmepriv->wps_beacon_ie) {
  7293. u32 free_len = pmlmepriv->wps_beacon_ie_len;
  7294. pmlmepriv->wps_beacon_ie_len = 0;
  7295. rtw_mfree(pmlmepriv->wps_beacon_ie, free_len);
  7296. pmlmepriv->wps_beacon_ie = NULL;
  7297. }
  7298. pmlmepriv->wps_beacon_ie = rtw_malloc(wps_ielen);
  7299. if (pmlmepriv->wps_beacon_ie == NULL) {
  7300. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7301. return -EINVAL;
  7302. }
  7303. _rtw_memcpy(pmlmepriv->wps_beacon_ie, wps_ie, wps_ielen);
  7304. pmlmepriv->wps_beacon_ie_len = wps_ielen;
  7305. update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE);
  7306. }
  7307. /* buf += wps_ielen; */
  7308. /* len -= wps_ielen; */
  7309. #ifdef CONFIG_P2P
  7310. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  7311. if (p2p_ie) {
  7312. #ifdef CONFIG_DEBUG_CFG80211
  7313. RTW_INFO("bcn_p2p_ielen=%d\n", p2p_ielen);
  7314. #endif
  7315. if (pmlmepriv->p2p_beacon_ie) {
  7316. u32 free_len = pmlmepriv->p2p_beacon_ie_len;
  7317. pmlmepriv->p2p_beacon_ie_len = 0;
  7318. rtw_mfree(pmlmepriv->p2p_beacon_ie, free_len);
  7319. pmlmepriv->p2p_beacon_ie = NULL;
  7320. }
  7321. pmlmepriv->p2p_beacon_ie = rtw_malloc(p2p_ielen);
  7322. if (pmlmepriv->p2p_beacon_ie == NULL) {
  7323. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7324. return -EINVAL;
  7325. }
  7326. _rtw_memcpy(pmlmepriv->p2p_beacon_ie, p2p_ie, p2p_ielen);
  7327. pmlmepriv->p2p_beacon_ie_len = p2p_ielen;
  7328. }
  7329. #endif /* CONFIG_P2P */
  7330. #ifdef CONFIG_WFD
  7331. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  7332. if (wfd_ie) {
  7333. #ifdef CONFIG_DEBUG_CFG80211
  7334. RTW_INFO("bcn_wfd_ielen=%d\n", wfd_ielen);
  7335. #endif
  7336. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_BEACON_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  7337. return -EINVAL;
  7338. }
  7339. #endif /* CONFIG_WFD */
  7340. pmlmeext->bstart_bss = _TRUE;
  7341. }
  7342. return ret;
  7343. }
  7344. static int rtw_cfg80211_set_probe_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  7345. {
  7346. int ret = 0;
  7347. uint wps_ielen = 0;
  7348. u8 *wps_ie;
  7349. u32 p2p_ielen = 0;
  7350. u8 *p2p_ie;
  7351. u32 wfd_ielen = 0;
  7352. u8 *wfd_ie;
  7353. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  7354. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7355. #ifdef CONFIG_DEBUG_CFG80211
  7356. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7357. #endif
  7358. if (len > 0) {
  7359. wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen);
  7360. if (wps_ie) {
  7361. uint attr_contentlen = 0;
  7362. u16 uconfig_method, *puconfig_method = NULL;
  7363. #ifdef CONFIG_DEBUG_CFG80211
  7364. RTW_INFO("probe_resp_wps_ielen=%d\n", wps_ielen);
  7365. #endif
  7366. if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) {
  7367. u8 sr = 0;
  7368. rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
  7369. if (sr != 0)
  7370. RTW_INFO("%s, got sr\n", __func__);
  7371. else {
  7372. RTW_INFO("GO mode process WPS under site-survey, sr no set\n");
  7373. return ret;
  7374. }
  7375. }
  7376. if (pmlmepriv->wps_probe_resp_ie) {
  7377. u32 free_len = pmlmepriv->wps_probe_resp_ie_len;
  7378. pmlmepriv->wps_probe_resp_ie_len = 0;
  7379. rtw_mfree(pmlmepriv->wps_probe_resp_ie, free_len);
  7380. pmlmepriv->wps_probe_resp_ie = NULL;
  7381. }
  7382. pmlmepriv->wps_probe_resp_ie = rtw_malloc(wps_ielen);
  7383. if (pmlmepriv->wps_probe_resp_ie == NULL) {
  7384. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7385. return -EINVAL;
  7386. }
  7387. /* add PUSH_BUTTON config_method by driver self in wpsie of probe_resp at GO Mode */
  7388. puconfig_method = (u16 *)rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_CONF_METHOD , NULL, &attr_contentlen);
  7389. if (puconfig_method != NULL) {
  7390. /* struct registry_priv *pregistrypriv = &padapter->registrypriv; */
  7391. struct wireless_dev *wdev = padapter->rtw_wdev;
  7392. #ifdef CONFIG_DEBUG_CFG80211
  7393. /* printk("config_method in wpsie of probe_resp = 0x%x\n", be16_to_cpu(*puconfig_method)); */
  7394. #endif
  7395. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  7396. /* for WIFI-DIRECT LOGO 4.2.2, AUTO GO can't set PUSH_BUTTON flags */
  7397. if (wdev->iftype == NL80211_IFTYPE_P2P_GO) {
  7398. uconfig_method = WPS_CM_PUSH_BUTTON;
  7399. uconfig_method = cpu_to_be16(uconfig_method);
  7400. *puconfig_method &= ~uconfig_method;
  7401. }
  7402. #endif
  7403. }
  7404. _rtw_memcpy(pmlmepriv->wps_probe_resp_ie, wps_ie, wps_ielen);
  7405. pmlmepriv->wps_probe_resp_ie_len = wps_ielen;
  7406. }
  7407. /* buf += wps_ielen; */
  7408. /* len -= wps_ielen; */
  7409. #ifdef CONFIG_P2P
  7410. p2p_ie = rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen);
  7411. if (p2p_ie) {
  7412. u8 is_GO = _FALSE;
  7413. u32 attr_contentlen = 0;
  7414. u16 cap_attr = 0;
  7415. #ifdef CONFIG_DEBUG_CFG80211
  7416. RTW_INFO("probe_resp_p2p_ielen=%d\n", p2p_ielen);
  7417. #endif
  7418. /* Check P2P Capability ATTR */
  7419. if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_CAPABILITY, (u8 *)&cap_attr, (uint *) &attr_contentlen)) {
  7420. u8 grp_cap = 0;
  7421. /* RTW_INFO( "[%s] Got P2P Capability Attr!!\n", __FUNCTION__ ); */
  7422. cap_attr = le16_to_cpu(cap_attr);
  7423. grp_cap = (u8)((cap_attr >> 8) & 0xff);
  7424. is_GO = (grp_cap & BIT(0)) ? _TRUE : _FALSE;
  7425. if (is_GO)
  7426. RTW_INFO("Got P2P Capability Attr, grp_cap=0x%x, is_GO\n", grp_cap);
  7427. }
  7428. if (is_GO == _FALSE) {
  7429. if (pmlmepriv->p2p_probe_resp_ie) {
  7430. u32 free_len = pmlmepriv->p2p_probe_resp_ie_len;
  7431. pmlmepriv->p2p_probe_resp_ie_len = 0;
  7432. rtw_mfree(pmlmepriv->p2p_probe_resp_ie, free_len);
  7433. pmlmepriv->p2p_probe_resp_ie = NULL;
  7434. }
  7435. pmlmepriv->p2p_probe_resp_ie = rtw_malloc(p2p_ielen);
  7436. if (pmlmepriv->p2p_probe_resp_ie == NULL) {
  7437. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7438. return -EINVAL;
  7439. }
  7440. _rtw_memcpy(pmlmepriv->p2p_probe_resp_ie, p2p_ie, p2p_ielen);
  7441. pmlmepriv->p2p_probe_resp_ie_len = p2p_ielen;
  7442. } else {
  7443. if (pmlmepriv->p2p_go_probe_resp_ie) {
  7444. u32 free_len = pmlmepriv->p2p_go_probe_resp_ie_len;
  7445. pmlmepriv->p2p_go_probe_resp_ie_len = 0;
  7446. rtw_mfree(pmlmepriv->p2p_go_probe_resp_ie, free_len);
  7447. pmlmepriv->p2p_go_probe_resp_ie = NULL;
  7448. }
  7449. pmlmepriv->p2p_go_probe_resp_ie = rtw_malloc(p2p_ielen);
  7450. if (pmlmepriv->p2p_go_probe_resp_ie == NULL) {
  7451. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7452. return -EINVAL;
  7453. }
  7454. _rtw_memcpy(pmlmepriv->p2p_go_probe_resp_ie, p2p_ie, p2p_ielen);
  7455. pmlmepriv->p2p_go_probe_resp_ie_len = p2p_ielen;
  7456. }
  7457. }
  7458. #endif /* CONFIG_P2P */
  7459. #ifdef CONFIG_WFD
  7460. wfd_ie = rtw_get_wfd_ie(buf, len, NULL, &wfd_ielen);
  7461. if (wfd_ie) {
  7462. #ifdef CONFIG_DEBUG_CFG80211
  7463. RTW_INFO("probe_resp_wfd_ielen=%d\n", wfd_ielen);
  7464. #endif
  7465. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_PROBE_RESP_IE, wfd_ie, wfd_ielen) != _SUCCESS)
  7466. return -EINVAL;
  7467. }
  7468. #endif /* CONFIG_WFD */
  7469. }
  7470. return ret;
  7471. }
  7472. static int rtw_cfg80211_set_assoc_resp_wpsp2pie(struct net_device *net, char *buf, int len)
  7473. {
  7474. int ret = 0;
  7475. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  7476. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  7477. u8 *ie;
  7478. u32 ie_len;
  7479. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7480. if (len <= 0)
  7481. goto exit;
  7482. ie = rtw_get_wps_ie(buf, len, NULL, &ie_len);
  7483. if (ie && ie_len) {
  7484. if (pmlmepriv->wps_assoc_resp_ie) {
  7485. u32 free_len = pmlmepriv->wps_assoc_resp_ie_len;
  7486. pmlmepriv->wps_assoc_resp_ie_len = 0;
  7487. rtw_mfree(pmlmepriv->wps_assoc_resp_ie, free_len);
  7488. pmlmepriv->wps_assoc_resp_ie = NULL;
  7489. }
  7490. pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
  7491. if (pmlmepriv->wps_assoc_resp_ie == NULL) {
  7492. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7493. return -EINVAL;
  7494. }
  7495. _rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, ie, ie_len);
  7496. pmlmepriv->wps_assoc_resp_ie_len = ie_len;
  7497. }
  7498. ie = rtw_get_p2p_ie(buf, len, NULL, &ie_len);
  7499. if (ie && ie_len) {
  7500. if (pmlmepriv->p2p_assoc_resp_ie) {
  7501. u32 free_len = pmlmepriv->p2p_assoc_resp_ie_len;
  7502. pmlmepriv->p2p_assoc_resp_ie_len = 0;
  7503. rtw_mfree(pmlmepriv->p2p_assoc_resp_ie, free_len);
  7504. pmlmepriv->p2p_assoc_resp_ie = NULL;
  7505. }
  7506. pmlmepriv->p2p_assoc_resp_ie = rtw_malloc(ie_len);
  7507. if (pmlmepriv->p2p_assoc_resp_ie == NULL) {
  7508. RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
  7509. return -EINVAL;
  7510. }
  7511. _rtw_memcpy(pmlmepriv->p2p_assoc_resp_ie, ie, ie_len);
  7512. pmlmepriv->p2p_assoc_resp_ie_len = ie_len;
  7513. }
  7514. #ifdef CONFIG_WFD
  7515. ie = rtw_get_wfd_ie(buf, len, NULL, &ie_len);
  7516. if (rtw_mlme_update_wfd_ie_data(pmlmepriv, MLME_ASSOC_RESP_IE, ie, ie_len) != _SUCCESS)
  7517. return -EINVAL;
  7518. #endif
  7519. exit:
  7520. return ret;
  7521. }
  7522. int rtw_cfg80211_set_mgnt_wpsp2pie(struct net_device *net, char *buf, int len,
  7523. int type)
  7524. {
  7525. int ret = 0;
  7526. uint wps_ielen = 0;
  7527. u32 p2p_ielen = 0;
  7528. #ifdef CONFIG_DEBUG_CFG80211
  7529. RTW_INFO("%s, ielen=%d\n", __func__, len);
  7530. #endif
  7531. if ((rtw_get_wps_ie(buf, len, NULL, &wps_ielen) && (wps_ielen > 0))
  7532. #ifdef CONFIG_P2P
  7533. || (rtw_get_p2p_ie(buf, len, NULL, &p2p_ielen) && (p2p_ielen > 0))
  7534. #endif
  7535. ) {
  7536. if (net != NULL) {
  7537. switch (type) {
  7538. case 0x1: /* BEACON */
  7539. ret = rtw_cfg80211_set_beacon_wpsp2pie(net, buf, len);
  7540. break;
  7541. case 0x2: /* PROBE_RESP */
  7542. ret = rtw_cfg80211_set_probe_resp_wpsp2pie(net, buf, len);
  7543. #ifdef CONFIG_P2P
  7544. if (ret == 0)
  7545. adapter_wdev_data((_adapter *)rtw_netdev_priv(net))->probe_resp_ie_update_time = rtw_get_current_time();
  7546. #endif
  7547. break;
  7548. case 0x4: /* ASSOC_RESP */
  7549. ret = rtw_cfg80211_set_assoc_resp_wpsp2pie(net, buf, len);
  7550. break;
  7551. }
  7552. }
  7553. }
  7554. return ret;
  7555. }
  7556. #ifdef CONFIG_80211N_HT
  7557. static void rtw_cfg80211_init_ht_capab_ex(_adapter *padapter
  7558. , struct ieee80211_sta_ht_cap *ht_cap, BAND_TYPE band, u8 rf_type)
  7559. {
  7560. struct registry_priv *pregistrypriv = &padapter->registrypriv;
  7561. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  7562. struct ht_priv *phtpriv = &pmlmepriv->htpriv;
  7563. u8 stbc_rx_enable = _FALSE;
  7564. rtw_ht_use_default_setting(padapter);
  7565. /* RX LDPC */
  7566. if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_RX))
  7567. ht_cap->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  7568. /* TX STBC */
  7569. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX))
  7570. ht_cap->cap |= IEEE80211_HT_CAP_TX_STBC;
  7571. /* RX STBC */
  7572. if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_RX)) {
  7573. /*rtw_rx_stbc 0: disable, bit(0):enable 2.4g, bit(1):enable 5g*/
  7574. if (band == BAND_ON_2_4G)
  7575. stbc_rx_enable = (pregistrypriv->rx_stbc & BIT(0)) ? _TRUE : _FALSE;
  7576. if (band == BAND_ON_5G)
  7577. stbc_rx_enable = (pregistrypriv->rx_stbc & BIT(1)) ? _TRUE : _FALSE;
  7578. if (stbc_rx_enable) {
  7579. switch (rf_type) {
  7580. case RF_1T1R:
  7581. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/*RX STBC One spatial stream*/
  7582. break;
  7583. case RF_2T2R:
  7584. case RF_1T2R:
  7585. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/* Only one spatial-stream STBC RX is supported */
  7586. break;
  7587. case RF_3T3R:
  7588. case RF_3T4R:
  7589. case RF_4T4R:
  7590. ht_cap->cap |= IEEE80211_HT_CAP_RX_STBC_1R;/* Only one spatial-stream STBC RX is supported */
  7591. break;
  7592. default:
  7593. RTW_INFO("[warning] rf_type %d is not expected\n", rf_type);
  7594. break;
  7595. }
  7596. }
  7597. }
  7598. }
  7599. static void rtw_cfg80211_init_ht_capab(_adapter *padapter
  7600. , struct ieee80211_sta_ht_cap *ht_cap, BAND_TYPE band, u8 rf_type)
  7601. {
  7602. struct registry_priv *regsty = &padapter->registrypriv;
  7603. struct hal_spec_t *hal_spec = GET_HAL_SPEC(padapter);
  7604. u8 rx_nss = 0;
  7605. if (!regsty->ht_enable || !is_supported_ht(regsty->wireless_mode))
  7606. return;
  7607. ht_cap->ht_supported = 1;
  7608. ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  7609. IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 |
  7610. IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
  7611. rtw_cfg80211_init_ht_capab_ex(padapter, ht_cap, band, rf_type);
  7612. /*
  7613. *Maximum length of AMPDU that the STA can receive.
  7614. *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
  7615. */
  7616. ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  7617. /*Minimum MPDU start spacing , */
  7618. ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  7619. ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  7620. rx_nss = rtw_min(rf_type_to_rf_rx_cnt(rf_type), hal_spec->rx_nss_num);
  7621. switch (rx_nss) {
  7622. case 1:
  7623. ht_cap->mcs.rx_mask[0] = 0xFF;
  7624. break;
  7625. case 2:
  7626. ht_cap->mcs.rx_mask[0] = 0xFF;
  7627. ht_cap->mcs.rx_mask[1] = 0xFF;
  7628. break;
  7629. case 3:
  7630. ht_cap->mcs.rx_mask[0] = 0xFF;
  7631. ht_cap->mcs.rx_mask[1] = 0xFF;
  7632. ht_cap->mcs.rx_mask[2] = 0xFF;
  7633. break;
  7634. case 4:
  7635. ht_cap->mcs.rx_mask[0] = 0xFF;
  7636. ht_cap->mcs.rx_mask[1] = 0xFF;
  7637. ht_cap->mcs.rx_mask[2] = 0xFF;
  7638. ht_cap->mcs.rx_mask[3] = 0xFF;
  7639. break;
  7640. default:
  7641. rtw_warn_on(1);
  7642. RTW_INFO("%s, error rf_type=%d\n", __func__, rf_type);
  7643. };
  7644. ht_cap->mcs.rx_highest = cpu_to_le16(
  7645. rtw_mcs_rate(rf_type
  7646. , hal_is_bw_support(padapter, CHANNEL_WIDTH_40)
  7647. , hal_is_bw_support(padapter, CHANNEL_WIDTH_40) ? ht_cap->cap & IEEE80211_HT_CAP_SGI_40 : ht_cap->cap & IEEE80211_HT_CAP_SGI_20
  7648. , ht_cap->mcs.rx_mask) / 10);
  7649. }
  7650. #endif /* CONFIG_80211N_HT */
  7651. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  7652. static void rtw_cfg80211_init_vht_capab(_adapter *padapter
  7653. , struct ieee80211_sta_vht_cap *sta_vht_cap, BAND_TYPE band, u8 rf_type)
  7654. {
  7655. struct registry_priv *regsty = &padapter->registrypriv;
  7656. u8 vht_cap_ie[2 + 12] = {0};
  7657. if (!REGSTY_IS_11AC_ENABLE(regsty) || !is_supported_vht(regsty->wireless_mode))
  7658. return;
  7659. rtw_vht_use_default_setting(padapter);
  7660. rtw_build_vht_cap_ie(padapter, vht_cap_ie);
  7661. sta_vht_cap->vht_supported = 1;
  7662. _rtw_memcpy(&sta_vht_cap->cap, vht_cap_ie + 2, 4);
  7663. _rtw_memcpy(&sta_vht_cap->vht_mcs, vht_cap_ie + 2 + 4, 8);
  7664. }
  7665. #endif /* defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) */
  7666. void rtw_cfg80211_init_wdev_data(_adapter *padapter)
  7667. {
  7668. #ifdef CONFIG_CONCURRENT_MODE
  7669. struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter);
  7670. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  7671. #endif
  7672. }
  7673. void rtw_cfg80211_init_wiphy(_adapter *padapter)
  7674. {
  7675. u8 rf_type;
  7676. struct ieee80211_supported_band *band;
  7677. struct wireless_dev *pwdev = padapter->rtw_wdev;
  7678. struct wiphy *wiphy = pwdev->wiphy;
  7679. rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
  7680. RTW_INFO("%s:rf_type=%d\n", __func__, rf_type);
  7681. if (IsSupported24G(padapter->registrypriv.wireless_mode)) {
  7682. band = wiphy->bands[NL80211_BAND_2GHZ];
  7683. if (band) {
  7684. #if defined(CONFIG_80211N_HT)
  7685. rtw_cfg80211_init_ht_capab(padapter, &band->ht_cap, BAND_ON_2_4G, rf_type);
  7686. #endif
  7687. }
  7688. }
  7689. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  7690. if (is_supported_5g(padapter->registrypriv.wireless_mode)) {
  7691. band = wiphy->bands[NL80211_BAND_5GHZ];
  7692. if (band) {
  7693. #if defined(CONFIG_80211N_HT)
  7694. rtw_cfg80211_init_ht_capab(padapter, &band->ht_cap, BAND_ON_5G, rf_type);
  7695. #endif
  7696. #if defined(CONFIG_80211AC_VHT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  7697. rtw_cfg80211_init_vht_capab(padapter, &band->vht_cap, BAND_ON_5G, rf_type);
  7698. #endif
  7699. }
  7700. }
  7701. #endif
  7702. /* copy mac_addr to wiphy */
  7703. _rtw_memcpy(wiphy->perm_addr, adapter_mac_addr(padapter), ETH_ALEN);
  7704. }
  7705. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7706. struct ieee80211_iface_limit rtw_limits[] = {
  7707. {
  7708. .max = 2,
  7709. .types = BIT(NL80211_IFTYPE_STATION)
  7710. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7711. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  7712. #endif
  7713. },
  7714. #ifdef CONFIG_AP_MODE
  7715. {
  7716. .max = 1,
  7717. .types = BIT(NL80211_IFTYPE_AP)
  7718. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7719. | BIT(NL80211_IFTYPE_P2P_GO)
  7720. #endif
  7721. },
  7722. #endif
  7723. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7724. {
  7725. .max = 1,
  7726. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  7727. },
  7728. #endif
  7729. #if defined(CONFIG_RTW_MESH)
  7730. {
  7731. .max = 1,
  7732. .types = BIT(NL80211_IFTYPE_MESH_POINT)
  7733. },
  7734. #endif
  7735. };
  7736. struct ieee80211_iface_combination rtw_combinations[] = {
  7737. {
  7738. .limits = rtw_limits,
  7739. .n_limits = ARRAY_SIZE(rtw_limits),
  7740. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7741. .max_interfaces = 3,
  7742. #else
  7743. .max_interfaces = 2,
  7744. #endif
  7745. .num_different_channels = 1,
  7746. },
  7747. };
  7748. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) */
  7749. static void rtw_cfg80211_preinit_wiphy(_adapter *adapter, struct wiphy *wiphy)
  7750. {
  7751. struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
  7752. struct registry_priv *regsty = dvobj_to_regsty(dvobj);
  7753. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  7754. wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT;
  7755. wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX;
  7756. wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS;
  7757. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  7758. wiphy->max_acl_mac_addrs = NUM_ACL;
  7759. #endif
  7760. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
  7761. wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION;
  7762. #endif
  7763. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
  7764. | BIT(NL80211_IFTYPE_ADHOC)
  7765. #ifdef CONFIG_AP_MODE
  7766. | BIT(NL80211_IFTYPE_AP)
  7767. #ifdef CONFIG_WIFI_MONITOR
  7768. | BIT(NL80211_IFTYPE_MONITOR)
  7769. #endif
  7770. #endif
  7771. #if defined(CONFIG_P2P) && ((LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE))
  7772. | BIT(NL80211_IFTYPE_P2P_CLIENT)
  7773. | BIT(NL80211_IFTYPE_P2P_GO)
  7774. #if defined(RTW_DEDICATED_P2P_DEVICE)
  7775. | BIT(NL80211_IFTYPE_P2P_DEVICE)
  7776. #endif
  7777. #endif
  7778. #ifdef CONFIG_RTW_MESH
  7779. | BIT(NL80211_IFTYPE_MESH_POINT) /* 2.6.26 */
  7780. #endif
  7781. ;
  7782. #if defined(CONFIG_ANDROID) && !defined(RTW_SINGLE_WIPHY)
  7783. if (is_primary_adapter(adapter)) {
  7784. wiphy->interface_modes &= ~(BIT(NL80211_IFTYPE_P2P_GO) | BIT(NL80211_IFTYPE_P2P_CLIENT));
  7785. RTW_INFO("%s primary- don't set p2p capability\n", __func__);
  7786. }
  7787. #endif
  7788. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  7789. #ifdef CONFIG_AP_MODE
  7790. wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes;
  7791. #endif /* CONFIG_AP_MODE */
  7792. #endif
  7793. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7794. #ifdef CONFIG_WIFI_MONITOR
  7795. wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  7796. #endif
  7797. #endif
  7798. #if defined(RTW_SINGLE_WIPHY) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7799. wiphy->iface_combinations = rtw_combinations;
  7800. wiphy->n_iface_combinations = ARRAY_SIZE(rtw_combinations);
  7801. #endif
  7802. wiphy->cipher_suites = rtw_cipher_suites;
  7803. wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites);
  7804. if (IsSupported24G(adapter->registrypriv.wireless_mode))
  7805. wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(BAND_ON_2_4G);
  7806. #ifdef CONFIG_IEEE80211_BAND_5GHZ
  7807. if (is_supported_5g(adapter->registrypriv.wireless_mode))
  7808. wiphy->bands[NL80211_BAND_5GHZ] = rtw_spt_band_alloc(BAND_ON_5G);
  7809. #endif
  7810. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) && LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0))
  7811. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS;
  7812. #endif
  7813. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  7814. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  7815. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME;
  7816. /* remove WIPHY_FLAG_OFFCHAN_TX, because we not support this feature */
  7817. /* wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME; */
  7818. #endif
  7819. #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) && \
  7820. LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0))
  7821. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  7822. #ifdef CONFIG_PNO_SUPPORT
  7823. wiphy->max_sched_scan_ssids = MAX_PNO_LIST_COUNT;
  7824. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
  7825. wiphy->max_match_sets = MAX_PNO_LIST_COUNT;
  7826. #endif
  7827. #endif
  7828. #endif
  7829. #if defined(CONFIG_PM) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7830. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0))
  7831. wiphy->wowlan = wowlan_stub;
  7832. #else
  7833. wiphy->wowlan = &wowlan_stub;
  7834. #endif
  7835. #endif
  7836. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  7837. wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  7838. #ifndef CONFIG_TDLS_DRIVER_SETUP
  7839. wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP; /* Driver handles key exchange */
  7840. wiphy->flags |= NL80211_ATTR_HT_CAPABILITY;
  7841. #endif /* CONFIG_TDLS_DRIVER_SETUP */
  7842. #endif /* CONFIG_TDLS */
  7843. if (regsty->power_mgnt != PS_MODE_ACTIVE)
  7844. wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  7845. else
  7846. wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  7847. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  7848. /* wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM; */
  7849. #endif
  7850. #ifdef CONFIG_RTW_MESH
  7851. wiphy->flags |= 0
  7852. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7853. | WIPHY_FLAG_IBSS_RSN
  7854. #endif
  7855. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  7856. | WIPHY_FLAG_MESH_AUTH
  7857. #endif
  7858. ;
  7859. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
  7860. wiphy->features |= 0
  7861. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
  7862. | NL80211_FEATURE_USERSPACE_MPM
  7863. #endif
  7864. ;
  7865. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)) */
  7866. #endif /* CONFIG_RTW_MESH */
  7867. }
  7868. #ifdef CONFIG_RFKILL_POLL
  7869. void rtw_cfg80211_init_rfkill(struct wiphy *wiphy)
  7870. {
  7871. wiphy_rfkill_set_hw_state(wiphy, 0);
  7872. wiphy_rfkill_start_polling(wiphy);
  7873. }
  7874. void rtw_cfg80211_deinit_rfkill(struct wiphy *wiphy)
  7875. {
  7876. wiphy_rfkill_stop_polling(wiphy);
  7877. }
  7878. static void cfg80211_rtw_rfkill_poll(struct wiphy *wiphy)
  7879. {
  7880. _adapter *padapter = NULL;
  7881. bool blocked = _FALSE;
  7882. u8 valid = 0;
  7883. padapter = wiphy_to_adapter(wiphy);
  7884. if (adapter_to_dvobj(padapter)->processing_dev_remove == _TRUE) {
  7885. /*RTW_INFO("cfg80211_rtw_rfkill_poll: device is removed!\n");*/
  7886. return;
  7887. }
  7888. blocked = rtw_hal_rfkill_poll(padapter, &valid);
  7889. /*RTW_INFO("cfg80211_rtw_rfkill_poll: valid=%d, blocked=%d\n",
  7890. valid, blocked);*/
  7891. if (valid)
  7892. wiphy_rfkill_set_hw_state(wiphy, blocked);
  7893. }
  7894. #endif
  7895. #if defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
  7896. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) && (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7897. #define SURVEY_INFO_TIME SURVEY_INFO_CHANNEL_TIME
  7898. #define SURVEY_INFO_TIME_BUSY SURVEY_INFO_CHANNEL_TIME_BUSY
  7899. #define SURVEY_INFO_TIME_EXT_BUSY SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
  7900. #define SURVEY_INFO_TIME_RX SURVEY_INFO_CHANNEL_TIME_RX
  7901. #define SURVEY_INFO_TIME_TX SURVEY_INFO_CHANNEL_TIME_TX
  7902. #endif
  7903. #ifdef CONFIG_FIND_BEST_CHANNEL
  7904. static void rtw_cfg80211_set_survey_info_with_find_best_channel(struct wiphy *wiphy
  7905. , struct net_device *netdev, int idx, struct survey_info *info)
  7906. {
  7907. _adapter *adapter = (_adapter *)rtw_netdev_priv(netdev);
  7908. struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
  7909. RT_CHANNEL_INFO *ch_set = rfctl->channel_set;
  7910. u8 ch_num = rfctl->max_chan_nums;
  7911. u32 total_rx_cnt = 0;
  7912. int i;
  7913. s8 noise = -50; /*channel noise in dBm. This and all following fields are optional */
  7914. u64 time = 100; /*amount of time in ms the radio was turn on (on the channel)*/
  7915. u64 time_busy = 0; /*amount of time the primary channel was sensed busy*/
  7916. info->filled = SURVEY_INFO_NOISE_DBM
  7917. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7918. | SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY
  7919. #endif
  7920. ;
  7921. for (i = 0; i < ch_num; i++)
  7922. total_rx_cnt += ch_set[i].rx_count;
  7923. time_busy = ch_set[idx].rx_count * time / total_rx_cnt;
  7924. noise += ch_set[idx].rx_count * 50 / total_rx_cnt;
  7925. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7926. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7927. info->channel_time = time;
  7928. info->channel_time_busy = time_busy;
  7929. #else
  7930. info->time = time;
  7931. info->time_busy = time_busy;
  7932. #endif
  7933. #endif
  7934. info->noise = noise;
  7935. /* reset if final channel is got */
  7936. if (idx == ch_num - 1) {
  7937. for (i = 0; i < ch_num; i++)
  7938. ch_set[i].rx_count = 0;
  7939. }
  7940. }
  7941. #endif /* CONFIG_FIND_BEST_CHANNEL */
  7942. #if defined(CONFIG_RTW_ACS) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  7943. static void rtw_cfg80211_set_survey_info_with_clm(PADAPTER padapter, int idx, struct survey_info *pinfo)
  7944. {
  7945. s8 noise = -50; /*channel noise in dBm. This and all following fields are optional */
  7946. u64 time = SURVEY_TO; /*amount of time in ms the radio was turn on (on the channel)*/
  7947. u64 time_busy = 0; /*amount of time the primary channel was sensed busy*/
  7948. u8 chan = (u8)idx;
  7949. if ((idx < 0) || (pinfo == NULL))
  7950. return;
  7951. pinfo->filled = SURVEY_INFO_NOISE_DBM
  7952. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7953. | SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY
  7954. #endif
  7955. ;
  7956. time_busy = rtw_acs_get_clm_ratio_by_ch_idx(padapter, chan);
  7957. noise = rtw_noise_query_by_chan_idx(padapter, chan);
  7958. /* RTW_INFO("%s: ch-idx:%d time=%llu(ms), time_busy=%llu(ms), noise=%d(dbm)\n", __func__, idx, time, time_busy, noise); */
  7959. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
  7960. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
  7961. pinfo->channel_time = time;
  7962. pinfo->channel_time_busy = time_busy;
  7963. #else
  7964. pinfo->time = time;
  7965. pinfo->time_busy = time_busy;
  7966. #endif
  7967. #endif
  7968. pinfo->noise = noise;
  7969. }
  7970. #endif
  7971. int rtw_hostapd_acs_dump_survey(struct wiphy *wiphy, struct net_device *netdev, int idx, struct survey_info *info)
  7972. {
  7973. PADAPTER padapter = (_adapter *)rtw_netdev_priv(netdev);
  7974. struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
  7975. RT_CHANNEL_INFO *pch_set = rfctl->channel_set;
  7976. u8 max_chan_nums = rfctl->max_chan_nums;
  7977. u32 freq = 0;
  7978. u8 ret = 0;
  7979. u16 channel = 0;
  7980. if (!netdev || !info) {
  7981. RTW_INFO("%s: invial parameters.\n", __func__);
  7982. return -EINVAL;
  7983. }
  7984. _rtw_memset(info, 0, sizeof(struct survey_info));
  7985. if (padapter->bup == _FALSE) {
  7986. RTW_INFO("%s: net device is down.\n", __func__);
  7987. return -EIO;
  7988. }
  7989. if (idx >= max_chan_nums)
  7990. return -ENOENT;
  7991. channel = pch_set[idx].ChannelNum;
  7992. freq = rtw_ch2freq(channel);
  7993. info->channel = ieee80211_get_channel(wiphy, freq);
  7994. /* RTW_INFO("%s: channel %d, freq %d\n", __func__, channel, freq); */
  7995. if (!info->channel)
  7996. return -EINVAL;
  7997. if (info->channel->flags == IEEE80211_CHAN_DISABLED)
  7998. return ret;
  7999. #ifdef CONFIG_FIND_BEST_CHANNEL
  8000. rtw_cfg80211_set_survey_info_with_find_best_channel(wiphy, netdev, idx, info);
  8001. #elif defined(CONFIG_RTW_ACS) && defined(CONFIG_BACKGROUND_NOISE_MONITOR)
  8002. rtw_cfg80211_set_survey_info_with_clm(padapter, idx, info);
  8003. #else
  8004. RTW_ERR("%s: unknown acs operation!\n", __func__);
  8005. #endif
  8006. return ret;
  8007. }
  8008. #endif /* defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)) */
  8009. static struct cfg80211_ops rtw_cfg80211_ops = {
  8010. .change_virtual_intf = cfg80211_rtw_change_iface,
  8011. .add_key = cfg80211_rtw_add_key,
  8012. .get_key = cfg80211_rtw_get_key,
  8013. .del_key = cfg80211_rtw_del_key,
  8014. .set_default_key = cfg80211_rtw_set_default_key,
  8015. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
  8016. .set_default_mgmt_key = cfg80211_rtw_set_default_mgmt_key,
  8017. #endif
  8018. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
  8019. .set_rekey_data = cfg80211_rtw_set_rekey_data,
  8020. #endif /*CONFIG_GTK_OL*/
  8021. .get_station = cfg80211_rtw_get_station,
  8022. .scan = cfg80211_rtw_scan,
  8023. .set_wiphy_params = cfg80211_rtw_set_wiphy_params,
  8024. .connect = cfg80211_rtw_connect,
  8025. .disconnect = cfg80211_rtw_disconnect,
  8026. .join_ibss = cfg80211_rtw_join_ibss,
  8027. .leave_ibss = cfg80211_rtw_leave_ibss,
  8028. .set_tx_power = cfg80211_rtw_set_txpower,
  8029. .get_tx_power = cfg80211_rtw_get_txpower,
  8030. .set_power_mgmt = cfg80211_rtw_set_power_mgmt,
  8031. .set_pmksa = cfg80211_rtw_set_pmksa,
  8032. .del_pmksa = cfg80211_rtw_del_pmksa,
  8033. .flush_pmksa = cfg80211_rtw_flush_pmksa,
  8034. #ifdef CONFIG_AP_MODE
  8035. .add_virtual_intf = cfg80211_rtw_add_virtual_intf,
  8036. .del_virtual_intf = cfg80211_rtw_del_virtual_intf,
  8037. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
  8038. .add_beacon = cfg80211_rtw_add_beacon,
  8039. .set_beacon = cfg80211_rtw_set_beacon,
  8040. .del_beacon = cfg80211_rtw_del_beacon,
  8041. #else
  8042. .start_ap = cfg80211_rtw_start_ap,
  8043. .change_beacon = cfg80211_rtw_change_beacon,
  8044. .stop_ap = cfg80211_rtw_stop_ap,
  8045. #endif
  8046. #if CONFIG_RTW_MACADDR_ACL && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
  8047. .set_mac_acl = cfg80211_rtw_set_mac_acl,
  8048. #endif
  8049. .add_station = cfg80211_rtw_add_station,
  8050. .del_station = cfg80211_rtw_del_station,
  8051. .change_station = cfg80211_rtw_change_station,
  8052. .dump_station = cfg80211_rtw_dump_station,
  8053. .change_bss = cfg80211_rtw_change_bss,
  8054. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
  8055. .set_txq_params = cfg80211_rtw_set_txq_params,
  8056. #endif
  8057. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
  8058. .set_channel = cfg80211_rtw_set_channel,
  8059. #endif
  8060. /* .auth = cfg80211_rtw_auth, */
  8061. /* .assoc = cfg80211_rtw_assoc, */
  8062. #endif /* CONFIG_AP_MODE */
  8063. #if defined(CONFIG_RTW_MESH) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
  8064. .get_mesh_config = cfg80211_rtw_get_mesh_config,
  8065. .update_mesh_config = cfg80211_rtw_update_mesh_config,
  8066. .join_mesh = cfg80211_rtw_join_mesh,
  8067. .leave_mesh = cfg80211_rtw_leave_mesh,
  8068. .add_mpath = cfg80211_rtw_add_mpath,
  8069. .del_mpath = cfg80211_rtw_del_mpath,
  8070. .change_mpath = cfg80211_rtw_change_mpath,
  8071. .get_mpath = cfg80211_rtw_get_mpath,
  8072. .dump_mpath = cfg80211_rtw_dump_mpath,
  8073. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
  8074. .get_mpp = cfg80211_rtw_get_mpp,
  8075. .dump_mpp = cfg80211_rtw_dump_mpp,
  8076. #endif
  8077. #endif
  8078. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
  8079. .set_monitor_channel = cfg80211_rtw_set_monitor_channel,
  8080. #endif
  8081. #ifdef CONFIG_P2P
  8082. .remain_on_channel = cfg80211_rtw_remain_on_channel,
  8083. .cancel_remain_on_channel = cfg80211_rtw_cancel_remain_on_channel,
  8084. #if defined(RTW_DEDICATED_P2P_DEVICE)
  8085. .start_p2p_device = cfg80211_rtw_start_p2p_device,
  8086. .stop_p2p_device = cfg80211_rtw_stop_p2p_device,
  8087. #endif
  8088. #endif /* CONFIG_P2P */
  8089. #ifdef CONFIG_RTW_80211R
  8090. .update_ft_ies = cfg80211_rtw_update_ft_ies,
  8091. #endif
  8092. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
  8093. .mgmt_tx = cfg80211_rtw_mgmt_tx,
  8094. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0))
  8095. .update_mgmt_frame_registrations = cfg80211_rtw_mgmt_frame_register,
  8096. #else
  8097. .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register,
  8098. #endif
  8099. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
  8100. .action = cfg80211_rtw_mgmt_tx,
  8101. #endif
  8102. #if defined(CONFIG_TDLS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
  8103. .tdls_mgmt = cfg80211_rtw_tdls_mgmt,
  8104. .tdls_oper = cfg80211_rtw_tdls_oper,
  8105. #endif /* CONFIG_TDLS */
  8106. #if defined(CONFIG_PNO_SUPPORT) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  8107. .sched_scan_start = cfg80211_rtw_sched_scan_start,
  8108. .sched_scan_stop = cfg80211_rtw_sched_scan_stop,
  8109. .suspend = cfg80211_rtw_suspend,
  8110. .resume = cfg80211_rtw_resume,
  8111. #endif /* CONFIG_PNO_SUPPORT */
  8112. #ifdef CONFIG_RFKILL_POLL
  8113. .rfkill_poll = cfg80211_rtw_rfkill_poll,
  8114. #endif
  8115. #if defined(CONFIG_RTW_HOSTAPD_ACS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
  8116. .dump_survey = rtw_hostapd_acs_dump_survey,
  8117. #endif
  8118. };
  8119. struct wiphy *rtw_wiphy_alloc(_adapter *padapter, struct device *dev)
  8120. {
  8121. struct wiphy *wiphy;
  8122. struct rtw_wiphy_data *wiphy_data;
  8123. /* wiphy */
  8124. wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct rtw_wiphy_data));
  8125. if (!wiphy) {
  8126. RTW_INFO("Couldn't allocate wiphy device\n");
  8127. goto exit;
  8128. }
  8129. set_wiphy_dev(wiphy, dev);
  8130. /* wiphy_data */
  8131. wiphy_data = rtw_wiphy_priv(wiphy);
  8132. wiphy_data->dvobj = adapter_to_dvobj(padapter);
  8133. #ifndef RTW_SINGLE_WIPHY
  8134. wiphy_data->adapter = padapter;
  8135. #endif
  8136. rtw_cfg80211_preinit_wiphy(padapter, wiphy);
  8137. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8138. exit:
  8139. return wiphy;
  8140. }
  8141. void rtw_wiphy_free(struct wiphy *wiphy)
  8142. {
  8143. if (!wiphy)
  8144. return;
  8145. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8146. if (wiphy->bands[NL80211_BAND_2GHZ]) {
  8147. rtw_spt_band_free(wiphy->bands[NL80211_BAND_2GHZ]);
  8148. wiphy->bands[NL80211_BAND_2GHZ] = NULL;
  8149. }
  8150. if (wiphy->bands[NL80211_BAND_5GHZ]) {
  8151. rtw_spt_band_free(wiphy->bands[NL80211_BAND_5GHZ]);
  8152. wiphy->bands[NL80211_BAND_5GHZ] = NULL;
  8153. }
  8154. wiphy_free(wiphy);
  8155. }
  8156. int rtw_wiphy_register(struct wiphy *wiphy)
  8157. {
  8158. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8159. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
  8160. rtw_cfgvendor_attach(wiphy);
  8161. #endif
  8162. rtw_regd_init(wiphy);
  8163. return wiphy_register(wiphy);
  8164. }
  8165. void rtw_wiphy_unregister(struct wiphy *wiphy)
  8166. {
  8167. RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
  8168. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
  8169. rtw_cfgvendor_detach(wiphy);
  8170. #endif
  8171. #if defined(RTW_DEDICATED_P2P_DEVICE)
  8172. rtw_pd_iface_free(wiphy);
  8173. #endif
  8174. return wiphy_unregister(wiphy);
  8175. }
  8176. int rtw_wdev_alloc(_adapter *padapter, struct wiphy *wiphy)
  8177. {
  8178. int ret = 0;
  8179. struct net_device *pnetdev = padapter->pnetdev;
  8180. struct wireless_dev *wdev;
  8181. struct rtw_wdev_priv *pwdev_priv;
  8182. RTW_INFO("%s(padapter=%p)\n", __func__, padapter);
  8183. /* wdev */
  8184. wdev = (struct wireless_dev *)rtw_zmalloc(sizeof(struct wireless_dev));
  8185. if (!wdev) {
  8186. RTW_INFO("Couldn't allocate wireless device\n");
  8187. ret = -ENOMEM;
  8188. goto exit;
  8189. }
  8190. wdev->wiphy = wiphy;
  8191. wdev->netdev = pnetdev;
  8192. wdev->iftype = NL80211_IFTYPE_STATION;
  8193. padapter->rtw_wdev = wdev;
  8194. pnetdev->ieee80211_ptr = wdev;
  8195. /* init pwdev_priv */
  8196. pwdev_priv = adapter_wdev_data(padapter);
  8197. pwdev_priv->rtw_wdev = wdev;
  8198. pwdev_priv->pmon_ndev = NULL;
  8199. pwdev_priv->ifname_mon[0] = '\0';
  8200. pwdev_priv->padapter = padapter;
  8201. pwdev_priv->scan_request = NULL;
  8202. _rtw_spinlock_init(&pwdev_priv->scan_req_lock);
  8203. pwdev_priv->connect_req = NULL;
  8204. _rtw_spinlock_init(&pwdev_priv->connect_req_lock);
  8205. pwdev_priv->p2p_enabled = _FALSE;
  8206. pwdev_priv->probe_resp_ie_update_time = rtw_get_current_time();
  8207. pwdev_priv->provdisc_req_issued = _FALSE;
  8208. rtw_wdev_invit_info_init(&pwdev_priv->invit_info);
  8209. rtw_wdev_nego_info_init(&pwdev_priv->nego_info);
  8210. pwdev_priv->bandroid_scan = _FALSE;
  8211. if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE)
  8212. pwdev_priv->power_mgmt = _TRUE;
  8213. else
  8214. pwdev_priv->power_mgmt = _FALSE;
  8215. _rtw_mutex_init(&pwdev_priv->roch_mutex);
  8216. #ifdef CONFIG_CONCURRENT_MODE
  8217. ATOMIC_SET(&pwdev_priv->switch_ch_to, 1);
  8218. #endif
  8219. #ifdef CONFIG_RTW_CFGVEDNOR_RSSIMONITOR
  8220. pwdev_priv->rssi_monitor_enable = 0;
  8221. pwdev_priv->rssi_monitor_max = 0;
  8222. pwdev_priv->rssi_monitor_min = 0;
  8223. #endif
  8224. exit:
  8225. return ret;
  8226. }
  8227. void rtw_wdev_free(struct wireless_dev *wdev)
  8228. {
  8229. if (!wdev)
  8230. return;
  8231. RTW_INFO("%s(wdev=%p)\n", __func__, wdev);
  8232. if (wdev_to_ndev(wdev)) {
  8233. _adapter *adapter = (_adapter *)rtw_netdev_priv(wdev_to_ndev(wdev));
  8234. struct rtw_wdev_priv *wdev_priv = adapter_wdev_data(adapter);
  8235. _irqL irqL;
  8236. _rtw_spinlock_free(&wdev_priv->scan_req_lock);
  8237. _enter_critical_bh(&wdev_priv->connect_req_lock, &irqL);
  8238. rtw_wdev_free_connect_req(wdev_priv);
  8239. _exit_critical_bh(&wdev_priv->connect_req_lock, &irqL);
  8240. _rtw_spinlock_free(&wdev_priv->connect_req_lock);
  8241. _rtw_mutex_free(&wdev_priv->roch_mutex);
  8242. }
  8243. rtw_mfree((u8 *)wdev, sizeof(struct wireless_dev));
  8244. }
  8245. void rtw_wdev_unregister(struct wireless_dev *wdev)
  8246. {
  8247. struct net_device *ndev;
  8248. _adapter *adapter;
  8249. struct rtw_wdev_priv *pwdev_priv;
  8250. if (!wdev)
  8251. return;
  8252. RTW_INFO("%s(wdev=%p)\n", __func__, wdev);
  8253. ndev = wdev_to_ndev(wdev);
  8254. if (!ndev)
  8255. return;
  8256. adapter = (_adapter *)rtw_netdev_priv(ndev);
  8257. pwdev_priv = adapter_wdev_data(adapter);
  8258. rtw_cfg80211_indicate_scan_done(adapter, _TRUE);
  8259. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) || defined(COMPAT_KERNEL_RELEASE)
  8260. #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 2)
  8261. if (wdev->current_bss) {
  8262. #else
  8263. if (wdev->connected) {
  8264. #endif
  8265. RTW_INFO(FUNC_ADPT_FMT" clear current_bss by cfg80211_disconnected\n", FUNC_ADPT_ARG(adapter));
  8266. rtw_cfg80211_indicate_disconnect(adapter, 0, 1);
  8267. }
  8268. #endif
  8269. if (pwdev_priv->pmon_ndev) {
  8270. RTW_INFO("%s, unregister monitor interface\n", __func__);
  8271. unregister_netdev(pwdev_priv->pmon_ndev);
  8272. }
  8273. }
  8274. int rtw_cfg80211_ndev_res_alloc(_adapter *adapter)
  8275. {
  8276. int ret = _FAIL;
  8277. #if !defined(RTW_SINGLE_WIPHY)
  8278. struct wiphy *wiphy;
  8279. struct device *dev = dvobj_to_dev(adapter_to_dvobj(adapter));
  8280. wiphy = rtw_wiphy_alloc(adapter, dev);
  8281. if (wiphy == NULL)
  8282. goto exit;
  8283. adapter->wiphy = wiphy;
  8284. #endif
  8285. if (rtw_wdev_alloc(adapter, adapter_to_wiphy(adapter)) == 0)
  8286. ret = _SUCCESS;
  8287. #if !defined(RTW_SINGLE_WIPHY)
  8288. if (ret != _SUCCESS) {
  8289. rtw_wiphy_free(wiphy);
  8290. adapter->wiphy = NULL;
  8291. }
  8292. #endif
  8293. exit:
  8294. return ret;
  8295. }
  8296. void rtw_cfg80211_ndev_res_free(_adapter *adapter)
  8297. {
  8298. rtw_wdev_free(adapter->rtw_wdev);
  8299. adapter->rtw_wdev = NULL;
  8300. #if !defined(RTW_SINGLE_WIPHY)
  8301. rtw_wiphy_free(adapter_to_wiphy(adapter));
  8302. adapter->wiphy = NULL;
  8303. #endif
  8304. }
  8305. int rtw_cfg80211_ndev_res_register(_adapter *adapter)
  8306. {
  8307. int ret = _FAIL;
  8308. #if !defined(RTW_SINGLE_WIPHY)
  8309. if (rtw_wiphy_register(adapter_to_wiphy(adapter)) < 0) {
  8310. RTW_INFO("%s rtw_wiphy_register fail for if%d\n", __func__, (adapter->iface_id + 1));
  8311. goto exit;
  8312. }
  8313. #ifdef CONFIG_RFKILL_POLL
  8314. rtw_cfg80211_init_rfkill(adapter_to_wiphy(adapter));
  8315. #endif
  8316. #endif
  8317. ret = _SUCCESS;
  8318. exit:
  8319. return ret;
  8320. }
  8321. void rtw_cfg80211_ndev_res_unregister(_adapter *adapter)
  8322. {
  8323. rtw_wdev_unregister(adapter->rtw_wdev);
  8324. }
  8325. int rtw_cfg80211_dev_res_alloc(struct dvobj_priv *dvobj)
  8326. {
  8327. int ret = _FAIL;
  8328. #if defined(RTW_SINGLE_WIPHY)
  8329. struct wiphy *wiphy;
  8330. struct device *dev = dvobj_to_dev(dvobj);
  8331. wiphy = rtw_wiphy_alloc(dvobj_get_primary_adapter(dvobj), dev);
  8332. if (wiphy == NULL)
  8333. goto exit;
  8334. dvobj->wiphy = wiphy;
  8335. #endif
  8336. ret = _SUCCESS;
  8337. exit:
  8338. return ret;
  8339. }
  8340. void rtw_cfg80211_dev_res_free(struct dvobj_priv *dvobj)
  8341. {
  8342. #if defined(RTW_SINGLE_WIPHY)
  8343. rtw_wiphy_free(dvobj_to_wiphy(dvobj));
  8344. dvobj->wiphy = NULL;
  8345. #endif
  8346. }
  8347. int rtw_cfg80211_dev_res_register(struct dvobj_priv *dvobj)
  8348. {
  8349. int ret = _FAIL;
  8350. #if defined(RTW_SINGLE_WIPHY)
  8351. if (rtw_wiphy_register(dvobj_to_wiphy(dvobj)) != 0)
  8352. goto exit;
  8353. #ifdef CONFIG_RFKILL_POLL
  8354. rtw_cfg80211_init_rfkill(dvobj_to_wiphy(dvobj));
  8355. #endif
  8356. #endif
  8357. ret = _SUCCESS;
  8358. exit:
  8359. return ret;
  8360. }
  8361. void rtw_cfg80211_dev_res_unregister(struct dvobj_priv *dvobj)
  8362. {
  8363. #if defined(RTW_SINGLE_WIPHY)
  8364. #ifdef CONFIG_RFKILL_POLL
  8365. rtw_cfg80211_deinit_rfkill(dvobj_to_wiphy(dvobj));
  8366. #endif
  8367. rtw_wiphy_unregister(dvobj_to_wiphy(dvobj));
  8368. #endif
  8369. }
  8370. #endif /* CONFIG_IOCTL_CFG80211 */