ioctl_cfg80211.c 288 KB

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