ioctl_cfg80211.c 290 KB

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