ioctl_cfg80211.c 289 KB

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