ioctl_cfg80211.c 290 KB

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